memtest86plus/system/tsc.h

41 lines
786 B
C
Raw Normal View History

2020-05-24 15:30:55 -05:00
// SPDX-License-Identifier: GPL-2.0
#ifndef TSC_H
#define TSC_H
/**
* \file
*
2020-05-24 15:30:55 -05:00
* Provides access to the CPU timestamp counter.
*
*//*
* Copyright (C) 2020-2022 Martin Whitaker.
2020-05-24 15:30:55 -05:00
*/
#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" \
)
/**
2020-05-24 15:30:55 -05:00
* 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