memtest86plus/system/tsc.h
2020-05-24 21:30:55 +01:00

38 lines
761 B
C

// SPDX-License-Identifier: GPL-2.0
#ifndef TSC_H
#define TSC_H
/*
* Provides access to the CPU timestamp counter.
*
* Copyright (C) 2020 Martin Whitaker.
*/
#include <stdint.h>
#define rdtsc(low, high) \
__asm__ __volatile__("rdtsc" \
: "=a" (low), \
"=d" (high) \
)
#define rdtscl(low) \
__asm__ __volatile__("rdtsc" \
: "=a" (low) \
: /* no inputs */ \
: "edx" \
)
/*
* Reads and returns the timestamp counter value.
*/
static inline uint64_t get_tsc(void)
{
uint32_t tl;
uint32_t th;
rdtsc(tl, th);
return (uint64_t)th << 32 | (uint64_t)tl;
}
#endif // TSC_H