Skip to content

Commit

Permalink
change to cha
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Aug 23, 2023
1 parent 40b184d commit 83d8417
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 116 deletions.
7 changes: 6 additions & 1 deletion artifact/gen_workloads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
# monetdb
# pointer_chasing lmbench3
# wrf stream
# mlc
# mlc

git clone https://github.com/scott-beamer/gapbs.git
cd gapbs
make benchmark

12 changes: 0 additions & 12 deletions include/alloc.h

This file was deleted.

34 changes: 22 additions & 12 deletions include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <vector>
#include <optional>

/* CPU Models */
enum { CPU_MDL_BDX = 63, CPU_MDL_SKX = 85, CPU_MDL_SPR = 143, CPU_MDL_ADL = 151, CPU_MDL_END = 0x0ffff };
Expand Down Expand Up @@ -51,18 +52,25 @@ struct LatencyPass {
double ma_wb;
};

struct CBOElem {
struct CHAElem {
uint64_t llc_wb;
};

struct CPUElem {
uint64_t all_dram_rds;
uint64_t cpu_l2stall_t;
uint64_t cpu_llcl_hits;
uint64_t cpu_llcl_miss;
uint64_t cpu_bandwidth_read;
uint64_t cpu_bandwidth_write;
std::map<uint64_t, uint64_t> cpu_munmap_address_length;
};

struct CPUTargetElem {
uint64_t all_dram_rds;
uint64_t cpu_l2stall_t;
uint64_t cpu_llcl_hits;
uint64_t cpu_llcl_miss;
uint64_t cpu_cxl_traffic_read;
uint64_t cpu_cxl_traffic_write;
};

struct PEBSElem {
Expand All @@ -79,34 +87,36 @@ struct CPUInfo {

struct Elem {
struct CPUInfo cpuinfo;
struct CBOElem *cbos;
struct CPUElem *cpus;
std::vector<CHAElem> chas;
std::vector<CPUElem> cpus;
struct PEBSElem pebs;
};

class PMUInfo {
public:
std::vector<Uncore> cbos;
std::vector<Uncore> chas;
std::vector<Incore> cpus;
Helper *helper;
PMUInfo(pid_t pid, Helper *h, struct PerfConfig *perf_config);
~PMUInfo();
int start_all_pmcs();
int stop_all_pmcs();
int freeze_counters_cbo_all();
int unfreeze_counters_cbo_all();
int freeze_counters_cha_all();
int unfreeze_counters_cha_all();
};

struct PerfConfig {
const char *path_format_cbo_type;
uint64_t cbo_config;
const char *path_format_cha_type;
uint64_t cha_config;
uint64_t all_dram_rds_config;
uint64_t all_dram_rds_config1;
uint64_t cpu_l2stall_config;
uint64_t cpu_llcl_hits_config;
uint64_t cpu_llcl_miss_config;
uint64_t cpu_bandwidth_read_config;
uint64_t cpu_bandwidth_write_config;
std::optional<uint64_t> cpu_cxl_traffic_read_config; // use this to initialize the cxl traffic
std::optional<uint64_t> cpu_cxl_traffic_write_config; // use this to initialize the cxl traffic
};

struct ModelContext {
Expand All @@ -117,12 +127,12 @@ struct ModelContext {
class Helper {
public:
int cpu;
int cbo;
int cha;
double cpu_freq;
PerfConfig perf_conf;
Helper();
static int num_of_cpu();
static int num_of_cbo();
static int num_of_cha();
static void detach_children();
static void noop_handler(int signum);
double cpu_frequency() const;
Expand Down
14 changes: 6 additions & 8 deletions include/incore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ class Incore {
public:
PerfInfo *perf[5];
struct PerfConfig *perf_config;
Incore(const pid_t pid, const int cpu, struct PerfConfig *perf_config);
Incore(pid_t pid, int cpu, struct PerfConfig *perf_config);
~Incore() = default;
int start();
int stop();
// 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);
void init_cpu_mem_read(const pid_t pid, const int cpu);
void init_cpu_mem_write(const pid_t pid, const int cpu);
void init_cpu_ebpf(const pid_t pid, const int cpu);
void init_cpu_l2stall(pid_t pid,int cpu);
void init_cpu_llcl_hits(pid_t pid,int cpu);
void init_cpu_llcl_miss(pid_t pid,int cpu);
void init_cpu_mem_read(pid_t pid,int cpu);
void init_cpu_mem_write(pid_t pid,int cpu);

int read_cpu_elems(struct CPUElem *cpu_elem);
};
Expand Down
4 changes: 2 additions & 2 deletions include/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Monitor;
class Monitors {
public:
std::vector<Monitor> mon;
Monitors(int tnum, cpu_set_t *use_cpuset, int nmem, Helper h);
Monitors(int tnum, cpu_set_t *use_cpuset, Helper h);
~Monitors() = default;

void stop_all(const int);
Expand Down Expand Up @@ -57,7 +57,7 @@ class Monitor {
bool is_process;
struct PEBS *pebs_ctx;

Monitor(const int nmem, Helper h);
Monitor(Helper h);

void stop();
void run();
Expand Down
2 changes: 1 addition & 1 deletion include/uncore.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Uncore {
Uncore(const uint32_t unc_idx, PerfConfig *perf_config);
~Uncore() = default;

int read_cbo_elems(struct CBOElem *elem);
int read_cha_elems(struct CHAElem *elem);
};

#endif // CXL_MEM_SIMULATOR_UNCORE_H
57 changes: 29 additions & 28 deletions src/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const struct ModelContext model_ctx[] = {{CPU_MDL_BDX,
{"/sys/bus/event_source/devices/uncore_cbox_%u/type",
/*
* cbo_config:
* cha_config:
* unc_c_llc_victims.m_state
* umask=0x1,event=0x37
*/
Expand Down Expand Up @@ -51,7 +51,7 @@ const struct ModelContext model_ctx[] = {{CPU_MDL_BDX,
{CPU_MDL_SKX,
{"/sys/bus/event_source/devices/uncore_cha_%u/type",
/*
* cbo_config:
* cha_config:
* UNC_C_LLC_VICTIMS
* umask=0x21,event=37
*/
Expand Down Expand Up @@ -95,7 +95,7 @@ const struct ModelContext model_ctx[] = {{CPU_MDL_BDX,
{CPU_MDL_SPR,
{"/sys/bus/event_source/devices/uncore_cha_%u/type",
/*
* cbo_config:
* cha_config:
* UNC_C_LLC_VICTIMS => OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD
* umask=0x10,event=b0
*/
Expand Down Expand Up @@ -139,7 +139,7 @@ const struct ModelContext model_ctx[] = {{CPU_MDL_BDX,
{CPU_MDL_ADL,
{"/sys/bus/event_source/devices/uncore_cbox_%u/type",
/*
* cbo_config:
* cha_config:
* UNC_C_LLC_VICTIMS => OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD
* umask=0x21,event=10
*/
Expand Down Expand Up @@ -192,21 +192,21 @@ int Helper::num_of_cpu() {
return ncpu;
}

int Helper::num_of_cbo() {
int ncbo = 0;
for (; ncbo < 128; ++ncbo) {
std::string path = fmt::format("/sys/bus/event_source/devices/uncore_cbox_{}/type", ncbo);
// LOG(DEBUG) << path;
int Helper::num_of_cha() {
int ncha = 0;
for (; ncha < 128; ++ncha) {
std::string path = fmt::format("/sys/bus/event_source/devices/uncore_cha_{}/type", ncha);
// LOG(DEBUG) << path;
if (!std::filesystem::exists(path)) {
break;
}
}
LOG(DEBUG) << fmt::format("num_of_cbo={}\n", ncbo);
return ncbo;
LOG(DEBUG) << fmt::format("num_of_cha={}\n", ncha);
return ncha;
}

double Helper::cpu_frequency() const {
int i = 0;
int i;
int cpu = 0;
double cpu_mhz = 0.0;
double max_cpu_mhz = 0.0;
Expand All @@ -232,13 +232,13 @@ PerfConfig Helper::detect_model(uint32_t model) {
}
i++;
}
LOG(ERROR) << "Failed to execute. This CPU model is not supported. Update src/types.c\n";
LOG(ERROR) << "Failed to execute. This CPU model is not supported. Refer to perfmon or pcm to add support\n";
throw;
}
Helper::Helper() : perf_conf({}) {
cpu = num_of_cpu();
LOG(DEBUG) << cpu;
cbo = num_of_cbo();
cha = num_of_cha();
cpu_freq = cpu_frequency();
}
void Helper::noop_handler(int sig) { ; }
Expand All @@ -248,7 +248,7 @@ void Helper::detach_children() {
sa.sa_handler = noop_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_NOCLDWAIT;
if (sigaction(SIGCHLD, &sa, NULL) < 0) {
if (sigaction(SIGCHLD, &sa, nullptr) < 0) {
LOG(ERROR) << fmt::format("Failed to sigaction: %s", strerror(errno));
}
}
Expand All @@ -267,16 +267,16 @@ int PMUInfo::start_all_pmcs() {
PMUInfo::PMUInfo(pid_t pid, Helper *helper, struct PerfConfig *perf_config) : helper(helper) {
int i, r, n;

n = helper->num_of_cbo();
n = helper->num_of_cha();

for (i = 0; i < n; i++) {
this->cbos.emplace_back(i, perf_config);
this->chas.emplace_back(i, perf_config);
}

// unfreeze counters
r = this->unfreeze_counters_cbo_all();
r = this->unfreeze_counters_cha_all();
if (r < 0) {
LOG(DEBUG) << fmt::format("unfreeze_counters_cbo_all failed.\n");
LOG(DEBUG) << fmt::format("unfreeze_counters_cha_all failed.\n");
throw;
}

Expand Down Expand Up @@ -305,31 +305,32 @@ int PMUInfo::stop_all_pmcs() {
return 0;
}

int PMUInfo::unfreeze_counters_cbo_all() {
int PMUInfo::unfreeze_counters_cha_all() {
int i, r;

for (i = 0; i < helper->num_of_cbo(); i++) {
r = this->cbos[i].perf->start();
for (i = 0; i < helper->num_of_cha(); i++) {
r = this->chas[i].perf->start();
if (r < 0) {
LOG(ERROR) << fmt::format("perf_start failed. cbo:{}\n", i);
LOG(ERROR) << fmt::format("perf_start failed. cha:{}\n", i);
return r;
}
}
return 0;
}
int PMUInfo::freeze_counters_cbo_all() {
int PMUInfo::freeze_counters_cha_all() {
int i, r;

for (i = 0; i < helper->num_of_cbo(); i++) {
r = this->cbos[i].perf->stop();
for (i = 0; i < helper->num_of_cha(); i++) {
r = this->chas[i].perf->stop();
if (r < 0) {
LOG(ERROR) << fmt::format("perf_stop failed. cbo:{}\n", i);
LOG(ERROR) << fmt::format("perf_stop failed. cha:{}\n", i);
return r;
}
}
return 0;
}
PMUInfo::~PMUInfo() {
this->cpus.clear();
this->cbos.clear();
this->chas.clear();
stop_all_pmcs();
}
10 changes: 0 additions & 10 deletions src/incore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ 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_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 Down Expand Up @@ -84,12 +81,6 @@ int Incore::read_cpu_elems(struct CPUElem *elem) {
}
LOG(DEBUG) << fmt::format("read cpu_llcl_miss:{}\n", elem->cpu_llcl_miss);

// r = this->perf[4]->read_pmu(&elem->cpu_bandwidth_read);
// if (r < 0) {
// LOG(ERROR) << fmt::format("read cpu_bandwidth_read failed.\n");
// return r;
// }
// LOG(DEBUG) << fmt::format("read cpu_bandwidth_read:{}\n", elem->cpu_bandwidth_read);
r = this->perf[4]->read_pmu(&elem->cpu_bandwidth_write);
if (r < 0) {
LOG(ERROR) << fmt::format("read cpu_bandwidth_write failed.\n");
Expand All @@ -99,7 +90,6 @@ int Incore::read_cpu_elems(struct CPUElem *elem) {
}
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_cpu_mem_read(pid, cpu);
this->init_cpu_l2stall(pid, cpu);
this->init_cpu_llcl_hits(pid, cpu);
Expand Down
Loading

0 comments on commit 83d8417

Please sign in to comment.