Commit 4d907d60f992b1747a8676e5f788ba971e0e322a
0 parents
Exists in
master
First Checkpoint
Showing 8 changed files with 493 additions and 0 deletions Inline Diff
osproject.c
View file @
4d907d6
File was created | 1 | /* | ||
2 | * * hello.c The simplest kernel module. | |||
3 | * */ | |||
4 | #include <stdio.h> | |||
5 | ||||
6 | #define ARMV7_PMNC_E (1 << 0) /* Enable all counters */ | |||
7 | #define ARMV7_PMNC_P (1 << 1) /* Reset all counters */ | |||
8 | #define ARMV7_PMNC_C (1 << 2) /* Cycle counter reset */ | |||
9 | #define ARMV7_PMNC_D (1 << 3) /* CCNT counts every 64th cpu cycle */ | |||
10 | #define ARMV7_PMNC_X (1 << 4) /* Export to ETM */ | |||
11 | #define ARMV7_PMNC_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ | |||
12 | #define ARMV7_PMNC_N_SHIFT 11 /* Number of counters supported */ | |||
13 | #define ARMV7_PMNC_N_MASK 0x1f | |||
14 | #define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */ | |||
15 | ||||
16 | /*101b9173 | |||
17 | static u32 armv7_pmnc_read(void) | |||
18 | { | |||
19 | u32 val; | |||
20 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(val)); | |||
21 | return val; | |||
22 | } | |||
23 | ||||
24 | static void armv7_pmnc_write(u32 val) | |||
25 | { | |||
26 | val &= ARMV7_PMNC_MASK; | |||
27 | isb(); | |||
28 | asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(val)); | |||
29 | } | |||
30 | */ | |||
31 | ||||
32 | static void dummy() | |||
33 | { | |||
34 | } | |||
35 | ||||
36 | int main() | |||
37 | { | |||
38 | unsigned int regr; | |||
39 | unsigned int i; | |||
40 | unsigned int a, b; | |||
41 | ||||
42 | printf("CSE237A: Hello world.\n"); | |||
43 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
44 | printf("regr: %x\n", regr); | |||
45 |
osproject_cswitch.c
View file @
4d907d6
File was created | 1 | /* | ||
2 | * cswitch.c -- | |||
3 | * | |||
4 | * Simple program to test context switching by sending short | |||
5 | * messages back and forth through a pipe. Invocation: | |||
6 | * | |||
7 | * cswitch count | |||
8 | * | |||
9 | * Count tells how many times a one-byte message should be sent | |||
10 | * back and forth between two processes. | |||
11 | * | |||
12 | * Copyright 1987, 1989 Regents of the University of California | |||
13 | * Permission to use, copy, modify, and distribute this | |||
14 | * software and its documentation for any purpose and without | |||
15 | * fee is hereby granted, provided that the above copyright | |||
16 | * notice appear in all copies. The University of California | |||
17 | * makes no representations about the suitability of this | |||
18 | * software for any purpose. It is provided "as is" without | |||
19 | * express or implied warranty. | |||
20 | */ | |||
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 | #include <stdio.h> | |||
27 | #include <sys/time.h> | |||
28 | ||||
29 | main(argc,argv) | |||
30 | int argc; | |||
31 | char **argv; | |||
32 | { | |||
33 | int count, i, toSlave[2], fromSlave[2]; | |||
34 | int pid; | |||
35 | char buffer[10]; | |||
36 | struct timeval begin ,end; | |||
37 | int micros; | |||
38 | double timePer; | |||
39 | extern int errno; | |||
40 | ||||
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); | |||
47 | pipe(toSlave); | |||
48 | pipe(fromSlave); | |||
49 | 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 | } | |||
59 | } | |||
60 | if (pid == -1) { | |||
61 | fprintf(stderr, "Couldn't fork slave process: error %d.\n", | |||
62 | errno); | |||
63 | return; | |||
64 | } | |||
65 | read(fromSlave[0], buffer, 1); | |||
66 | gettimeofday(&begin, (struct timezone *) NULL); | |||
67 | for (i = 0; i < count; i++) { | |||
68 | write(toSlave[1], "a", 1); | |||
69 | read(fromSlave[0], buffer, 1); | |||
70 | } | |||
71 | gettimeofday(&end, (struct timezone *) NULL); | |||
72 | micros = 1000000*(end.tv_sec - begin.tv_sec) | |||
73 | + end.tv_usec - begin.tv_usec; | |||
74 | write(toSlave[1], "b", 1); | |||
75 | timePer = micros; |
osproject_pipe.c
View file @
4d907d6
File was created | 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) { |
osproject_syscall.c
View file @
4d907d6
File was created | 1 | #include <stdio.h> | ||
2 | ||||
3 | int main() | |||
4 | { | |||
5 | unsigned int regr; | |||
6 | unsigned int i; | |||
7 | unsigned int a, b; | |||
8 | ||||
9 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
10 | printf("regr: %x\n", regr); | |||
11 | ||||
12 | regr = 0; | |||
13 | while ( regr < 10) | |||
14 | { | |||
15 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | |||
16 | i = getpid(); | |||
17 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); | |||
18 | ||||
19 | printf("PID: %u, Time for getpid: %u\n", i, b - a); |
osproject_task.c
View file @
4d907d6
File was created | 1 | #include <stdio.h> | ||
2 | ||||
3 | int main() | |||
4 | { | |||
5 | unsigned int regr; | |||
6 | unsigned int a, b; | |||
7 | unsigned int avg; | |||
8 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
9 | printf("regr: %x\n", regr); | |||
10 | ||||
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" (b)); | |||
14 | regr += (b - a); | |||
15 | } | |||
16 | ||||
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 | } |
osproject_thread.c
View file @
4d907d6
File was created | 1 | #include<stdio.h> | ||
2 | #include<string.h> | |||
3 | #include<pthread.h> | |||
4 | #include<stdlib.h> | |||
5 | #include<unistd.h> | |||
6 | ||||
7 | pthread_t tid[100]; | |||
8 | ||||
9 | void* doSomeThing(void *arg) | |||
10 | { | |||
11 | } | |||
12 | ||||
13 | int main(void) | |||
14 | { | |||
15 | int i = 0; | |||
16 | int err; | |||
17 | int avg = 0; | |||
18 | int a, b; | |||
19 | ||||
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); |
osproject_threadpipe.c
View file @
4d907d6
File was created | 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)); |
osproject_time.c
View file @
4d907d6
File was created | 1 | #include <stdio.h> | ||
2 | ||||
3 | /* | |||
4 | static void dummy() | |||
5 | { | |||
6 | } | |||
7 | */ | |||
8 | ||||
9 | int dummy1(int a) | |||
10 | { | |||
11 | int i = a; | |||
12 | return i; | |||
13 | } | |||
14 | ||||
15 | int dummy2(int a, int b) | |||
16 | { | |||
17 | int i = b; | |||
18 | return i; | |||
19 | } | |||
20 | ||||
21 | int dummy3(int a, int b, int c) | |||
22 | { | |||
23 | int i = c; | |||
24 | return i; | |||
25 | } | |||
26 | ||||
27 | int dummy4(int a, int b, int c, int d) | |||
28 | { | |||
29 | int i = d; | |||
30 | return i; | |||
31 | } | |||
32 | ||||
33 | int dummy5(int a, int b, int c, int d, int e) | |||
34 | { | |||
35 | int i = e; | |||
36 | return i; | |||
37 | } | |||
38 | ||||
39 | int dummy6(int a, int b, int c, int d, int e, int f) | |||
40 | { | |||
41 | int i = f; | |||
42 | return i; | |||
43 | } | |||
44 | ||||
45 | int dummy7(int a, int b, int c, int d, int e, int f, int g) | |||
46 | { | |||
47 | int i = g; | |||
48 | return i; | |||
49 | } | |||
50 | ||||
51 | int main() | |||
52 | { | |||
53 | unsigned int regr; | |||
54 | unsigned int a, b; | |||
55 | unsigned int c1, c2, c3, c4, c5, c6, c7; | |||
56 | int d; | |||
57 | ||||
58 | printf("CSE237A: Hello world.\n"); | |||
59 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
60 | printf("regr: %x\n", regr); | |||
61 | ||||
62 | /* | |||
63 | for (i = 0; i < 10; i++) { | |||
64 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | |||
65 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); | |||
66 | printf("c[%u]: %u\n", i, b - a); | |||
67 | } | |||
68 | ||||
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); | |||
78 | ||||
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); | |||
83 | ||||
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); | |||
88 | ||||
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); |