LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 03-20-2014, 10:32 AM   #1
tj62
LQ Newbie
 
Registered: Mar 2014
Posts: 3

Rep: Reputation: Disabled
Reading via I2C from User Space very CPU consumimg


I have written a small application to communicate with TCA6424A IO-expander. I do this on a Linux-Debian ARM processor from user space. I followed those guidelines:

Everything works fine except that the i2c_smbus_read_byte_data(fd,address) is very CPU consuming. Writing the same register with i2c_smbus_write_byte_data(fd, address,regValue) only takes a fractional CPU compared to the read-command. As I'm reading very fast incoming pulses on 8 inputs of the TCA6424A, I loose pulses because the CPU is overwhelmed with the frequent CPU demanding i2c_smbus_read_byte_data(fd,address) calls. How can it be that the read operation is so much heavier than the write-operation? Can I solve this problem by writing a device kernel-driver? I would like to avoid that as I'm not familiar with that. Another thing I have noticed is that if I call ioctl(fd,I2C_PEC,1) after opening the i2C to use check-sums both smbus- read and write fail. That is also strange?

Just to compare here are some results:

Test 1:
In a 1-5000 loop read Input register 0 in TCA6424A.
It took 26 seconds. That is 5.2mS per byte read.
This is far too slow.

Test2:
In a 1-50000 (10 times longer) loop wrote Output register 1 in TCA6424A (the relays).
It took 4 seconds. That is 80uS per byte as expected.

Test3:
In a 1-5000 loop read Input register 2 in a TLC59116f LED manager.
It took 26 seconds. That is 5.2mS per byte read.
Same slow result as with the IO expander.


I have navigated that the time/CPU consumption happens in i ioctl() call that i2c_smbus_read_byte_data() is calling.


Result, there is something very wrong regarding the Linux User Space I2C-dev driver....unless all I2C based hardware behave like this. Why should that be?
 
Old 03-23-2014, 03:59 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
My hunch would be that the read function needs to do some polling in a tight loop, whereas the write function can sleep between bit writes. Without knowing more details of the userspace driver, that's just speculative.
 
Old 03-24-2014, 05:09 AM   #3
tj62
LQ Newbie
 
Registered: Mar 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Well maybe I did not point it clearly enough out. But it is the ioctl() call done inside i2c_smbus_read_byte_data() that is causing this. I have also tried simple read() with same problematic result.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
user space I2C in Pandaboard sskece Linux - Newbie 0 03-20-2013 05:44 PM
[SOLVED] Reading the value of Jiffies from User Space cruiser Linux - Newbie 3 08-13-2012 12:55 AM
How to access register set of an i2c device from user space ? tanniru Linux - Kernel 1 04-26-2011 08:22 AM
How to access register set of an i2c device from user space ? tanniru Linux - Networking 0 04-26-2011 02:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration