2020-05-24 15:30:55 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef TSC_H
|
|
|
|
#define TSC_H
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2020-05-24 15:30:55 -05:00
|
|
|
* Provides access to the CPU timestamp counter.
|
|
|
|
*
|
2022-02-19 13:56:55 -06:00
|
|
|
*//*
|
2022-02-19 10:17:40 -06:00
|
|
|
* 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" \
|
|
|
|
)
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
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
|