Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Aug 2023 15:10:35 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 5eab523053db - main - timerfd: compute fflags before calling falloc
Message-ID:  <202308251510.37PFAZCt061459@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg:

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

commit 5eab523053db79b4bd4f926c7d7ac04444d9c1da
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-08-25 15:09:21 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-08-25 15:09:21 +0000

    timerfd: compute fflags before calling falloc
    
    While here dodge list locking in timerfd_adjust if empty.
---
 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202308251510.37PFAZCt061459>