1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/common/include/villas/tsc.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
925 B
C++
Raw Permalink Normal View History

/* Measure time and sleep with IA-32 time-stamp counter.
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#if !(__x86_64__ || __i386__)
#error this header is for x86 only
#endif
#include <cinttypes>
#include <cpuid.h>
2021-09-13 15:11:51 +02:00
#include <x86intrin.h>
2019-10-27 20:23:47 +01:00
#include <villas/kernel/kernel.hpp>
#ifndef bit_TSC
#define bit_TSC (1 << 4)
#endif
#define bit_TSC_INVARIANT (1 << 8)
#define bit_RDTSCP (1 << 27)
2021-08-11 12:40:19 -04:00
struct Tsc {
uint64_t frequency;
bool rdtscp_supported;
bool is_invariant;
};
__attribute__((unused)) static uint64_t tsc_now(struct Tsc *t) {
uint32_t tsc_aux;
return t->rdtscp_supported ? __rdtscp(&tsc_aux) : __rdtsc();
2018-10-21 20:24:47 +01:00
}
int tsc_init(struct Tsc *t) __attribute__((warn_unused_result));
2021-08-11 12:40:19 -04:00
uint64_t tsc_rate_to_cycles(struct Tsc *t, double rate);