Deleted Added
full compact
kern_clock.c (34901) kern_clock.c (34961)
1static volatile int print_tci = 1;
2
3/*-
4 * Copyright (c) 1997, 1998 Poul-Henning Kamp <phk@FreeBSD.org>
5 * Copyright (c) 1982, 1986, 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed

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

34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
1static volatile int print_tci = 1;
2
3/*-
4 * Copyright (c) 1997, 1998 Poul-Henning Kamp <phk@FreeBSD.org>
5 * Copyright (c) 1982, 1986, 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed

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

34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
42 * $Id: kern_clock.c,v 1.58 1998/03/16 10:19:12 phk Exp $
42 * $Id: kern_clock.c,v 1.59 1998/03/26 20:51:31 phk Exp $
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/dkstat.h>
48#include <sys/callout.h>
49#include <sys/kernel.h>
50#include <sys/proc.h>

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

92
93long tk_cancc;
94long tk_nin;
95long tk_nout;
96long tk_rawcc;
97
98struct timecounter *timecounter;
99
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/dkstat.h>
48#include <sys/callout.h>
49#include <sys/kernel.h>
50#include <sys/proc.h>

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

92
93long tk_cancc;
94long tk_nin;
95long tk_nout;
96long tk_rawcc;
97
98struct timecounter *timecounter;
99
100time_t time_second;
101
100/*
101 * Clock handling routines.
102 *
103 * This code is written to operate with two timers that run independently of
104 * each other.
105 *
106 * The main timer, running hz times per second, is used to trigger interval
107 * timers, timeouts and rescheduling as needed.

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

131
132int stathz;
133int profhz;
134static int profprocs;
135int ticks;
136static int psdiv, pscnt; /* prof => stat divider */
137int psratio; /* ratio: prof / stat */
138
102/*
103 * Clock handling routines.
104 *
105 * This code is written to operate with two timers that run independently of
106 * each other.
107 *
108 * The main timer, running hz times per second, is used to trigger interval
109 * timers, timeouts and rescheduling as needed.

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

133
134int stathz;
135int profhz;
136static int profprocs;
137int ticks;
138static int psdiv, pscnt; /* prof => stat divider */
139int psratio; /* ratio: prof / stat */
140
139struct timeval time;
140volatile struct timeval mono_time;
141
142/*
143 * Initialize clock frequencies and start both clocks running.
144 */
145/* ARGSUSED*/
146static void
147initclocks(dummy)

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

218 softclock();
219 } else
220 setsoftclock();
221 } else if (softticks + 1 == ticks)
222 ++softticks;
223}
224
225/*
141volatile struct timeval mono_time;
142
143/*
144 * Initialize clock frequencies and start both clocks running.
145 */
146/* ARGSUSED*/
147static void
148initclocks(dummy)

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

219 softclock();
220 } else
221 setsoftclock();
222 } else if (softticks + 1 == ticks)
223 ++softticks;
224}
225
226/*
226 * Compute number of hz until specified time. Used to
227 * compute third argument to timeout() from an absolute time.
228 * XXX this interface is often inconvenient. We often just need the
229 * number of ticks in a timeval, but to use hzto() for that we have
230 * to add `time' to the timeval and do everything at splclock().
227 * Compute number of ticks in the specified amount of time.
231 */
232int
228 */
229int
233hzto(tv)
230tvtohz(tv)
234 struct timeval *tv;
235{
236 register unsigned long ticks;
237 register long sec, usec;
238 int s;
239
240 /*
241 * If the number of usecs in the whole seconds part of the time

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

252 * case but it is slightly slower and assumes that hz is integral.
253 *
254 * Otherwise, round the time difference down to the maximum
255 * representable value.
256 *
257 * If ints have 32 bits, then the maximum value for any timeout in
258 * 10ms ticks is 248 days.
259 */
231 struct timeval *tv;
232{
233 register unsigned long ticks;
234 register long sec, usec;
235 int s;
236
237 /*
238 * If the number of usecs in the whole seconds part of the time

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

249 * case but it is slightly slower and assumes that hz is integral.
250 *
251 * Otherwise, round the time difference down to the maximum
252 * representable value.
253 *
254 * If ints have 32 bits, then the maximum value for any timeout in
255 * 10ms ticks is 248 days.
256 */
260 s = splclock();
261 sec = tv->tv_sec - time.tv_sec;
262 usec = tv->tv_usec - time.tv_usec;
263 splx(s);
257 sec = tv->tv_sec;
258 usec = tv->tv_usec;
264 if (usec < 0) {
265 sec--;
266 usec += 1000000;
267 }
268 if (sec < 0) {
269#ifdef DIAGNOSTIC
270 if (usec > 0) {
271 sec++;
272 usec -= 1000000;
273 }
259 if (usec < 0) {
260 sec--;
261 usec += 1000000;
262 }
263 if (sec < 0) {
264#ifdef DIAGNOSTIC
265 if (usec > 0) {
266 sec++;
267 usec -= 1000000;
268 }
274 printf("hzto: negative time difference %ld sec %ld usec\n",
269 printf("tvotohz: negative time difference %ld sec %ld usec\n",
275 sec, usec);
276#endif
277 ticks = 1;
278 } else if (sec <= LONG_MAX / 1000000)
279 ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1))
280 / tick + 1;
281 else if (sec <= LONG_MAX / hz)
282 ticks = sec * hz
283 + ((unsigned long)usec + (tick - 1)) / tick + 1;
284 else
285 ticks = LONG_MAX;
286 if (ticks > INT_MAX)
287 ticks = INT_MAX;
288 return (ticks);
289}
290
270 sec, usec);
271#endif
272 ticks = 1;
273 } else if (sec <= LONG_MAX / 1000000)
274 ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1))
275 / tick + 1;
276 else if (sec <= LONG_MAX / hz)
277 ticks = sec * hz
278 + ((unsigned long)usec + (tick - 1)) / tick + 1;
279 else
280 ticks = LONG_MAX;
281 if (ticks > INT_MAX)
282 ticks = INT_MAX;
283 return (ticks);
284}
285
286
291/*
287/*
288 * Compute number of hz until specified time. Used to
289 * compute third argument to timeout() from an absolute time.
290 */
291int
292hzto(tv)
293 struct timeval *tv;
294{
295 register long sec, usec;
296 struct timeval t2;
297
298 getmicrotime(&t2);
299 t2.tv_sec = tv->tv_sec - t2.tv_sec;
300 t2.tv_usec = tv->tv_usec - t2.tv_usec;
301 return (tvtohz(&t2));
302}
303
304/*
292 * Start profiling on a process.
293 *
294 * Kernel profiling passes proc0 which never exits and hence
295 * keeps the profile clock running constantly.
296 */
297void
298startprofclock(p)
299 register struct proc *p;

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

632 tc = timecounter->other;
633 tco = tc->other;
634 *tc = *timecounter;
635 tc->other = tco;
636 tc->offset_sec = ts->tv_sec;
637 tc->offset_nano = (u_int64_t)ts->tv_nsec << 32;
638 tc->offset_micro = ts->tv_nsec / 1000;
639 tc->offset_count = tc->get_timecount();
305 * Start profiling on a process.
306 *
307 * Kernel profiling passes proc0 which never exits and hence
308 * keeps the profile clock running constantly.
309 */
310void
311startprofclock(p)
312 register struct proc *p;

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

645 tc = timecounter->other;
646 tco = tc->other;
647 *tc = *timecounter;
648 tc->other = tco;
649 tc->offset_sec = ts->tv_sec;
650 tc->offset_nano = (u_int64_t)ts->tv_nsec << 32;
651 tc->offset_micro = ts->tv_nsec / 1000;
652 tc->offset_count = tc->get_timecount();
640 time.tv_sec = tc->offset_sec;
641 time.tv_usec = tc->offset_micro;
653 time_second = tc->offset_sec;
642 timecounter = tc;
643 splx(s);
644}
645
646void
647switch_timecounter(struct timecounter *newtc)
648{
649 int s;

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

706 tc->frequency = tc->tweak->frequency;
707 tc->adjustment = tc->tweak->adjustment;
708 ntp_update_second(tc); /* XXX only needed if xntpd runs */
709 tco_setscales(tc);
710 }
711
712 tc->offset_micro = (tc->offset_nano / 1000) >> 32;
713
654 timecounter = tc;
655 splx(s);
656}
657
658void
659switch_timecounter(struct timecounter *newtc)
660{
661 int s;

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

718 tc->frequency = tc->tweak->frequency;
719 tc->adjustment = tc->tweak->adjustment;
720 ntp_update_second(tc); /* XXX only needed if xntpd runs */
721 tco_setscales(tc);
722 }
723
724 tc->offset_micro = (tc->offset_nano / 1000) >> 32;
725
714 time.tv_usec = tc->offset_micro;
715 time.tv_sec = tc->offset_sec;
726 time_second = tc->offset_sec;
716 timecounter = tc;
717}
718
719static int
720sysctl_kern_timecounter_frequency SYSCTL_HANDLER_ARGS
721{
722
723 return (sysctl_handle_opaque(oidp, &timecounter->tweak->frequency,

--- 18 unchanged lines hidden ---
727 timecounter = tc;
728}
729
730static int
731sysctl_kern_timecounter_frequency SYSCTL_HANDLER_ARGS
732{
733
734 return (sysctl_handle_opaque(oidp, &timecounter->tweak->frequency,

--- 18 unchanged lines hidden ---