-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathworkload.c
96 lines (85 loc) · 2.49 KB
/
workload.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
/*
* B-Queue -- An efficient and practical queueing for fast core-to-core
* communication
*
* Copyright (C) 2011 Junchang Wang <[email protected]>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sched.h>
#include <stdint.h>
#include "fifo.h"
#include "workload.h"
/* All the consumers Read it. */
static char volatile src[MEM_LEN];
/* All the consumers Write to it. */
/* FIXME: there is cache thrashing */
static char volatile dst[MEM_LEN];
/* RAND_MAX assumed to be 32767 */
int myrand(unsigned long * next) {
*next = *next * 1103515245 + 12345;
return((unsigned)(*next/65536) % 32768);
}
/* making myrand works fine on 64bit systems. */
#define MY_RAND_MAX (32767)
#define rand myrand
/* FIXME: function rand() is not reentrant
* Check "man 3 rand"
* We need rand_r(), however it contains a lock
*/
inline unsigned long workload(unsigned long *next)
{
unsigned long result = 0;
int seed;
#if (PROBAB_MEMCPY>0)
seed = 1 + (int)( (float)PROBAB_MEMCPY * (rand(next) / (MY_RAND_MAX + 1.0)));
if(seed == 2) {
//printf(" PROBAB_MEMCPY \n ");
memcpy((char *)dst, (char *)src, MEM_LEN);
}
#endif
#if (PROBAB_MALLOC>0)
seed = 1 + (int)( (float)PROBAB_MALLOC * (rand(next) / (MY_RAND_MAX + 1.0)));
if(seed == 2) {
//printf(" PROBAB_MALLOC \n ");
temp = (char *)malloc(MEM_LEN);
temp[MEM_LEN-1] = '1';
free(temp);
}
#endif
#if (PROBAB_YIELD>0)
seed = 1 + (int)( (float)PROBAB_YIELD * (rand(next) / (MY_RAND_MAX + 1.0)));
if(seed == 2) {
//printf(" PROBAB_YIELD \n ");
sched_yield();
}
#endif
#if (PROBAB_WORKLOAD>0)
unsigned long i;
seed = 1 + (int)( (float)PROBAB_WORKLOAD * (rand(next) / (MY_RAND_MAX + 1.0)));
if(seed == 2) {
//printf(" PROBAB_LOAD \n ");
//wait_ticks(WORKLOAD);
for(i=0; i<WORKLOAD; i++) {
result += i;
result += result;
}
}
#endif
return result;
}