example adapts to new interface
(cherry picked from commit ada0992f7398f4bf00a9a61358808775a3ca1693)
This commit is contained in:
parent
e24432fa3a
commit
65a6ad412e
248
0001-example-adapts-to-new-interface.patch
Normal file
248
0001-example-adapts-to-new-interface.patch
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
From abd9fa539173ebe5bd09b363469a17b5d2f85593 Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhoukaiqi <zhoukaiqi@huawei.com>
|
||||||
|
Date: Fri, 31 May 2024 11:28:59 +0800
|
||||||
|
Subject: [PATCH] example adapts to new interface
|
||||||
|
|
||||||
|
---
|
||||||
|
example/CMakeLists.txt | 2 +-
|
||||||
|
example/adapt/adapt.cpp | 52 ++++++++++++++++------------
|
||||||
|
example/include/frame/common.h | 62 +++++++++++++++++++++++++---------
|
||||||
|
include/interface.h | 6 ++--
|
||||||
|
4 files changed, 81 insertions(+), 41 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
|
||||||
|
index 6a93f42..75395ce 100644
|
||||||
|
--- a/example/CMakeLists.txt
|
||||||
|
+++ b/example/CMakeLists.txt
|
||||||
|
@@ -1,6 +1,6 @@
|
||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
|
project(tune-example)
|
||||||
|
-
|
||||||
|
+add_compile_options(-g -fPIC -Wall -Wextra)
|
||||||
|
add_subdirectory(tune)
|
||||||
|
add_subdirectory(adapt)
|
||||||
|
diff --git a/example/adapt/adapt.cpp b/example/adapt/adapt.cpp
|
||||||
|
index 7582efd..c285e06 100644
|
||||||
|
--- a/example/adapt/adapt.cpp
|
||||||
|
+++ b/example/adapt/adapt.cpp
|
||||||
|
@@ -17,73 +17,83 @@
|
||||||
|
#include "tune.h"
|
||||||
|
#include <cstring>
|
||||||
|
uint64_t g_scenario_buf_cnt = 0;
|
||||||
|
-char *get_version()
|
||||||
|
+
|
||||||
|
+const char *get_version()
|
||||||
|
{
|
||||||
|
return "v1.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
-char *get_description()
|
||||||
|
+const char *get_name()
|
||||||
|
{
|
||||||
|
return "tune_example";
|
||||||
|
}
|
||||||
|
|
||||||
|
-char *get_name()
|
||||||
|
+const char *get_description()
|
||||||
|
{
|
||||||
|
return "tune_example";
|
||||||
|
}
|
||||||
|
|
||||||
|
-char *get_dep()
|
||||||
|
+const char *get_dep()
|
||||||
|
{
|
||||||
|
return "scenario_example";
|
||||||
|
}
|
||||||
|
|
||||||
|
-int get_cycle()
|
||||||
|
+int get_priority()
|
||||||
|
+{
|
||||||
|
+ return 2;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int get_period()
|
||||||
|
{
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
-void enable()
|
||||||
|
+bool enable()
|
||||||
|
{
|
||||||
|
+ return true;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
void disable()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
-void tune(void *info[], int len)
|
||||||
|
+void run(const struct Param *para)
|
||||||
|
{
|
||||||
|
|
||||||
|
- for (int i = 0; i < len; i++) {
|
||||||
|
- struct DataHeader *header = (struct DataHeader *)info[i];
|
||||||
|
- if (strcmp(header->type, SCENARIO_ACCESS_BUF) == 0) {
|
||||||
|
- int dataNum = std::min(header->count - g_scenario_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, SCENARIO_ACCESS_BUF) == 0) {
|
||||||
|
+ int dataNum = std::min(ringbuf->count - g_scenario_buf_cnt, (uint64_t)ringbuf->buf_len);
|
||||||
|
if (dataNum != 1) { // demo only support one data
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct DataBuf *buf = nullptr;
|
||||||
|
- int offset = (header->index + header->buf_len - 0) % header->buf_len;
|
||||||
|
- buf = &header->buf[offset];
|
||||||
|
+ int offset = (ringbuf->index + ringbuf->buf_len - 0) % ringbuf->buf_len;
|
||||||
|
+ buf = &ringbuf->buf[offset];
|
||||||
|
Tune &ins = Tune::getInstance();
|
||||||
|
ins.read_access_data((struct uncore_scenario *)buf->data, buf->len);
|
||||||
|
ins.migration();
|
||||||
|
- g_scenario_buf_cnt = header->count;
|
||||||
|
+ g_scenario_buf_cnt = ringbuf->count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-
|
||||||
|
-struct TuneInterface tune_interface = {
|
||||||
|
+struct Interface tune_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,
|
||||||
|
- .tune = tune,
|
||||||
|
+ .get_ring_buf = nullptr,
|
||||||
|
+ .run = run,
|
||||||
|
};
|
||||||
|
-extern "C" int get_instance(TuneInterface * *ins)
|
||||||
|
+
|
||||||
|
+extern "C" int get_instance(struct Interface **interface)
|
||||||
|
{
|
||||||
|
- *ins = &tune_interface;
|
||||||
|
+ *interface = &tune_interface;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
-
|
||||||
|
diff --git a/example/include/frame/common.h b/example/include/frame/common.h
|
||||||
|
index 63a14c2..d2a0f7c 100644
|
||||||
|
--- a/example/include/frame/common.h
|
||||||
|
+++ b/example/include/frame/common.h
|
||||||
|
@@ -11,33 +11,63 @@
|
||||||
|
******************************************************************************/
|
||||||
|
#ifndef __OEAWARE_COMMON__
|
||||||
|
#define __OEAWARE_COMMON__
|
||||||
|
+#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
-#define DATA_HEADER_TYPE_SIZE 64
|
||||||
|
-
|
||||||
|
-struct TuneInterface {
|
||||||
|
- char *(*get_version)();
|
||||||
|
- char *(*get_name)();
|
||||||
|
- char *(*get_description)();
|
||||||
|
- char *(*get_dep)();
|
||||||
|
- int (*get_cycle)();
|
||||||
|
- void (*enable)();
|
||||||
|
- void (*disable)();
|
||||||
|
- void (*tune)(void *[], int);
|
||||||
|
-};
|
||||||
|
+#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
|
||||||
|
diff --git a/include/interface.h b/include/interface.h
|
||||||
|
index e5d69dc..0221244 100644
|
||||||
|
--- a/include/interface.h
|
||||||
|
+++ b/include/interface.h
|
||||||
|
@@ -26,11 +26,11 @@ struct DataBuf {
|
||||||
|
|
||||||
|
struct DataRingBuf {
|
||||||
|
/* instance name */
|
||||||
|
- const char *instance_name;
|
||||||
|
+ const char *instance_name;
|
||||||
|
/* buf write index, initial value is -1 */
|
||||||
|
int index;
|
||||||
|
/* instance run times */
|
||||||
|
- uint64_t count;
|
||||||
|
+ uint64_t count;
|
||||||
|
struct DataBuf *buf;
|
||||||
|
int buf_len;
|
||||||
|
};
|
||||||
|
@@ -49,7 +49,7 @@ struct Interface {
|
||||||
|
* for instance execution.
|
||||||
|
*/
|
||||||
|
const char* (*get_dep)();
|
||||||
|
- /* Instance scheduling priority. In a uniform time period, a instance with a
|
||||||
|
+ /* Instance scheduling priority. In a uniform time period, a instance with a
|
||||||
|
* lower priority is scheduled first.
|
||||||
|
*/
|
||||||
|
int (*get_priority)();
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
@ -1,10 +1,11 @@
|
|||||||
Name: oeAware-tune
|
Name: oeAware-tune
|
||||||
Version: v1.0.0
|
Version: v1.0.0
|
||||||
Release: 1
|
Release: 2
|
||||||
Summary: %{name} interconnect with the existing optimization of openEuler and develop new optimization features.
|
Summary: %{name} interconnect with the existing optimization of openEuler and develop new optimization features.
|
||||||
License: MulanPSL2
|
License: MulanPSL2
|
||||||
URL: https://gitee.com/openeuler/%{name}
|
URL: https://gitee.com/openeuler/%{name}
|
||||||
Source0: %{name}-%{version}.tar.gz
|
Source0: %{name}-%{version}.tar.gz
|
||||||
|
Patch1: 0001-example-adapts-to-new-interface.patch
|
||||||
|
|
||||||
BuildRequires: cmake make gcc-c++
|
BuildRequires: cmake make gcc-c++
|
||||||
BuildRequires: numactl-devel
|
BuildRequires: numactl-devel
|
||||||
@ -32,5 +33,8 @@ install -D -m 0640 ./thread_tune/thread_tune.conf %{buildroot}%{_libdir}/oeAware
|
|||||||
%attr(0640, root, root) %{_libdir}/oeAware-plugin/thread_tune.conf
|
%attr(0640, root, root) %{_libdir}/oeAware-plugin/thread_tune.conf
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri May 31 2024 zhoukaiqi <zhoukaiqi@huawei.com> - v1.0.0-2
|
||||||
|
- example adapts to new interface
|
||||||
|
|
||||||
* Thu May 30 2024 zhoukaiqi <zhoukaiqi@huawei.com> - v1.0.0-1
|
* Thu May 30 2024 zhoukaiqi <zhoukaiqi@huawei.com> - v1.0.0-1
|
||||||
- support automatic core binding for UnixBench
|
- support automatic core binding for UnixBench
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user