Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 May 2021 00:59:12 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: fbf613c93fd2 - stable/13 - filt_timerexpire: do not iterate over the interval
Message-ID:  <202105100059.14A0xCf4001915@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

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

commit fbf613c93fd2db057b7f80917556228998ba720b
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-04-28 16:28:49 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-05-10 00:47:35 +0000

    filt_timerexpire: do not iterate over the interval
    
    (cherry picked from commit 7cb40543e96451092d5bc6bb3d96ebee364327e0)
---
 sys/kern/kern_event.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 45d505fca757..03f4b3afbc28 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -718,6 +718,7 @@ filt_timerexpire_l(struct knote *kn, bool proc_locked)
 {
 	struct kq_timer_cb_data *kc;
 	struct proc *p;
+	uint64_t delta;
 	sbintime_t now;
 
 	kc = kn->kn_ptr.p_v;
@@ -728,9 +729,17 @@ filt_timerexpire_l(struct knote *kn, bool proc_locked)
 		return;
 	}
 
-	for (now = sbinuptime(); kc->next <= now; kc->next += kc->to)
-		kn->kn_data++;
-	KNOTE_ACTIVATE(kn, 0);	/* XXX - handle locking */
+	now = sbinuptime();
+	if (now >= kc->next) {
+		delta = (now - kc->next) / kc->to;
+		if (delta == 0)
+			delta = 1;
+		kn->kn_data += delta;
+		kc->next += (delta + 1) * kc->to;
+		if (now >= kc->next)	/* overflow */
+			kc->next = now + kc->to;
+		KNOTE_ACTIVATE(kn, 0);	/* XXX - handle locking */
+	}
 
 	/*
 	 * Initial check for stopped kc->p is racy.  It is fine to



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