SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
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
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
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
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
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
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
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
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
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
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
The End

Thanks! Questions?

Vasily Khoruzhick, Synesis LLC

Kernel USB API vs Userspace (libusb)

October, 2013

11 / 11

Contenu connexe

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

Application Deployment Architecture
Application Deployment ArchitectureApplication Deployment Architecture
Application Deployment ArchitectureSaurav Basu
 
Making a Headless Android Device
Making a Headless Android DeviceMaking a Headless Android Device
Making a Headless Android DevicePatricia Aas
 
Embedded Recipes 2019 - Overview of Fuchsia, a new operating system
Embedded Recipes 2019 - Overview of Fuchsia, a new operating systemEmbedded Recipes 2019 - Overview of Fuchsia, a new operating system
Embedded Recipes 2019 - Overview of Fuchsia, a new operating systemAnne Nicolas
 
Easy Data for PhoneGap apps with PouchDB
Easy Data for PhoneGap apps with PouchDBEasy Data for PhoneGap apps with PouchDB
Easy Data for PhoneGap apps with PouchDBHolly Schinsky
 
Container Support in IBM Spectrum LSF
Container Support in IBM Spectrum LSFContainer Support in IBM Spectrum LSF
Container Support in IBM Spectrum LSFGabor Samu
 
Базы данных. ZooKeeper
Базы данных. ZooKeeperБазы данных. ZooKeeper
Базы данных. ZooKeeperVadim Tsesko
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009Bhasker Kode
 
Making a Headless Android Device (Oslo Embedded Meetup 2018)
Making a Headless Android Device (Oslo Embedded Meetup 2018)Making a Headless Android Device (Oslo Embedded Meetup 2018)
Making a Headless Android Device (Oslo Embedded Meetup 2018)Patricia Aas
 
Глеб Смирнов: Что нового в FreeBSD 10.0
Глеб Смирнов: Что нового в FreeBSD 10.0Глеб Смирнов: Что нового в FreeBSD 10.0
Глеб Смирнов: Что нового в FreeBSD 10.0Yandex
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)ngotogenome
 
LSC@LDAPCon 2011
LSC@LDAPCon 2011LSC@LDAPCon 2011
LSC@LDAPCon 2011sbahloul
 
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)Egor Elizarov
 
Storage Is Not Virtualized Enough - part 1
Storage Is Not Virtualized Enough - part 1Storage Is Not Virtualized Enough - part 1
Storage Is Not Virtualized Enough - part 1Zhipeng Huang
 
Open Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNETOpen Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNETNikos Kormpakis
 
Lxc – next gen virtualization for cloud intro (cloudexpo)
Lxc – next gen virtualization for cloud   intro (cloudexpo)Lxc – next gen virtualization for cloud   intro (cloudexpo)
Lxc – next gen virtualization for cloud intro (cloudexpo)Boden Russell
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Aaron Zauner
 

Similaire à Vasily Khoruzhik - libusb vs linux kernel — сравнение userspace & kernelspace API (20)

Application Deployment Architecture
Application Deployment ArchitectureApplication Deployment Architecture
Application Deployment Architecture
 
Making a Headless Android Device
Making a Headless Android DeviceMaking a Headless Android Device
Making a Headless Android Device
 
Zlib.3
Zlib.3Zlib.3
Zlib.3
 
Embedded Recipes 2019 - Overview of Fuchsia, a new operating system
Embedded Recipes 2019 - Overview of Fuchsia, a new operating systemEmbedded Recipes 2019 - Overview of Fuchsia, a new operating system
Embedded Recipes 2019 - Overview of Fuchsia, a new operating system
 
olibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linuxolibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linux
 
Easy Data for PhoneGap apps with PouchDB
Easy Data for PhoneGap apps with PouchDBEasy Data for PhoneGap apps with PouchDB
Easy Data for PhoneGap apps with PouchDB
 
Container Support in IBM Spectrum LSF
Container Support in IBM Spectrum LSFContainer Support in IBM Spectrum LSF
Container Support in IBM Spectrum LSF
 
Базы данных. ZooKeeper
Базы данных. ZooKeeperБазы данных. ZooKeeper
Базы данных. ZooKeeper
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009
 
Core Android
Core AndroidCore Android
Core Android
 
Making a Headless Android Device (Oslo Embedded Meetup 2018)
Making a Headless Android Device (Oslo Embedded Meetup 2018)Making a Headless Android Device (Oslo Embedded Meetup 2018)
Making a Headless Android Device (Oslo Embedded Meetup 2018)
 
Глеб Смирнов: Что нового в FreeBSD 10.0
Глеб Смирнов: Что нового в FreeBSD 10.0Глеб Смирнов: Что нового в FreeBSD 10.0
Глеб Смирнов: Что нового в FreeBSD 10.0
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
 
LSC@LDAPCon 2011
LSC@LDAPCon 2011LSC@LDAPCon 2011
LSC@LDAPCon 2011
 
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
 
Storage Is Not Virtualized Enough - part 1
Storage Is Not Virtualized Enough - part 1Storage Is Not Virtualized Enough - part 1
Storage Is Not Virtualized Enough - part 1
 
freebsd-watitis
freebsd-watitisfreebsd-watitis
freebsd-watitis
 
Open Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNETOpen Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNET
 
Lxc – next gen virtualization for cloud intro (cloudexpo)
Lxc – next gen virtualization for cloud   intro (cloudexpo)Lxc – next gen virtualization for cloud   intro (cloudexpo)
Lxc – next gen virtualization for cloud intro (cloudexpo)
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
 

Plus de Minsk Linux User Group

Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P...
 Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P... Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P...
Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P...Minsk Linux User Group
 
Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...
Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...
Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...Minsk Linux User Group
 
Святлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасць
Святлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасцьСвятлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасць
Святлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасцьMinsk Linux User Group
 
Тимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использования
Тимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использованияТимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использования
Тимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использованияMinsk Linux User Group
 
Андрэй Захарэвіч - Як мы ставілі KDE пад FreeBSD
Андрэй Захарэвіч - Як мы ставілі KDE пад FreeBSDАндрэй Захарэвіч - Як мы ставілі KDE пад FreeBSD
Андрэй Захарэвіч - Як мы ставілі KDE пад FreeBSDMinsk Linux User Group
 
Vitaly ̈_Vi ̈ Shukela - My FOSS projects
Vitaly  ̈_Vi ̈ Shukela - My FOSS projectsVitaly  ̈_Vi ̈ Shukela - My FOSS projects
Vitaly ̈_Vi ̈ Shukela - My FOSS projectsMinsk Linux User Group
 
Alexander Lomov - Cloud Foundry и BOSH: истории из жизни
Alexander Lomov - Cloud Foundry и BOSH: истории из жизниAlexander Lomov - Cloud Foundry и BOSH: истории из жизни
Alexander Lomov - Cloud Foundry и BOSH: истории из жизниMinsk Linux User Group
 
Vikentsi Lapa — How does software testing become software development?
Vikentsi Lapa — How does software testing  become software development?Vikentsi Lapa — How does software testing  become software development?
Vikentsi Lapa — How does software testing become software development?Minsk Linux User Group
 
Михаил Волчек — Свободные лицензии. быть или не быть? Продолжение
Михаил Волчек — Свободные лицензии. быть или не быть? ПродолжениеМихаил Волчек — Свободные лицензии. быть или не быть? Продолжение
Михаил Волчек — Свободные лицензии. быть или не быть? ПродолжениеMinsk Linux User Group
 
Максим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPN
Максим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPNМаксим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPN
Максим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPNMinsk Linux User Group
 
Слава Машканов — “Wubuntu”: Построение гетерогенной среды Windows+Linux на н...
Слава Машканов — “Wubuntu”: Построение гетерогенной среды  Windows+Linux на н...Слава Машканов — “Wubuntu”: Построение гетерогенной среды  Windows+Linux на н...
Слава Машканов — “Wubuntu”: Построение гетерогенной среды Windows+Linux на н...Minsk Linux User Group
 
MajorDoMo: Открытая платформа Умного Дома
MajorDoMo: Открытая платформа Умного ДомаMajorDoMo: Открытая платформа Умного Дома
MajorDoMo: Открытая платформа Умного ДомаMinsk Linux User Group
 
Максим Салов - Отладочный монитор
Максим Салов - Отладочный мониторМаксим Салов - Отладочный монитор
Максим Салов - Отладочный мониторMinsk Linux User Group
 
Максим Мельников - FOSDEM 2014 overview
Максим Мельников - FOSDEM 2014 overviewМаксим Мельников - FOSDEM 2014 overview
Максим Мельников - FOSDEM 2014 overviewMinsk Linux User Group
 
Константин Шевцов - Пара слов о Jenkins
Константин Шевцов - Пара слов о JenkinsКонстантин Шевцов - Пара слов о Jenkins
Константин Шевцов - Пара слов о JenkinsMinsk Linux User Group
 
Ермакович Света - Операция «Пингвин»
Ермакович Света - Операция «Пингвин»Ермакович Света - Операция «Пингвин»
Ермакович Света - Операция «Пингвин»Minsk Linux User Group
 
Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...
Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...
Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...Minsk Linux User Group
 
Алексей Туля - А нужен ли вам erlang?
Алексей Туля - А нужен ли вам erlang?Алексей Туля - А нужен ли вам erlang?
Алексей Туля - А нужен ли вам erlang?Minsk Linux User Group
 

Plus de Minsk Linux User Group (20)

Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P...
 Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P... Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P...
Vladimir ’mend0za’ Shakhov — Linux firmware for iRMC controller on Fujitsu P...
 
Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...
Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...
Андрэй Захарэвіч — Hack the Hackpad: Першая спроба публічнага кіравання задач...
 
Святлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасць
Святлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасцьСвятлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасць
Святлана Ермаковіч — Вікі-дапаможнік. Як узмацніць беларускую вікі-супольнасць
 
Тимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использования
Тимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использованияТимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использования
Тимофей Титовец — Elastic+Logstash+Kibana: Архитектура и опыт использования
 
Андрэй Захарэвіч - Як мы ставілі KDE пад FreeBSD
Андрэй Захарэвіч - Як мы ставілі KDE пад FreeBSDАндрэй Захарэвіч - Як мы ставілі KDE пад FreeBSD
Андрэй Захарэвіч - Як мы ставілі KDE пад FreeBSD
 
Vitaly ̈_Vi ̈ Shukela - My FOSS projects
Vitaly  ̈_Vi ̈ Shukela - My FOSS projectsVitaly  ̈_Vi ̈ Shukela - My FOSS projects
Vitaly ̈_Vi ̈ Shukela - My FOSS projects
 
Vitaly ̈_Vi ̈ Shukela - Dive
Vitaly  ̈_Vi ̈ Shukela - DiveVitaly  ̈_Vi ̈ Shukela - Dive
Vitaly ̈_Vi ̈ Shukela - Dive
 
Alexander Lomov - Cloud Foundry и BOSH: истории из жизни
Alexander Lomov - Cloud Foundry и BOSH: истории из жизниAlexander Lomov - Cloud Foundry и BOSH: истории из жизни
Alexander Lomov - Cloud Foundry и BOSH: истории из жизни
 
Vikentsi Lapa — How does software testing become software development?
Vikentsi Lapa — How does software testing  become software development?Vikentsi Lapa — How does software testing  become software development?
Vikentsi Lapa — How does software testing become software development?
 
Михаил Волчек — Свободные лицензии. быть или не быть? Продолжение
Михаил Волчек — Свободные лицензии. быть или не быть? ПродолжениеМихаил Волчек — Свободные лицензии. быть или не быть? Продолжение
Михаил Волчек — Свободные лицензии. быть или не быть? Продолжение
 
Максим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPN
Максим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPNМаксим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPN
Максим Мельников — IPv6 at Home: NAT64, DNS64, OpenVPN
 
Слава Машканов — “Wubuntu”: Построение гетерогенной среды Windows+Linux на н...
Слава Машканов — “Wubuntu”: Построение гетерогенной среды  Windows+Linux на н...Слава Машканов — “Wubuntu”: Построение гетерогенной среды  Windows+Linux на н...
Слава Машканов — “Wubuntu”: Построение гетерогенной среды Windows+Linux на н...
 
MajorDoMo: Открытая платформа Умного Дома
MajorDoMo: Открытая платформа Умного ДомаMajorDoMo: Открытая платформа Умного Дома
MajorDoMo: Открытая платформа Умного Дома
 
Максим Салов - Отладочный монитор
Максим Салов - Отладочный мониторМаксим Салов - Отладочный монитор
Максим Салов - Отладочный монитор
 
Максим Мельников - FOSDEM 2014 overview
Максим Мельников - FOSDEM 2014 overviewМаксим Мельников - FOSDEM 2014 overview
Максим Мельников - FOSDEM 2014 overview
 
Константин Шевцов - Пара слов о Jenkins
Константин Шевцов - Пара слов о JenkinsКонстантин Шевцов - Пара слов о Jenkins
Константин Шевцов - Пара слов о Jenkins
 
Ермакович Света - Операция «Пингвин»
Ермакович Света - Операция «Пингвин»Ермакович Света - Операция «Пингвин»
Ермакович Света - Операция «Пингвин»
 
Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...
Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...
Михаил Волчек - Смогут ли беларусы вкусить плоды Творческих Общин? Creative C...
 
Vikentsi Lapa - Tools for testing
Vikentsi Lapa - Tools for testingVikentsi Lapa - Tools for testing
Vikentsi Lapa - Tools for testing
 
Алексей Туля - А нужен ли вам erlang?
Алексей Туля - А нужен ли вам erlang?Алексей Туля - А нужен ли вам erlang?
Алексей Туля - А нужен ли вам erlang?
 

Dernier

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

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

  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. The End Thanks! Questions? Vasily Khoruzhick, Synesis LLC Kernel USB API vs Userspace (libusb) October, 2013 11 / 11