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 Inline Diff

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