-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_sequential_read.c
70 lines (58 loc) · 2.13 KB
/
plugin_sequential_read.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
/*
Copyright (C) 2012
Fabien Gaud <[email protected]>, Baptiste Lepers <[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.
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/>.
*/
/*
* In this benchmark plugin, each worker thread/core performs
* a sequence of (64-bit) memory load instructions on contiguous
* memory locations inside a per-thread buffer
*/
#include "plugin_sequential_read.h"
#include <stdlib.h>
#include <string.h>
/*
* Init phase:
* Memset the array so that it is fully paged in memory before the bench
*/
void bench_seq_init(uint64_t *memory_to_access, uint64_t memory_size) {
memset(memory_to_access, 0, memory_size);
}
/*
* Benchmark
* The "O0" attribute is required to make sure that the compiler does not optimize the code
*/
uint64_t bench_seq_read(uint64_t* memory_to_access, uint64_t memory_size, uint64_t time, uint32_t thread_no) {
int j, fake = 0;
uint64_t start, current, nb_iterations = 0;
rdtscll(start);
while(1) {
/*
* The loop is partially unrolled in order to increase
* the ratio of load instructions vs branch instructions
*/
for (j = 0; j < (memory_size / sizeof(*memory_to_access)); j += 8) {
fake += memory_to_access[j];
fake += memory_to_access[j + 1];
fake += memory_to_access[j + 2];
fake += memory_to_access[j + 3];
fake += memory_to_access[j + 4];
fake += memory_to_access[j + 5];
fake += memory_to_access[j + 6];
fake += memory_to_access[j + 7];
}
nb_iterations++;
rdtscll(current);
if(current - start >= time)
break;
}
return memory_size * nb_iterations;
}