From 10d42721e97fed6932af9d2f77334b391b3b07ed Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 15 Sep 2021 21:51:58 +0200 Subject: [PATCH] Add read_cycle_counter --- core/time.c | 7 +++++++ core/time.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/core/time.c b/core/time.c index 4bd7f42..b08b77d 100644 --- a/core/time.c +++ b/core/time.c @@ -27,3 +27,10 @@ unsigned long usecs_to_jiffies(const unsigned int u) // This could overflow return (u * HZ) / 1000000L; } + +#include +inline uint64_t read_cycle_counter() +{ + uint64_t tsc = __rdtsc(); + return tsc; +} diff --git a/core/time.h b/core/time.h index 699b33d..a5a4bdd 100644 --- a/core/time.h +++ b/core/time.h @@ -1,4 +1,5 @@ #pragma once +#include #define HZ 100 /* @@ -50,3 +51,5 @@ unsigned int jiffies_to_msecs(const unsigned long j); unsigned int jiffies_to_usecs(const unsigned long j); unsigned long msecs_to_jiffies(const unsigned int m); unsigned long usecs_to_jiffies(const unsigned int u); + +uint64_t read_cycle_counter();