100 lines
2.2 KiB
C++
100 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "gen.hh"
|
|
#include "defs.hh"
|
|
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
|
|
constexpr static unsigned int NM_LEVEL_NUMA = 0;
|
|
constexpr static unsigned int NM_LEVEL_CPU = 1;
|
|
constexpr static unsigned int NM_LEVEL_CORE = 2;
|
|
constexpr static unsigned int NM_MAX_LEVEL = NM_LEVEL_CORE + 1;
|
|
|
|
constexpr static int NM_MAX_OBJS_PER_LVL = 256;
|
|
|
|
// misc functions
|
|
|
|
// 0 on success -1 on error
|
|
int nm_init(int verbosity);
|
|
|
|
uint64_t nm_tsc2ns(uint64_t tsc);
|
|
|
|
uint64_t nm_get_uptime_ns();
|
|
|
|
// topology stuff
|
|
struct nm_obj;
|
|
|
|
struct nm_obj *
|
|
nm_find_parent_obj(struct nm_obj * start, int parent_level);
|
|
|
|
int
|
|
nm_obj_count(int level);
|
|
|
|
struct nm_obj *
|
|
nm_obj_from_id(int level, int id);
|
|
|
|
struct nm_obj *
|
|
nm_obj_find_parent(struct nm_obj * start, int parent_level);
|
|
|
|
int
|
|
nm_obj_get_id(struct nm_obj * obj);
|
|
|
|
int
|
|
nm_obj_get_level(struct nm_obj * obj);
|
|
|
|
static inline int
|
|
get_node_from_core(int coreid)
|
|
{
|
|
return nm_obj_get_id(nm_obj_find_parent(nm_obj_from_id(NM_LEVEL_CORE, coreid), NM_LEVEL_NUMA));
|
|
}
|
|
|
|
// memload generator
|
|
class memload_generator {
|
|
private:
|
|
DISALLOW_EVIL_CONSTRUCTORS(memload_generator);
|
|
constexpr static uint32_t FROM_REGION_CNT = 0x2; // 2 regions
|
|
struct thread_info {
|
|
pthread_t pthr;
|
|
std::atomic<uint64_t> num_trans;
|
|
Generator *ia_gen;
|
|
std::atomic<int> init_status;
|
|
std::atomic<int> *state;
|
|
constexpr static int INIT_START = 0;
|
|
constexpr static int INIT_SUCCESS = 1;
|
|
constexpr static int INIT_FAILED = 2;
|
|
void *from_region;
|
|
void *to_region;
|
|
uint32_t to_domainid;
|
|
uint32_t from_domainid;
|
|
};
|
|
constexpr static uint32_t TRANSACTION_SZ = 0x2000; // transaction sz must >= region_sz
|
|
constexpr static uint32_t REGION_SZ = 0x2000 * 0x2000; // 64MB per core
|
|
std::vector<struct thread_info *> thr_infos;
|
|
|
|
std::atomic<int> state;
|
|
constexpr static uint32_t STATE_READY = 0;
|
|
constexpr static uint32_t STATE_START = 1;
|
|
constexpr static uint32_t STATE_STOP = 2;
|
|
|
|
uint64_t begin_ts;
|
|
uint64_t stop_ts;
|
|
|
|
static void *worker_thrd(void *_tinfo);
|
|
|
|
public:
|
|
memload_generator(uint64_t from_cmask, uint64_t to_cmask, uint64_t bps,
|
|
bool *success);
|
|
void start();
|
|
void stop();
|
|
uint64_t get_bps();
|
|
~memload_generator();
|
|
};
|
|
|
|
// allocators
|
|
void *
|
|
nm_malloc(unsigned int node, size_t size);
|
|
|
|
void
|
|
nm_free(unsigned int node, void * addr);
|