rust-embedded / gpio-cdev

Rust interface to the Linux GPIO Character Device API (/dev/gpiochip...)
Apache License 2.0
213 stars 37 forks source link

Is kernel event queueing per-process? #50

Closed tal-zvon closed 3 years ago

tal-zvon commented 3 years ago

Just looking for a bit of clarification here.

From what I understand, this is how it works:

Importantly, this queue is per-process. As in, when our Rust application starts up, and uses gpio_cdev to register to be notified about a pin state change with:

let handle = chip.get_line(N)?.request(LineRequestFlags::INPUT, 0, "read-input")?;

The kernel sets up a queue specifically for this process, for this one line.

The alternative, which I'm really hoping isn't the case, is that there's one queue per line that the kernel maintains, and when your Rust application starts, and registers to be notified, the queue may already have events in it that may potentially need to be discarded.

posborne commented 3 years ago

The kernel has a queue per LineRequest which are not shared between processes. You should even be able to have multiple per process if you have a use case for that.

https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib-cdev.c#L469

Note that if the FIFO fills, events will be dropped:

https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib-cdev.c#L523