Skip to content

Commit 4ea1636

Browse files
amlutoingomolnar
authored andcommitted
x86/asm/tsc: Rename native_read_tsc() to rdtsc()
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 <bp@suse.de> Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Huang Rui <ray.huang@amd.com> Cc: John Stultz <john.stultz@linaro.org> Cc: Len Brown <lenb@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: kvm ML <kvm@vger.kernel.org> Link: http://lkml.kernel.org/r/fd43e16281991f096c1e4d21574d9e1402c62d39.1434501121.git.luto@kernel.org [ Ported it to v4.2-rc1. ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent fe47ae6 commit 4ea1636

25 files changed

Lines changed: 59 additions & 50 deletions

File tree

‎arch/x86/boot/compressed/aslr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static unsigned long get_random_long(void)
8282

8383
if (has_cpuflag(X86_FEATURE_TSC)) {
8484
debug_putstr(" RDTSC");
85-
raw = native_read_tsc();
85+
raw = rdtsc();
8686

8787
random ^= raw;
8888
use_i8254 = false;

‎arch/x86/entry/vdso/vclock_gettime.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ notrace static cycle_t vread_tsc(void)
186186
* but no one has ever seen it happen.
187187
*/
188188
rdtsc_barrier();
189-
ret = (cycle_t)native_read_tsc();
189+
ret = (cycle_t)rdtsc();
190190

191191
last = gtod->cycle_last;
192192

‎arch/x86/include/asm/msr.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@ notrace static inline int native_write_msr_safe(unsigned int msr,
109109
extern int rdmsr_safe_regs(u32 regs[8]);
110110
extern int wrmsr_safe_regs(u32 regs[8]);
111111

112-
static __always_inline unsigned long long native_read_tsc(void)
112+
/**
113+
* rdtsc() - returns the current TSC without ordering constraints
114+
*
115+
* rdtsc() returns the result of RDTSC as a 64-bit integer. The
116+
* only ordering constraint it supplies is the ordering implied by
117+
* "asm volatile": it will put the RDTSC in the place you expect. The
118+
* CPU can and will speculatively execute that RDTSC, though, so the
119+
* results can be non-monotonic if compared on different CPUs.
120+
*/
121+
static __always_inline unsigned long long rdtsc(void)
113122
{
114123
DECLARE_ARGS(val, low, high);
115124

‎arch/x86/include/asm/pvclock.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
6262
static __always_inline
6363
u64 pvclock_get_nsec_offset(const struct pvclock_vcpu_time_info *src)
6464
{
65-
u64 delta = native_read_tsc() - src->tsc_timestamp;
65+
u64 delta = rdtsc() - src->tsc_timestamp;
6666
return pvclock_scale_delta(delta, src->tsc_to_system_mul,
6767
src->tsc_shift);
6868
}

‎arch/x86/include/asm/stackprotector.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static __always_inline void boot_init_stack_canary(void)
7272
* on during the bootup the random pool has true entropy too.
7373
*/
7474
get_random_bytes(&canary, sizeof(canary));
75-
tsc = native_read_tsc();
75+
tsc = rdtsc();
7676
canary += tsc + (tsc << 32UL);
7777

7878
current->stack_canary = canary;

‎arch/x86/include/asm/tsc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static inline cycles_t get_cycles(void)
2626
return 0;
2727
#endif
2828

29-
return native_read_tsc();
29+
return rdtsc();
3030
}
3131

3232
extern void tsc_init(void);

‎arch/x86/kernel/apb_timer.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int apbt_clocksource_register(void)
263263

264264
/* Verify whether apbt counter works */
265265
t1 = dw_apb_clocksource_read(clocksource_apbt);
266-
start = native_read_tsc();
266+
start = rdtsc();
267267

268268
/*
269269
* We don't know the TSC frequency yet, but waiting for
@@ -273,7 +273,7 @@ static int apbt_clocksource_register(void)
273273
*/
274274
do {
275275
rep_nop();
276-
now = native_read_tsc();
276+
now = rdtsc();
277277
} while ((now - start) < 200000UL);
278278

279279
/* APBT is the only always on clocksource, it has to work! */
@@ -390,13 +390,13 @@ unsigned long apbt_quick_calibrate(void)
390390
old = dw_apb_clocksource_read(clocksource_apbt);
391391
old += loop;
392392

393-
t1 = native_read_tsc();
393+
t1 = rdtsc();
394394

395395
do {
396396
new = dw_apb_clocksource_read(clocksource_apbt);
397397
} while (new < old);
398398

399-
t2 = native_read_tsc();
399+
t2 = rdtsc();
400400

401401
shift = 5;
402402
if (unlikely(loop >> shift == 0)) {

‎arch/x86/kernel/apic/apic.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static int lapic_next_deadline(unsigned long delta,
457457
{
458458
u64 tsc;
459459

460-
tsc = native_read_tsc();
460+
tsc = rdtsc();
461461
wrmsrl(MSR_IA32_TSC_DEADLINE, tsc + (((u64) delta) * TSC_DIVISOR));
462462
return 0;
463463
}
@@ -592,7 +592,7 @@ static void __init lapic_cal_handler(struct clock_event_device *dev)
592592
unsigned long pm = acpi_pm_read_early();
593593

594594
if (cpu_has_tsc)
595-
tsc = native_read_tsc();
595+
tsc = rdtsc();
596596

597597
switch (lapic_cal_loops++) {
598598
case 0:
@@ -1209,7 +1209,7 @@ void setup_local_APIC(void)
12091209
long long max_loops = cpu_khz ? cpu_khz : 1000000;
12101210

12111211
if (cpu_has_tsc)
1212-
tsc = native_read_tsc();
1212+
tsc = rdtsc();
12131213

12141214
if (disable_apic) {
12151215
disable_ioapic_support();
@@ -1293,7 +1293,7 @@ void setup_local_APIC(void)
12931293
}
12941294
if (queued) {
12951295
if (cpu_has_tsc && cpu_khz) {
1296-
ntsc = native_read_tsc();
1296+
ntsc = rdtsc();
12971297
max_loops = (cpu_khz << 10) - (ntsc - tsc);
12981298
} else
12991299
max_loops--;

‎arch/x86/kernel/cpu/amd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
125125

126126
n = K6_BUG_LOOP;
127127
f_vide = vide;
128-
d = native_read_tsc();
128+
d = rdtsc();
129129
while (n--)
130130
f_vide();
131-
d2 = native_read_tsc();
131+
d2 = rdtsc();
132132
d = d2-d;
133133

134134
if (d > 20*K6_BUG_LOOP)

‎arch/x86/kernel/cpu/mcheck/mce.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void mce_setup(struct mce *m)
125125
{
126126
memset(m, 0, sizeof(struct mce));
127127
m->cpu = m->extcpu = smp_processor_id();
128-
m->tsc = native_read_tsc();
128+
m->tsc = rdtsc();
129129
/* We hope get_seconds stays lockless */
130130
m->time = get_seconds();
131131
m->cpuvendor = boot_cpu_data.x86_vendor;
@@ -1784,7 +1784,7 @@ static void collect_tscs(void *data)
17841784
{
17851785
unsigned long *cpu_tsc = (unsigned long *)data;
17861786

1787-
cpu_tsc[smp_processor_id()] = native_read_tsc();
1787+
cpu_tsc[smp_processor_id()] = rdtsc();
17881788
}
17891789

17901790
static int mce_apei_read_done;

0 commit comments

Comments
 (0)