Lines Matching +full:timebase +full:- +full:frequency

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com)
11 * to make clock more stable (2.4.0-test5). The only thing
20 * - improve precision and reproducibility of timebase frequency
22 * - for astronomical applications: add a new function to get
26 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
50 #include <linux/posix-timers.h>
72 #include <asm/asm-prototypes.h>
81 .name = "timebase",
146 * Factor for converting from cputime_t (timebase ticks) to
147 * microseconds. This is stored as 0.64 fixed-point binary fraction.
166 * or if that doesn't exist return the timebase value passed in.
187 u64 i = local_paca->dtl_ridx; in scan_dispatch_log()
188 struct dtl_entry *dtl = local_paca->dtl_curr; in scan_dispatch_log()
189 struct dtl_entry *dtl_end = local_paca->dispatch_log_end; in scan_dispatch_log()
190 struct lppaca *vpa = local_paca->lppaca_ptr; in scan_dispatch_log()
198 if (i == be64_to_cpu(vpa->dtl_idx)) in scan_dispatch_log()
200 while (i < be64_to_cpu(vpa->dtl_idx)) { in scan_dispatch_log()
201 dtb = be64_to_cpu(dtl->timebase); in scan_dispatch_log()
202 tb_delta = be32_to_cpu(dtl->enqueue_to_dispatch_time) + in scan_dispatch_log()
203 be32_to_cpu(dtl->ready_to_enqueue_time); in scan_dispatch_log()
205 if (i + N_DISPATCH_LOG < be64_to_cpu(vpa->dtl_idx)) { in scan_dispatch_log()
207 i = be64_to_cpu(vpa->dtl_idx) - N_DISPATCH_LOG; in scan_dispatch_log()
208 dtl = local_paca->dispatch_log + (i % N_DISPATCH_LOG); in scan_dispatch_log()
219 dtl = local_paca->dispatch_log; in scan_dispatch_log()
221 local_paca->dtl_ridx = i; in scan_dispatch_log()
222 local_paca->dtl_curr = dtl; in scan_dispatch_log()
233 struct cpu_accounting_data *acct = &local_paca->accounting; in accumulate_stolen_time()
235 sst = scan_dispatch_log(acct->starttime_user); in accumulate_stolen_time()
236 ust = scan_dispatch_log(acct->starttime); in accumulate_stolen_time()
237 acct->stime -= sst; in accumulate_stolen_time()
238 acct->utime -= ust; in accumulate_stolen_time()
239 acct->steal_time += ust + sst; in accumulate_stolen_time()
247 if (get_paca()->dtl_ridx != be64_to_cpu(get_lppaca()->dtl_idx)) in calculate_stolen_time()
274 deltascaled = nowscaled - acct->startspurr; in vtime_delta_scaled()
275 acct->startspurr = nowscaled; in vtime_delta_scaled()
276 utime = acct->utime - acct->utime_sspurr; in vtime_delta_scaled()
277 acct->utime_sspurr = acct->utime; in vtime_delta_scaled()
284 * and user time (udelta) values obtained from the timebase in vtime_delta_scaled()
286 * the user ticks get saved up in paca->user_time_scaled to be in vtime_delta_scaled()
294 utime_scaled = deltascaled - stime_scaled; in vtime_delta_scaled()
299 acct->utime_scaled += utime_scaled; in vtime_delta_scaled()
314 stime = now - acct->starttime; in vtime_delta()
315 acct->starttime = now; in vtime_delta()
330 *stime -= min(*stime, steal_time); in vtime_delta_kernel()
331 acct->steal_time += steal_time; in vtime_delta_kernel()
341 if (tsk->flags & PF_VCPU) { in vtime_account_kernel()
342 acct->gtime += stime; in vtime_account_kernel()
344 acct->utime_scaled += stime_scaled; in vtime_account_kernel()
347 acct->stime += stime; in vtime_account_kernel()
349 acct->stime_scaled += stime_scaled; in vtime_account_kernel()
361 acct->idle_time += stime + steal_time; in vtime_account_idle()
372 acct->stime_scaled += stime_scaled; in vtime_account_irq_field()
379 vtime_account_irq_field(acct, &acct->softirq_time); in vtime_account_softirq()
385 vtime_account_irq_field(acct, &acct->hardirq_time); in vtime_account_hardirq()
392 if (acct->utime_scaled) in vtime_flush_scaled()
393 tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled); in vtime_flush_scaled()
394 if (acct->stime_scaled) in vtime_flush_scaled()
395 tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled); in vtime_flush_scaled()
397 acct->utime_scaled = 0; in vtime_flush_scaled()
398 acct->utime_sspurr = 0; in vtime_flush_scaled()
399 acct->stime_scaled = 0; in vtime_flush_scaled()
408 * get_paca()->user_time_scaled is up to date.
414 if (acct->utime) in vtime_flush()
415 account_user_time(tsk, cputime_to_nsecs(acct->utime)); in vtime_flush()
417 if (acct->gtime) in vtime_flush()
418 account_guest_time(tsk, cputime_to_nsecs(acct->gtime)); in vtime_flush()
420 if (IS_ENABLED(CONFIG_PPC_SPLPAR) && acct->steal_time) { in vtime_flush()
421 account_steal_time(cputime_to_nsecs(acct->steal_time)); in vtime_flush()
422 acct->steal_time = 0; in vtime_flush()
425 if (acct->idle_time) in vtime_flush()
426 account_idle_time(cputime_to_nsecs(acct->idle_time)); in vtime_flush()
428 if (acct->stime) in vtime_flush()
429 account_system_index_time(tsk, cputime_to_nsecs(acct->stime), in vtime_flush()
432 if (acct->hardirq_time) in vtime_flush()
433 account_system_index_time(tsk, cputime_to_nsecs(acct->hardirq_time), in vtime_flush()
435 if (acct->softirq_time) in vtime_flush()
436 account_system_index_time(tsk, cputime_to_nsecs(acct->softirq_time), in vtime_flush()
441 acct->utime = 0; in vtime_flush()
442 acct->gtime = 0; in vtime_flush()
443 acct->idle_time = 0; in vtime_flush()
444 acct->stime = 0; in vtime_flush()
445 acct->hardirq_time = 0; in vtime_flush()
446 acct->softirq_time = 0; in vtime_flush()
467 while (mftb() - start < loops) in __delay()
486 return regs->link; in profile_pc()
496 * 64-bit uses a byte in the PACA, 32-bit uses a per-cpu variable...
513 #else /* 32-bit */
526 * 64-bit code that uses irq soft-mask can just cause an immediate in arch_irq_work_raise()
532 * level manipulations of irq soft-mask state (e.g., trace_hardirqs_on) in arch_irq_work_raise()
550 * timer_interrupt - gets called when the decrementer overflows,
580 /* Conditionally hard-enable interrupts now that the DEC has been in DEFINE_INTERRUPT_HANDLER_ASYNC()
603 if (evt->event_handler) in DEFINE_INTERRUPT_HANDLER_ASYNC()
604 evt->event_handler(evt); in DEFINE_INTERRUPT_HANDLER_ASYNC()
607 now = *next_tb - now; in DEFINE_INTERRUPT_HANDLER_ASYNC()
674 * Scheduler clock - returns current time in nanosec units.
678 * are 64-bit unsigned numbers.
682 return mulhdu(get_tb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift; in sched_clock()
689 * Running clock - attempts to give a view of time passing for a virtualised
697 * timebase into the VTB when it takes a guest off the CPU, reading the in running_clock()
705 return mulhdu(get_vtb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift; in running_clock()
713 return local_clock() - kcpustat_this_cpu->cpustat[CPUTIME_STEAL]; in running_clock()
723 /* The cpu node should have timebase and clock frequency properties */ in get_freq()
749 * The watchdog may have already been enabled by u-boot. So leave in start_cpu_decrementer()
762 if (!get_freq("ibm,extended-timebase-frequency", 2, &ppc_tb_freq) && in generic_calibrate_decr()
763 !get_freq("timebase-frequency", 1, &ppc_tb_freq)) { in generic_calibrate_decr()
765 printk(KERN_ERR "WARNING: Estimating decrementer frequency " in generic_calibrate_decr()
771 if (!get_freq("ibm,extended-clock-frequency", 2, &ppc_proc_freq) && in generic_calibrate_decr()
772 !get_freq("clock-frequency", 1, &ppc_proc_freq)) { in generic_calibrate_decr()
774 printk(KERN_ERR "WARNING: Estimating processor frequency " in generic_calibrate_decr()
784 return -ENODEV; in update_persistent_clock64()
796 ts->tv_nsec = 0; in __read_persistent_clock()
805 ts->tv_sec = ppc_md.get_boot_time() - timezone_offset; in __read_persistent_clock()
810 ts->tv_sec = 0; in __read_persistent_clock()
815 ts->tv_sec = rtc_tm_to_time64(&tm); in __read_persistent_clock()
823 if (ts->tv_sec < 0) { in read_persistent_clock64()
824 ts->tv_sec = 0; in read_persistent_clock64()
825 ts->tv_nsec = 0; in read_persistent_clock64()
842 clock->name); in clocksource_init()
847 clock->name, clock->mult, clock->shift); in clocksource_init()
874 dec->cpumask = cpumask_of(cpu); in register_decrementer_clockevent()
879 dec->name, dec->mult, dec->shift, cpu); in register_decrementer_clockevent()
882 decrementer_clockevent.mult = dec->mult; in register_decrementer_clockevent()
883 decrementer_clockevent.shift = dec->shift; in register_decrementer_clockevent()
913 if (of_property_read_u32(cpu, "ibm,dec-bits", &bits) == 0) { in set_decrementer_max()
915 pr_warn("time_init: firmware supplied invalid ibm,dec-bits"); in set_decrementer_max()
920 decrementer_max = (1ul << (bits - 1)) - 1; in set_decrementer_max()
956 /* Normal PowerPC with timebase register */ in time_init()
958 printk(KERN_DEBUG "time_init: decrementer frequency = %lu.%.6lu MHz\n", in time_init()
960 printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n", in time_init()
971 * which is the timebase frequency. in time_init()
973 * the 128-bit result as a 64.64 fixed-point number. in time_init()
986 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */ in time_init()
991 sys_tz.tz_minuteswest = -timezone_offset / 60; in time_init()
995 vdso_data->tb_ticks_per_sec = tb_ticks_per_sec; in time_init()
1017 * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit
1033 ra = ((u64)(a - (w * divisor)) << 32) + b; in div128_by_32()
1044 dr->result_high = ((u64)w << 32) + x; in div128_by_32()
1045 dr->result_low = ((u64)y << 32) + z; in div128_by_32()
1049 /* We don't need to calibrate delay, we use the CPU timebase for that */
1068 return -EOPNOTSUPP; in rtc_generic_set_time()
1071 return -EOPNOTSUPP; in rtc_generic_set_time()
1086 return -ENODEV; in rtc_init()
1088 pdev = platform_device_register_data(NULL, "rtc-generic", -1, in rtc_init()