From 533e5057ed2503013643bf8450588e4aa58c2b7e Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 6 Mar 2021 01:31:20 +0200 Subject: [PATCH] Add helper for kqueue timers callout scheduling Reviewed by: markj Tested by: markj, pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D29106 --- sys/kern/kern_event.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 5185723b8d1..5e9f1fc35df 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -676,10 +676,19 @@ timer2sbintime(int64_t data, int flags) struct kq_timer_cb_data { struct callout c; + struct knote *kn; + int cpuid; sbintime_t next; /* next timer event fires at */ sbintime_t to; /* precalculated timer period, 0 for abs */ }; +static void +kqtimer_sched_callout(struct kq_timer_cb_data *kc) +{ + callout_reset_sbt_on(&kc->c, kc->next, 0, filt_timerexpire, kc->kn, + kc->cpuid, C_ABSOLUTE); +} + static void filt_timerexpire(void *knx) { @@ -696,8 +705,7 @@ filt_timerexpire(void *knx) if (kc->to == 0) return; kc->next += kc->to; - callout_reset_sbt_on(&kc->c, kc->next, 0, filt_timerexpire, kn, - PCPU_GET(cpuid), C_ABSOLUTE); + kqtimer_sched_callout(kc); } /* @@ -753,6 +761,8 @@ filt_timerattach(struct knote *kn) kn->kn_flags |= EV_CLEAR; /* automatically set */ kn->kn_status &= ~KN_DETACHED; /* knlist_add clears it */ kn->kn_ptr.p_v = kc = malloc(sizeof(*kc), M_KQUEUE, M_WAITOK); + kc->kn = kn; + kc->cpuid = PCPU_GET(cpuid); callout_init(&kc->c, 1); filt_timerstart(kn, to); @@ -772,8 +782,7 @@ filt_timerstart(struct knote *kn, sbintime_t to) kc->next = to + sbinuptime(); kc->to = to; } - callout_reset_sbt_on(&kc->c, kc->next, 0, filt_timerexpire, kn, - PCPU_GET(cpuid), C_ABSOLUTE); + kqtimer_sched_callout(kc); } static void