Round up instead of towards 0 in clock_getres() so that a resolution of

0 is never returned.

PR:		41781
MFC after:	3 days
This commit is contained in:
Bruce Evans 2002-09-25 12:00:38 +00:00
parent 3ec6f79c1e
commit ac0653dcc8

View File

@ -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);