Commit 8eef3f5dcb05c7322a51ffe1f523ee1fd46e617d
1 parent
a6ea1595c9
Exists in
master
getpid syscall
Showing 7 changed files with 55 additions and 7 deletions Side-by-side Diff
cpu/getpid.c
View file @
8eef3f5
1 | +#define _GNU_SOURCE | |
2 | +#include <unistd.h> | |
3 | +#include <sys/syscall.h> | |
4 | +#include <sys/types.h> | |
5 | +#include <signal.h> | |
6 | +#include <sys/time.h> | |
7 | +#include <stdio.h> | |
8 | + | |
9 | +int main(int argc, char *argv[]) | |
10 | +{ | |
11 | + pid_t tid; | |
12 | + int i = 0; | |
13 | + float avg_read_time = 0; | |
14 | + struct timeval tv1, tv2; | |
15 | + float avg_syscall_time = 0; | |
16 | + unsigned int dummy; | |
17 | + | |
18 | + for (i = 0; i < 1000; i++) { | |
19 | + gettimeofday(&tv1, NULL); | |
20 | + gettimeofday(&tv2, NULL); | |
21 | + avg_read_time += (tv2.tv_sec*1e6 + tv2.tv_usec - tv1.tv_sec*1e6 - tv1.tv_usec); | |
22 | + } | |
23 | + | |
24 | + printf("avg_read_time: %f\n", avg_read_time/1000.0); | |
25 | + | |
26 | + for (i = 0; i < 100; i++) { | |
27 | + gettimeofday(&tv1, NULL); | |
28 | + syscall(SYS_tgkill, getpid(), tid, SIGHUP); | |
29 | + gettimeofday(&tv2, NULL); | |
30 | + dummy += (tv2.tv_sec*1e6 + tv2.tv_usec - tv1.tv_sec*1e6 - tv1.tv_usec); | |
31 | + avg_syscall_time += dummy; | |
32 | + printf("avg_syscall_time: %u\n", dummy); | |
33 | + avg_syscall_time -= avg_read_time; | |
34 | + } | |
35 | + printf("avg_syscall_time: %f\n", avg_syscall_time/100.0); | |
36 | + return 0; | |
37 | +} |
cpu/loop_overhead_time.c
View file @
8eef3f5
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1)); |
13 | 13 | for (i = 0; i < 1000; i++); |
14 | 14 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2)); |
15 | - avg = (time2 - time1 - 5); //5 is measurement overhead for mrc | |
15 | + avg = (time2 - time1 - 5)/1000; //5 is measurement overhead for mrc | |
16 | 16 | sum++; |
17 | 17 | } |
18 | 18 | printf("%f", avg/100); |
cpu/loop_overhead_time.o
View file @
8eef3f5
cpu/reading_time.c
View file @
8eef3f5
... | ... | @@ -9,13 +9,13 @@ |
9 | 9 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (time)); |
10 | 10 | |
11 | 11 | time = 0; |
12 | - for (i = 0; i < 1000; i++) { | |
12 | + for (i = 0; i < 10000; i++) { | |
13 | 13 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); |
14 | 14 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); |
15 | 15 | time += b - a; |
16 | 16 | //printf("%d,", b-a); |
17 | 17 | } |
18 | - avg = time / 1000; | |
18 | + avg = time / 10000; | |
19 | 19 | printf("Measurement overhead: %f\n", avg); |
20 | 20 | return 0; |
21 | 21 | } |
cpu/reading_time.o
View file @
8eef3f5
cpu/syscall.c
View file @
8eef3f5
1 | 1 | #include <stdio.h> |
2 | +#include <sys/syscall.h> | |
3 | +#include <sys/types.h> | |
4 | +#include <unistd.h> | |
5 | +#include <stdio.h> | |
6 | +#include <assert.h> | |
2 | 7 | |
3 | 8 | int main() |
4 | 9 | { |
5 | 10 | unsigned int regr; |
6 | - unsigned int i; | |
7 | - unsigned int a, b; | |
11 | + unsigned int i, i2; | |
12 | + unsigned int a, b, c; | |
8 | 13 | |
9 | 14 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); |
10 | 15 | // printf("regr: %x\n", regr); |
11 | 16 | |
12 | 17 | regr = 0; |
18 | + i2 = getpid(); | |
13 | 19 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); |
14 | - i = getpid(); | |
20 | + //syscall(getpid()); | |
21 | + i = syscall(SYS_getpid); | |
15 | 22 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); |
16 | - printf("PID: %u, Time for getpid: %u\n", i, b - a); | |
23 | + //getpid(); | |
24 | + i = syscall(SYS_getpid); | |
25 | + //syscall(getpid()); | |
26 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (c)); | |
27 | + printf("PID: %u %u, Time for getpid: %u, %u\n", i, i2, b - a, c - b); | |
17 | 28 | return 0; |
18 | 29 | } |
cpu/syscall.o
View file @
8eef3f5