This repository has been archived by the owner on Jul 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilization.c
108 lines (90 loc) · 1.95 KB
/
utilization.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <time.h>
void *foreverCPULoop(void *arg)
{
/*
* Using random numbers tasks both FPU instruction branching
*/
char *str;
str=(char*)arg;
printf("inside CPU loop");
while(1)
{
srand(time(NULL));
float i = 99.9 * 99.9;
int j = 99 * rand();
if(i>j){
float i = 88.8 * rand();
}
}
return NULL;
}
void *foreverHDDLoop(void *arg)
{
/*
* Writes random numbers to 10,000 character file. Randomly chooses
* a location under index 5000 to read 5000 characters forward on
*/
while(1)
{
printf("inside HDD loop");
FILE *file;
file = fopen("taskHDDFile","w");
int iterator;
srand(time(NULL));
for ( iterator = 0; iterator < 10000; iterator++ )
{
fprintf(file,"%d",rand());
}
fclose(file);
char buffer[sizeof(int)*10000];
if (file = fopen("taskHDDFile", "r+"))
{
for ( iterator = 0; iterator < 5; iterator++ )
{
int random_number = rand() %5000;
fread(buffer, 1, (random_number+5000), file);
}
fclose(file);
}
}
return NULL;
}
void *foreverMemLoop(void *arg)
{
/*
* Creates large Matrix. Matrices are stored in memory as row1,row2,...rowN
* thus accessing column 1 of row1,row2,row3, etc. causes cache miss at each
* access
*/
srand(time(NULL));
while(1)
{
printf("inside Mem loop");
int temp_array[1024][1024];
int column, row;
for(column=0; column<=1023; column++)
{
for(row=0; row<=1023; row++)
{
temp_array[row][column] = rand();
}
}
}
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t pth1, pth2, pth3, pth4;
pthread_create(&pth1,NULL,foreverCPULoop,"processing...");
pthread_create(&pth2,NULL,foreverCPULoop,"processing...");
pthread_create(&pth3,NULL,foreverCPULoop,"processing...");
pthread_create(&pth4,NULL,foreverCPULoop,"processing...");
pthread_join(pth1, NULL );
pthread_join(pth2, NULL );
pthread_join(pth3, NULL );
pthread_join(pth4, NULL );
return 0;
}