kern_clocksource.c (a889a65ba36985dfb31111ac1607be35ca2b2c8c) kern_clocksource.c (ece453d5faded062b4a7202a5399fe10417148ef)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2010-2013 Alexander Motin <mav@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 130 unchanged lines hidden (view full) ---

139 sbintime_t now;
140 struct pcpu_state *state;
141 int done;
142
143 if (doconfigtimer() || busy)
144 return (FILTER_HANDLED);
145 state = DPCPU_PTR(timerstate);
146 now = state->now;
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2010-2013 Alexander Motin <mav@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 130 unchanged lines hidden (view full) ---

139 sbintime_t now;
140 struct pcpu_state *state;
141 int done;
142
143 if (doconfigtimer() || busy)
144 return (FILTER_HANDLED);
145 state = DPCPU_PTR(timerstate);
146 now = state->now;
147 CTR3(KTR_SPARE2, "ipi at %d: now %d.%08x",
148 curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
147 CTR2(KTR_SPARE2, "ipi: now %d.%08x",
148 (int)(now >> 32), (u_int)(now & 0xffffffff));
149 done = handleevents(now, 0);
150 return (done ? FILTER_HANDLED : FILTER_STRAY);
151}
152
153/*
154 * Handle all events for specified time on this CPU
155 */
156static int
157handleevents(sbintime_t now, int fake)
158{
159 sbintime_t t, *hct;
160 struct trapframe *frame;
161 struct pcpu_state *state;
162 int usermode;
163 int done, runs;
164
149 done = handleevents(now, 0);
150 return (done ? FILTER_HANDLED : FILTER_STRAY);
151}
152
153/*
154 * Handle all events for specified time on this CPU
155 */
156static int
157handleevents(sbintime_t now, int fake)
158{
159 sbintime_t t, *hct;
160 struct trapframe *frame;
161 struct pcpu_state *state;
162 int usermode;
163 int done, runs;
164
165 CTR3(KTR_SPARE2, "handle at %d: now %d.%08x",
166 curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
165 CTR2(KTR_SPARE2, "handle: now %d.%08x",
166 (int)(now >> 32), (u_int)(now & 0xffffffff));
167 done = 0;
168 if (fake) {
169 frame = NULL;
170 usermode = 0;
171 } else {
172 frame = curthread->td_intr_frame;
173 usermode = TRAPF_USERMODE(frame);
174 }

--- 110 unchanged lines hidden (view full) ---

285 event = state->nextevent;
286#ifdef KTR
287 c = cpu;
288#endif
289 }
290 }
291 }
292#endif
167 done = 0;
168 if (fake) {
169 frame = NULL;
170 usermode = 0;
171 } else {
172 frame = curthread->td_intr_frame;
173 usermode = TRAPF_USERMODE(frame);
174 }

--- 110 unchanged lines hidden (view full) ---

285 event = state->nextevent;
286#ifdef KTR
287 c = cpu;
288#endif
289 }
290 }
291 }
292#endif
293 CTR4(KTR_SPARE2, "next at %d: next %d.%08x by %d",
294 curcpu, (int)(event >> 32), (u_int)(event & 0xffffffff), c);
293 CTR3(KTR_SPARE2, "next: next %d.%08x by %d",
294 (int)(event >> 32), (u_int)(event & 0xffffffff), c);
295 return (event);
296}
297
298/* Hardware timer callback function. */
299static void
300timercb(struct eventtimer *et, void *arg)
301{
302 sbintime_t now;

--- 13 unchanged lines hidden (view full) ---

316 } else
317 next = &nexttick;
318 now = sbinuptime();
319 if (periodic)
320 *next = now + timerperiod;
321 else
322 *next = -1; /* Next tick is not scheduled yet. */
323 state->now = now;
295 return (event);
296}
297
298/* Hardware timer callback function. */
299static void
300timercb(struct eventtimer *et, void *arg)
301{
302 sbintime_t now;

--- 13 unchanged lines hidden (view full) ---

316 } else
317 next = &nexttick;
318 now = sbinuptime();
319 if (periodic)
320 *next = now + timerperiod;
321 else
322 *next = -1; /* Next tick is not scheduled yet. */
323 state->now = now;
324 CTR3(KTR_SPARE2, "intr at %d: now %d.%08x",
325 curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
324 CTR2(KTR_SPARE2, "intr: now %d.%08x",
325 (int)(now >> 32), (u_int)(now & 0xffffffff));
326
327#ifdef SMP
328#ifdef EARLY_AP_STARTUP
329 MPASS(mp_ncpus == 1 || smp_started);
330#endif
331 /* Prepare broadcasting to other CPUs for non-per-CPU timers. */
332 bcast = 0;
333#ifdef EARLY_AP_STARTUP

--- 58 unchanged lines hidden (view full) ---

392 /*
393 * Try to start all periodic timers aligned
394 * to period to make events synchronous.
395 */
396 tmp = now % timerperiod;
397 new = timerperiod - tmp;
398 if (new < tmp) /* Left less then passed. */
399 new += timerperiod;
326
327#ifdef SMP
328#ifdef EARLY_AP_STARTUP
329 MPASS(mp_ncpus == 1 || smp_started);
330#endif
331 /* Prepare broadcasting to other CPUs for non-per-CPU timers. */
332 bcast = 0;
333#ifdef EARLY_AP_STARTUP

--- 58 unchanged lines hidden (view full) ---

392 /*
393 * Try to start all periodic timers aligned
394 * to period to make events synchronous.
395 */
396 tmp = now % timerperiod;
397 new = timerperiod - tmp;
398 if (new < tmp) /* Left less then passed. */
399 new += timerperiod;
400 CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x",
401 curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff),
400 CTR4(KTR_SPARE2, "load p: now %d.%08x first in %d.%08x",
401 (int)(now >> 32), (u_int)(now & 0xffffffff),
402 (int)(new >> 32), (u_int)(new & 0xffffffff));
403 *next = new + now;
404 et_start(timer, new, timerperiod);
405 }
406 } else {
407 new = getnextevent(state);
408 eq = (new == *next);
402 (int)(new >> 32), (u_int)(new & 0xffffffff));
403 *next = new + now;
404 et_start(timer, new, timerperiod);
405 }
406 } else {
407 new = getnextevent(state);
408 eq = (new == *next);
409 CTR4(KTR_SPARE2, "load at %d: next %d.%08x eq %d",
410 curcpu, (int)(new >> 32), (u_int)(new & 0xffffffff), eq);
409 CTR3(KTR_SPARE2, "load: next %d.%08x eq %d",
410 (int)(new >> 32), (u_int)(new & 0xffffffff), eq);
411 if (!eq) {
412 *next = new;
413 et_start(timer, new - now, 0);
414 }
415 }
416}
417
418/*

--- 348 unchanged lines hidden (view full) ---

767 )
768 return (-1);
769 state = DPCPU_PTR(timerstate);
770 ET_HW_LOCK(state);
771 if (periodic)
772 now = state->now;
773 else
774 now = sbinuptime();
411 if (!eq) {
412 *next = new;
413 et_start(timer, new - now, 0);
414 }
415 }
416}
417
418/*

--- 348 unchanged lines hidden (view full) ---

767 )
768 return (-1);
769 state = DPCPU_PTR(timerstate);
770 ET_HW_LOCK(state);
771 if (periodic)
772 now = state->now;
773 else
774 now = sbinuptime();
775 CTR3(KTR_SPARE2, "idle at %d: now %d.%08x",
776 curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
775 CTR2(KTR_SPARE2, "idle: now %d.%08x",
776 (int)(now >> 32), (u_int)(now & 0xffffffff));
777 t = getnextcpuevent(state, 1);
778 state->idle = 1;
779 state->nextevent = t;
780 if (!periodic)
781 loadtimer(now, 0);
782 ET_HW_UNLOCK(state);
783 return (MAX(t - now, 0));
784}

--- 11 unchanged lines hidden (view full) ---

796 state = DPCPU_PTR(timerstate);
797 if (atomic_load_int(&state->idle) == 0 || busy)
798 return;
799 spinlock_enter();
800 if (periodic)
801 now = state->now;
802 else
803 now = sbinuptime();
777 t = getnextcpuevent(state, 1);
778 state->idle = 1;
779 state->nextevent = t;
780 if (!periodic)
781 loadtimer(now, 0);
782 ET_HW_UNLOCK(state);
783 return (MAX(t - now, 0));
784}

--- 11 unchanged lines hidden (view full) ---

796 state = DPCPU_PTR(timerstate);
797 if (atomic_load_int(&state->idle) == 0 || busy)
798 return;
799 spinlock_enter();
800 if (periodic)
801 now = state->now;
802 else
803 now = sbinuptime();
804 CTR3(KTR_SPARE2, "active at %d: now %d.%08x",
805 curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff));
804 CTR2(KTR_SPARE2, "active: now %d.%08x",
805 (int)(now >> 32), (u_int)(now & 0xffffffff));
806 td = curthread;
807 td->td_intr_nesting_level++;
808 handleevents(now, 1);
809 td->td_intr_nesting_level--;
810 spinlock_exit();
811}
812
813/*

--- 18 unchanged lines hidden (view full) ---

832void
833cpu_new_callout(int cpu, sbintime_t bt, sbintime_t bt_opt)
834{
835 struct pcpu_state *state;
836
837 /* Do not touch anything if somebody reconfiguring timers. */
838 if (busy)
839 return;
806 td = curthread;
807 td->td_intr_nesting_level++;
808 handleevents(now, 1);
809 td->td_intr_nesting_level--;
810 spinlock_exit();
811}
812
813/*

--- 18 unchanged lines hidden (view full) ---

832void
833cpu_new_callout(int cpu, sbintime_t bt, sbintime_t bt_opt)
834{
835 struct pcpu_state *state;
836
837 /* Do not touch anything if somebody reconfiguring timers. */
838 if (busy)
839 return;
840 CTR6(KTR_SPARE2, "new co at %d: on %d at %d.%08x - %d.%08x",
841 curcpu, cpu, (int)(bt_opt >> 32), (u_int)(bt_opt & 0xffffffff),
840
841 CTR5(KTR_SPARE2, "new co: on %d at %d.%08x - %d.%08x",
842 cpu, (int)(bt_opt >> 32), (u_int)(bt_opt & 0xffffffff),
842 (int)(bt >> 32), (u_int)(bt & 0xffffffff));
843
844 KASSERT(!CPU_ABSENT(cpu), ("Absent CPU %d", cpu));
845 state = DPCPU_ID_PTR(cpu, timerstate);
846 ET_HW_LOCK(state);
847
848 /*
849 * If there is callout time already set earlier -- do nothing.

--- 136 unchanged lines hidden ---
843 (int)(bt >> 32), (u_int)(bt & 0xffffffff));
844
845 KASSERT(!CPU_ABSENT(cpu), ("Absent CPU %d", cpu));
846 state = DPCPU_ID_PTR(cpu, timerstate);
847 ET_HW_LOCK(state);
848
849 /*
850 * If there is callout time already set earlier -- do nothing.

--- 136 unchanged lines hidden ---