Commit c71458d20f17ef747cb314f2526701454e35335a
1 parent
4d907d60f9
Exists in
master
Context switch working
Showing 1 changed file with 28 additions and 40 deletions Side-by-side Diff
osproject_cswitch.c
View file @
c71458d
... | ... | @@ -19,62 +19,50 @@ |
19 | 19 | * express or implied warranty. |
20 | 20 | */ |
21 | 21 | |
22 | -#ifndef lint | |
23 | -static char rcsid[] = "$Header: /sprite/src/benchmarks/cswitch/RCS/cswitch.c,v 1.1 89/08/31 13:19:37 ouster Exp $ SPRITE (Berkeley)"; | |
24 | -#endif not lint | |
25 | - | |
26 | 22 | #include <stdio.h> |
27 | -#include <sys/time.h> | |
28 | - | |
29 | -main(argc,argv) | |
30 | - int argc; | |
31 | - char **argv; | |
23 | +int main(int argc, char **argv) | |
32 | 24 | { |
33 | 25 | int count, i, toSlave[2], fromSlave[2]; |
34 | 26 | int pid; |
35 | 27 | char buffer[10]; |
36 | - struct timeval begin ,end; | |
37 | - int micros; | |
28 | + unsigned int begin ,end; | |
38 | 29 | double timePer; |
39 | - extern int errno; | |
30 | + unsigned int regr; | |
31 | + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |
32 | + printf("regr: %x\n", regr); | |
40 | 33 | |
41 | - if (argc != 2 ) { | |
42 | - fprintf(stderr, "Ping takes one argument: count.\n"); | |
43 | - return; | |
44 | - } | |
45 | - count = 0; | |
46 | - sscanf(argv[1], "%d", &count); | |
34 | + count = 10; | |
47 | 35 | pipe(toSlave); |
48 | 36 | pipe(fromSlave); |
49 | 37 | pid = fork(); |
50 | - if (pid == 0) { | |
51 | - write(fromSlave[1], "a", 1); | |
52 | - while (1) { | |
53 | - read(toSlave[0], buffer, 1); | |
54 | - if (buffer[0] != 'a') { | |
55 | - exit(0); | |
56 | - } | |
57 | - write(fromSlave[1], "a", 1); | |
58 | - } | |
38 | + if (pid == 0) { | |
39 | + write(fromSlave[1], "a", 1); | |
40 | + while (1) { | |
41 | + read(toSlave[0], buffer, 1); | |
42 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (end)); | |
43 | + if (buffer[0] != 'a') { | |
44 | + printf("Exiting\n"); | |
45 | + return -1; | |
46 | + } | |
47 | + //write(fromSlave[1], "a", 1); | |
48 | + printf("end: %u\n", end); | |
49 | + } | |
59 | 50 | } |
60 | - if (pid == -1) { | |
61 | - fprintf(stderr, "Couldn't fork slave process: error %d.\n", | |
62 | - errno); | |
63 | - return; | |
64 | - } | |
51 | + if (pid == -1) { | |
52 | + printf("Couldn't fork slave process: error %d.\n"); | |
53 | + return; | |
54 | + } | |
65 | 55 | read(fromSlave[0], buffer, 1); |
66 | - gettimeofday(&begin, (struct timezone *) NULL); | |
67 | 56 | for (i = 0; i < count; i++) { |
68 | - write(toSlave[1], "a", 1); | |
69 | - read(fromSlave[0], buffer, 1); | |
57 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (begin)); | |
58 | + write(toSlave[1], "a", 1); | |
59 | + //read(fromSlave[0], buffer, 1); | |
60 | + usleep(10000); | |
61 | + printf("Start: %u\n", begin); | |
70 | 62 | } |
71 | - gettimeofday(&end, (struct timezone *) NULL); | |
72 | - micros = 1000000*(end.tv_sec - begin.tv_sec) | |
73 | - + end.tv_usec - begin.tv_usec; | |
74 | 63 | write(toSlave[1], "b", 1); |
75 | - timePer = micros; | |
76 | - timePer /= count * 1000; | |
77 | 64 | |
65 | + timePer = (end - begin)/count; | |
78 | 66 | printf("Elapsed time per ping (2 context switches): %.2f milliseconds.\n", |
79 | 67 | timePer); |
80 | 68 | } |