Add read_cycle_counter

This commit is contained in:
Mathieu Maret 2021-09-15 21:51:58 +02:00
parent 5a078249d0
commit 10d42721e9
2 changed files with 10 additions and 0 deletions

View File

@ -27,3 +27,10 @@ unsigned long usecs_to_jiffies(const unsigned int u)
// This could overflow // This could overflow
return (u * HZ) / 1000000L; return (u * HZ) / 1000000L;
} }
#include <x86intrin.h>
inline uint64_t read_cycle_counter()
{
uint64_t tsc = __rdtsc();
return tsc;
}

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#define HZ 100 #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 int jiffies_to_usecs(const unsigned long j);
unsigned long msecs_to_jiffies(const unsigned int m); unsigned long msecs_to_jiffies(const unsigned int m);
unsigned long usecs_to_jiffies(const unsigned int u); unsigned long usecs_to_jiffies(const unsigned int u);
uint64_t read_cycle_counter();