1 /* SPDX-License-Identifier: GPL-2.0-only */
8 #if CONFIG(TSC_SYNC_MFENCE)
9 #define TSC_SYNC "mfence\n"
10 #elif CONFIG(TSC_SYNC_LFENCE)
11 #define TSC_SYNC "lfence\n"
20 typedef struct tsc_struct tsc_t
;
22 static inline tsc_t
rdtsc(void)
28 : "=a" (res
.lo
), "=d"(res
.hi
) /* outputs */
33 /* Simple 32- to 64-bit multiplication. Uses 16-bit words to avoid overflow.
34 * This code is used to prevent use of libgcc's umoddi3.
36 static inline void multiply_to_tsc(tsc_t
*const tsc
, const u32 a
, const u32 b
)
38 tsc
->lo
= (a
& 0xffff) * (b
& 0xffff);
39 tsc
->hi
= ((tsc
->lo
>> 16)
40 + ((a
& 0xffff) * (b
>> 16))
41 + ((b
& 0xffff) * (a
>> 16)));
42 tsc
->lo
= ((tsc
->hi
& 0xffff) << 16) | (tsc
->lo
& 0xffff);
43 tsc
->hi
= ((a
>> 16) * (b
>> 16)) + (tsc
->hi
>> 16);
46 static inline uint64_t tsc_to_uint64(tsc_t tstamp
)
48 return (((uint64_t)tstamp
.hi
) << 32) + tstamp
.lo
;
51 static inline unsigned long long rdtscll(void)
53 return tsc_to_uint64(rdtsc());
56 /* Provided by CPU/chipset code for the TSC rate in MHz. */
57 unsigned long tsc_freq_mhz(void);
59 static inline int tsc_constant_rate(void)
61 return !CONFIG(UNKNOWN_TSC_RATE
);
64 #endif /* CPU_X86_TSC_H */