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 * ----------------------------------------------------------------------------
10 #include <sys/cdefs.h>
11 __FBSDID("$FreeBSD$");
15 #include <sys/param.h>
16 #include <sys/kernel.h>
17 #include <sys/sysctl.h>
18 #include <sys/syslog.h>
19 #include <sys/systm.h>
20 #include <sys/timepps.h>
21 #include <sys/timetc.h>
22 #include <sys/timex.h>
25 * A large step happens on boot. This constant detects such steps.
26 * It is relatively small so that ntp_update_second gets called enough
27 * in the typical 'missed a couple of seconds' case, but doesn't loop
28 * forever when the time step is large.
30 #define LARGE_STEP 200
33 * Implement a dummy timecounter which we can use until we get a real one
34 * in the air. This allows the console and other early stuff to use
39 dummy_get_timecount(struct timecounter *tc)
46 static struct timecounter dummy_timecounter = {
47 dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000
51 /* These fields must be initialized by the driver. */
52 struct timecounter *th_counter;
53 int64_t th_adjustment;
55 u_int th_offset_count;
56 struct bintime th_offset;
57 struct timeval th_microtime;
58 struct timespec th_nanotime;
59 /* Fields not to be copied in tc_windup start with th_generation. */
60 volatile u_int th_generation;
61 struct timehands *th_next;
64 static struct timehands th0;
65 static struct timehands th9 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th0};
66 static struct timehands th8 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th9};
67 static struct timehands th7 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th8};
68 static struct timehands th6 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th7};
69 static struct timehands th5 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th6};
70 static struct timehands th4 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th5};
71 static struct timehands th3 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th4};
72 static struct timehands th2 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th3};
73 static struct timehands th1 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th2};
74 static struct timehands th0 = {
77 (uint64_t)-1 / 1000000,
86 static struct timehands *volatile timehands = &th0;
87 struct timecounter *timecounter = &dummy_timecounter;
88 static struct timecounter *timecounters = &dummy_timecounter;
90 time_t time_second = 1;
91 time_t time_uptime = 1;
93 static struct bintime boottimebin;
94 struct timeval boottime;
95 static int sysctl_kern_boottime(SYSCTL_HANDLER_ARGS);
96 SYSCTL_PROC(_kern, KERN_BOOTTIME, boottime, CTLTYPE_STRUCT|CTLFLAG_RD,
97 NULL, 0, sysctl_kern_boottime, "S,timeval", "System boottime");
99 SYSCTL_NODE(_kern, OID_AUTO, timecounter, CTLFLAG_RW, 0, "");
101 static int timestepwarnings;
102 SYSCTL_INT(_kern_timecounter, OID_AUTO, stepwarnings, CTLFLAG_RW,
103 ×tepwarnings, 0, "");
105 #define TC_STATS(foo) \
107 SYSCTL_UINT(_kern_timecounter, OID_AUTO, foo, CTLFLAG_RD, &foo, 0, "");\
110 TC_STATS(nbinuptime); TC_STATS(nnanouptime); TC_STATS(nmicrouptime);
111 TC_STATS(nbintime); TC_STATS(nnanotime); TC_STATS(nmicrotime);
112 TC_STATS(ngetbinuptime); TC_STATS(ngetnanouptime); TC_STATS(ngetmicrouptime);
113 TC_STATS(ngetbintime); TC_STATS(ngetnanotime); TC_STATS(ngetmicrotime);
118 static void tc_windup(void);
119 static void cpu_tick_calibrate(int);
122 sysctl_kern_boottime(SYSCTL_HANDLER_ARGS)
127 if (req->flags & SCTL_MASK32) {
128 tv[0] = boottime.tv_sec;
129 tv[1] = boottime.tv_usec;
130 return SYSCTL_OUT(req, tv, sizeof(tv));
133 return SYSCTL_OUT(req, &boottime, sizeof(boottime));
137 * Return the difference between the timehands' counter value now and what
138 * was when we copied it to the timehands' offset_count.
140 static __inline u_int
141 tc_delta(struct timehands *th)
143 struct timecounter *tc;
146 return ((tc->tc_get_timecount(tc) - th->th_offset_count) &
147 tc->tc_counter_mask);
151 * Functions for reading the time. We have to loop until we are sure that
152 * the timehands that we operated on was not updated under our feet. See
153 * the comment in <sys/time.h> for a description of these 12 functions.
157 binuptime(struct bintime *bt)
159 struct timehands *th;
165 gen = th->th_generation;
167 bintime_addx(bt, th->th_scale * tc_delta(th));
168 } while (gen == 0 || gen != th->th_generation);
172 nanouptime(struct timespec *tsp)
178 bintime2timespec(&bt, tsp);
182 microuptime(struct timeval *tvp)
188 bintime2timeval(&bt, tvp);
192 bintime(struct bintime *bt)
197 bintime_add(bt, &boottimebin);
201 nanotime(struct timespec *tsp)
207 bintime2timespec(&bt, tsp);
211 microtime(struct timeval *tvp)
217 bintime2timeval(&bt, tvp);
221 getbinuptime(struct bintime *bt)
223 struct timehands *th;
229 gen = th->th_generation;
231 } while (gen == 0 || gen != th->th_generation);
235 getnanouptime(struct timespec *tsp)
237 struct timehands *th;
243 gen = th->th_generation;
244 bintime2timespec(&th->th_offset, tsp);
245 } while (gen == 0 || gen != th->th_generation);
249 getmicrouptime(struct timeval *tvp)
251 struct timehands *th;
257 gen = th->th_generation;
258 bintime2timeval(&th->th_offset, tvp);
259 } while (gen == 0 || gen != th->th_generation);
263 getbintime(struct bintime *bt)
265 struct timehands *th;
271 gen = th->th_generation;
273 } while (gen == 0 || gen != th->th_generation);
274 bintime_add(bt, &boottimebin);
278 getnanotime(struct timespec *tsp)
280 struct timehands *th;
286 gen = th->th_generation;
287 *tsp = th->th_nanotime;
288 } while (gen == 0 || gen != th->th_generation);
292 getmicrotime(struct timeval *tvp)
294 struct timehands *th;
300 gen = th->th_generation;
301 *tvp = th->th_microtime;
302 } while (gen == 0 || gen != th->th_generation);
306 * Initialize a new timecounter and possibly use it.
309 tc_init(struct timecounter *tc)
313 u = tc->tc_frequency / tc->tc_counter_mask;
314 /* XXX: We need some margin here, 10% is a guess */
317 if (u > hz && tc->tc_quality >= 0) {
318 tc->tc_quality = -2000;
320 printf("Timecounter \"%s\" frequency %ju Hz",
321 tc->tc_name, (uintmax_t)tc->tc_frequency);
322 printf(" -- Insufficient hz, needs at least %u\n", u);
324 } else if (tc->tc_quality >= 0 || bootverbose) {
325 printf("Timecounter \"%s\" frequency %ju Hz quality %d\n",
326 tc->tc_name, (uintmax_t)tc->tc_frequency,
330 tc->tc_next = timecounters;
333 * Never automatically use a timecounter with negative quality.
334 * Even though we run on the dummy counter, switching here may be
335 * worse since this timecounter may not be monotonous.
337 if (tc->tc_quality < 0)
339 if (tc->tc_quality < timecounter->tc_quality)
341 if (tc->tc_quality == timecounter->tc_quality &&
342 tc->tc_frequency < timecounter->tc_frequency)
344 (void)tc->tc_get_timecount(tc);
345 (void)tc->tc_get_timecount(tc);
349 /* Report the frequency of the current timecounter. */
351 tc_getfrequency(void)
354 return (timehands->th_counter->tc_frequency);
358 * Step our concept of UTC. This is done by modifying our estimate of
363 tc_setclock(struct timespec *ts)
365 struct timespec tbef, taft;
366 struct bintime bt, bt2;
368 cpu_tick_calibrate(1);
371 timespec2bintime(ts, &bt);
373 bintime_sub(&bt, &bt2);
374 bintime_add(&bt2, &boottimebin);
376 bintime2timeval(&bt, &boottime);
378 /* XXX fiddle all the little crinkly bits around the fiords... */
381 if (timestepwarnings) {
383 "Time stepped from %jd.%09ld to %jd.%09ld (%jd.%09ld)\n",
384 (intmax_t)tbef.tv_sec, tbef.tv_nsec,
385 (intmax_t)taft.tv_sec, taft.tv_nsec,
386 (intmax_t)ts->tv_sec, ts->tv_nsec);
388 cpu_tick_calibrate(1);
392 * Initialize the next struct timehands in the ring and make
393 * it the active timehands. Along the way we might switch to a different
394 * timecounter and/or do seconds processing in NTP. Slightly magic.
400 struct timehands *th, *tho;
402 u_int delta, ncount, ogen;
407 * Make the next timehands a copy of the current one, but do not
408 * overwrite the generation or next pointer. While we update
409 * the contents, the generation must be zero.
413 ogen = th->th_generation;
414 th->th_generation = 0;
415 bcopy(tho, th, offsetof(struct timehands, th_generation));
418 * Capture a timecounter delta on the current timecounter and if
419 * changing timecounters, a counter value from the new timecounter.
420 * Update the offset fields accordingly.
422 delta = tc_delta(th);
423 if (th->th_counter != timecounter)
424 ncount = timecounter->tc_get_timecount(timecounter);
427 th->th_offset_count += delta;
428 th->th_offset_count &= th->th_counter->tc_counter_mask;
429 bintime_addx(&th->th_offset, th->th_scale * delta);
432 * Hardware latching timecounters may not generate interrupts on
433 * PPS events, so instead we poll them. There is a finite risk that
434 * the hardware might capture a count which is later than the one we
435 * got above, and therefore possibly in the next NTP second which might
436 * have a different rate than the current NTP second. It doesn't
437 * matter in practice.
439 if (tho->th_counter->tc_poll_pps)
440 tho->th_counter->tc_poll_pps(tho->th_counter);
443 * Deal with NTP second processing. The for loop normally
444 * iterates at most once, but in extreme situations it might
445 * keep NTP sane if timeouts are not run for several seconds.
446 * At boot, the time step can be large when the TOD hardware
447 * has been read, so on really large steps, we call
448 * ntp_update_second only twice. We need to call it twice in
449 * case we missed a leap second.
452 bintime_add(&bt, &boottimebin);
453 i = bt.sec - tho->th_microtime.tv_sec;
458 ntp_update_second(&th->th_adjustment, &bt.sec);
460 boottimebin.sec += bt.sec - t;
462 /* Update the UTC timestamps used by the get*() functions. */
463 /* XXX shouldn't do this here. Should force non-`get' versions. */
464 bintime2timeval(&bt, &th->th_microtime);
465 bintime2timespec(&bt, &th->th_nanotime);
467 /* Now is a good time to change timecounters. */
468 if (th->th_counter != timecounter) {
469 th->th_counter = timecounter;
470 th->th_offset_count = ncount;
474 * Recalculate the scaling factor. We want the number of 1/2^64
475 * fractions of a second per period of the hardware counter, taking
476 * into account the th_adjustment factor which the NTP PLL/adjtime(2)
477 * processing provides us with.
479 * The th_adjustment is nanoseconds per second with 32 bit binary
480 * fraction and we want 64 bit binary fraction of second:
482 * x = a * 2^32 / 10^9 = a * 4.294967296
484 * The range of th_adjustment is +/- 5000PPM so inside a 64bit int
485 * we can only multiply by about 850 without overflowing, that
486 * leaves no suitably precise fractions for multiply before divide.
488 * Divide before multiply with a fraction of 2199/512 results in a
489 * systematic undercompensation of 10PPM of th_adjustment. On a
490 * 5000PPM adjustment this is a 0.05PPM error. This is acceptable.
492 * We happily sacrifice the lowest of the 64 bits of our result
493 * to the goddess of code clarity.
496 scale = (u_int64_t)1 << 63;
497 scale += (th->th_adjustment / 1024) * 2199;
498 scale /= th->th_counter->tc_frequency;
499 th->th_scale = scale * 2;
502 * Now that the struct timehands is again consistent, set the new
503 * generation number, making sure to not make it zero.
507 th->th_generation = ogen;
509 /* Go live with the new struct timehands. */
510 time_second = th->th_microtime.tv_sec;
511 time_uptime = th->th_offset.sec;
515 /* Report or change the active timecounter hardware. */
517 sysctl_kern_timecounter_hardware(SYSCTL_HANDLER_ARGS)
520 struct timecounter *newtc, *tc;
524 strlcpy(newname, tc->tc_name, sizeof(newname));
526 error = sysctl_handle_string(oidp, &newname[0], sizeof(newname), req);
527 if (error != 0 || req->newptr == NULL ||
528 strcmp(newname, tc->tc_name) == 0)
530 for (newtc = timecounters; newtc != NULL; newtc = newtc->tc_next) {
531 if (strcmp(newname, newtc->tc_name) != 0)
534 /* Warm up new timecounter. */
535 (void)newtc->tc_get_timecount(newtc);
536 (void)newtc->tc_get_timecount(newtc);
544 SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | CTLFLAG_RW,
545 0, 0, sysctl_kern_timecounter_hardware, "A", "");
548 /* Report or change the active timecounter hardware. */
550 sysctl_kern_timecounter_choice(SYSCTL_HANDLER_ARGS)
553 struct timecounter *tc;
558 for (tc = timecounters; error == 0 && tc != NULL; tc = tc->tc_next) {
559 sprintf(buf, "%s%s(%d)",
560 spc, tc->tc_name, tc->tc_quality);
561 error = SYSCTL_OUT(req, buf, strlen(buf));
567 SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD,
568 0, 0, sysctl_kern_timecounter_choice, "A", "");
571 * RFC 2783 PPS-API implementation.
575 pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps)
578 struct pps_fetch_args *fapi;
580 struct pps_kcbind_args *kapi;
583 KASSERT(pps != NULL, ("NULL pps pointer in pps_ioctl"));
587 case PPS_IOC_DESTROY:
589 case PPS_IOC_SETPARAMS:
590 app = (pps_params_t *)data;
591 if (app->mode & ~pps->ppscap)
593 pps->ppsparam = *app;
595 case PPS_IOC_GETPARAMS:
596 app = (pps_params_t *)data;
597 *app = pps->ppsparam;
598 app->api_version = PPS_API_VERS_1;
601 *(int*)data = pps->ppscap;
604 fapi = (struct pps_fetch_args *)data;
605 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)
607 if (fapi->timeout.tv_sec || fapi->timeout.tv_nsec)
609 pps->ppsinfo.current_mode = pps->ppsparam.mode;
610 fapi->pps_info_buf = pps->ppsinfo;
614 kapi = (struct pps_kcbind_args *)data;
615 /* XXX Only root should be able to do this */
616 if (kapi->tsformat && kapi->tsformat != PPS_TSFMT_TSPEC)
618 if (kapi->kernel_consumer != PPS_KC_HARDPPS)
620 if (kapi->edge & ~pps->ppscap)
622 pps->kcmode = kapi->edge;
633 pps_init(struct pps_state *pps)
635 pps->ppscap |= PPS_TSFMT_TSPEC;
636 if (pps->ppscap & PPS_CAPTUREASSERT)
637 pps->ppscap |= PPS_OFFSETASSERT;
638 if (pps->ppscap & PPS_CAPTURECLEAR)
639 pps->ppscap |= PPS_OFFSETCLEAR;
643 pps_capture(struct pps_state *pps)
645 struct timehands *th;
647 KASSERT(pps != NULL, ("NULL pps pointer in pps_capture"));
649 pps->capgen = th->th_generation;
651 pps->capcount = th->th_counter->tc_get_timecount(th->th_counter);
652 if (pps->capgen != th->th_generation)
657 pps_event(struct pps_state *pps, int event)
660 struct timespec ts, *tsp, *osp;
661 u_int tcount, *pcount;
665 KASSERT(pps != NULL, ("NULL pps pointer in pps_event"));
666 /* If the timecounter was wound up underneath us, bail out. */
667 if (pps->capgen == 0 || pps->capgen != pps->capth->th_generation)
670 /* Things would be easier with arrays. */
671 if (event == PPS_CAPTUREASSERT) {
672 tsp = &pps->ppsinfo.assert_timestamp;
673 osp = &pps->ppsparam.assert_offset;
674 foff = pps->ppsparam.mode & PPS_OFFSETASSERT;
675 fhard = pps->kcmode & PPS_CAPTUREASSERT;
676 pcount = &pps->ppscount[0];
677 pseq = &pps->ppsinfo.assert_sequence;
679 tsp = &pps->ppsinfo.clear_timestamp;
680 osp = &pps->ppsparam.clear_offset;
681 foff = pps->ppsparam.mode & PPS_OFFSETCLEAR;
682 fhard = pps->kcmode & PPS_CAPTURECLEAR;
683 pcount = &pps->ppscount[1];
684 pseq = &pps->ppsinfo.clear_sequence;
688 * If the timecounter changed, we cannot compare the count values, so
689 * we have to drop the rest of the PPS-stuff until the next event.
691 if (pps->ppstc != pps->capth->th_counter) {
692 pps->ppstc = pps->capth->th_counter;
693 *pcount = pps->capcount;
694 pps->ppscount[2] = pps->capcount;
698 /* Convert the count to a timespec. */
699 tcount = pps->capcount - pps->capth->th_offset_count;
700 tcount &= pps->capth->th_counter->tc_counter_mask;
701 bt = pps->capth->th_offset;
702 bintime_addx(&bt, pps->capth->th_scale * tcount);
703 bintime_add(&bt, &boottimebin);
704 bintime2timespec(&bt, &ts);
706 /* If the timecounter was wound up underneath us, bail out. */
707 if (pps->capgen != pps->capth->th_generation)
710 *pcount = pps->capcount;
715 timespecadd(tsp, osp);
716 if (tsp->tv_nsec < 0) {
717 tsp->tv_nsec += 1000000000;
726 * Feed the NTP PLL/FLL.
727 * The FLL wants to know how many (hardware) nanoseconds
728 * elapsed since the previous event.
730 tcount = pps->capcount - pps->ppscount[2];
731 pps->ppscount[2] = pps->capcount;
732 tcount &= pps->capth->th_counter->tc_counter_mask;
733 scale = (u_int64_t)1 << 63;
734 scale /= pps->capth->th_counter->tc_frequency;
738 bintime_addx(&bt, scale * tcount);
739 bintime2timespec(&bt, &ts);
740 hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec);
746 * Timecounters need to be updated every so often to prevent the hardware
747 * counter from overflowing. Updating also recalculates the cached values
748 * used by the get*() family of functions, so their precision depends on
749 * the update frequency.
753 SYSCTL_INT(_kern_timecounter, OID_AUTO, tick, CTLFLAG_RD, &tc_tick, 0, "");
759 static time_t last_calib;
761 if (++count < tc_tick)
765 if (time_uptime != last_calib && !(time_uptime & 0xf)) {
766 cpu_tick_calibrate(0);
767 last_calib = time_uptime;
772 inittimecounter(void *dummy)
777 * Set the initial timeout to
778 * max(1, <approx. number of hardclock ticks in a millisecond>).
779 * People should probably not use the sysctl to set the timeout
780 * to smaller than its inital value, since that value is the
781 * smallest reasonable one. If they want better timestamps they
782 * should use the non-"get"* functions.
785 tc_tick = (hz + 500) / 1000;
788 p = (tc_tick * 1000000) / hz;
789 printf("Timecounters tick every %d.%03u msec\n", p / 1000, p % 1000);
791 /* warm up new timecounter (again) and get rolling. */
792 (void)timecounter->tc_get_timecount(timecounter);
793 (void)timecounter->tc_get_timecount(timecounter);
796 SYSINIT(timecounter, SI_SUB_CLOCKS, SI_ORDER_SECOND, inittimecounter, NULL)
798 /* Cpu tick handling -------------------------------------------------*/
800 static int cpu_tick_variable;
801 static uint64_t cpu_tick_frequency;
807 static uint64_t base;
808 static unsigned last;
810 struct timecounter *tc;
812 tc = timehands->th_counter;
813 u = tc->tc_get_timecount(tc) & tc->tc_counter_mask;
815 base += (uint64_t)tc->tc_counter_mask + 1;
821 * This function gets called ever 16 seconds on only one designated
822 * CPU in the system from hardclock() via tc_ticktock().
824 * Whenever the real time clock is stepped we get called with reset=1
825 * to make sure we handle suspend/resume and similar events correctly.
829 cpu_tick_calibrate(int reset)
831 static uint64_t c_last;
832 uint64_t c_this, c_delta;
833 static struct bintime t_last;
834 struct bintime t_this, t_delta;
838 /* The clock was stepped, abort & reset */
843 /* we don't calibrate fixed rate cputicks */
844 if (!cpu_tick_variable)
847 getbinuptime(&t_this);
848 c_this = cpu_ticks();
849 if (t_last.sec != 0) {
850 c_delta = c_this - c_last;
852 bintime_sub(&t_delta, &t_last);
854 printf("%ju.%016jx ",
855 (uintmax_t)t_delta.sec, (uintmax_t)t_delta.frac);
858 * Validate that 16 +/- 1/256 seconds passed.
859 * After division by 16 this gives us a precision of
860 * roughly 250PPM which is sufficient
862 if (t_delta.sec > 16 || (
863 t_delta.sec == 16 && t_delta.frac >= (0x01LL << 56))) {
866 printf("\ttoo long\n");
867 } else if (t_delta.sec < 15 ||
868 (t_delta.sec == 15 && t_delta.frac <= (0xffLL << 56))) {
871 printf("\ttoo short\n");
876 * 2^(64-20) / 16[s] =
878 * 17.592.186.044.416 / 16 =
879 * 1.099.511.627.776 [Hz]
881 divi = t_delta.sec << 20;
882 divi |= t_delta.frac >> (64 - 20);
886 (uintmax_t)c_delta, (uintmax_t)divi);
889 printf(" = %ju", c_delta);
890 if (c_delta > cpu_tick_frequency) {
892 printf("\thigher\n");
893 cpu_tick_frequency = c_delta;
905 set_cputicker(cpu_tick_f *func, uint64_t freq, unsigned var)
909 cpu_ticks = tc_cpu_ticks;
911 cpu_tick_frequency = freq;
912 cpu_tick_variable = var;
921 if (cpu_ticks == tc_cpu_ticks)
922 return (tc_getfrequency());
923 return (cpu_tick_frequency);
927 * We need to be slightly careful converting cputicks to microseconds.
928 * There is plenty of margin in 64 bits of microseconds (half a million
929 * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply
930 * before divide conversion (to retain precision) we find that the
931 * margin shrinks to 1.5 hours (one millionth of 146y).
932 * With a three prong approach we never loose significant bits, no
933 * matter what the cputick rate and length of timeinterval is.
937 cputick2usec(uint64_t tick)
940 if (tick > 18446744073709551LL) /* floor(2^64 / 1000) */
941 return (tick / (cpu_tickrate() / 1000000LL));
942 else if (tick > 18446744073709LL) /* floor(2^64 / 1000000) */
943 return ((tick * 1000LL) / (cpu_tickrate() / 1000LL));
945 return ((tick * 1000000LL) / cpu_tickrate());
948 cpu_tick_f *cpu_ticks = tc_cpu_ticks;