diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ec96cd17de19102b82f70a72f08ee6d0c1a93e29..610080263298e971bc83c81de9c78701d504ed72 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -2,5 +2,6 @@ cmake_minimum_required(VERSION 3.15) project(scenario-example) +add_compile_options(-g -fPIC -Wall -Wextra) add_subdirectory(scenario) add_subdirectory(adapt) diff --git a/example/adapt/adapt.cpp b/example/adapt/adapt.cpp index cfb4e8ed9474df373daee69d2f9b900eec830abe..35e4916fdec95a604d9a5fc632d5002a9e30b245 100644 --- a/example/adapt/adapt.cpp +++ b/example/adapt/adapt.cpp @@ -16,34 +16,40 @@ #include "collector.h" #define UNCORE_SCENARIO_BUF_NUM 1 -struct DataHeader g_uncore_scenario_buf = { 0 }; +struct DataRingBuf g_uncore_scenario_buf = { 0, 0, 0, 0, 0}; uint64_t g_pmu_uncore_buf_cnt = 0; -char *get_version() + +const char *get_version() { return "v1.0"; } -char *get_description() +const char *get_name() { return "scenario_example"; } -char *get_name() +const char *get_description() { return "scenario_example"; } -char *get_dep() +const char *get_dep() { - return "collector_pmu_uncore"; + return PMU_UNCORE; } -int get_cycle() +int get_priority() +{ + return 1; +} + +int get_period() { return 1000; } -void enable() +bool enable() { if (g_uncore_scenario_buf.buf == NULL) { g_uncore_scenario_buf.buf = (struct DataBuf *)malloc(sizeof(struct DataBuf) * UNCORE_SCENARIO_BUF_NUM); @@ -51,41 +57,43 @@ void enable() g_uncore_scenario_buf.index = -1; g_uncore_scenario_buf.count = 0; } + + return true; } + void disable() { } -void aware(void *info[], int len) +void run(const struct Param *para) { Scenario &ins = Scenario::getInstance(); ins.system_loop_init(); - for (int i = 0; i < len; i++) { - struct DataHeader *header = (struct DataHeader *)info[i]; - if (strcmp(header->type, PMU_UNCORE) == 0) { - int dataNum = std::min(header->count - g_pmu_uncore_buf_cnt, (uint64_t)header->buf_len); + for (int i = 0; i < para->len; i++) { + struct DataRingBuf *ringbuf = (struct DataRingBuf *)para->ring_bufs[i]; + if (strcmp(ringbuf->instance_name, PMU_UNCORE) == 0) { + int dataNum = std::min(ringbuf->count - g_pmu_uncore_buf_cnt, (uint64_t)ringbuf->buf_len); struct DataBuf *buf = nullptr; for (int n = 0; n < dataNum; n++) { - int offset = (header->index + header->buf_len - n) % header->buf_len; - buf = &header->buf[offset]; + int offset = (ringbuf->index + ringbuf->buf_len - n) % ringbuf->buf_len; + buf = &ringbuf->buf[offset]; ins.system_uncore_update((PmuData *)buf->data, buf->len); } if (dataNum > 0) { ins.access_buf_updata(); } - g_pmu_uncore_buf_cnt = header->count; + g_pmu_uncore_buf_cnt = ringbuf->count; } } } -void *get_ring_buf() +const struct DataRingBuf *get_ring_buf() { Scenario &ins = Scenario::getInstance(); const ScenarioBuf access_buf = ins.get_scenario_buf(SBT_ACCESS); - struct DataHeader header; - strcpy(g_uncore_scenario_buf.type, SCENARIO_ACCESS_BUF); + g_uncore_scenario_buf.instance_name = SCENARIO_ACCESS_BUF; g_uncore_scenario_buf.index++; g_uncore_scenario_buf.index %= UNCORE_SCENARIO_BUF_NUM; g_uncore_scenario_buf.count++; @@ -94,24 +102,26 @@ void *get_ring_buf() g_uncore_scenario_buf.buf->len = access_buf.bufLen; g_uncore_scenario_buf.buf->data = access_buf.buf; - return (void *)&g_uncore_scenario_buf; + return &g_uncore_scenario_buf; } -struct ScenarioInterface aware_interface = { +struct Interface aware_interface = { .get_version = get_version, .get_name = get_name, .get_description = get_description, .get_dep = get_dep, - .get_cycle = get_cycle, + .get_priority = get_priority, + .get_type = nullptr, + .get_period = get_period, .enable = enable, .disable = disable, - .aware = aware, .get_ring_buf = get_ring_buf, + .run = run, }; -extern "C" int get_instance(ScenarioInterface * *ins) +extern "C" int get_instance(struct Interface **interface) { - *ins = &aware_interface; + *interface = &aware_interface; return 1; } diff --git a/example/include/dep_plugin/collector.h b/example/include/dep_plugin/collector.h index d449bc5b25e016816bcd6a85fd4ec9c489ba1823..fff85431add0a2cd9b1b780f2ea7c72b94881ad2 100644 --- a/example/include/dep_plugin/collector.h +++ b/example/include/dep_plugin/collector.h @@ -39,9 +39,9 @@ struct PmuData { }; }; -#define PMU_CYCLES_COUNTING "PMU_CYCLES_COUNTING" -#define PMU_CYCLES_SAMPLING "PMU_CYCLES_SAMPLING" -#define PMU_UNCORE "PMU_UNCORE" -#define PMU_SPE "PMU_SPE" +#define PMU_CYCLES_COUNTING "pmu_cycles_counting" +#define PMU_CYCLES_SAMPLING "pmu_cycles_sampling" +#define PMU_UNCORE "pmu_uncore_counting" +#define PMU_SPE "pmu_spe_sampling" -#endif \ No newline at end of file +#endif diff --git a/example/include/frame/common.h b/example/include/frame/common.h index d57694dba37bc5258725c392dd09a6afa12677c9..d2a0f7c4b45f9457d9738033adbbbd22d745a9c3 100644 --- a/example/include/frame/common.h +++ b/example/include/frame/common.h @@ -11,34 +11,63 @@ ******************************************************************************/ #ifndef __OEAWARE_COMMON__ #define __OEAWARE_COMMON__ +#include #include -#define DATA_HEADER_TYPE_SIZE 64 - -struct ScenarioInterface { - char *(*get_version)(); - char *(*get_name)(); - char *(*get_description)(); - char *(*get_dep)(); - int (*get_cycle)(); - void (*enable)(); - void (*disable)(); - void (*aware)(void *[], int); - void *(*get_ring_buf)(); -}; +#ifdef __cplusplus +extern "C" { +#endif struct DataBuf { int len; void *data; }; -struct DataHeader { - char type[DATA_HEADER_TYPE_SIZE]; - int index = -1; +struct DataRingBuf { + /* instance name */ + const char *instance_name; + /* buf write index, initial value is -1 */ + int index; + /* instance run times */ uint64_t count; struct DataBuf *buf; int buf_len; }; +struct Param { + const struct DataRingBuf **ring_bufs; + int len; +}; + +struct Interface { + const char* (*get_version)(); + /* The instance name is a unique identifier in the system. */ + const char* (*get_name)(); + const char* (*get_description)(); + /* Specifies the instance dependencies, which is used as the input information + * for instance execution. + */ + const char* (*get_dep)(); + /* Instance scheduling priority. In a uniform time period, a instance with a + * lower priority is scheduled first. + */ + int (*get_priority)(); + int (*get_type)(); + /* Instance execution period. */ + int (*get_period)(); + bool (*enable)(); + void (*disable)(); + const struct DataRingBuf* (*get_ring_buf)(); + void (*run)(const struct Param*); +}; + +/* Obtains the instances from the plugin. + * The return value is the number of instances. + */ +int get_instance(struct Interface **interface); + +#ifdef __cplusplus +} +#endif -#endif \ No newline at end of file +#endif