Paul Morneau
Paul Morneau

Reputation: 33

Embedded Linux: kernel drivers vs user space drivers?

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:

The 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

Answers (2)

jbm
jbm

Reputation: 3163

Of the top of my head:

Userland approach pros:

  • faster to develop / easier to debug
  • if buggy and crash, cannot crash your whole system

Userland approach cons:

  • "performances" - which I'll leave as a very vague concept here and today...

In the case of your application, putting that in perspective:

  • since we can safely bet that humidity does not change dramatically in short amount of time,
  • and/or your sensor have some non negligible hysteresis anyway (would it be only for mechanical reasons, ex a drop of water fall on it, it will not dissapear in a millisecond),
  • ...and you probably don't plan to send humidity measures every millisecond - do you?
  • ...and even if you did, most of the latency (as "vs performance") will be from that part that will make it a JSON, send it to the server (both being clearly jobs for userland), and - though that may be none of your business, this is still part of the use case - networking condition and processing time by the by the server,

...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

Harry
Harry

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

Related Questions