-/* $OpenBSD: clock.c,v 1.73 2022/12/22 19:51:11 cheloha Exp $ */
+/* $OpenBSD: clock.c,v 1.74 2022/12/29 22:44:23 cheloha Exp $ */
/* $NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp $ */
/*
void sys_tick_start(void);
void stick_start(void);
+void tick_rearm(uint64_t);
+void sys_tick_rearm(uint64_t);
void stick_rearm(uint64_t);
int tickintr(void *);
/* Reset the interrupt. */
s = intr_disable();
- tickcmpr_set(ci->ci_tick);
+ tick_rearm(ci->ci_tick);
intr_restore(s);
return (1);
/* Reset the interrupt. */
s = intr_disable();
- sys_tickcmpr_set(ci->ci_tick);
+ sys_tick_rearm(ci->ci_tick);
intr_restore(s);
return (1);
tick_enable();
- /*
- * Try to make the tick interrupts as synchronously as possible on
- * all CPUs to avoid inaccuracies for migrating processes.
- */
-
s = intr_disable();
- ci->ci_tick = roundup(tick(), tick_increment);
- tickcmpr_set(ci->ci_tick);
+ ci->ci_tick = tick();
+ tick_rearm(ci->ci_tick);
intr_restore(s);
}
+void
+tick_rearm(uint64_t cmp)
+{
+ uint64_t now, off = 8;
+
+ tickcmpr_set(cmp);
+ now = tick();
+ while (cmp <= now) {
+ cmp += off;
+ tickcmpr_set(cmp);
+ now = tick();
+ off *= 2;
+ }
+}
+
void
sys_tick_start(void)
{
sys_tick_enable();
}
- /*
- * Try to make the tick interrupts as synchronously as possible on
- * all CPUs to avoid inaccuracies for migrating processes.
- */
-
s = intr_disable();
- ci->ci_tick = roundup(sys_tick(), tick_increment);
- sys_tickcmpr_set(ci->ci_tick);
+ ci->ci_tick = sys_tick();
+ sys_tick_rearm(ci->ci_tick);
intr_restore(s);
}
+void
+sys_tick_rearm(uint64_t cmp)
+{
+ uint64_t now, off = 8;
+
+ sys_tickcmpr_set(cmp);
+ now = sys_tick();
+ while (cmp <= now) {
+ cmp += off;
+ sys_tickcmpr_set(cmp);
+ now = sys_tick();
+ off *= 2;
+ }
+}
+
void
stick_start(void)
{
tick_enable();
- /*
- * Try to make the tick interrupts as synchronously as possible on
- * all CPUs to avoid inaccuracies for migrating processes.
- */
-
s = intr_disable();
ci->ci_tick = stick();
stick_rearm(ci->ci_tick);
-/* $OpenBSD: locore.s,v 1.195 2022/12/22 19:51:11 cheloha Exp $ */
+/* $OpenBSD: locore.s,v 1.196 2022/12/29 22:44:23 cheloha Exp $ */
/* $NetBSD: locore.s,v 1.137 2001/08/13 06:10:10 jdolecek Exp $ */
/*
* sure those two instructions are in the same cache line.
*/
ENTRY(tickcmpr_set)
- ba 1f
- mov 8, %o2 ! Initial step size
.align 64
-1: wr %o0, 0, %tick_cmpr
+ wr %o0, 0, %tick_cmpr
rd %tick_cmpr, %g0
-
- rd %tick, %o1 ! Read current %tick
- sllx %o1, 1, %o1
- srlx %o1, 1, %o1
-
- cmp %o0, %o1 ! Make sure the value we wrote to
- bg,pt %xcc, 2f ! %tick_cmpr was in the future.
- add %o0, %o2, %o0 ! If not, add the step size, double
- ba,pt %xcc, 1b ! the step size and try again.
- sllx %o2, 1, %o2
-2:
retl
nop
END(tickcmpr_set)
END(sys_tick_enable)
ENTRY(sys_tickcmpr_set)
- ba 1f
- mov 8, %o2 ! Initial step size
.align 64
-1: wr %o0, 0, %sys_tick_cmpr
+ wr %o0, 0, %sys_tick_cmpr
rd %sys_tick_cmpr, %g0
-
- rd %sys_tick, %o1 ! Read current %sys_tick
- sllx %o1, 1, %o1
- srlx %o1, 1, %o1
-
- cmp %o0, %o1 ! Make sure the value we wrote to
- bg,pt %xcc, 2f ! %sys_tick_cmpr was in the future.
- add %o0, %o2, %o0 ! If not, add the step size, double
- ba,pt %xcc, 1b ! the step size and try again.
- sllx %o2, 1, %o2
-2:
retl
nop
END(sys_tickcmpr_set)