kern_tc.c (4e82e5f6f12ff08bbb166b47efbdfe312568afdc) | kern_tc.c (4f2073fb4c3f4490496a186153ae2fd0361e8561) |
---|---|
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 */ --- 7 unchanged lines hidden (view full) --- 16#include <sys/kernel.h> 17#include <sys/sysctl.h> 18#include <sys/systm.h> 19#include <sys/timepps.h> 20#include <sys/timetc.h> 21#include <sys/timex.h> 22 23/* | 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 */ --- 7 unchanged lines hidden (view full) --- 16#include <sys/kernel.h> 17#include <sys/sysctl.h> 18#include <sys/systm.h> 19#include <sys/timepps.h> 20#include <sys/timetc.h> 21#include <sys/timex.h> 22 23/* |
24 * a large step happens on boot. This constant detects such 25 * a steps. It is relatively small so that ntp_update_second gets called 26 * enough in the typical 'missed a couple of seconds' case, but doesn't 27 * loop forever when the time step is large. 28 */ 29#define LARGE_STEP 200 30 31/* |
|
24 * Implement a dummy timecounter which we can use until we get a real one 25 * in the air. This allows the console and other early stuff to use 26 * time services. 27 */ 28 29static u_int 30dummy_get_timecount(struct timecounter *tc) 31{ --- 307 unchanged lines hidden (view full) --- 339static void 340tc_windup(void) 341{ 342 struct bintime bt; 343 struct timehands *th, *tho; 344 u_int64_t scale; 345 u_int delta, ncount, ogen; 346 int i; | 32 * Implement a dummy timecounter which we can use until we get a real one 33 * in the air. This allows the console and other early stuff to use 34 * time services. 35 */ 36 37static u_int 38dummy_get_timecount(struct timecounter *tc) 39{ --- 307 unchanged lines hidden (view full) --- 347static void 348tc_windup(void) 349{ 350 struct bintime bt; 351 struct timehands *th, *tho; 352 u_int64_t scale; 353 u_int delta, ncount, ogen; 354 int i; |
355 time_t t; |
|
347 348 /* 349 * Make the next timehands a copy of the current one, but do not 350 * overwrite the generation or next pointer. While we update 351 * the contents, the generation must be zero. 352 */ 353 tho = timehands; 354 th = tho->th_next; --- 21 unchanged lines hidden (view full) --- 376 * the hardware might capture a count which is later than the one we 377 * got above, and therefore possibly in the next NTP second which might 378 * have a different rate than the current NTP second. It doesn't 379 * matter in practice. 380 */ 381 if (tho->th_counter->tc_poll_pps) 382 tho->th_counter->tc_poll_pps(tho->th_counter); 383 | 356 357 /* 358 * Make the next timehands a copy of the current one, but do not 359 * overwrite the generation or next pointer. While we update 360 * the contents, the generation must be zero. 361 */ 362 tho = timehands; 363 th = tho->th_next; --- 21 unchanged lines hidden (view full) --- 385 * the hardware might capture a count which is later than the one we 386 * got above, and therefore possibly in the next NTP second which might 387 * have a different rate than the current NTP second. It doesn't 388 * matter in practice. 389 */ 390 if (tho->th_counter->tc_poll_pps) 391 tho->th_counter->tc_poll_pps(tho->th_counter); 392 |
393 /* 394 * Compute the UTC time, before any leapsecond adjustments, are 395 * made. 396 */ 397 bt = th->th_offset; 398 bintime_add(&bt, &boottimebin); 399 |
|
384 /* 385 * Deal with NTP second processing. The for loop normally only 386 * iterates once, but in extreme situations it might keep NTP sane | 400 /* 401 * Deal with NTP second processing. The for loop normally only 402 * iterates once, but in extreme situations it might keep NTP sane |
387 * if timeouts are not run for several seconds. | 403 * if timeouts are not run for several seconds. At boot, the 404 * time step can be large when the TOD hardware has been read, so 405 * on really large steps, we call ntp_update_second only once. |
388 */ | 406 */ |
389 for (i = th->th_offset.sec - tho->th_offset.sec; i > 0; i--) 390 ntp_update_second(&th->th_adjustment, &th->th_offset.sec); | 407 for (i = bt.sec - tho->th_microtime.tv_sec; i > 0; i--) { 408 t = bt.sec; 409 ntp_update_second(&th->th_adjustment, &bt.sec); 410 if (bt.sec != t) 411 boottimebin.sec += bt.sec - t; 412 if (i > LARGE_STEP) 413 break; 414 } |
391 392 /* Now is a good time to change timecounters. */ 393 if (th->th_counter != timecounter) { 394 th->th_counter = timecounter; 395 th->th_offset_count = ncount; 396 } 397 398 /*- --- 19 unchanged lines hidden (view full) --- 418 * to the goddess of code clarity. 419 * 420 */ 421 scale = (u_int64_t)1 << 63; 422 scale += (th->th_adjustment / 1024) * 2199; 423 scale /= th->th_counter->tc_frequency; 424 th->th_scale = scale * 2; 425 | 415 416 /* Now is a good time to change timecounters. */ 417 if (th->th_counter != timecounter) { 418 th->th_counter = timecounter; 419 th->th_offset_count = ncount; 420 } 421 422 /*- --- 19 unchanged lines hidden (view full) --- 442 * to the goddess of code clarity. 443 * 444 */ 445 scale = (u_int64_t)1 << 63; 446 scale += (th->th_adjustment / 1024) * 2199; 447 scale /= th->th_counter->tc_frequency; 448 th->th_scale = scale * 2; 449 |
426 /* Update the UTC timestamps used for the get*() functions. */ 427 bt = th->th_offset; 428 bintime_add(&bt, &boottimebin); | |
429 bintime2timeval(&bt, &th->th_microtime); 430 bintime2timespec(&bt, &th->th_nanotime); 431 432 /* 433 * Now that the struct timehands is again consistent, set the new 434 * generation number, making sure to not make it zero. 435 */ 436 if (++ogen == 0) --- 264 unchanged lines hidden --- | 450 bintime2timeval(&bt, &th->th_microtime); 451 bintime2timespec(&bt, &th->th_nanotime); 452 453 /* 454 * Now that the struct timehands is again consistent, set the new 455 * generation number, making sure to not make it zero. 456 */ 457 if (++ogen == 0) --- 264 unchanged lines hidden --- |