git: fa786d4da669 - releng/14.0 - timerfd: compute fflags before calling falloc
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 28 Sep 2023 22:28:15 UTC
The branch releng/14.0 has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=fa786d4da669dcb02884d79565f6dd1b8e0db1c7
commit fa786d4da669dcb02884d79565f6dd1b8e0db1c7
Author: Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-08-25 15:09:21 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-09-28 22:26:20 +0000
timerfd: compute fflags before calling falloc
While here dodge list locking in timerfd_adjust if empty.
(cherry picked from commit 5eab523053db79b4bd4f926c7d7ac04444d9c1da)
Approved by: re (cperciva@)
(cherry picked from commit fc0c24482f11c403480c5219810a27d8591a8fb6)
Approved-by: re (cperciva)
---
sys/kern/sys_timerfd.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/sys/kern/sys_timerfd.c b/sys/kern/sys_timerfd.c
index 2bf2a05c443c..c8b45a926b02 100644
--- a/sys/kern/sys_timerfd.c
+++ b/sys/kern/sys_timerfd.c
@@ -129,6 +129,9 @@ timerfd_jumped(void)
struct timerfd *tfd;
struct timespec boottime, diff;
+ if (LIST_EMPTY(&timerfd_list))
+ return;
+
timerfd_getboottime(&boottime);
sx_xlock(&timerfd_list_lock);
LIST_FOREACH(tfd, &timerfd_list, entry) {
@@ -418,7 +421,7 @@ kern_timerfd_create(struct thread *td, int clockid, int flags)
{
struct file *fp;
struct timerfd *tfd;
- int error, fd, fflags = 0;
+ int error, fd, fflags;
AUDIT_ARG_VALUE(clockid);
AUDIT_ARG_FFLAGS(flags);
@@ -427,8 +430,12 @@ kern_timerfd_create(struct thread *td, int clockid, int flags)
return (EINVAL);
if ((flags & ~(TFD_CLOEXEC | TFD_NONBLOCK)) != 0)
return (EINVAL);
+
+ fflags = FREAD;
if ((flags & TFD_CLOEXEC) != 0)
fflags |= O_CLOEXEC;
+ if ((flags & TFD_NONBLOCK) != 0)
+ fflags |= FNONBLOCK;
error = falloc(td, &fp, &fd, fflags);
if (error != 0)
@@ -447,9 +454,6 @@ kern_timerfd_create(struct thread *td, int clockid, int flags)
LIST_INSERT_HEAD(&timerfd_list, tfd, entry);
sx_xunlock(&timerfd_list_lock);
- fflags = FREAD;
- if ((flags & TFD_NONBLOCK) != 0)
- fflags |= FNONBLOCK;
finit(fp, fflags, DTYPE_TIMERFD, tfd, &timerfdops);
fdrop(fp, td);