-
-
Save zenofile/e4e997058bde0da02ba73f01f32931e1 to your computer and use it in GitHub Desktop.
This file contains 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 <mcroce@redhat.com> | |
* 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