linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* using eventfd between userspace and kernelspace
@ 2019-08-20 14:47 Cosmin Marin
  0 siblings, 0 replies; only message in thread
From: Cosmin Marin @ 2019-08-20 14:47 UTC (permalink / raw)
  To: linux-kernel

Hi folks,

I have some doubts regarding the usage of eventfd and I'm seeking for some advice/suggestions. I want to use eventfd in a producer-consumer manner (EFD_SEMAPHORE) between a process's userspace and a kernel module.

The desired behaviour: periodically, a userspace thread writes to the eventfd while some kernel tasks (under the context of other userspace threads) read from it. When the eventfd reaches 0, the readers will block waiting for the producer. The consumers will always terminate at producer's command via an IOCTL.

Now, I have the following doubts:
1) Older versions of Kernel provided a way to read (eventfd_ctx_read) an eventfd from the kernel but that's no longer available; the counterpart for write (eventfd_signal) it's still there, though.
What I am looking for is a portable way between different versions  to read an eventfd from kernel. One option is to get a pointer to the "file" structure based on the "fd" and call the corresponding read function (f = fget(fd); f->f_op->read()).

Does anybody see a problem with directly calling f_op->read() ? Obviously, another option would be to reintroduce eventfd_ctx_read.

2) I also need the semantics to be slightly different: I want to be able to reset the eventfd's counter every so often instead of adding to/incrementing the current eventfd value; that is, I need a write() to set the counter to a specific value. In my view some ways for the implementation are either to add a new flag (EFD_COUNTER_SET) that would work together with EFD_SEMAPHORE or a dedicated IOCTL for this purpose.

Any other suggestions/comments ? Would something like that be accepted in upstream ?

Cosmin

Sent with ProtonMail Secure Email.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-20 14:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 14:47 using eventfd between userspace and kernelspace Cosmin Marin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).