Reputation: 33
Is there a best approach (or at least some advantages and disadvantages) when choosing between the use of kernel space or user space drivers in Linux?
For example, let's say I'm developing a board for sensing humidity built on the Sensirion SHT21 sensor. My application will read a sample from the sensor and then present it in JSON form for a web application to consume.
In order to "talk" with the SHT21 sensor I can either:
echo sht21 0x40 > /sys/class/i2c-adapter/i2c-0/new_device
and access the humidity readings via hwmon
, parse the output and then use it in my applicationwrite()
and read()
operations against /dev/i2c-0
and calculate the humidity myself, then use it in my applicationThe first approach makes use of the sht21
kernel driver, the latter works entirely in user space.
Which one should I go for? How should I choose?
Upvotes: 3
Views: 2279
Reputation: 3163
Of the top of my head:
Userland approach pros:
Userland approach cons:
In the case of your application, putting that in perspective:
...all in all, I would 200% go with the userland approach.
Kernel space may be technically more "fun" or "rewarding", but engineering put "pragmatic" before "fun". :-)
Upvotes: 2
Reputation: 11638
In both cases your driving what happens from user space, option 2 implies writing a driver which I would avoid, if it already exists your good.
If there's a driver that parses and makes sense of some the data that's being used in production use it if it's easier to use or has a large user base. If it's trivial to parse the raw data and you're truly squeezed for space (I doubt this because you running a kernel) then write your own parser etc.
To be short what's the least work ie the least complex, do that.
Upvotes: 0