-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime.c
83 lines (71 loc) · 1.47 KB
/
prime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Copyright (c) 2005 Russ Cox, MIT; see COPYRIGHT */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <task.h>
#include <sys/time.h>
int quiet;
int goal;
int buffer;
uint64_t start_time = 0;
uint64_t end_time = 0;
uint64_t GetCurrentMs() {
struct timeval time;
gettimeofday(&time, NULL);
//return time.tv_sec * 1000 + time.tv_usec / 1000;
return time.tv_sec * 1000ul + time.tv_usec / 1000;
}
uint64_t GetCurrentUs() {
struct timeval time;
gettimeofday(&time, NULL);
return time.tv_sec * 1000 * 1000ul + time.tv_usec;
}
void
primetask(void *arg)
{
//Channel *c, *nc;
int c, p, i;
c = arg;
//p = chanrecvul(c);
//if(p > goal)
// taskexitall(0);
//if(!quiet)
// printf("%d\n", p);
//nc = chancreate(sizeof(unsigned long), buffer);
//taskcreate(primetask, nc, 32768);
//for(;;){
// i = chanrecvul(c);
// if(i%p)
// chansendul(nc, i);
//}
while(c--)
taskyield();
end_time = GetCurrentMs();
printf("end_time: %ld\n", end_time);
printf("elapse time: %ld\n", end_time - start_time);
}
void
taskmain(int argc, char **argv)
{
int i;
Channel *c;
if(argc>1)
goal = atoi(argv[1]);
else
goal = 100;
printf("goal=%d\n", goal);
c = chancreate(sizeof(unsigned long), buffer);
taskcreate(primetask, 1000000, 32768);
start_time = GetCurrentMs();
printf("start_time: %ld\n", start_time);
}
void*
emalloc(unsigned long n)
{
return calloc(n ,1);
}
long
lrand(void)
{
return rand();
}