Skip to content
This repository was archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
x86/asm/tsc: Rename native_read_tsc() to rdtsc()
Browse files Browse the repository at this point in the history
Now that there is no paravirt TSC, the "native" is
inappropriate. The function does RDTSC, so give it the obvious
name: rdtsc().

Suggested-by: Borislav Petkov <[email protected]>
Signed-off-by: Andy Lutomirski <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Huang Rui <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: kvm ML <[email protected]>
Link: http://lkml.kernel.org/r/fd43e16281991f096c1e4d21574d9e1402c62d39.1434501121.git.luto@kernel.org
[ Ported it to v4.2-rc1. ]
Signed-off-by: Ingo Molnar <[email protected]>
Change-Id: Id5a396f0c61f2c624d35ff4c9cedc1c73aba2cfe
  • Loading branch information
Ingo Molnar authored and pavlaras committed Aug 7, 2020
1 parent f5ba619 commit cadcb8b
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions arch/x86/include/asm/msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ notrace static inline int native_write_msr_safe(unsigned int msr,
return err;
}

extern unsigned long long native_read_tsc(void);
extern unsigned long long rdtsc(void);

extern int rdmsr_safe_regs(u32 regs[8]);
extern int wrmsr_safe_regs(u32 regs[8]);

static __always_inline unsigned long long __native_read_tsc(void)
static __always_inline unsigned long long __rdtsc(void)
{
DECLARE_ARGS(val, low, high);

Expand Down Expand Up @@ -180,7 +180,7 @@ static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
}

#define rdtscl(low) \
((low) = (u32)__native_read_tsc())
((low) = (u32)__rdtsc())

#define rdpmc(counter, low, high) \
do { \
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/paravirt.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static inline cycles_t get_cycles(void)
return 0;
#endif

return native_read_tsc();
return rdtsc();
}

static inline unsigned long long paravirt_sched_clock(void)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/pvclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
static __always_inline
u64 pvclock_get_nsec_offset(const struct pvclock_vcpu_time_info *src)
{
u64 delta = __native_read_tsc() - src->tsc_timestamp;
u64 delta = __rdtsc() - src->tsc_timestamp;
return pvclock_scale_delta(delta, src->tsc_to_system_mul,
src->tsc_shift);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/stackprotector.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static __always_inline void boot_init_stack_canary(void)
* on during the bootup the random pool has true entropy too.
*/
get_random_bytes(&canary, sizeof(canary));
tsc = __native_read_tsc();
tsc = __rdtsc();
canary += tsc + (tsc << 32UL);

current->stack_canary = canary;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/include/asm/tsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static inline cycles_t get_cycles(void)
return 0;
#endif

return native_read_tsc();
return rdtsc();
}

static __always_inline cycles_t vget_cycles(void)
Expand All @@ -39,7 +39,7 @@ static __always_inline cycles_t vget_cycles(void)
if (!cpu_has_tsc)
return 0;
#endif
return (cycles_t)__native_read_tsc();
return (cycles_t)__rdtsc();
}

extern void tsc_init(void);
Expand Down
8 changes: 4 additions & 4 deletions arch/x86/kernel/apb_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static int apbt_clocksource_register(void)

/* Verify whether apbt counter works */
t1 = dw_apb_clocksource_read(clocksource_apbt);
start = native_read_tsc();
start = rdtsc();

/*
* We don't know the TSC frequency yet, but waiting for
Expand All @@ -287,7 +287,7 @@ static int apbt_clocksource_register(void)
*/
do {
rep_nop();
now = native_read_tsc();
now = rdtsc();
} while ((now - start) < 200000UL);

/* APBT is the only always on clocksource, it has to work! */
Expand Down Expand Up @@ -404,13 +404,13 @@ unsigned long apbt_quick_calibrate(void)
old = dw_apb_clocksource_read(clocksource_apbt);
old += loop;

t1 = __native_read_tsc();
t1 = __rdtsc();

do {
new = dw_apb_clocksource_read(clocksource_apbt);
} while (new < old);

t2 = __native_read_tsc();
t2 = __rdtsc();

shift = 5;
if (unlikely(loop >> shift == 0)) {
Expand Down
8 changes: 4 additions & 4 deletions arch/x86/kernel/apic/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static int lapic_next_deadline(unsigned long delta,
{
u64 tsc;

tsc = native_read_tsc();
tsc = rdtsc();
wrmsrl(MSR_IA32_TSC_DEADLINE, tsc + (((u64) delta) * TSC_DIVISOR));
return 0;
}
Expand Down Expand Up @@ -606,7 +606,7 @@ static void __init lapic_cal_handler(struct clock_event_device *dev)
unsigned long pm = acpi_pm_read_early();

if (cpu_has_tsc)
tsc = native_read_tsc();
tsc = rdtsc();

switch (lapic_cal_loops++) {
case 0:
Expand Down Expand Up @@ -1266,7 +1266,7 @@ void setup_local_APIC(void)
long long max_loops = cpu_khz ? cpu_khz : 1000000;

if (cpu_has_tsc)
tsc = native_read_tsc();
tsc = rdtsc();

if (disable_apic) {
disable_ioapic_support();
Expand Down Expand Up @@ -1361,7 +1361,7 @@ void setup_local_APIC(void)
}
if (queued) {
if (cpu_has_tsc && cpu_khz) {
ntsc = native_read_tsc();
ntsc = rdtsc();
max_loops = (cpu_khz << 10) - (ntsc - tsc);
} else
max_loops--;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/mcheck/mce.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void mce_setup(struct mce *m)
{
memset(m, 0, sizeof(struct mce));
m->cpu = m->extcpu = smp_processor_id();
m->tsc = native_read_tsc();
m->tsc = rdtsc();
/* We hope get_seconds stays lockless */
m->time = get_seconds();
m->cpuvendor = boot_cpu_data.x86_vendor;
Expand Down Expand Up @@ -1730,7 +1730,7 @@ static void collect_tscs(void *data)
{
unsigned long *cpu_tsc = (unsigned long *)data;

cpu_tsc[smp_processor_id()] = native_read_tsc();
cpu_tsc[smp_processor_id()] = rdtsc();
}

static int mce_apei_read_done;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/espfix_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void init_espfix_random(void)
*/
if (!arch_get_random_long(&rand)) {
/* The constant is an arbitrary large prime */
rand = native_read_tsc();
rand = rdtsc();
rand *= 0xc345c6b72fd16123UL;
}

Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/hpet.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ static int hpet_clocksource_register(void)

/* Verify whether hpet counter works */
t1 = hpet_readl(HPET_COUNTER);
start = native_read_tsc();
start = rdtsc();

/*
* We don't know the TSC frequency yet, but waiting for
Expand All @@ -777,7 +777,7 @@ static int hpet_clocksource_register(void)
*/
do {
rep_nop();
now = native_read_tsc();
now = rdtsc();
} while ((now - start) < 200000UL);

if (t1 == hpet_readl(HPET_COUNTER)) {
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/paravirt.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ struct pv_cpu_ops pv_cpu_ops = {
.wbinvd = native_wbinvd,
.read_msr = native_read_msr_safe,
.write_msr = native_write_msr_safe,
.read_tsc = native_read_tsc,
.read_tsc = rdtsc,
.read_pmc = native_read_pmc,
.read_tscp = native_read_tscp,
.load_tr_desc = native_load_tr_desc,
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/trace_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ u64 notrace trace_clock_x86_tsc(void)
u64 ret;

rdtsc_barrier();
ret = native_read_tsc();
ret = rdtsc();

return ret;
}
10 changes: 5 additions & 5 deletions arch/x86/kernel/tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ u64 native_sched_clock(void)
}

/* read the Time Stamp Counter: */
this_offset = native_read_tsc();
this_offset = rdtsc();

/* return the value in ns */
return __cycles_2_ns(this_offset);
Expand All @@ -77,11 +77,11 @@ unsigned long long
sched_clock(void) __attribute__((alias("native_sched_clock")));
#endif

unsigned long long native_read_tsc(void)
unsigned long long rdtsc(void)
{
return __native_read_tsc();
return __rdtsc();
}
EXPORT_SYMBOL(native_read_tsc);
EXPORT_SYMBOL(rdtsc);

int check_tsc_unstable(void)
{
Expand Down Expand Up @@ -619,7 +619,7 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
scale = &per_cpu(cyc2ns, cpu);
offset = &per_cpu(cyc2ns_offset, cpu);

tsc_now = native_read_tsc();
tsc_now = rdtsc();
ns_now = __cycles_2_ns(tsc_now);

if (cpu_khz) {
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ static void start_apic_timer(struct kvm_lapic *apic)
local_irq_save(flags);

now = apic->lapic_timer.timer.base->get_time();
guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu, native_read_tsc());
guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu, rdtsc());
if (likely(tscdeadline > guest_tsc)) {
ns = (tscdeadline - guest_tsc) * 1000000ULL;
do_div(ns, this_tsc_khz);
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kvm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ static u64 svm_compute_tsc_offset(struct kvm_vcpu *vcpu, u64 target_tsc)
{
u64 tsc;

tsc = svm_scale_tsc(vcpu, native_read_tsc());
tsc = svm_scale_tsc(vcpu, rdtsc());

return target_tsc - tsc;
}
Expand Down Expand Up @@ -3009,7 +3009,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
switch (ecx) {
case MSR_IA32_TSC: {
*data = svm->vmcb->control.tsc_offset +
svm_scale_tsc(vcpu, native_read_tsc());
svm_scale_tsc(vcpu, rdtsc());

break;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ static u64 guest_read_tsc(void)
{
u64 host_tsc, tsc_offset;

host_tsc = native_read_tsc();
host_tsc = rdtsc();
tsc_offset = vmcs_read64(TSC_OFFSET);
return host_tsc + tsc_offset;
}
Expand Down Expand Up @@ -2113,7 +2113,7 @@ static void vmx_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment, bool ho

static u64 vmx_compute_tsc_offset(struct kvm_vcpu *vcpu, u64 target_tsc)
{
return target_tsc - native_read_tsc();
return target_tsc - rdtsc();
}

static bool guest_cpuid_has_vmx(struct kvm_vcpu *vcpu)
Expand Down
10 changes: 5 additions & 5 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
return 1;
}
if (!use_master_clock) {
host_tsc = native_read_tsc();
host_tsc = rdtsc();
kernel_ns = get_kernel_ns();
}

Expand Down Expand Up @@ -2738,7 +2738,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)

if (unlikely(vcpu->cpu != cpu) || check_tsc_unstable()) {
s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 :
native_read_tsc() - vcpu->arch.last_host_tsc;
rdtsc() - vcpu->arch.last_host_tsc;
if (tsc_delta < 0)
mark_tsc_unstable("KVM discovered backwards TSC");
if (check_tsc_unstable()) {
Expand Down Expand Up @@ -2766,7 +2766,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
{
kvm_x86_ops->vcpu_put(vcpu);
kvm_put_guest_fpu(vcpu);
vcpu->arch.last_host_tsc = native_read_tsc();
vcpu->arch.last_host_tsc = rdtsc();
}

static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu,
Expand Down Expand Up @@ -5853,7 +5853,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
hw_breakpoint_restore();

vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu,
native_read_tsc());
rdtsc());

vcpu->mode = OUTSIDE_GUEST_MODE;
smp_wmb();
Expand Down Expand Up @@ -6628,7 +6628,7 @@ int kvm_arch_hardware_enable(void *garbage)
if (ret != 0)
return ret;

local_tsc = native_read_tsc();
local_tsc = rdtsc();
stable = !check_tsc_unstable();
list_for_each_entry(kvm, &vm_list, vm_list) {
kvm_for_each_vcpu(i, vcpu, kvm) {
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/lib/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void use_tsc_delay(void)
int read_current_timer(unsigned long *timer_val)
{
if (delay_fn == delay_tsc) {
*timer_val = native_read_tsc();
*timer_val = rdtsc();
return 0;
}
return -1;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/xen/enlighten.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
.read_msr = native_read_msr_safe,
.write_msr = xen_write_msr_safe,

.read_tsc = native_read_tsc,
.read_tsc = rdtsc,
.read_pmc = native_read_pmc,

.read_tscp = native_read_tscp,
Expand Down
4 changes: 2 additions & 2 deletions drivers/thermal/intel_powerclamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static bool powerclamp_adjust_controls(unsigned int target_ratio,

/* check result for the last window */
msr_now = pkg_state_counter();
tsc_now = native_read_tsc();
tsc_now = rdtsc();

/* calculate pkg cstate vs tsc ratio */
if (!msr_last || !tsc_last)
Expand Down Expand Up @@ -482,7 +482,7 @@ static void poll_pkg_cstate(struct work_struct *dummy)
u64 val64;

msr_now = pkg_state_counter();
tsc_now = native_read_tsc();
tsc_now = rdtsc();
jiffies_now = jiffies;

/* calculate pkg cstate vs tsc ratio */
Expand Down
4 changes: 2 additions & 2 deletions tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ static int __init cpufreq_test_tsc(void)

printk(KERN_DEBUG "start--> \n");
then = read_pmtmr();
then_tsc = native_read_tsc();
then_tsc = rdtsc();
for (i=0;i<20;i++) {
mdelay(100);
now = read_pmtmr();
now_tsc = native_read_tsc();
now_tsc = rdtsc();
diff = (now - then) & 0xFFFFFF;
diff_tsc = now_tsc - then_tsc;
printk(KERN_DEBUG "t1: %08u t2: %08u diff_pmtmr: %08u diff_tsc: %016llu\n", then, now, diff, diff_tsc);
Expand Down

0 comments on commit cadcb8b

Please sign in to comment.