-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregion.cpp
More file actions
116 lines (103 loc) · 3.08 KB
/
Copy pathregion.cpp
File metadata and controls
116 lines (103 loc) · 3.08 KB
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
109
110
111
112
113
114
115
116
#include "region.h"
#include "bucket.h"
#include "cachesim.h"
#include "datastructs.h"
#include "pin.H"
#include <cassert>
#include <cstring>
#include <cxxabi.h>
#include <iostream>
std::unordered_map<char *, Region *> g_regions;
Region::Region(char *region) : region_{strdup(region)}, thread_count_{0}
{
// add region buckets for every CacheSim, init with zero
size_t num_cachesims = g_cachesims.size();
buckets_.reserve(num_cachesims);
buckets_entry_.reserve(num_cachesims);
for (size_t i = 0; i < num_cachesims; i++) {
buckets_.push_back(std::vector<BucketPair>{Bucket::min_dists.size()});
buckets_entry_.push_back(std::vector<BucketPair>{Bucket::min_dists.size()});
}
}
Region::~Region()
{
// std::cout << "free region: " << region_ << "\n";
free(region_);
region_ = nullptr;
}
void Region::on_region_entry()
{
// make snapshot of current buckets access counts
thread_count_++;
if (thread_count_ > 1) {
return;
}
// std::cout << "entry region: " << region_ << "\n";
/** TODO: better implementation */
size_t cs_num = 0;
for (auto &cs : g_cachesims) {
size_t b = 0;
for (auto &bucket : cs->partition0_.buckets()) {
buckets_entry_[cs_num][b].first = bucket;
b++;
}
b = 0;
for (auto &bucket : cs->partition1_.buckets()) {
buckets_entry_[cs_num][b].second = bucket;
b++;
}
cs_num++;
}
}
void Region::on_region_exit()
{
// last thread leaving a region does the counting
thread_count_--;
if (thread_count_ > 0) {
return;
}
// std::cout << "exit region: " << region_ << "\n";
/** TODO: better implementation */
size_t cs_num = 0;
for (auto &cs : g_cachesims) {
size_t b = 0;
for (auto &bucket : cs->partition0_.buckets()) {
buckets_[cs_num][b].first.add_sub(bucket, buckets_entry_[cs_num][b].first);
b++;
}
b = 0;
for (auto &bucket : cs->partition1_.buckets()) {
buckets_[cs_num][b].second.add_sub(bucket, buckets_entry_[cs_num][b].second);
b++;
}
cs_num++;
}
}
void Region::register_datastruct()
{
buckets_.push_back(std::vector<BucketPair>{Bucket::min_dists.size()});
buckets_entry_.push_back(std::vector<BucketPair>{Bucket::min_dists.size()});
}
/** TODO: there is also a more portable pin function for this **/
void Region::demangle_name()
{
int status = -1;
char *demangled_name = abi::__cxa_demangle(region_, NULL, NULL, &status);
// printf("Demangled: %s\n", demangled_name);
// set region name to the demangled name without arguments if it was a mangled function
if (nullptr != demangled_name) {
free(region_);
region_ = demangled_name;
strtok(region_, "(");
}
// std::cout << "new region: " << region_ << "\n";
}
void Region::print_csv(FILE *csv_out)
{
demangle_name();
size_t cs_num = 0;
for (auto &cs : g_cachesims) {
cs->print_csv(csv_out, region_, buckets_[cs_num]);
cs_num++;
}
}