Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/arch/ia64/kernel/time.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1998-2003 Hewlett-Packard Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Stephane Eranian <eranian@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	David Mosberger <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 1999-2000 VA Linux Systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/profile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/timex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/timekeeper_internal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/sched/cputime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/hw_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/sal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "fsyscall_gtod_data.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "irq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static u64 itc_get_cycles(struct clocksource *cs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct fsyscall_gtod_data_t fsyscall_gtod_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) struct itc_jitter_data_t itc_jitter_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) volatile int time_keeper_id = 0; /* smp_processor_id() of time-keeper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #ifdef CONFIG_IA64_DEBUG_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) unsigned long last_cli_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) EXPORT_SYMBOL(last_cli_ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static struct clocksource clocksource_itc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.name           = "itc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.rating         = 350,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.read           = itc_get_cycles,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.mask           = CLOCKSOURCE_MASK(64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.flags          = CLOCK_SOURCE_IS_CONTINUOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static struct clocksource *itc_clocksource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) extern u64 cycle_to_nsec(u64 cyc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) void vtime_flush(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct thread_info *ti = task_thread_info(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	u64 delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (ti->utime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		account_user_time(tsk, cycle_to_nsec(ti->utime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (ti->gtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		account_guest_time(tsk, cycle_to_nsec(ti->gtime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (ti->idle_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		account_idle_time(cycle_to_nsec(ti->idle_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (ti->stime) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		delta = cycle_to_nsec(ti->stime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		account_system_index_time(tsk, delta, CPUTIME_SYSTEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (ti->hardirq_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		delta = cycle_to_nsec(ti->hardirq_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		account_system_index_time(tsk, delta, CPUTIME_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (ti->softirq_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		delta = cycle_to_nsec(ti->softirq_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		account_system_index_time(tsk, delta, CPUTIME_SOFTIRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	ti->utime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ti->gtime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ti->idle_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	ti->stime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	ti->hardirq_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	ti->softirq_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * Called from the context switch with interrupts disabled, to charge all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * accumulated times to the current process, and to prepare accounting on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * the next process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void arch_vtime_task_switch(struct task_struct *prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct thread_info *pi = task_thread_info(prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct thread_info *ni = task_thread_info(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ni->ac_stamp = pi->ac_stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ni->ac_stime = ni->ac_utime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Account time for a transition between system, hard irq or soft irq state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * Note that this function is called with interrupts enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static __u64 vtime_delta(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct thread_info *ti = task_thread_info(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	__u64 now, delta_stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	WARN_ON_ONCE(!irqs_disabled());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	now = ia64_get_itc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	delta_stime = now - ti->ac_stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ti->ac_stamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return delta_stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void vtime_account_kernel(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct thread_info *ti = task_thread_info(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	__u64 stime = vtime_delta(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if ((tsk->flags & PF_VCPU) && !irq_count())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		ti->gtime += stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	else if (hardirq_count())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		ti->hardirq_time += stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	else if (in_serving_softirq())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		ti->softirq_time += stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		ti->stime += stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) EXPORT_SYMBOL_GPL(vtime_account_kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void vtime_account_idle(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct thread_info *ti = task_thread_info(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ti->idle_time += vtime_delta(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) timer_interrupt (int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	unsigned long new_itm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (cpu_is_offline(smp_processor_id())) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	new_itm = local_cpu_data->itm_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (!time_after(ia64_get_itc(), new_itm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		printk(KERN_ERR "Oops: timer tick before it's due (itc=%lx,itm=%lx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		       ia64_get_itc(), new_itm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	profile_tick(CPU_PROFILING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		update_process_times(user_mode(get_irq_regs()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		new_itm += local_cpu_data->itm_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (smp_processor_id() == time_keeper_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			xtime_update(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		local_cpu_data->itm_next = new_itm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		if (time_after(new_itm, ia64_get_itc()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		 * Allow IPIs to interrupt the timer loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		 * If we're too close to the next clock tick for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		 * comfort, we increase the safety margin by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		 * intentionally dropping the next tick(s).  We do NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		 * update itm.next because that would force us to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		 * xtime_update() which in turn would let our clock run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		 * too fast (with the potentially devastating effect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		 * of losing monotony of time).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		while (!time_after(new_itm, ia64_get_itc() + local_cpu_data->itm_delta/2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			new_itm += local_cpu_data->itm_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		ia64_set_itm(new_itm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		/* double check, in case we got hit by a (slow) PMI: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	} while (time_after_eq(ia64_get_itc(), new_itm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * Encapsulate access to the itm structure for SMP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ia64_cpu_local_tick (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	unsigned long shift = 0, delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/* arrange for the cycle counter to generate a timer interrupt: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	ia64_set_itv(IA64_TIMER_VECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	delta = local_cpu_data->itm_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 * Stagger the timer tick for each CPU so they don't occur all at (almost) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 * same time:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		unsigned long hi = 1UL << ia64_fls(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		shift = (2*(cpu - hi) + 1) * delta/hi/2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	local_cpu_data->itm_next = ia64_get_itc() + delta + shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	ia64_set_itm(local_cpu_data->itm_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int nojitter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int __init nojitter_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	nojitter = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	printk("Jitter checking for ITC timers disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) __setup("nojitter", nojitter_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void ia64_init_itm(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	unsigned long platform_base_freq, itc_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct pal_freq_ratio itc_ratio, proc_ratio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	long status, platform_base_drift, itc_drift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * According to SAL v2.6, we need to use a SAL call to determine the platform base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 * frequency and then a PAL call to determine the frequency ratio between the ITC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 * and the base frequency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	status = ia64_sal_freq_base(SAL_FREQ_BASE_PLATFORM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				    &platform_base_freq, &platform_base_drift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		printk(KERN_ERR "SAL_FREQ_BASE_PLATFORM failed: %s\n", ia64_sal_strerror(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		status = ia64_pal_freq_ratios(&proc_ratio, NULL, &itc_ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		if (status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			printk(KERN_ERR "PAL_FREQ_RATIOS failed with status=%ld\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		/* invent "random" values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		       "SAL/PAL failed to obtain frequency info---inventing reasonable values\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		platform_base_freq = 100000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		platform_base_drift = -1;	/* no drift info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		itc_ratio.num = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		itc_ratio.den = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (platform_base_freq < 40000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		printk(KERN_ERR "Platform base frequency %lu bogus---resetting to 75MHz!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		       platform_base_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		platform_base_freq = 75000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		platform_base_drift = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (!proc_ratio.den)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		proc_ratio.den = 1;	/* avoid division by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (!itc_ratio.den)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		itc_ratio.den = 1;	/* avoid division by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	itc_freq = (platform_base_freq*itc_ratio.num)/itc_ratio.den;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	local_cpu_data->itm_delta = (itc_freq + HZ/2) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	printk(KERN_DEBUG "CPU %d: base freq=%lu.%03luMHz, ITC ratio=%u/%u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	       "ITC freq=%lu.%03luMHz", smp_processor_id(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	       platform_base_freq / 1000000, (platform_base_freq / 1000) % 1000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	       itc_ratio.num, itc_ratio.den, itc_freq / 1000000, (itc_freq / 1000) % 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (platform_base_drift != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		itc_drift = platform_base_drift*itc_ratio.num/itc_ratio.den;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		printk("+/-%ldppm\n", itc_drift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		itc_drift = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	local_cpu_data->proc_freq = (platform_base_freq*proc_ratio.num)/proc_ratio.den;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	local_cpu_data->itc_freq = itc_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	local_cpu_data->cyc_per_usec = (itc_freq + USEC_PER_SEC/2) / USEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	local_cpu_data->nsec_per_cyc = ((NSEC_PER_SEC<<IA64_NSEC_PER_CYC_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 					+ itc_freq/2)/itc_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		/* On IA64 in an SMP configuration ITCs are never accurately synchronized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		 * Jitter compensation requires a cmpxchg which may limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		 * the scalability of the syscalls for retrieving time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		 * The ITC synchronization is usually successful to within a few
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		 * ITC ticks but this is not a sure thing. If you need to improve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		 * timer performance in SMP situations then boot the kernel with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		 * "nojitter" option. However, doing so may result in time fluctuating (maybe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		 * even going backward) if the ITC offsets between the individual CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		 * are too large.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		if (!nojitter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			itc_jitter_data.itc_jitter = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		 * ITC is drifty and we have not synchronized the ITCs in smpboot.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		 * ITC values may fluctuate significantly between processors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		 * Clock should not be used for hrtimers. Mark itc as only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		 * useful for boot and testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		 * Note that jitter compensation is off! There is no point of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		 * synchronizing ITCs since they may be large differentials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		 * that change over time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		 * The only way to fix this would be to repeatedly sync the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		 * ITCs. Until that time we have to avoid ITC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		clocksource_itc.rating = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	/* avoid softlock up message when cpu is unplug and plugged again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	touch_softlockup_watchdog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	/* Setup the CPU local timer tick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	ia64_cpu_local_tick();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!itc_clocksource) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		clocksource_register_hz(&clocksource_itc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 						local_cpu_data->itc_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		itc_clocksource = &clocksource_itc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static u64 itc_get_cycles(struct clocksource *cs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	unsigned long lcycle, now, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (!itc_jitter_data.itc_jitter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		return get_cycles();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	lcycle = itc_jitter_data.itc_lastcycle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	now = get_cycles();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (lcycle && time_after(lcycle, now))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		return lcycle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	 * Keep track of the last timer value returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	 * In an SMP environment, you could lose out in contention of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * cmpxchg. If so, your cmpxchg returns new value which the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 * winner of contention updated to. Use the new value instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ret = cmpxchg(&itc_jitter_data.itc_lastcycle, lcycle, now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (unlikely(ret != lcycle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) void read_persistent_clock64(struct timespec64 *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	efi_gettimeofday(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) time_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	register_percpu_irq(IA64_TIMER_VECTOR, timer_interrupt, IRQF_IRQPOLL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			    "timer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	ia64_init_itm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * Generic udelay assumes that if preemption is allowed and the thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * migrates to another CPU, that the ITC values are synchronized across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * all CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ia64_itc_udelay (unsigned long usecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	unsigned long start = ia64_get_itc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	unsigned long end = start + usecs*local_cpu_data->cyc_per_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	while (time_before(ia64_get_itc(), end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) void (*ia64_udelay)(unsigned long usecs) = &ia64_itc_udelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) udelay (unsigned long usecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	(*ia64_udelay)(usecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) EXPORT_SYMBOL(udelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* IA64 doesn't cache the timezone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) void update_vsyscall_tz(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) void update_vsyscall(struct timekeeper *tk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	write_seqcount_begin(&fsyscall_gtod_data.seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	/* copy vsyscall data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	fsyscall_gtod_data.clk_mask = tk->tkr_mono.mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	fsyscall_gtod_data.clk_mult = tk->tkr_mono.mult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	fsyscall_gtod_data.clk_shift = tk->tkr_mono.shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	fsyscall_gtod_data.clk_fsys_mmio = tk->tkr_mono.clock->archdata.fsys_mmio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	fsyscall_gtod_data.clk_cycle_last = tk->tkr_mono.cycle_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	fsyscall_gtod_data.wall_time.sec = tk->xtime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	fsyscall_gtod_data.wall_time.snsec = tk->tkr_mono.xtime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	fsyscall_gtod_data.monotonic_time.sec = tk->xtime_sec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 					      + tk->wall_to_monotonic.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	fsyscall_gtod_data.monotonic_time.snsec = tk->tkr_mono.xtime_nsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 						+ ((u64)tk->wall_to_monotonic.tv_nsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 							<< tk->tkr_mono.shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	/* normalize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	while (fsyscall_gtod_data.monotonic_time.snsec >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 					(((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		fsyscall_gtod_data.monotonic_time.snsec -=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 					((u64)NSEC_PER_SEC) << tk->tkr_mono.shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		fsyscall_gtod_data.monotonic_time.sec++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	write_seqcount_end(&fsyscall_gtod_data.seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)