Commit 17110dd658a61de166c9fcee007d68575b7d271b

Authored by Sathya Narayanan
1 parent c71458d20f
Exists in master

Latest 2/1

Showing 8 changed files with 139 additions and 266 deletions Side-by-side Diff

loopoverhead.c View file @ 17110dd
  1 +#include <stdio.h>
  2 +
  3 +int main()
  4 +{
  5 + int time1, time2, sum=0;
  6 + int i;
  7 + int avg = 0;
  8 + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (i));
  9 + printf("regr: %x\n", i);
  10 +
  11 + while(sum < 1000) {
  12 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1));
  13 + for (i = 0; i < 100; i++);
  14 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2));
  15 + sum++;
  16 + avg += (time2 - time1 - 5);
  17 + }
  18 +
  19 + printf("Loop overhead: %u\n", avg/(1000));
  20 +}
... ... @@ -39,15 +39,16 @@
39 39 unsigned int i;
40 40 unsigned int a, b;
41 41  
42   - printf("CSE237A: Hello world.\n");
43 42 asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
44 43 printf("regr: %x\n", regr);
45 44  
46   - for (i = 0; i < 10; i++) {
  45 + regr = 0;
  46 + for (i = 0; i < 1000; i++) {
47 47 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
48 48 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
49   - printf("c[%u]: %u\n", i, b - a);
  49 + regr += b - a;
50 50 }
  51 + printf("Measurement overhead: %u\n", regr);
51 52  
52 53  
53 54 return 1;
osproject_pipe.c View file @ 17110dd
1   -#include <sys/types.h>
2   -#include <unistd.h>
3   -#include <stdio.h>
4   -#include <stdlib.h>
5   -#include <signal.h>
6   -
7   -/* Read characters from the pipe and echo them to stdout. */
8   -
9   -unsigned int time1, time2;
10   -unsigned int avg = 0;
11   -
12   -int read_from_pipe (int file)
13   -{
14   -
15   - unsigned int c;
16   - FILE *stream = fdopen (file, "r");
17   - fread(&c, sizeof(c), 1, stream);
18   - //while ((c = fgetc (stream)) != EOF)
19   - // putchar (c);
20   - fclose (stream);
21   - return c;
22   -
23   -}
24   -
25   -/* Write some random text to the pipe. */
26   -
27   -void write_to_pipe (int file)
28   -{
29   - unsigned int c;
30   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (c));
31   - FILE *stream;
32   - stream = fdopen (file, "w");
33   - fwrite(&c, sizeof(c), 1, stream);
34   -// fprintf (stream, "hello, world!\n");
35   -// fprintf (stream, "goodbye, world!\n");
36   - fclose (stream);
37   -
38   -}
39   -
40   -int main (void)
41   -{
42   - pid_t pid;
43   - int mypipe[2];
44   - int i = 0;
45   - unsigned int regr;
46   -
47   - /* Create the pipe. */
48   - if (pipe (mypipe)) {
49   - printf ("Pipe failed.\n");
50   - return EXIT_FAILURE;
51   - }
52   -
53   - asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
54   - printf("regr: %x\n", regr);
55   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (regr));
56   - /* Create the child process. */
57   - if ((pid = fork()) == -1)
58   - exit(1);
59   -
60   - if (pid) {
61   - while(i < 100) {
62   - /* This is the child process. Close other end first. */
63   - printf("parent process\n");
64   - close (mypipe[1]);
65   - time1 = read_from_pipe (mypipe[0]);
66   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2));
67   - printf("time2: %u, time1: %u, avg: %u\n", time2, time1, time2 - time1);
68   - avg += (time2 - time1);
69   - i++;
70   - }
71   - //kill(pid, SIGKILL);
72   - } else {
73   - while( i < 100) {
74   - /* This is the parent process. Close other end first. */
75   - printf("child process\n");
76   - close (mypipe[0]);
77   - //asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1));
78   - write_to_pipe (mypipe[1]);
79   - usleep(1000);
80   - i++;
81   - }
82   - }
83   -
84   - printf("Avg switching time: %u\n", avg);
85   - return 0;
86   -}
osproject_syscall.c View file @ 17110dd
... ... @@ -5,20 +5,24 @@
5 5 unsigned int regr;
6 6 unsigned int i;
7 7 unsigned int a, b;
  8 + float avg = 0.0;
8 9  
9 10 asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
10 11 printf("regr: %x\n", regr);
11 12  
12 13 regr = 0;
13   - while ( regr < 10)
  14 + while ( regr < 10000)
14 15 {
15 16 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
16 17 i = getpid();
17 18 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
18   -
19   - printf("PID: %u, Time for getpid: %u\n", i, b - a);
  19 + if (regr==0)
  20 + printf("PID: %u, Time for getpid: %u\n", i, b - a);
  21 + else
  22 + avg+=(b-a);
20 23 regr++;
21 24 }
  25 + printf("Time: %f\n", avg/9999);
22 26 return 1;
23 27 }
osproject_task.c View file @ 17110dd
1 1 #include <stdio.h>
  2 +#include <stdlib.h>
2 3  
3 4 int main()
4 5 {
5 6 unsigned int regr;
6 7 unsigned int a, b;
7 8 unsigned int avg;
  9 + int status;
8 10 asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
9 11 printf("regr: %x\n", regr);
10 12  
11   - for (regr = 0; regr < 100; regr++) {
12   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  13 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  14 + int pid = fork();
  15 + if (pid) {
13 16 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
14   - regr += (b - a);
  17 + printf("Time for fork: %u\n", b - a);
15 18 }
16 19  
17   - regr /= 100;
18   - printf("Measurement overhead: %u\n", regr);
19   - regr = 0;
20   - while (regr < 100) {
21   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
22   - fork();
23   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
24   - printf("Time for fork: %u\n", b - a);
25   - avg += (b - a);
26   - regr++;
27   - }
28   -
29   - printf("Fork avg: %u\n", avg);
30   - return 1;
  20 + return 0;
31 21 }
osproject_thread.c View file @ 17110dd
... ... @@ -5,9 +5,14 @@
5 5 #include<unistd.h>
6 6  
7 7 pthread_t tid[100];
8   -
9   -void* doSomeThing(void *arg)
  8 +int avg =0;
  9 +static const int iterations = 50000;
  10 +int b=0; //Nasty
  11 +void* doSomeThing(void *somectx)
10 12 {
  13 + int i;
  14 + for(i =0;i< iterations; i++)
  15 + sched_yield();
11 16 }
12 17  
13 18 int main(void)
14 19  
15 20  
... ... @@ -15,26 +20,21 @@
15 20 int i = 0;
16 21 int err;
17 22 int avg = 0;
18   - int a, b;
  23 + int a;
19 24  
20   - printf("Entering the thing\n");
21   -
22   - asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (err));
23   - printf("regr: %x\n", err);
24   -
25   - while(i < 100) {
26   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
27   - err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
28   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
29   - if (err != 0)
30   - printf("Error in thread creation\n");
31   - //printf("Time for fork: %u\n", b - a);
32   - avg += (b - a);
33   - pthread_cancel(tid[i]);
34   - i++;
  25 + printf("Thread Creation Overhead\n");
  26 + //Create only one thread
  27 + if(pthread_create(&(tid[i]), NULL, &doSomeThing, NULL)){
  28 + exit(1);
35 29 }
36   -
37   - printf("Avg thread creation time is %d\n", avg/100);
  30 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  31 + for(i=0; i < iterations; i++)
  32 + sched_yield();
  33 + asm volatile("mrc p15, 0, %0, c9, c13, 0": "=r" (b));
  34 + //2 because there are two context switches for every iteration
  35 + printf("Before:%d, After:%d",a,b);
  36 + printf("Avg thread creation time: %d\n ms", (b-a)/(iterations*2));
  37 +
38 38 return 1;
39 39 }
osproject_threadpipe.c View file @ 17110dd
1   -#include<stdio.h>
2   -#include<string.h>
3   -#include<pthread.h>
4   -#include<stdlib.h>
5   -#include<unistd.h>
6   -#include<sys/types.h>
7   -#include<sys/time.h>
8   -
9   -int fd[2];
10   -int n = 0;
11   -long now = 0;
12   -
13   -unsigned int time1, time2, time3;
14   -unsigned int avg = 0;
15   -
16   -void * writeThread()
17   -{
18   -// for(n=1000;n>0;n--)
19   -// {
20   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1));
21   - write(fd[1],(void*)&time1,sizeof(time1));
22   -
23   - usleep(1000);
24   -// }
25   - return 0;
26   -}
27   -
28   -void * readThread()
29   -{
30   - unsigned int switchTime;
31   -// for(n=1000;n>0;n--)
32   -// {
33   - read(fd[0],(void*)&time3,sizeof(time3));
34   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2));
35   - switchTime = time2 - time3;
36   - avg = avg + switchTime;
37   -// }
38   - avg = avg/1000;
39   - return 0;
40   -}
41   -
42   -
43   -
44   -
45   -int main(int argc, char ** argv) {
46   -
47   - pthread_t tid1,tid2;
48   - int i = 0;
49   - unsigned int regr;
50   -
51   - /* Create the pipe. */
52   - if (pipe (fd)) {
53   - printf ("Pipe failed.\n");
54   - return EXIT_FAILURE;
55   - }
56   -
57   - asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
58   - printf("regr: %x\n", regr);
59   - if (regr == 0)
60   - exit(1);
61   - printf("here\n");
62   - pthread_create(&tid1,NULL,writeThread,NULL);
63   - pthread_create(&tid2,NULL,readThread,NULL);
64   - /*pthread_join(tid1,NULL);
65   - * pthread_join(tid2,NULL);
66   - * */
67   - printf("%u",avg);
68   - return 0;
69   -}
osproject_time.c View file @ 17110dd
1 1 #include <stdio.h>
2 2  
3   -/*
  3 +
4 4 static void dummy()
5 5 {
6 6 }
7   -*/
8 7  
9   -int dummy1(int a)
  8 +void dummy1(int a)
10 9 {
11   - int i = a;
12   - return i;
13 10 }
14 11  
15   -int dummy2(int a, int b)
  12 +void dummy2(int a, int b)
16 13 {
17   - int i = b;
18   - return i;
19 14 }
20 15  
21   -int dummy3(int a, int b, int c)
  16 +void dummy3(int a, int b, int c)
22 17 {
23   - int i = c;
24   - return i;
25 18 }
26 19  
27   -int dummy4(int a, int b, int c, int d)
  20 +void dummy4(int a, int b, int c, int d)
28 21 {
29   - int i = d;
30   - return i;
31 22 }
32 23  
33   -int dummy5(int a, int b, int c, int d, int e)
  24 +void dummy5(int a, int b, int c, int d, int e)
34 25 {
35   - int i = e;
36   - return i;
37 26 }
38 27  
39   -int dummy6(int a, int b, int c, int d, int e, int f)
  28 +void dummy6(int a, int b, int c, int d, int e, int f)
40 29 {
41   - int i = f;
42   - return i;
43 30 }
44 31  
45   -int dummy7(int a, int b, int c, int d, int e, int f, int g)
  32 +void dummy7(int a, int b, int c, int d, int e, int f, int g)
46 33 {
47   - int i = g;
48   - return i;
49 34 }
50 35  
51 36 int main()
52 37  
53 38  
54 39  
55 40  
56 41  
57 42  
58 43  
59 44  
60 45  
61 46  
62 47  
... ... @@ -53,60 +38,88 @@
53 38 unsigned int regr;
54 39 unsigned int a, b;
55 40 unsigned int c1, c2, c3, c4, c5, c6, c7;
56   - int d;
  41 + int d, i;
  42 + float c[8];
  43 + for (i=0; i<8; i++)
  44 + c[i]=0;
57 45  
58   - printf("CSE237A: Hello world.\n");
59 46 asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
60 47 printf("regr: %x\n", regr);
61 48  
62   -/*
63   - for (i = 0; i < 10; i++) {
  49 + for (i = 0; i < 50000; i++) {
64 50 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  51 + dummy();
65 52 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
66   - printf("c[%u]: %u\n", i, b - a);
  53 + c[0] += b - a - 5;
67 54 }
  55 + printf("Procedure call overhead: %f\n", c[0]/50000);
  56 + for (i = 0; i < 50000; i++) {
  57 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  58 + dummy1(1);
  59 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  60 +// printf("Procedure call overhead with one arg: %f\n", b - a);
  61 + c[1] += b - a - 5;
  62 + }
  63 + printf("Procedure call overhead: %f\n", c[1]/50000);
68 64  
69   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
70   - dummy();
71   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
72   - printf("Procedure call overhead: %u\n", b - a);
73   -*/
74   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
75   - d = dummy1(1);
76   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
77   - printf("Procedure call overhead with one arg: %u\n", b - a);
  65 + for (i = 0; i < 50000; i++) {
  66 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  67 + dummy2(c1, 2);
  68 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  69 +// printf("Procedure call overhead with 2 args: %f\n", b - a);
  70 + c[2] += b - a - 5;
  71 + }
  72 + printf("Procedure call overhead: %f\n", c[2]/50000);
78 73  
79   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
80   - d = dummy2(c1, 2);
81   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
82   - printf("Procedure call overhead with 2 args: %u\n", b - a);
  74 + for (i = 0; i < 50000; i++) {
  75 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  76 + dummy3(c1, c2, 3);
  77 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  78 +// printf("Procedure call overhead with 3 args: %f\n", b - a);
  79 + c[3] += b - a - 5;
  80 + }
  81 + printf("Procedure call overhead: %f\n", c[3]/50000);
83 82  
84   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
85   - d = dummy3(c1, c2, 3);
86   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
87   - printf("Procedure call overhead with 3 args: %u\n", b - a);
  83 + for (i = 0; i < 50000; i++) {
  84 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  85 + dummy4(c1, c2, c3, 4);
  86 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  87 +// printf("Procedure call overhead with 4 args: %f\n", b - a);
  88 + c[4] += b - a - 5;
  89 + }
  90 + printf("Procedure call overhead: %f\n", c[4]/50000);
88 91  
89   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
90   - d = dummy4(c1, c2, c3, 4);
91   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
92   - printf("Procedure call overhead with 4 args: %u\n", b - a);
  92 + for (i = 0; i < 50000; i++) {
  93 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  94 + dummy5(c1, c2, c3, c4, 5);
  95 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  96 +// printf("Procedure call overhead with 5 args: %f\n", b - a);
  97 + c[5] += b - a - 5;
  98 + }
  99 + printf("Procedure call overhead: %f\n", c[5]/50000);
93 100  
94   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
95   - d = dummy5(c1, c2, c3, c4, 5);
96   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
97   - printf("Procedure call overhead with 5 args: %u\n", b - a);
  101 + for (i = 0; i < 50000; i++) {
  102 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  103 + dummy6(c1, c2, c3, c4, c5, 6);
  104 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  105 +// printf("Procedure call overhead with 6 args: %f\n", b - a);
  106 + c[6] += b - a - 5;
  107 + }
  108 + printf("Procedure call overhead: %f\n", c[6]/50000);
98 109  
99   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
100   - d = dummy6(c1, c2, c3, c4, c5, 6);
101   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
102   - printf("Procedure call overhead with 6 args: %u\n", b - a);
103   -
104   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
105   - d = dummy7(c1, c2, c3, c4, c5, c6, 7);
106   - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
107   - printf("Procedure call overhead with 7 args: %u\n", b - a);
108   - printf("d: %d\n", d);
109   -
  110 + for (i = 0; i < 50000; i++) {
  111 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  112 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  113 + dummy7(c1, c2, c3, c4, c5, c6, 7);
  114 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  115 +// printf("Procedure call overhead with 7 args: %f\n", b - a);
  116 + c[7] += b - a - 5;
  117 + }
  118 + printf("Procedure call overhead: %f\n", c[7]/50000);
  119 +/*
  120 + for (i = 0; i < 8; i++)
  121 + printf("i: %d, time: %f\n", i, c[i]);
  122 +*/
110 123 return 0;
111 124 }