-
Notifications
You must be signed in to change notification settings - Fork 63
/
libpfc-raw-helpers.hpp
56 lines (45 loc) · 1.77 KB
/
libpfc-raw-helpers.hpp
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
/*
* libpfc-raw-helpers.hpp
*
* Stuff dealing with "raw" libpfc benchmarks, which are those that embed the rdpmc call directly
* in the benchmark itself, rather than using the generic mechanism exposed by LibPfcTimer.
*/
#ifndef LIBPFC_RAW_HELPERS_HPP_
#define LIBPFC_RAW_HELPERS_HPP_
#include "libpfc-timer.hpp"
#if USE_LIBPFC
#include <functional>
extern "C" {
/**
* libpfc raw functions implement this function and store their timing results in result,
* which is passed in rdx (the LibpfcNow* argument)
* [rdx + 0] <-- INST_RETIRED.ANY
* [rdx + 8] <-- CPU_CLK_UNHALTED.THREAD (aka clock cycles)
* [rdx + 16] <-- CPU_CLK_UNHALTED.REF_TSC
* [rdx + 24] <-- programmable counter 1
* ...
*/
using libpfc_raw1 = void(size_t loop_count, void *arg, LibpfcNow* results);
libpfc_raw1 raw_rdpmc0_overhead;
libpfc_raw1 raw_rdpmc4_overhead;
}
template <int samples, libpfc_raw1 METHOD, bench2_f WARM_EVERY = inlined_empty>
std::array<LibpfcNow, samples> libpfc_raw_adapt(size_t loop_count, void *arg) {
std::array<LibpfcNow, samples> result = {};
for (int i = 0; i < samples; i++) {
WARM_EVERY(loop_count, arg);
METHOD(loop_count, arg, &result[i]);
}
return result;
}
/**
* Create an overhead calculation function which is suitable for use by OneShotMaker.withOverhead()
*/
template <libpfc_raw1 OMETHOD>
std::function<LibpfcNow(Context&)> libpfc_raw_overhead_adapt(const std::string& name, size_t loop_count = 0, void* arg = nullptr) {
// calculate the overhead using raw_rdpmc_overhead, binding loops and arg to 0 and nullptr
auto o1 = std::bind(libpfc_raw_adapt<ONESHOT_OVERHEAD_TOTAL, OMETHOD>, 0, nullptr);
return [o1, name](Context& c){ return rawToOverhead<LibpfcTimer>(c, o1, name); };
}
#endif // USE_LIBPFC
#endif /* LIBPFC_RAW_HELPERS_HPP_ */