mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 10:15:57 +01:00
x86_64: rdstc
arm: attempt pmccntr, but didn't work, TODO why: no QEMU support?
This commit is contained in:
@@ -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[]
|
||||
|
||||
26
kernel_module/user/rdtsc.c
Normal file
26
kernel_module/user/rdtsc.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user