kern_tc.c (118842) | kern_tc.c (118987) |
---|---|
1/*- 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 */ 9 10#include <sys/cdefs.h> | 1/*- 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 */ 9 10#include <sys/cdefs.h> |
11__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 118842 2003-08-12 20:34:31Z mux $"); | 11__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 118987 2003-08-16 08:23:53Z phk $"); |
12 13#include "opt_ntp.h" 14 15#include <sys/param.h> 16#include <sys/kernel.h> 17#include <sys/sysctl.h> 18#include <sys/systm.h> 19#include <sys/timepps.h> --- 18 unchanged lines hidden (view full) --- 38dummy_get_timecount(struct timecounter *tc) 39{ 40 static u_int now; 41 42 return (++now); 43} 44 45static struct timecounter dummy_timecounter = { | 12 13#include "opt_ntp.h" 14 15#include <sys/param.h> 16#include <sys/kernel.h> 17#include <sys/sysctl.h> 18#include <sys/systm.h> 19#include <sys/timepps.h> --- 18 unchanged lines hidden (view full) --- 38dummy_get_timecount(struct timecounter *tc) 39{ 40 static u_int now; 41 42 return (++now); 43} 44 45static struct timecounter dummy_timecounter = { |
46 dummy_get_timecount, 0, ~0u, 1000000, "dummy", | 46 dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000 |
47}; 48 49struct timehands { 50 /* These fields must be initialized by the driver. */ 51 struct timecounter *th_counter; 52 int64_t th_adjustment; 53 u_int64_t th_scale; 54 u_int th_offset_count; --- 221 unchanged lines hidden (view full) --- 276 do { 277 th = timehands; 278 gen = th->th_generation; 279 *tvp = th->th_microtime; 280 } while (gen == 0 || gen != th->th_generation); 281} 282 283/* | 47}; 48 49struct timehands { 50 /* These fields must be initialized by the driver. */ 51 struct timecounter *th_counter; 52 int64_t th_adjustment; 53 u_int64_t th_scale; 54 u_int th_offset_count; --- 221 unchanged lines hidden (view full) --- 276 do { 277 th = timehands; 278 gen = th->th_generation; 279 *tvp = th->th_microtime; 280 } while (gen == 0 || gen != th->th_generation); 281} 282 283/* |
284 * Initialize a new timecounter. 285 * We should really try to rank the timecounters and intelligently determine 286 * if the new timecounter is better than the current one. This is subject 287 * to further study. For now always use the new timecounter. | 284 * Initialize a new timecounter and possibly use it. |
288 */ 289void 290tc_init(struct timecounter *tc) 291{ 292 unsigned u; 293 | 285 */ 286void 287tc_init(struct timecounter *tc) 288{ 289 unsigned u; 290 |
294 printf("Timecounter \"%s\" frequency %ju Hz", 295 tc->tc_name, (intmax_t)tc->tc_frequency); | 291 if (tc->tc_quality >= 0 || bootverbose) 292 printf("Timecounter \"%s\" frequency %ju Hz quality %d", 293 tc->tc_name, (intmax_t)tc->tc_frequency, 294 tc->tc_quality); |
296 297 u = tc->tc_frequency / tc->tc_counter_mask; 298 if (u > hz) { 299 printf(" -- Insufficient hz, needs at least %u\n", u); 300 return; 301 } | 295 296 u = tc->tc_frequency / tc->tc_counter_mask; 297 if (u > hz) { 298 printf(" -- Insufficient hz, needs at least %u\n", u); 299 return; 300 } |
301 printf("\n"); |
|
302 tc->tc_next = timecounters; 303 timecounters = tc; | 302 tc->tc_next = timecounters; 303 timecounters = tc; |
304 printf("\n"); | |
305 (void)tc->tc_get_timecount(tc); 306 (void)tc->tc_get_timecount(tc); | 304 (void)tc->tc_get_timecount(tc); 305 (void)tc->tc_get_timecount(tc); |
306 /* Never automatically use a timecounter with negative quality */ 307 if (tc->tc_quality < 0) 308 return; 309 if (tc->tc_quality < timecounter->tc_quality) 310 return; |
|
307 timecounter = tc; 308} 309 310/* Report the frequency of the current timecounter. */ 311u_int64_t 312tc_getfrequency(void) 313{ 314 --- 176 unchanged lines hidden (view full) --- 491 return (0); 492 } 493 return (EINVAL); 494} 495 496SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | CTLFLAG_RW, 497 0, 0, sysctl_kern_timecounter_hardware, "A", ""); 498 | 311 timecounter = tc; 312} 313 314/* Report the frequency of the current timecounter. */ 315u_int64_t 316tc_getfrequency(void) 317{ 318 --- 176 unchanged lines hidden (view full) --- 495 return (0); 496 } 497 return (EINVAL); 498} 499 500SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | CTLFLAG_RW, 501 0, 0, sysctl_kern_timecounter_hardware, "A", ""); 502 |
503 504/* Report or change the active timecounter hardware. */ 505static int 506sysctl_kern_timecounter_choice(SYSCTL_HANDLER_ARGS) 507{ 508 char buf[32], *spc; 509 struct timecounter *tc; 510 int error; 511 512 spc = ""; 513 error = 0; 514 for (tc = timecounters; error == 0 && tc != NULL; tc = tc->tc_next) { 515 sprintf(buf, "%s%s(%d)", 516 spc, tc->tc_name, tc->tc_quality); 517 error = SYSCTL_OUT(req, buf, strlen(buf)); 518 spc = " "; 519 } 520 return (error); 521} 522 523SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD, 524 0, 0, sysctl_kern_timecounter_choice, "A", ""); 525 |
|
499/* 500 * RFC 2783 PPS-API implementation. 501 */ 502 503int 504pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps) 505{ 506 pps_params_t *app; --- 215 unchanged lines hidden --- | 526/* 527 * RFC 2783 PPS-API implementation. 528 */ 529 530int 531pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps) 532{ 533 pps_params_t *app; --- 215 unchanged lines hidden --- |