From 20fffd027438d4ff975fb9000f517bd854b44379 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 3 Mar 2003 05:29:09 +0000 Subject: - Shift the tick count by 10 and back around sched_pctcpu_update() calculations. Keep this changes local to the function so the tick count is in its natural form otherwise. Previously 1000 was added each time a tick fired and we divided by 1000 when it was reported. This is done to reduce rounding errors. --- sys/kern/sched_ule.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 7de1c2e..6379608 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -418,8 +418,14 @@ sched_pctcpu_update(struct kse *ke) /* * Adjust counters and watermark for pctcpu calc. */ + /* + * Shift the tick count out so that the divide doesn't round away + * our results. + */ + ke->ke_ticks <<= 10; ke->ke_ticks = (ke->ke_ticks / (ke->ke_ltick - ke->ke_ftick)) * SCHED_CPU_TICKS; + ke->ke_ticks >>= 10; ke->ke_ltick = ticks; ke->ke_ftick = ke->ke_ltick - SCHED_CPU_TICKS; } @@ -665,7 +671,7 @@ sched_clock(struct thread *td) KASSERT((td != NULL), ("schedclock: null thread pointer")); /* Adjust ticks for pctcpu */ - ke->ke_ticks += 10000; + ke->ke_ticks++; ke->ke_ltick = ticks; /* Go up to one second beyond our max and then trim back down */ if (ke->ke_ftick + SCHED_CPU_TICKS + hz < ke->ke_ltick) @@ -865,7 +871,7 @@ sched_pctcpu(struct kse *ke) sched_pctcpu_update(ke); /* How many rtick per second ? */ - rtick = ke->ke_ticks / (SCHED_CPU_TIME * 10000); + rtick = ke->ke_ticks / SCHED_CPU_TIME; pctcpu = (FSCALE * ((FSCALE * rtick)/realstathz)) >> FSHIFT; } -- cgit v1.1