<?xml version="1.0" encoding="utf-8"?>
<!-- name="generator" content="pyblosxom/1.4.3 01/10/2008" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
<channel>
<title>The Geekess   </title>
<link>http://sarah.thesharps.us</link>
<description>Linux, bicycling, open source, gardening, amateur rockets, and other seemingly unrelated hobbies.</description>
<language>en</language>
<item>
  <title>USB 3.0 and Linux</title>
  <link>http://sarah.thesharps.us/2008-12-07-13-35.html</link>
  <description><![CDATA[
<p>USB is getting a facelift!</p>

<p>In the beginning, there was USB 1.1, with the "low speed" and "full speed"
devices (at 1 Mbps and 12 Mbps, respectively).  Then USB 2.0 came along with
"high speed" devices that ran at 480 Mbps.  Now the new USB 3.0 bus
specification defines "SuperSpeed" devices that run at 5 Gbps (5,120 Mbps).</p>

<p><center>
<img src="http://lh5.ggpht.com/_KnE2M8e3X8Q/STQ4kNz0RFI/AAAAAAAABJ0/z7CV74jd6V0/s400/ss-logo.jpg" alt="SuperSpeed Logo - image copyright 2008 Sarah
Sharp" title="" />
</center></p>

<p>Now that the bus specification is public, I can finally talk about the code I've
been developing at work.  I've been writing a Linux driver for xHCI (the new USB
3.0 host controller), and changing the Linux kernel stack to support USB 3.0
devices.  On November 17th, I got to demo my work at the world's first USB 3.0
<a href="http://www.usb.org/developers/presentations/">"SuperSpeed" Developers Conference</a>.</p>

<p><center>
<embed id="VideoPlayback"
src="http://video.google.com/googleplayer.swf?docid=-6015621370324169356&amp;hl=en&amp;fs=true"
style="width:400px;height:326px" allowFullScreen="true"
allowScriptAccess="always" type="application/x-shockwave-flash"></embed>
</center></p>

<p>This is a demo showing a USB 3.0 Mass Storage Device (commonly called a USB
drive, thumb drive, or flash drive) prototype running under Linux with an
unmodified Mass Storage Device driver.  My Linux xHCI driver is necessary to
communicate with the USB 3.0 device through the xHCI host controller prototype.
The FPGA prototype was provided by Fresco Logic, a company that sells host
controller and device IP.</p>

<p>The demo showed speeds that were about 3.5 times faster than USB 2.0 high speed
devices.  I expect this demo to be even faster when the device and host
controller are implemented in silicon.</p>

<h2>Details about USB 3.0</h2>

<p>USB 3.0 is 10 times faster than USB 2.0.  Roughly speaking, it means that a file
that takes 30 minutes to transfer over USB 2.0 could take 3 minutes to transfer
under USB 3.0.</p>

<p>USB 3.0 also provides better power management, which translates to longer laptop
battery life.  USB 3.0 is backwards compatible.  That means you can plug all
your USB 2.0 devices into a USB 3.0 port, or plug your USB 3.0 device into a USB
2.0 port.  The USB 3.0 device will work at USB 2.0 speeds in the latter case,
but that means consumers don't have to upgrade their PC or laptop to use USB 3.0
devices at the slower speed.</p>

<p></p>

<h2>FAQ</h2>

<p><b>Q: When will there be USB 3.0 host controllers and devices?</b></p>

<p>A: Jeff Ravencraft, USB-IF President and Chairman, estimates that USB 3.0
devices will be shipped as early as mid-2009.  See <a
href="http://www.usb.org/developers/presentations/SuperSpeed_USB_DevCon_Keynote_RavencraftRajagopalan.pdf">his
SuperSpeed DevCon keynote slides</a>, page 14.</p>

<p><img
src="http://lh5.ggpht.com/_KnE2M8e3X8Q/STx0t6a5MQI/AAAAAAAABMM/_SR1jaxt-O8/s800/usb-3-timeline-ravencraft.png"
/></p>

<p><b>Q: When will Windows have USB 3.0 support?</b></p>

<p><center>
<img
src="http://blogs.msdn.com/blogfiles/tims/WindowsLiveWriter/Windows7TechnicalEvangelistAreYOUThePers_9896/StartBTN-Vista_rgb_3.png">
</center></p>

<p>A: In the SuperSpeed Developers Conference keynote, Sriram Rajagopalan of
Microsoft announced that they needed to rearchitect the USB stack, and they
would have USB 3.0 support in "Windows 7+".  Windows 7 is Microsoft's operating
system version after Vista.</p>

<p>From a later Windows USB 3.0 session, Lars Giusti's slides say, "Early input
from some partners indicates they would like us to consider supporting it on
Windows Vista and newer Windows OS."  Of course, that is only a statement of a
request for support, not an official statement of support for USB 3.0 under
Windows Vista.  Nothing has been said of Windows XP.</p>

<p>Basically, Windows users have been promised official USB 3.0 support for Windows
7, not Vista or XP or older OSes. Some other USB vendors might ship unofficial
Windows drivers for other Windows OSes, but that is the official word from
Redmond as of now.</p>

<p><b>Q: When will Linux have USB 3.0 support?</b></p>

<p><center>
<img
src="http://lh5.ggpht.com/_KnE2M8e3X8Q/SUE83tHhEVI/AAAAAAAABNY/OoDDmasfdAg/s400/Tux.png"
alt="Tux, the Linux mascot"/>
</center></p>

<p>For Linux to have basic USB 3.0 support, two things need to be added.  First, we
need to add support to the Linux USB stack to handle the new device speed and
other changes mandated by the USB 3.0 bus specification.  Second, we need to
have a driver for the xHCI host controller.  A host controller is the hardware
that sits behind your USB port and talks to the USB devices you plug in.</p>

<p>Now that the bus specification is public, I can start pushing the patches for
the USB core changes.  They will need to be reviewed and possibly changed before
they make it into the mainline kernel.  Once the changes make it into the
mainline kernel, they'll be picked up by Linux Operating System Vendors like
RedHat, Novell, and Ubuntu.</p>

<p>The xHCI host controller driver is a little trickier.  The xHCI specification is
not public yet.  It's currently <a
href="http://www.intel.com/technology/usb/xhcispec.htm">available under NDA with
Intel as a 0.9 draft specification</a>.  Since it's not a public specification,
I'm forbidden to ship code that would reveal what's in the specification.  That
means the xHCI driver can't be sent out for review by the whole Linux community
until the xHCI specification is public.  The driver is much bigger than the USB
core code changes, so I know it will go through several review iterations before
it gets accepted into the mainline kernel.</p>

<p>The beauty of this open source process is that you can watch the development by
following the <a href="http://www.linux-usb.org/mailing.html">Linux USB mailing
list</a>.  I'll also update my blog with any announcements about Linux USB 3.0.</p>

<p><b>Q: Ok, so what does "basic" Linux USB 3.0 support mean?</b></p>

<p>A: Basic support means that some features might be lacking.  We might not have
awesome power management right off the bat, or we might be missing USB 3.0
support from some class drivers, or, heck, some versions of my xHCI driver might
crash your system.  My driver will be marked EXPERIMENTAL for a reason. ;)</p>

<p>The Linux philosophy is to ship early, and ship often.  When code is shipped,
more eyes can look at it and improve the code.  Shipping partially functional
code is better than waiting until the code is "perfect" and having the community
report some fatal flaw or, worse, not understand why you're trying to get
changes in.</p>

<p><b>Q: Will there be a Linux compliance program?</b></p>

<p>A: The USB-IF has run, and always will run, the official USB compliance program.
Devices and host controllers that pass the compliance suite are allowed to use
the official USB logos on their products.  There are no plans for a separate
Linux compliance program.</p>

<p>However, I'm willing to test new devices and host controllers on an unofficial
basis to make sure they work properly under Linux.  You can contact me at my
Intel work address at Sarah.A.Sharp at linux.intel.com.</p>

<h2>About the SuperSpeed DevCon Windows Demo</h2>

<p><center>
<img src="http://lh4.ggpht.com/_KnE2M8e3X8Q/STQ4U6I8B2I/AAAAAAAABJM/JrftQzMbVX4/s800/keynote-demo-3040722677_d6b57f3614.jpg" alt="Fresco Logic in the keynote - image copyright 2008 Dian
Kurniawan" title="" />
</center></p>

<p>I can't really talk about my Linux demo without talking about the Windows Demo
that was in the SuperSpeed Developers Conference keynote.  The demo was created
by the Intel team that works closely with the USB-IF.  It was the same demo they
used for IDF Taipei in August 2008.  The demo used the same Fresco Logic USB 3.0
prototypes and nearly the same PC system that I used.</p>

<p>Their goal was to show the maximum speed possible from the host controller and
USB 3.0 device.  To do that, they ran a simple compliance test suite that
allocated a giant DMA buffer and sent data as fast as possible to the USB 3.0
device.  The device was programmed to use the USB 3.0 protocol, but it was
basically a loop back device.  Their demo showed speeds of 318 MBps.</p>

<p><center>
<img src="http://lh5.ggpht.com/_KnE2M8e3X8Q/STQ4VhG6YxI/AAAAAAAABJU/i5qDCBn29hY/s800/keynote-demo-screenshot-3041564730_cb3facda72.jpg" alt="Fresco Logic windows keynote screenshot - image copyright 2008 Dian
Kurniawan" title="" />
</center></p>

<p>The "wire speed" of USB 3.0 is 5Gbps.  The 8b10b encoding and upper-level
protocol overhead make USB 3.0 applications see less than that.  The projected
max application bandwidth for USB 3.0 devices is in the 400MBps range.  In
comparison, the wire speed of USB 2.0 is 60MBps, and applications see around
35MBps.</p>

<h2>About the SuperSpeed DevCon Linux Demo</h2>

<p><center>
<img src="http://lh4.ggpht.com/_KnE2M8e3X8Q/STQ4UgLZ-FI/AAAAAAAABJE/BbIvgWWFpsE/s800/fresco-logic-booth-3043423207_e8f27919e3.jpg" alt="Linux and Windows USB 3.0 demos side by side - image copyright Dian
Kurniawan" title="" />
</center></p>

<p>Fresco Logic, a company selling USB 3.0 host controller and device IP, provided
hardware prototypes for an xHCI host controller and a USB 3.0 Mass Storage
Device.  For the demo, the host controller and the device was implemented on the
same FPGA.  I didn't have time to get a two-card solution working.</p>

<p><center>
<img src="http://lh4.ggpht.com/_KnE2M8e3X8Q/STQ4V14oEQI/AAAAAAAABJc/IoB4rSjsB6Q/s800/linux-demo-3044263054_b776f6c81d.jpg" alt="Linux USB 3.0 demo - image copyright 2008 Sarah
Sharp" title="" />
</center></p>

<p>The Linux demo copied Arjan's 5-second boot video to the MSD, and played it
using mplayer.  The demo then read the 64KB mass storage device using dd with
various block sizes, and displayed the host controller bandwidth measurements on
a traffic graph.  Visitors could see traffic spikes as the dd commands started
and completed.  They could also see the bandwidth increase as the block size
increased to 16KB.  In trial runs, block sizes larger than 16KB did not increase
performance.</p>

<p>The script forced the system to drop all caches between runs (with
<code>echo 3 &gt; /proc/sys/vm/drop_caches</code>).  This made sure that the video would
actually be fetched from the device, instead of being cached.  The dd command
also used the direct I/O flag to ensure parts of the disk would not be cached.</p>

<p>The timing measurements were taken with ktime_get(), which uses high res timers.
The goal was to measure the best possible bandwidth the operating system would
see.  This is the same measurement that the Windows demo used.  The Windows
compliance driver allocated one giant DMA buffer.  The Linux stack set up
DMA scatter-gather lists dynamically, as real applications requested data.</p>

<p>The measurements were fairly simple.  When an URB was enqueued, the host
controller driver would take a timestamp with ktime_get() just before the URB's
buffer was passed off to the hardware.  When the host controller interrupted the
system to indicate buffer completion, the host controller driver would take
another timestamp.  The delta time and the number of bytes transferred was then
passed off to a generic HCD statistics reporting module that would return the
delta time and bytes pairs to userspace.  I got this reporting working two days
before the demo.</p>

<p><center>
<img src="http://lh4.ggpht.com/_KnE2M8e3X8Q/STQ4kbl656I/AAAAAAAABJ8/vjIUAK6kYRw/s800/ss-demo-usb-stack-scaled.png" alt="Linux USB demo stack - image copyright 2008 Sarah
Sharp" title="" />
</center></p>

<p>My wonderful husband, Jamey, found an open source real-time graphing program
called <a href="http://www.thregr.org/~wavexx/software/trend/">Trend</a>.  It
looked perfect for the demo, except for the fact that it would only update when
it was given data.  Since the HCD stats file would block when there wasn't data
(we didn't want to spend too many CPU cycles returning zero), Jamey wrote <a
href="http://minilop.net/~sarah/trend-sample.c">a threaded C program</a> to
sample the input from the HCD stats file.</p>

<p>The program takes the HCD stats file as an input, calculates the throughput (in
MBps) for each pair read from the stats file, and passes off the max throughput
to Trend for each sample.  It would pass zeros off to Trend if the file I/O was
blocked.  This meant the Trend graph updated at the same rate, even if there was
no USB traffic.  The Trend graph also auto-updated its vertical scale as the
throughput increased.  This seemed to confuse some people, but I thought the
"growing" effect was fun.</p>

<p>The Windows demo saw around 318 MBps, while the Linux demo typically showed 125
MBps.  I saw as high as 233 MBps while formatting the disk.  dd is not the best
application to use for performance testing; I only used to whip up a simple
demo.</p>

<p>Application layer measurements showed poor performance (around 2 MBps).  I think
two things added fixed latencies between the application layer and the host
controller hardware.  First, there was a massive amount of debugging output in
the host controller driver and mass storage driver.  Second, I had placed some
msleep() calls in the USB MSD driver so that I could see the debugging output
and trigger a PCI analyzer at the same time.  I didn't have time to take those
out before I ran my demo.  I need to run more tests to disable debugging and
profile the upper layer stack for other bottlenecks.</p>

<p>If you're interested in seeing the demo run on an EHCI host controller and a
high speed USB 2.0 MSD, you can view the Google video <a
href="http://video.google.com/videoplay?docid=-7831617927964500623">here</a>, or
download the higher resolution ogg <a
href="http://www.box.net/lite/58ff6vub0t">here</a>.</p>

]]></description>
</item>

</channel>
</rss>
