Compare View
Commits (3)
Diff
Showing 7 changed files Inline Diff
memory_access_time.c
View file @
6c373d6
File was created | 1 | #include<stdio.h> | ||
2 | #include <sys/time.h> | |||
3 | #include <stdlib.h> | |||
4 | ||||
5 | #define KB 1024 | |||
6 | #define MB 1024 * KB | |||
7 | #define MAX_ARRAY_SIZE 32*MB | |||
8 | #define STRIDE_SIZE 16 | |||
9 | #define CPU_FREQ 900 | |||
10 | ||||
11 | typedef unsigned long long int u64; | |||
12 | ||||
13 | u64 access_time_1(u64 size, int stride_size){ | |||
14 | struct timeval start, end; | |||
15 | struct timezone tz; | |||
16 | ||||
17 | int *array = (int *)malloc(size); | |||
18 | int len = (size)/sizeof(int); | |||
19 | unsigned int i; | |||
20 | ||||
21 | gettimeofday(&start, &tz); | |||
22 | for(i=0; i < MAX_ARRAY_SIZE; i++) { | |||
23 | array[( i * stride_size) % len]++; | |||
24 | } | |||
25 | gettimeofday(&end, &tz); | |||
26 | ||||
27 | free(array); | |||
28 | return ((end.tv_sec * 1e6) + end.tv_usec - (start.tv_sec * 1e6) - start.tv_usec); | |||
29 | } | |||
30 | ||||
31 | int main() | |||
32 | { | |||
33 | int i, j; | |||
34 | ||||
35 | for (j = 4; j <= 256; j*=2) { | |||
36 | printf("Stride size: %u\n", j); | |||
37 | for (i = 1024; i <= 32 * MB; i*=2) { | |||
38 | u64 access_time = access_time_1(i, j); | |||
39 | u64 overhead = 10; | |||
40 | double avg = (access_time * 1000.0)/(2 * MAX_ARRAY_SIZE); | |||
41 | printf("Size: %uKB access: %lluus, avg: %gns\n", i >> 10, access_time, avg - overhead); | |||
42 | } | |||
43 | } | |||
44 | return 0; | |||
45 | } | |||
#include<stdio.h> | 1 | 46 | ||
#include <sys/time.h> | 2 | |||
#include <stdlib.h> | 3 | |||
4 | ||||
#define KB 1024 | 5 | |||
#define MB 1024 * KB | 6 | |||
#define MAX_ARRAY_SIZE 32*MB | 7 | |||
#define STRIDE_SIZE 16 | 8 | |||
#define CPU_FREQ 900 | 9 | |||
10 | ||||
typedef unsigned long long int u64; | 11 | |||
12 | ||||
u64 access_time_1(u64 size, int stride_size){ | 13 | |||
struct timeval start, end; | 14 | |||
struct timezone tz; | 15 | |||
16 | ||||
int *array = (int *)malloc(size); | 17 | |||
int len = (size)/sizeof(int); | 18 | |||
unsigned int i; | 19 | |||
20 | ||||
gettimeofday(&start, &tz); | 21 | |||
for(i=0; i < MAX_ARRAY_SIZE; i++) { | 22 | |||
array[( i * stride_size) % len]++; | 23 | |||
} | 24 | |||
gettimeofday(&end, &tz); | 25 | |||
26 | ||||
free(array); | 27 | |||
return ((end.tv_sec * 1e6) + end.tv_usec - (start.tv_sec * 1e6) - start.tv_usec); | 28 | |||
} | 29 | |||
30 | ||||
int main() | 31 | |||
{ | 32 | |||
int i, j; | 33 | |||
34 | ||||
for (j = 4; j <= 32; j*=2) { | 35 | |||
printf("Stride size: %u\n", j); | 36 | |||
for (i = 1024; i <= 32 * MB; i*=2) { | 37 |
osproject_memory_ram_access.c
View file @
6c373d6
File was created | 1 | #include <stdio.h> | ||
2 | ||||
3 | int main() | |||
4 | { | |||
5 | unsigned int regr; | |||
6 | unsigned int a, b, i; | |||
7 | int arraya[8192] = {0}; | |||
8 | //int arrayb[8192]; | |||
9 | unsigned int avg = 0; | |||
10 | int temp; | |||
11 | ||||
12 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
13 | printf("regr: %x\n", regr); | |||
14 | ||||
15 | regr = 0; | |||
16 | ||||
17 | printf("Time for 256: %u\n", avg/1024); | |||
18 | return 1; | |||
19 | } | |||
#include <stdio.h> | 1 | 20 | ||
2 | ||||
int main() | 3 | |||
{ | 4 | |||
unsigned int regr; | 5 | |||
unsigned int a, b, i; | 6 | |||
int arraya[8192] = {0}; | 7 | |||
//int arrayb[8192]; | 8 | |||
unsigned int avg = 0; | 9 | |||
int temp; | 10 | |||
11 | ||||
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | 12 | |||
printf("regr: %x\n", regr); | 13 | |||
14 | ||||
regr = 0; | 15 |
osproject_syscall.c
View file @
6c373d6
#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 | ||||
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | 9 | 8 | ||
printf("regr: %x\n", regr); | 10 | 9 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |
11 | 10 | printf("regr: %x\n", regr); | ||
regr = 0; | 12 | 11 | ||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | 13 | 12 | regr = 0; | |
i = getpid(); | 14 | 13 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | |
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); | 15 | 14 | i = getpid(); | |
printf("PID: %u, Time for getpid: %u\n", i, b - a); | 16 | 15 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); | |
return 1; | 17 | 16 | printf("PID: %u, Time for getpid: %u\n", i, b - a); | |
} | 18 | |||
19 |
osproject_thread_creation.c
View file @
6c373d6
File was created | 1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | |||
3 | #include <pthread.h> | |||
4 | ||||
5 | int func(void *arg) { | |||
6 | return 0; | |||
7 | } | |||
8 | ||||
9 | #define STACK_SIZE 4096 | |||
10 | ||||
11 | int main() | |||
12 | { | |||
13 | unsigned int regr; | |||
14 | unsigned int a, b; | |||
15 | unsigned int avg; | |||
16 | int status; | |||
17 | void *child_stack = malloc(STACK_SIZE); | |||
18 | int thread_pid; | |||
19 | ||||
20 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
21 | printf("regr: %x\n", regr); | |||
22 | ||||
23 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | |||
24 | thread_pid = clone(&func, child_stack+STACK_SIZE, CLONE_SIGHAND|CLONE_FS|CLONE_VM|CLONE_FILES, NULL); | |||
25 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); | |||
26 | printf("Time for fork: %u\n", b - a); | |||
27 | ||||
28 | return 0; | |||
29 | } | |||
#include <stdio.h> | 1 | 30 | ||
#include <stdlib.h> | 2 | |||
#include <pthread.h> | 3 | |||
4 | ||||
int func(void *arg) { | 5 | |||
return 0; | 6 | |||
} | 7 | |||
8 | ||||
#define STACK_SIZE 4096 | 9 | |||
10 | ||||
int main() | 11 | |||
{ | 12 | |||
unsigned int regr; | 13 | |||
unsigned int a, b; | 14 | |||
unsigned int avg; | 15 | |||
int status; | 16 | |||
void *child_stack = malloc(STACK_SIZE); | 17 | |||
int thread_pid; | 18 | |||
19 | ||||
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | 20 | |||
printf("regr: %x\n", regr); | 21 | |||
22 | ||||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | 23 |
osproject_thread_time.c
View file @
6c373d6
File was created | 1 | #include <sched.h> | ||
2 | #include <pthread.h> | |||
3 | #include <unistd.h> | |||
4 | #include <stdio.h> | |||
5 | #include <stdlib.h> | |||
6 | #include <time.h> | |||
7 | #include <string.h> | |||
8 | #include <errno.h> | |||
9 | ||||
10 | static inline long long unsigned time_ns(struct timespec* const ts) { | |||
11 | if (clock_gettime(CLOCK_REALTIME, ts)) { | |||
12 | exit(1); | |||
13 | } | |||
14 | return ((long long unsigned) ts->tv_sec) * 1000000000LLU | |||
15 | + (long long unsigned) ts->tv_nsec; | |||
16 | } | |||
17 | ||||
18 | static const int iterations = 500000; | |||
19 | ||||
20 | static void* thread(void*ctx) { | |||
21 | (void)ctx; | |||
22 | int i; | |||
23 | for (i = 0; i < iterations; i++) | |||
24 | sched_yield(); | |||
25 | return NULL; | |||
26 | } | |||
27 | ||||
28 | int main(void) { | |||
29 | struct sched_param param; | |||
30 | int i; | |||
31 | param.sched_priority = 1; | |||
32 | if (sched_setscheduler(getpid(), SCHED_FIFO, ¶m)) | |||
33 | fprintf(stderr, "sched_setscheduler(): %s\n", strerror(errno)); | |||
34 | ||||
35 | struct timespec ts; | |||
36 | pthread_t thd; | |||
37 | if (pthread_create(&thd, NULL, thread, NULL)) { | |||
38 | return 1; | |||
39 | } | |||
40 | ||||
41 | long long unsigned start_ns = time_ns(&ts); | |||
42 | for (i = 0; i < iterations; i++) | |||
43 | sched_yield(); | |||
44 | long long unsigned delta = time_ns(&ts) - start_ns; | |||
45 | ||||
46 | const int nswitches = iterations << 2; | |||
47 | printf("%i thread context switches in %lluns (%.1fns/ctxsw)\n", | |||
48 | nswitches, delta, (delta / (float) nswitches)); | |||
49 | return 0; | |||
50 | } | |||
51 | ||||
#include <sched.h> | 1 | 52 | ||
#include <pthread.h> | 2 | |||
#include <unistd.h> | 3 | |||
#include <stdio.h> | 4 | |||
#include <stdlib.h> | 5 | |||
#include <time.h> | 6 | |||
#include <string.h> | 7 | |||
#include <errno.h> | 8 | |||
9 | ||||
static inline long long unsigned time_ns(struct timespec* const ts) { | 10 | |||
if (clock_gettime(CLOCK_REALTIME, ts)) { | 11 | |||
exit(1); | 12 | |||
} | 13 | |||
return ((long long unsigned) ts->tv_sec) * 1000000000LLU | 14 | |||
+ (long long unsigned) ts->tv_nsec; | 15 | |||
} | 16 | |||
17 | ||||
static const int iterations = 500000; | 18 | |||
19 | ||||
static void* thread(void*ctx) { | 20 | |||
(void)ctx; | 21 | |||
int i; | 22 | |||
for (i = 0; i < iterations; i++) | 23 | |||
sched_yield(); | 24 | |||
return NULL; | 25 | |||
} | 26 | |||
27 | ||||
int main(void) { | 28 | |||
struct sched_param param; | 29 | |||
int i; | 30 | |||
param.sched_priority = 1; | 31 | |||
if (sched_setscheduler(getpid(), SCHED_FIFO, ¶m)) | 32 | |||
fprintf(stderr, "sched_setscheduler(): %s\n", strerror(errno)); | 33 | |||
34 | ||||
struct timespec ts; | 35 | |||
pthread_t thd; | 36 | |||
if (pthread_create(&thd, NULL, thread, NULL)) { | 37 | |||
return 1; | 38 | |||
} | 39 | |||
40 | ||||
long long unsigned start_ns = time_ns(&ts); | 41 | |||
for (i = 0; i < iterations; i++) | 42 | |||
sched_yield(); | 43 |
osproject_tswitch.c
View file @
6c373d6
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 | #include <stdio.h> | |||
23 | int count, i, toSlave[2], fromSlave[2]; | |||
24 | ||||
25 | void *fn1() | |||
26 | { | |||
27 | char buffer[10]; | |||
28 | unsigned int end; | |||
29 | write(fromSlave[1], "a", 1); | |||
30 | while (1) { | |||
31 | read(toSlave[0], buffer, 1); | |||
32 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (end)); | |||
33 | printf("end: %u\n", end); | |||
34 | if (buffer[0] != 'a') { | |||
35 | return NULL; | |||
36 | } | |||
37 | //write(fromSlave[1], "a", 1); | |||
38 | } | |||
39 | } | |||
40 | ||||
41 | void *fn2() | |||
42 | { | |||
43 | unsigned int begin; | |||
44 | char buffer[10]; | |||
45 | read(fromSlave[0], buffer, 1); | |||
46 | for (i = 0; i < count; i++) { | |||
47 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (begin)); | |||
48 | write(toSlave[1], "a", 1); | |||
49 | //read(fromSlave[0], buffer, 1); | |||
50 | printf("Start: %u\n", begin); | |||
51 | // usleep(10000); | |||
52 | } | |||
53 | write(toSlave[1], "b", 1); | |||
54 | } | |||
55 | ||||
56 | int main(int argc, char **argv) | |||
57 | { | |||
58 | int pid; | |||
59 | char buffer[10]; | |||
60 | unsigned int begin ,end; | |||
61 | double timePer; | |||
62 | unsigned int regr; | |||
63 | int thread1, thread2; | |||
64 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
65 | printf("regr: %x\n", regr); | |||
66 | ||||
67 | count = 10; | |||
68 | pipe(toSlave); | |||
69 | pipe(fromSlave); | |||
70 | if(pthread_create(&thread1, NULL, &fn1, NULL)) { | |||
71 | printf("1 not created\n"); | |||
72 | exit(1); | |||
73 | } | |||
74 | ||||
75 | if(pthread_create(&thread2, NULL, &fn2, NULL)) { | |||
76 | printf("2 not created\n"); | |||
77 | exit(1); | |||
78 | } | |||
79 | pthread_join(thread1, NULL); | |||
80 | pthread_join(thread2, NULL); | |||
81 | return 0; | |||
82 | } | |||
/* | 1 | 83 | ||
* cswitch.c -- | 2 | |||
* | 3 | |||
* Simple program to test context switching by sending short | 4 | |||
* messages back and forth through a pipe. Invocation: | 5 | |||
* | 6 | |||
* cswitch count | 7 | |||
* | 8 | |||
* Count tells how many times a one-byte message should be sent | 9 | |||
* back and forth between two processes. | 10 | |||
* | 11 | |||
* Copyright 1987, 1989 Regents of the University of California | 12 | |||
* Permission to use, copy, modify, and distribute this | 13 | |||
* software and its documentation for any purpose and without | 14 | |||
* fee is hereby granted, provided that the above copyright | 15 | |||
* notice appear in all copies. The University of California | 16 | |||
* makes no representations about the suitability of this | 17 | |||
* software for any purpose. It is provided "as is" without | 18 | |||
* express or implied warranty. | 19 | |||
*/ | 20 | |||
21 | ||||
#include <stdio.h> | 22 | |||
int count, i, toSlave[2], fromSlave[2]; | 23 | |||
24 | ||||
void *fn1() | 25 | |||
{ | 26 | |||
char buffer[10]; | 27 | |||
unsigned int end; | 28 | |||
write(fromSlave[1], "a", 1); | 29 | |||
while (1) { | 30 | |||
read(toSlave[0], buffer, 1); | 31 | |||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (end)); | 32 | |||
printf("end: %u\n", end); | 33 | |||
if (buffer[0] != 'a') { | 34 | |||
return NULL; | 35 | |||
} | 36 | |||
//write(fromSlave[1], "a", 1); | 37 | |||
} | 38 | |||
} | 39 | |||
40 | ||||
void *fn2() | 41 | |||
{ | 42 | |||
unsigned int begin; | 43 | |||
char buffer[10]; | 44 | |||
read(fromSlave[0], buffer, 1); | 45 | |||
for (i = 0; i < count; i++) { | 46 | |||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (begin)); | 47 | |||
write(toSlave[1], "a", 1); | 48 | |||
//read(fromSlave[0], buffer, 1); | 49 | |||
printf("Start: %u\n", begin); | 50 | |||
// usleep(10000); | 51 | |||
} | 52 | |||
write(toSlave[1], "b", 1); | 53 | |||
} | 54 | |||
55 | ||||
int main(int argc, char **argv) | 56 | |||
{ | 57 | |||
int pid; | 58 | |||
char buffer[10]; | 59 | |||
unsigned int begin ,end; | 60 | |||
double timePer; | 61 | |||
unsigned int regr; | 62 | |||
int thread1, thread2; | 63 | |||
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | 64 | |||
printf("regr: %x\n", regr); | 65 | |||
66 | ||||
count = 10; | 67 | |||
pipe(toSlave); | 68 | |||
pipe(fromSlave); | 69 | |||
if(pthread_create(&thread1, NULL, &fn1, NULL)) { | 70 | |||
printf("1 not created\n"); | 71 | |||
exit(1); | 72 | |||
} | 73 | |||
74 | ||||
if(pthread_create(&thread2, NULL, &fn2, NULL)) { | 75 | |||
printf("2 not created\n"); | 76 |
osproject_tswitch_aravind.c
View file @
6c373d6
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 | #include <stdio.h> | |||
23 | #include <stdlib.h> | |||
24 | #include <pthread.h> | |||
25 | ||||
26 | int func(void *arg) { | |||
27 | return 0; | |||
28 | } | |||
29 | ||||
30 | #define STACK_SIZE 4096 | |||
31 | ||||
32 | ||||
33 | int main(int argc, char **argv) | |||
34 | { | |||
35 | int count, i, toSlave[2], fromSlave[2]; | |||
36 | int pid; | |||
37 | char buffer[10]; | |||
38 | unsigned int begin ,end; | |||
39 | double timePer; | |||
40 | unsigned int regr; | |||
41 | void *child_stack = malloc(STACK_SIZE); | |||
42 | int thread_pid; | |||
43 | asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |||
44 | printf("regr: %x\n", regr); | |||
45 | ||||
46 | count = 10; | |||
47 | pipe(toSlave); | |||
48 | pipe(fromSlave); | |||
49 | //pid = fork(); | |||
50 | pid = clone(&func, child_stack+STACK_SIZE, CLONE_SIGHAND|CLONE_FS|CLONE_VM|CLONE_FILES, NULL); | |||
51 | if (pid == 0) { | |||
52 | write(fromSlave[1], "a", 1); | |||
53 | while (1) { | |||
54 | read(toSlave[0], buffer, 1); | |||
55 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (end)); | |||
56 | if (buffer[0] != 'a') { | |||
57 | printf("Exiting\n"); | |||
58 | return -1; | |||
59 | } | |||
60 | //write(fromSlave[1], "a", 1); | |||
61 | printf("end: %u\n", end); | |||
62 | } | |||
63 | } | |||
64 | if (pid == -1) { | |||
65 | printf("Couldn't fork slave process: error %d.\n"); | |||
66 | return; | |||
67 | } | |||
68 | read(fromSlave[0], buffer, 1); | |||
69 | for (i = 0; i < count; i++) { | |||
70 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (begin)); | |||
71 | write(toSlave[1], "a", 1); | |||
72 | //read(fromSlave[0], buffer, 1); | |||
73 | usleep(10000); | |||
74 | printf("Start: %u\n", begin); | |||
75 | } | |||
76 | write(toSlave[1], "b", 1); | |||
77 | ||||
78 | timePer = (end - begin)/count; | |||
79 | printf("Elapsed time per ping (2 context switches): %.2f milliseconds.\n", | |||
80 | timePer); | |||
81 | } | |||
/* | 1 | 82 | ||
* cswitch.c -- | 2 | |||
* | 3 | |||
* Simple program to test context switching by sending short | 4 | |||
* messages back and forth through a pipe. Invocation: | 5 | |||
* | 6 | |||
* cswitch count | 7 | |||
* | 8 | |||
* Count tells how many times a one-byte message should be sent | 9 | |||
* back and forth between two processes. | 10 | |||
* | 11 | |||
* Copyright 1987, 1989 Regents of the University of California | 12 | |||
* Permission to use, copy, modify, and distribute this | 13 | |||
* software and its documentation for any purpose and without | 14 | |||
* fee is hereby granted, provided that the above copyright | 15 | |||
* notice appear in all copies. The University of California | 16 | |||
* makes no representations about the suitability of this | 17 | |||
* software for any purpose. It is provided "as is" without | 18 | |||
* express or implied warranty. | 19 | |||
*/ | 20 | |||
21 | ||||
#include <stdio.h> | 22 | |||
#include <stdlib.h> | 23 | |||
#include <pthread.h> | 24 | |||
25 | ||||
int func(void *arg) { | 26 | |||
return 0; | 27 | |||
} | 28 | |||
29 | ||||
#define STACK_SIZE 4096 | 30 | |||
31 | ||||
32 | ||||
int main(int argc, char **argv) | 33 | |||
{ | 34 | |||
int count, i, toSlave[2], fromSlave[2]; | 35 | |||
int pid; | 36 | |||
char buffer[10]; | 37 | |||
unsigned int begin ,end; | 38 | |||
double timePer; | 39 | |||
unsigned int regr; | 40 | |||
void *child_stack = malloc(STACK_SIZE); | 41 | |||
int thread_pid; | 42 | |||
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | 43 | |||
printf("regr: %x\n", regr); | 44 | |||
45 | ||||
count = 10; | 46 | |||
pipe(toSlave); | 47 | |||
pipe(fromSlave); | 48 | |||
//pid = fork(); | 49 | |||
pid = clone(&func, child_stack+STACK_SIZE, CLONE_SIGHAND|CLONE_FS|CLONE_VM|CLONE_FILES, NULL); | 50 | |||
if (pid == 0) { | 51 | |||
write(fromSlave[1], "a", 1); | 52 | |||
while (1) { | 53 | |||
read(toSlave[0], buffer, 1); | 54 | |||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (end)); | 55 | |||
if (buffer[0] != 'a') { | 56 | |||
printf("Exiting\n"); | 57 | |||
return -1; | 58 | |||
} | 59 | |||
//write(fromSlave[1], "a", 1); | 60 | |||
printf("end: %u\n", end); | 61 | |||
} | 62 | |||
} | 63 | |||
if (pid == -1) { | 64 | |||
printf("Couldn't fork slave process: error %d.\n"); | 65 | |||
return; | 66 | |||
} | 67 | |||
read(fromSlave[0], buffer, 1); | 68 | |||
for (i = 0; i < count; i++) { | 69 | |||
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (begin)); | 70 | |||
write(toSlave[1], "a", 1); | 71 | |||
//read(fromSlave[0], buffer, 1); | 72 | |||
usleep(10000); | 73 | |||
printf("Start: %u\n", begin); | 74 |