-
Notifications
You must be signed in to change notification settings - Fork 8.2k
timerfd #99433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
timerfd #99433
Conversation
124b4f3 to
47f8221
Compare
This add a timerfd-like interface similar to other systems. Although this is not POSIX, it is very popular alternative to POSIX timers. The implementation is based on the current eventfd implementation, with the relevant improvements and changes. Add the ZVFS_TIMERFD so we can selectively enable/disable the timerfd implementation. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
| zassert_equal(ret, 0, "timerfd blocked after write"); | ||
| zassert_equal(event, POLLIN, "POLLIN not set"); | ||
|
|
||
| zassert_equal(read(fd, &val, sizeof(val)), sizeof(val), "read failed"); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go home, SonarCloud. You are drunk. This is read(2). I suspect SonarCloud thinks this is like fread(3). I don't know why it thinks read(2) would write 64 bytes instead of 8.
| ret = is_blocked(fd, &event); | ||
| zassert_equal(ret, 0, "timerfd is blocked with initval != 0"); | ||
|
|
||
| ret = read(fd, &val, sizeof(val)); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
| uint64_t value; | ||
| struct timerfd_fixture *fixture = arg1; | ||
|
|
||
| zassert_equal(read(fixture->fd, &value, sizeof(value)), sizeof(value)); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
| zassert_equal(fds[0].revents, ZSOCK_POLLIN); | ||
|
|
||
| /* Check value */ | ||
| zassert_equal(read(fixture->fd, &value, sizeof(value)), sizeof(value)); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
| /* Try writing and reading. Should not fail. */ | ||
| zassert_ok(ioctl(fixture->fd, TFD_IOC_SET_TICKS, (uint64_t)3)); | ||
|
|
||
| ret = read(fixture->fd, &val, sizeof(val)); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
| { | ||
| timerfd_t value; | ||
|
|
||
| read(fd, &value, sizeof(value)); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
|
|
||
| /*TESTPOINT: Check if timerfd test passed*/ | ||
| uint64_t exp_count; | ||
| zassert_equal(read(fixture->fd, &exp_count, sizeof(exp_count)), sizeof(exp_count)); |
Check failure
Code scanning / SonarCloud
POSIX functions should not be called with arguments that trigger buffer overflows High test
43622a1 to
5a90157
Compare
This is a wrapper around zvfs_timerfd, so we provide a standard POSIX "compatible" timerfd interface. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This will test the timerfd interface and behavior similar to the popular interface available on other POSIX OS. The tests are based on the eventfd plus the POSIX timer tests. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Add the timerfd sample and README file. The timerfd follows a similar behavior as specified in other POSIX OS. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
|




We know timerfd is not POSIX, nor is eventfd, however these interfaces are popular enough to be available on Linux, NuttX, FreeBSD, etc.
We already have eventfd, we introduce here timerfd, which is a similar implementation as eventfd, and can be used as a no-thread, no-SIGNAL implementation alternative to POSIX timers.
This will allow applications to use a similar timerfd as defined in timerfd_create(2).