Commit 8a0f7262a03849b4e360e9ad1ae1d38b2b2bb2c3

Authored by Aravind Kumar
1 parent 951d6ba82c
Exists in master

Context switch process

Showing 1 changed file with 6 additions and 6 deletions Side-by-side Diff

cpu/context_switch_process.c View file @ 8a0f726
1 1 #include <stdio.h>
2 2 #include <stdlib.h>
  3 +
3 4 int main(int argc, char **argv)
4 5 {
5   - int count, i, toSlave[2], fromSlave[2];
  6 + int count, i, tochild[2], fromchild[2];
6 7 int pid, status;
7 8 char buffer[10];
8 9 unsigned int begin ,end;
9 10  
... ... @@ -12,12 +13,12 @@
12 13 printf("regr: %x\n", regr);
13 14  
14 15 count = 1000;
15   - pipe(toSlave);
  16 + pipe(tochild);
16 17 for (i = 0; i < count; i++)
17 18 {
18 19 pid = fork();
19 20 if (pid == 0) {
20   - read(toSlave[0], buffer, 1);
  21 + read(tochild[0], buffer, 1);
21 22 //if (buffer[0] != 'a') {
22 23 // printf("Exiting\n");
23 24 // return -1;
24 25  
... ... @@ -28,8 +29,8 @@
28 29 printf("Couldn't fork slave process: error %d.\n");
29 30 return -1;
30 31 } else {
  32 + write(tochild[1], "a", 1);
31 33 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (begin));
32   - write(toSlave[1], "a", 1);
33 34 waitpid(pid, &status, 0);
34 35 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (end));
35 36 //usleep(10000);
... ... @@ -39,7 +40,6 @@
39 40  
40 41 }
41 42 timePer = timePer/(2*900*count);
42   - printf("Average time taken for context switch: %.lf seconds.\n",
43   - timePer);
  43 + printf("Average time for context switch: %.lf seconds.\n", timePer);
44 44 }