summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_event.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/kern_event.c')
-rw-r--r--sys/kern/kern_event.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 9615d91..fc256f1 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -523,15 +523,38 @@ knote_fork(struct knlist *list, int pid)
* XXX: EVFILT_TIMER should perhaps live in kern_time.c beside the
* interval timer support code.
*/
+
+#define NOTE_TIMER_PRECMASK (NOTE_SECONDS|NOTE_MSECONDS|NOTE_USECONDS| \
+ NOTE_NSECONDS)
+
static __inline sbintime_t
-timer2sbintime(intptr_t data)
+timer2sbintime(intptr_t data, int flags)
{
+ sbintime_t modifier;
+
+ switch (flags & NOTE_TIMER_PRECMASK) {
+ case NOTE_SECONDS:
+ modifier = SBT_1S;
+ break;
+ case NOTE_MSECONDS: /* FALLTHROUGH */
+ case 0:
+ modifier = SBT_1MS;
+ break;
+ case NOTE_USECONDS:
+ modifier = SBT_1US;
+ break;
+ case NOTE_NSECONDS:
+ modifier = SBT_1NS;
+ break;
+ default:
+ return (-1);
+ }
#ifdef __LP64__
- if (data > SBT_MAX / SBT_1MS)
+ if (data > SBT_MAX / modifier)
return (SBT_MAX);
#endif
- return (SBT_1MS * data);
+ return (modifier * data);
}
static void
@@ -547,13 +570,13 @@ filt_timerexpire(void *knx)
if ((kn->kn_flags & EV_ONESHOT) != EV_ONESHOT) {
calloutp = (struct callout *)kn->kn_hook;
callout_reset_sbt_on(calloutp,
- timer2sbintime(kn->kn_sdata), 0 /* 1ms? */,
+ timer2sbintime(kn->kn_sdata, kn->kn_sfflags), 0,
filt_timerexpire, kn, PCPU_GET(cpuid), 0);
}
}
/*
- * data contains amount of time to sleep, in milliseconds
+ * data contains amount of time to sleep
*/
static int
filt_timerattach(struct knote *kn)
@@ -566,7 +589,11 @@ filt_timerattach(struct knote *kn)
return (EINVAL);
if ((intptr_t)kn->kn_sdata == 0 && (kn->kn_flags & EV_ONESHOT) == 0)
kn->kn_sdata = 1;
- to = timer2sbintime(kn->kn_sdata);
+ /* Only precision unit are supported in flags so far */
+ if (kn->kn_sfflags & ~NOTE_TIMER_PRECMASK)
+ return (EINVAL);
+
+ to = timer2sbintime(kn->kn_sdata, kn->kn_sfflags);
if (to < 0)
return (EINVAL);
@@ -583,7 +610,7 @@ filt_timerattach(struct knote *kn)
calloutp = malloc(sizeof(*calloutp), M_KQUEUE, M_WAITOK);
callout_init(calloutp, CALLOUT_MPSAFE);
kn->kn_hook = calloutp;
- callout_reset_sbt_on(calloutp, to, 0 /* 1ms? */,
+ callout_reset_sbt_on(calloutp, to, 0,
filt_timerexpire, kn, PCPU_GET(cpuid), 0);
return (0);
OpenPOWER on IntegriCloud