The arrow of time

Ivan Voras' blog

Trying AHCI in 8.0

One of the neat new things in 8 is the native AHCI driver which replaces the old one (which was a part of the "normal" ATA driver set and had not allowed the use of AHCI's full potential). It's remarkably easy to try it in a recent 8.0-RC system.

I have set up VirtualBox which has SATA AHCI as an option for emulated disk drives. My machine was created some tiem ago and was configured to use normal ATA drives, so some adaptation was neccessary. The new (and must be said - still exeperimental - because among other things this particular aspect might change in the future) driver uses different device names than the ATA driver did.

Instead of "ad" drives, the new AHCI drives are "ada", which is a combination of "ad" and "da". The new AHCI driver is integrated into the "Common Access Method" (CAM) system which among other things, runs SCSI and USB drives (which show as "da" drives, from "direct access"). Future development might go either way, though to avoid confusion the new name will probably not be "ad" because of a whole new feature set that isn't supported by the old familiar "ad" drives.

This means fstab needs to be tweaked. Since the naming could change in the future, it would be nice to have a naming scheme that didn't depend on exact drive names. Luckily, that's what glabel is for. And here is the first obstacle: during the development and in at least one FreeBSD release, glabel was configured to dump labels it found on the console, but many people were unhappy with this verbosity so now it doesn't. However, when drives are mounted for write/exclusive access, the labels disappear (since they cannot be used any longer), so now there is no way to find out my root file system's label by default. To get around this, the following line needs to be entered in /boot/loader.conf:

kern.geom.label.debug=1

This will cause glabel to display found label and other information on the next boot, which can be used to find all relevant labels. I use UFS ID labels for file systems. Another thing is the swap partition - since there is no intrinsic mechanism to label those, they need to be labeled externally:

glabel label swap /dev/ad0s1b

Now /etc/fstab can look something like this:

/dev/label/swap			none	swap	sw		0	0
/dev/ufsid/4a44ccdcd893e4f5 / ufs rw 1 1
/dev/acd0 /cdrom cd9660 ro,noauto 0 0

This provides device independant access to used partitions. Next step is enabling the AHCI driver. This is simply done by adding a line to loader.conf:

ahci_load="YES"

After reconfiguring VirtualBox to use the AHCI emulation for the old drive, the machine boots, finds the AHCI controller and the drive, and uses the labels to mount file systems and swap (note that in this configuration the boot and root drive is the AHCI drive! BIOS support is of course needed). To return to the old driver, the ahci_load line can be commented out or removed from loader.conf and the system rebooted - the labels will point to the drives as seen by the old driver.

So far, the new driver seems stable. It supports many new features such as NCQ and increased data transfer size. Users are reporting decent performance improvements. Users wishing to crank up sequential read performance might want to increase UFS readahead with the vfs.read_max sysctl (on the command line or in /etc/sysctl.conf, read at boot):

vfs.read_max=32

I've found that UFS readahead works very nicely with NCQ. The value of 32 translates to 512 KiB (with the default block size of 16 KiB).

To verify NCQ is enabled, use the camcontrol(8) utility:

# camcontrol tags ada0
(pass0:ahcich0:0:0:0): device openings: 32

The "device openings" is the number of tags supported by the device. Users familiar with SCSI drives will be used to using "camcontrol" for many things, and new users will find it helpful with commands like:

# camcontrol identify ada0
pass0: <VBOX HARDDISK 1.0> ATA/ATAPI-6 SATA 2.x device

protocol ATA/ATAPI-6 SATA 2.x
device model VBOX HARDDISK
serial number VB06fb759e-d8399071
firmware revision 1.0
cylinders 16383
heads 16
sectors/track 63
LBA supported 62914560 sectors
LBA48 supported 62914560 sectors
PIO supported PIO4
DMA supported WDMA2 UDMA6
overlap not supported

Feature Support Enable Value Vendor
write cache yes yes
read ahead yes yes
Native Command Queuing (NCQ) yes 31/0x1F
Tagged Command Queuing (TCQ) no no 31/0x1F
SMART no no
microcode download no no
security no no
power management yes yes
advanced power management no no 0/0x00
automatic acoustic management no no 0/0x00 0/0x00

This is how AHCI appears in dmesg:

ahci0: <AHCI controller> port 0xd240-0xd247,0xd250-0xd257,0xd260-0xd26f mem 0xf0804000-0xf0805fff irq 21 at device 13.0 on pci0
ahci0: [ITHREAD]
ahci0: AHCI v1.10 with 1 3Gbps ports, Port Multiplier not supported
ahcich0: <AHCI channel> at channel 0 on ahci0
ahcich0: [ITHREAD]
ada0 at ahcich0 bus 0 target 0 lun 0
ada0: <VBOX HARDDISK 1.0> ATA/ATAPI-6 SATA 2.x device
ada0: 300.000MB/s transfers
ada0: 30720MB (62914560 512 byte sectors: 16H 63S/T 16383C)
ada0: Native Command Queueing enabled

Officially, AHCI is still in development, so users noticing problems should first try and see if they are fixed in CURRENT code. All questions, problem problems etc should probably go the current@ or hardware@ mailing lists. It is developed by Alexander Motin.

#1 Re: Trying AHCI in 8.0

Added on 2009-11-18T01:53 by FAndrey

Alexander does a great job:)
summer, he read a paper on this topic at the conference KyivBSD, unfortunately there is Russian, but there are graphs
http://technet.v-time.com.ua/pub/KyivBSD09/a.motin%20-%20ata-cam.pdf

#2 Re: Trying AHCI in 8.0

Added on 2009-11-21T21:16 by Mr*Gibson

8.0 i shaping up pretty nicely.

Having new AHCI driver integrated into CAM promises to be a great step forward.

#3 Re: Trying AHCI in 8.0

Added on 2009-12-06T02:47 by Aragon

Speed, power management, and hotplug support - I'm loving the new AHCI.

 

#4 Re: Trying AHCI in 8.0

Added on 2010-02-12T09:35 by copypaiste

Go-go beastie! \^o^/ 8 branch with it's features, is surely coming out pretty cool.

Post your comment here!

Your name:
Comment title:
Text:
Type "xxx" here:

Comments are subject to moderation and will be deleted if deemed inappropriate. All content is © Ivan Voras. Comments are owned by their authors... who agree to basically surrender all rights by publishing them here :)