Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Aug 20, 2023
1 parent 0b022a4 commit 40b184d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 63 deletions.
5 changes: 5 additions & 0 deletions artifact/gen_workloads.sh
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
#!/bin/bash
# anns
# monetdb
# pointer_chasing lmbench3
# wrf stream
# mlc
2 changes: 1 addition & 1 deletion include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <fnmatch.h>
#include <linux/perf_event.h>
#include <map>
#include <signal.h>
#include <csignal>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down
3 changes: 2 additions & 1 deletion include/incore.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ union CPUID_INFO {
unsigned int eax, ebx, ecx, edx;
} reg;
};
/** This is a per cha metrics*/
class Incore {
public:
PerfInfo *perf[5];
Expand All @@ -21,7 +22,7 @@ class Incore {
~Incore() = default;
int start();
int stop();
void init_all_dram_rds(const pid_t pid, const int cpu);
// void init_all_dram_rds(const pid_t pid, const int cpu);
void init_cpu_l2stall(const pid_t pid, const int cpu);
void init_cpu_llcl_hits(const pid_t pid, const int cpu);
void init_cpu_llcl_miss(const pid_t pid, const int cpu);
Expand Down
32 changes: 0 additions & 32 deletions include/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,6 @@
#include <tuple>
#include <unistd.h>

class ThreadSafeMap {
public:
ThreadSafeMap() = default;

// Multiple threads/readers can read the Map's value at the same time.
std::map<unsigned long, std::tuple<unsigned long, unsigned long long int>> get() const {
std::shared_lock lock(mutex_);
return res;
}

// Only one thread/writer can increment/write the Map's value.
void insert(unsigned long address, unsigned long size, unsigned long long time) {
std::unique_lock lock(mutex_);
res[address] = std::make_tuple(size, time);
}

// Only one thread/writer can reset/write the Map's value.
void reset() {
std::unique_lock lock(mutex_);
res.clear();
}

private:
mutable std::shared_mutex mutex_;
std::map<unsigned long, std::tuple<unsigned long, unsigned long long>> res;
};

class PerfInfo {
public:
int fd;
Expand All @@ -58,18 +31,13 @@ class PerfInfo {
pid_t pid;
unsigned long flags;
struct perf_event_attr attr;
ThreadSafeMap *map;
std::jthread j;
PerfInfo(int group_fd, int cpu, pid_t pid, unsigned long flags, struct perf_event_attr attr);
PerfInfo(int fd, int group_fd, int cpu, pid_t pid, unsigned long flags, struct perf_event_attr attr);
~PerfInfo();
ssize_t read_pmu(uint64_t *value);
std::map<uint64_t, uint64_t> read_trace_pipe();
int start();
int stop();
};

PerfInfo *init_incore_perf(const pid_t pid, const int cpu, uint64_t conf, uint64_t conf1);
PerfInfo *init_incore_bpf_perf(const pid_t pid, const int cpu);
void write_trace_to_map(ThreadSafeMap *map);
#endif // CXL_MEM_SIMULATOR_PERF_H
24 changes: 10 additions & 14 deletions src/incore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int Incore::stop() {
}
return r;
}
void Incore::init_all_dram_rds(const pid_t pid, const int cpu) {
this->perf[0] = init_incore_perf(pid, cpu, perf_config->all_dram_rds_config, perf_config->all_dram_rds_config1);
}
// void Incore::init_all_dram_rds(const pid_t pid, const int cpu) {
// this->perf[0] = init_incore_perf(pid, cpu, perf_config->all_dram_rds_config, perf_config->all_dram_rds_config1);
// }
void Incore::init_cpu_mem_read(const pid_t pid, const int cpu) {
this->perf[0] = init_incore_perf(pid, cpu, perf_config->cpu_bandwidth_read_config, 0);
}
Expand All @@ -51,7 +51,7 @@ void Incore::init_cpu_llcl_miss(const pid_t pid, const int cpu) {
this->perf[3] = init_incore_perf(pid, cpu, perf_config->cpu_llcl_miss_config, 0);
}
void Incore::init_cpu_mem_write(const pid_t pid, const int cpu) {
this->perf[5] = init_incore_perf(pid, cpu, perf_config->cpu_bandwidth_write_config, 0);
this->perf[4] = init_incore_perf(pid, cpu, perf_config->cpu_bandwidth_write_config, 0);
}
int Incore::read_cpu_elems(struct CPUElem *elem) {
ssize_t r;
Expand Down Expand Up @@ -90,20 +90,16 @@ int Incore::read_cpu_elems(struct CPUElem *elem) {
// return r;
// }
// LOG(DEBUG) << fmt::format("read cpu_bandwidth_read:{}\n", elem->cpu_bandwidth_read);
// r = this->perf[5]->read_pmu(&elem->cpu_bandwidth_write);
// if (r < 0) {
// LOG(ERROR) << fmt::format("read cpu_bandwidth_write failed.\n");
// return r;
// }
// LOG(DEBUG) << fmt::format("read cpu_bandwidth_write:{}\n", elem->cpu_bandwidth_write);
if (this->perf[4] != nullptr) {
elem->cpu_munmap_address_length = this->perf[4]->read_trace_pipe();
LOG(DEBUG) << "read munmap result with size:" << elem->cpu_munmap_address_length.size() << "\n";
r = this->perf[4]->read_pmu(&elem->cpu_bandwidth_write);
if (r < 0) {
LOG(ERROR) << fmt::format("read cpu_bandwidth_write failed.\n");
return r;
}
LOG(DEBUG) << fmt::format("read cpu_bandwidth_write:{}\n", elem->cpu_bandwidth_write);
}
Incore::Incore(const pid_t pid, const int cpu, struct PerfConfig *perf_config) : perf_config(perf_config) {
/* reset all pmc values */
this->init_all_dram_rds(pid, cpu);
// this->init_all_dram_rds(pid, cpu);
this->init_cpu_mem_read(pid, cpu);
this->init_cpu_l2stall(pid, cpu);
this->init_cpu_llcl_hits(pid, cpu);
Expand Down
16 changes: 1 addition & 15 deletions src/perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ PerfInfo::PerfInfo(int group_fd, int cpu, pid_t pid, unsigned long flags, struct
ioctl(this->fd, PERF_EVENT_IOC_RESET, 0);
}
PerfInfo::PerfInfo(int fd, int group_fd, int cpu, pid_t pid, unsigned long flags, struct perf_event_attr attr)
: fd(fd), group_fd(group_fd), cpu(cpu), pid(pid), flags(flags), attr(attr) {
this->map = new ThreadSafeMap();
}
: fd(fd), group_fd(group_fd), cpu(cpu), pid(pid), flags(flags), attr(attr) {}
PerfInfo::~PerfInfo() {
this->j.join();
if (this->fd != -1) {
close(this->fd);
this->fd = -1;
Expand Down Expand Up @@ -53,17 +50,6 @@ int PerfInfo::stop() {
}
return 0;
}
std::map<uint64_t, uint64_t> PerfInfo::read_trace_pipe() {
auto traces = map->get();
std::map<uint64_t, uint64_t> addr_map;
for (auto r : traces) {
std::cout << r.first << " " << std::get<0>(r.second) << " " << std::get<1>(r.second) << std::endl;
// address, length, time -> address, length no lazyaccess
addr_map[r.first] = std::get<0>(r.second);
}
map->reset();
return addr_map;
}

PerfInfo *init_incore_perf(const pid_t pid, const int cpu, uint64_t conf, uint64_t conf1) {
int n_pid, n_cpu, group_fd, flags;
Expand Down

0 comments on commit 40b184d

Please sign in to comment.