Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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);
- /* a syscalls that does basically nothing but returning a number */
- getuid();
- time = __rdtscp(&junk) - time;
- /* the OS has always better things to do than take care of
- * our benchmarks, get the best value obtained
- */
- if (time < min)
- min = time;
- }
- printf("ctx: %llu clocks\n", min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement