Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Kernel USB API vs Userspace (libusb)
Vasily anarsoul Khoruzhick
email: anarsoul@gmail.com, skype: anarsoul
github.com/anar...
Template of (minimal) libusb app

libusb_init()
dev_handle = libusb_open_device_with_vid_pid(vid, pid)
libusb_claim_interf...
Template of (simple) kernel driver for USB device

USB ID compatibility table (possible to match device class also)
driver...
Generic Kernel vs Userspace differences

No one cleanups after you in Kernel
Dereferenced NULL pointer? -> reboot
Corrupted...
Entry point

Userspace: should obtain device handle by itself
(libusb_open_device_with_vid_pid())
Kernel: contains USB ID ...
Async API: libusb_transfer vs usb_urb

Represents single USB transfer
Contains source & destination (EP num, direction, po...
Async API libusb_submit_transfer() vs usb_urb_submit()

Almost no difference - both submit asynchronous transfer

Vasily Kh...
Sync API: libusb_{control,bulk,interrupt}_transfer vs
usb_{control,bulk,interrupt}_msg

Kernel: can’t use sync API in atom...
Userspace: Pros and Cons

Pros:
Good for prototyping, decent development speed
Easy to debug
Convenient synchronous API

C...
Kernel: Pros and Cons

Pros:
Decent performance and response latency

Cons:
Development speed is slower
Not so easy to deb...
The End

Thanks! Questions?

Vasily Khoruzhick, Synesis LLC

Kernel USB API vs Userspace (libusb)

October, 2013

11 / 11
Upcoming SlideShare
Loading in …5
×

0

Share

Download to read offline

Vasily Khoruzhik - libusb vs linux kernel — сравнение userspace & kernelspace API

Download to read offline

Доклад Василия Хоружика на октябрьской линуксовке MLUG 2013

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Vasily Khoruzhik - libusb vs linux kernel — сравнение userspace & kernelspace API

  1. 1. Kernel USB API vs Userspace (libusb) Vasily anarsoul Khoruzhick email: anarsoul@gmail.com, skype: anarsoul github.com/anarsoul Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 1 / 11
  2. 2. Template of (minimal) libusb app libusb_init() dev_handle = libusb_open_device_with_vid_pid(vid, pid) libusb_claim_interface(dev_handle, intf_num) libusb_set_interface_altsetting() libusb_alloc_transfer() ... libusb_fill_*_transfer() ... libusb_submit_transfer() ... completion callback ... libusb_close(dev_handle) libusb_exit() Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 2 / 11
  3. 3. Template of (simple) kernel driver for USB device USB ID compatibility table (possible to match device class also) driver probe function usb_driver_claim_interface() usb_set_interface() usb_alloc_urb() ... usb_fill_*_urb() ... usb_submit_urb() ... completion callback ... usb_free_urb() driver removal function Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 3 / 11
  4. 4. Generic Kernel vs Userspace differences No one cleanups after you in Kernel Dereferenced NULL pointer? -> reboot Corrupted some memory of other driver? -> reboot Atomic/non-atomic context Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 4 / 11
  5. 5. Entry point Userspace: should obtain device handle by itself (libusb_open_device_with_vid_pid()) Kernel: contains USB ID compatibility table, device handle is passed by driver core Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 5 / 11
  6. 6. Async API: libusb_transfer vs usb_urb Represents single USB transfer Contains source & destination (EP num, direction, pointer to buffer and its size) Completion callback In kernel completion callback is called from atomic context Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 6 / 11
  7. 7. Async API libusb_submit_transfer() vs usb_urb_submit() Almost no difference - both submit asynchronous transfer Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 7 / 11
  8. 8. Sync API: libusb_{control,bulk,interrupt}_transfer vs usb_{control,bulk,interrupt}_msg Kernel: can’t use sync API in atomic context Kernel: userspace: it’s convenient, but usually not a good idea to use synchronous API Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 8 / 11
  9. 9. Userspace: Pros and Cons Pros: Good for prototyping, decent development speed Easy to debug Convenient synchronous API Cons: Performance and response latency is worse Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 9 / 11
  10. 10. Kernel: Pros and Cons Pros: Decent performance and response latency Cons: Development speed is slower Not so easy to debug One should always keep in mind that it’s a kernel: Can’t sleep in completion callback Can’t use synchronous API in atomic context Be carefull with memory and other resources Async stuff is complicated, sync stuff in kernel is evil. Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 10 / 11
  11. 11. The End Thanks! Questions? Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 11 / 11

Доклад Василия Хоружика на октябрьской линуксовке MLUG 2013

Views

Total views

934

On Slideshare

0

From embeds

0

Number of embeds

2

Actions

Downloads

7

Shares

0

Comments

0

Likes

0

×