Accessing gpio in linux from user space and kernel space and Performance testing with dht11 sensor

Zafer SEN
2 min readApr 15, 2022

The beginning of the story. I just wondered how much performance difference happens when I access the gpio from the user space or kernel space.

For this experiment, I used dht11 sensor on Maaxboard Dev board based on Imx8mq mcu.

system’s specifics were like these:

Linux debian 4.14.78 aarch64 GNU/Linux

Accessing from the User Space

I calculate the percentage of corruption of data, it was % 83. I collected 12288 data with a sec interval, 10267 of them are corrupt data. Absolutely, it is unreliable.

in more detail of the code: https://github.com/zafersn/dht11-gpio-programming/tree/main/GPIOD-DHT11-TEST

Accessing from the Kernel Space:

the percentage of corruption in kernel space gpio programming. It was % 55.56. I collected 6763 number of dht11's data and 3763 of them were corrupted. Only 3022 of them were acceptable correct data.

in more detail of the code: https://github.com/zafersn/dht11-gpio-programming/tree/main/KERNEL-DHT11-TEST

Conclusion

When we compare both of them, Accessing the gpio from the kernel level for reading and writing at the level of a microsecond is significantly reliable and the accuracy rate is higher than accessing from the user level. For dht11 sensor you need to access gpio pins and briefly, read 40 bits from a GPIO pin and each bit can take a max 70 microseconds. When bit-level is high for max 28us or 70us, it means is logic 0 or 1, respectively. That is why I did experiment by using dht11 sensor. Because you need to access gpio and read or write data between 28us and 70us. it’s quite tough controlling gpio in that timing for OS.

There is more:

Quick discussion dht11 sensor and accessing from the user space

https://stackoverflow.com/questions/70588138/losing-data-bit-when-reading-from-gpio-by-libgpiod-on-linux

--

--