Re: [PATCH] eventfd: support delayed wakeup for non-semaphore eventfd to reduce cpu utilization

From: Wen Yang
Date: Tue Apr 18 2023 - 10:12:35 EST



在 2023/4/17 08:07, Hillf Danton 写道:
On 16 Apr 2023 19:31:55 +0800 Wen Yang <wenyang.linux@xxxxxxxxxxx>
For the NON SEMAPHORE eventfd, if it's counter has a nonzero value,
then a read(2) returns 8 bytes containing that value, and the counter's
value is reset to zero. Therefore, in the NON SEMAPHORE scenario,
N event_writes vs ONE event_read is possible.

However, the current implementation wakes up the read thread immediately
in eventfd_write so that the cpu utilization increases unnecessarily.

By adding a configurable delay after eventfd_write, these unnecessary
wakeup operations are avoided, thereby reducing cpu utilization.
If the EPOLLOUT wakeup in eventfd_read() breaks, feel free to specify it
in the commit message after updating the comment below.
/*
* Every time that a write(2) is performed on an eventfd, the
* value of the __u64 being written is added to "count" and a
* wakeup is performed on "wqh". A read(2) will return the "count"
* value to userspace, and will reset "count" to zero. The kernel
* side eventfd_signal() also, adds to the "count" counter and
* issue a wakeup.
*/

Thanks

We will modify it according to your suggestion and then send v2 later.

--

Best wishes,

Wen