Bug 252820 - Linuxulator: linux_timerfd_settime don't set expirations count to zero
Summary: Linuxulator: linux_timerfd_settime don't set expirations count to zero
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-emulation (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-19 06:44 UTC by shu
Modified: 2021-03-21 07:39 UTC (History)
3 users (show)

See Also:


Attachments
timerfd+epoll+LT (1.40 KB, text/plain)
2021-01-19 06:44 UTC, shu
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description shu 2021-01-19 06:44:19 UTC
Created attachment 221726 [details]
timerfd+epoll+LT

On Linux, read(2) timerfd returns an unsigned 8-byte integer (uint64_t) containing the number of expirations that have occurred, if the timer has already expired one or more times since its settings were last modified using timerfd_settime(), or since the last successful read(2).That's to say, once do a read or timerfd_settime operation, timer fd's expiration count should be zero.
Some Linux applications create timerfd and add it to epoll with LT mode, when event comes, they do timerfd_settime instead of read to stop event source from trigger, code in the attachment, On FreeBSD timerfd_settime don't set count to zero, so cause CPU high.
Comment 1 shu 2021-01-19 06:51:11 UTC
https://reviews.freebsd.org/D28231
Comment 2 Ed Maste freebsd_committer freebsd_triage 2021-02-08 01:38:53 UTC
Committed in ae71b794cbed
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-03-21 07:06:32 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=bf1863de6b1fb813192e45639b4cfde65a624b6b

commit bf1863de6b1fb813192e45639b4cfde65a624b6b
Author:     shu <ankohuu@outlook.com>
AuthorDate: 2021-02-03 16:51:45 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2021-03-21 07:03:22 +0000

    linux: make timerfd_settime(2) set expirations count to zero

    On Linux, read(2) from a timerfd file descriptor returns an unsigned
    8-byte integer (uint64_t) containing the number of expirations
    that have occurred, if the timer has already expired one or more
    times since its settings were last modified using timerfd_settime(),
    or since the last successful read(2).  That's to say, once we do
    a read or call timerfd_settime(), timer fd's expiration count should
    be zero.  Some Linux applications create timerfd and add it to epoll
    with LT mode, when event comes, they do timerfd_settime instead
    of read to stop event source from trigger.  On FreeBSD,
    timerfd_settime(2) didn't set the count to zero, which caused high
    CPU utilization.

    PR:             252820
    Submitted by:   ankohuu_outlook.com (Shunchao Hu)
    Differential Revision: https://reviews.freebsd.org/D28231

    (cherry picked from commit ae71b794cbed19e5e25effc3438720ad452ab87c)

 sys/compat/linux/linux_event.c | 1 +
 1 file changed, 1 insertion(+)
Comment 4 Dmitry Chagin freebsd_committer freebsd_triage 2021-03-21 07:39:55 UTC
Merged to stable/12 and stable/13, 10x!