x86_64: rdstc

arm: attempt pmccntr, but didn't work, TODO why: no QEMU support?
This commit is contained in:
Ciro Santilli
2018-04-15 12:40:01 +01:00
parent ae780f6750
commit 51e31cdc29
6 changed files with 118 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ These programs can also be compiled and used on host.
.... link:init_dev_kmsg.c[]
.. link:uio_read.c[]
.. link:rand_check.c[]
.. link:rdtsc.c[]
. Module tests
.. link:anonymous_inode.c[]
.. link:poll.c[]

View File

@@ -0,0 +1,26 @@
/*
Only works in x86_64.
- https://en.wikipedia.org/wiki/Time_Stamp_Counter
- https://stackoverflow.com/questions/9887839/clock-cycle-count-wth-gcc/9887979
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#if defined(__i386__) || defined(__x86_64__)
#include <x86intrin.h>
#endif
int main(void) {
uintmax_t val;
#if defined(__i386__) || defined(__x86_64__)
/* https://stackoverflow.com/questions/9887839/clock-cycle-count-wth-gcc/9887979 */
val = __rdtsc();
#else
val = 0;
#endif
printf("%jx\n", val);
return EXIT_SUCCESS;
}