From 23905c1c4617135e13d5c828d8bfb5ef751bcc4d Mon Sep 17 00:00:00 2001 From: bde Date: Wed, 25 Sep 2002 12:00:38 +0000 Subject: Round up instead of towards 0 in clock_getres() so that a resolution of 0 is never returned. PR: 41781 MFC after: 3 days --- sys/kern/kern_time.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'sys/kern') diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 417a754..46645ea 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -214,7 +214,12 @@ clock_getres(struct thread *td, struct clock_getres_args *uap) error = 0; if (SCARG(uap, tp)) { ts.tv_sec = 0; - ts.tv_nsec = 1000000000 / tc_getfrequency(); + /* + * Round up the result of the division cheaply by adding 1. + * Rounding up is especially important if rounding down + * would give 0. Perfect rounding is unimportant. + */ + ts.tv_nsec = 1000000000 / tc_getfrequency() + 1; error = copyout(&ts, SCARG(uap, tp), sizeof(ts)); } return (error); -- cgit v1.1