Skip to contentSkip to conversation

eventfd: support delayed wakeup for non-semaphore eventfd to reduce cpu utilization

PATCH Wen Yang 1 participant 1 message Apr 18, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Wen Yang

author
#1 lore raw
Quoted 11 lines · Hillf Danton

On 16 Apr 2023 19:31:55 +0800 Wen Yang <[email protected]>

Quoted 10 lines

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.

Quoted 10 lines

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