This is an example about dummy syscall test in linux kernel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include <sys/utsname.h> #include <errno.h> #include <time.h> #include <sched.h> #include <stdalign.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <syscall.h> #include <signal.h> #include <stdint.h> #include <errno.h> #include <string.h> #include <sys/wait.h>
int main(void) { unsigned long i = 0; int nr_mysyscall; struct utsname buffer; struct timespec tstart={0,0}, tend={0,0};
errno = 0; if (uname(&buffer) != 0) { perror("uname"); exit(EXIT_FAILURE); }
if (buffer.release[0] == '5') { printf("5.10 kernel\n"); clock_gettime(CLOCK_MONOTONIC, &tstart); for (i=0; i<30000000; i++) syscall(335); clock_gettime(CLOCK_MONOTONIC, &tend); printf("took about %.5f seconds\n", ((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec)); } else { printf("4.19 kernel\n"); clock_gettime(CLOCK_MONOTONIC, &tstart); for (i=0; i<30000000; i++) syscall(438); clock_gettime(CLOCK_MONOTONIC, &tend); printf("took about %.5f seconds\n", ((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec));
}
return 0; }
|