Last active
February 25, 2022 04:22
-
-
Save teknoraver/ebee75c5bc4eb8533b8e761d0e57b7d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ctx_time Copyright (C) 2018 Matteo Croce <[email protected]> | |
* a tool measure the context switch time in clock cycles | |
*/ | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <limits.h> | |
#include <string.h> | |
#include <x86intrin.h> | |
int main (int argc, char *argv[]) | |
{ | |
int i; | |
unsigned long long min = ULLONG_MAX; | |
unsigned long long time; | |
unsigned junk; | |
for (i = 0; i < 10000000; i++) { | |
time = __rdtscp(&junk); | |
/* Can't be used with BSD because raises a SIGSYS which | |
* consumes ~200 extra clock cycles even if trapped. | |
* Replace with: | |
* getuid(); | |
*/ | |
syscall(-1L); | |
time = __rdtscp(&junk) - time; | |
if (time < min) | |
min = time; | |
} | |
printf("ctx: %llu clocks\n", min); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment