1 Star 0 Fork 10

jinlun/dim

forked from src-openEuler/dim 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Support-init-function-for-measure-tasks.patch 6.43 KB
一键复制 编辑 原始数据 按行查看 历史
jinlun 提交于 2024-04-16 10:12 . backport some patches
From 76f757dd080abd646128ec39d8752ca1ab746355 Mon Sep 17 00:00:00 2001
From: Huaxin Lu <luhuaxin1@huawei.com>
Date: Fri, 8 Mar 2024 18:45:36 +0800
Subject: [PATCH 26/26] Support init function for measure tasks
---
src/core/dim_core_measure.c | 4 ++-
src/core/tasks/dim_core_measure_kernel.c | 2 ++
src/core/tasks/dim_core_measure_module.c | 2 ++
src/measure/dim_measure.c | 1 +
src/measure/dim_measure.h | 4 +++
src/measure/dim_measure_task.c | 32 ++++++++++++++++++-
src/monitor/dim_monitor_measure.c | 4 ++-
.../measure_task/dim_monitor_measure_data.c | 2 ++
.../measure_task/dim_monitor_measure_text.c | 2 ++
9 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/src/core/dim_core_measure.c b/src/core/dim_core_measure.c
index ff134e5..f5b378c 100644
--- a/src/core/dim_core_measure.c
+++ b/src/core/dim_core_measure.c
@@ -18,7 +18,9 @@ static struct dim_measure_task *dim_core_tasks[] = {
};
/* the global measurement handle */
-struct dim_measure dim_core_handle = { 0 };
+struct dim_measure dim_core_handle = {
+ .task_list = LIST_HEAD_INIT(dim_core_handle.task_list),
+};
/* lock to prevent trigger multiple measurement */
DEFINE_MUTEX(dim_core_measure_lock);
diff --git a/src/core/tasks/dim_core_measure_kernel.c b/src/core/tasks/dim_core_measure_kernel.c
index dbf0dfe..fa04ae4 100644
--- a/src/core/tasks/dim_core_measure_kernel.c
+++ b/src/core/tasks/dim_core_measure_kernel.c
@@ -165,5 +165,7 @@ static int kernel_text_measure(int mode, struct dim_measure *m)
struct dim_measure_task dim_core_measure_task_kernel_text = {
.name = "dim_core_measure_task_kernel_text",
+ .init = NULL,
+ .destroy = NULL,
.measure = kernel_text_measure,
};
diff --git a/src/core/tasks/dim_core_measure_module.c b/src/core/tasks/dim_core_measure_module.c
index aa3e2f3..feb6624 100644
--- a/src/core/tasks/dim_core_measure_module.c
+++ b/src/core/tasks/dim_core_measure_module.c
@@ -108,5 +108,7 @@ static int module_text_measure(int mode, struct dim_measure *m)
struct dim_measure_task dim_core_measure_task_module_text = {
.name = "dim_core_measure_task_module_text",
+ .init = NULL,
+ .destroy = NULL,
.measure = module_text_measure,
};
diff --git a/src/measure/dim_measure.c b/src/measure/dim_measure.c
index 06e9bb5..dd35cb8 100644
--- a/src/measure/dim_measure.c
+++ b/src/measure/dim_measure.c
@@ -91,6 +91,7 @@ void dim_measure_destroy(struct dim_measure *m)
return;
mutex_lock(&m->measure_lock);
+ dim_measure_tasks_unregister_all(m);
dim_measure_log_destroy_tree(&m->log);
dim_baseline_destroy_tree(&m->static_baseline);
dim_baseline_destroy_tree(&m->dynamic_baseline);
diff --git a/src/measure/dim_measure.h b/src/measure/dim_measure.h
index d2ca326..d73fbaf 100644
--- a/src/measure/dim_measure.h
+++ b/src/measure/dim_measure.h
@@ -78,6 +78,9 @@ struct dim_measure_task {
struct list_head node;
/* task name for log printing */
const char *name;
+ /* init and destroy functions */
+ int (*init)(void);
+ void (*destroy)(void);
/* measure function */
int (*measure)(int mode, struct dim_measure *m);
};
@@ -105,6 +108,7 @@ int dim_measure_dynamic_baseline_search(struct dim_measure *m,
int dim_measure_tasks_register(struct dim_measure *m,
struct dim_measure_task **tasks,
unsigned int num);
+void dim_measure_tasks_unregister_all(struct dim_measure *m);
void dim_measure_task_measure(int mode, struct dim_measure *m);
/* functions for dim measurement status */
diff --git a/src/measure/dim_measure_task.c b/src/measure/dim_measure_task.c
index ed97388..adfc57d 100644
--- a/src/measure/dim_measure_task.c
+++ b/src/measure/dim_measure_task.c
@@ -62,13 +62,29 @@ void dim_measure_task_measure(int mode, struct dim_measure *m)
static int task_register(struct dim_measure *m, struct dim_measure_task *t)
{
+ int ret = 0;
+
if (t == NULL || t->name == NULL || t->measure == NULL)
return -EINVAL;
+ if (t->init != NULL) {
+ ret = t->init();
+ if (ret < 0)
+ return ret;
+ }
+
list_add_tail(&t->node, &m->task_list);
return 0;
}
+static void task_unregister(struct dim_measure_task *t)
+{
+ if (t->destroy != NULL)
+ t->destroy();
+
+ list_del(&t->node);
+}
+
int dim_measure_tasks_register(struct dim_measure *m,
struct dim_measure_task **tasks,
unsigned int num)
@@ -81,11 +97,25 @@ int dim_measure_tasks_register(struct dim_measure *m,
for (; i < num; i++) {
ret = task_register(m, tasks[i]);
- if (ret < 0)
+ if (ret < 0) {
+ dim_measure_tasks_unregister_all(m);
return ret;
+ }
dim_info("register measure task: %s\n", tasks[i]->name);
}
return 0;
}
+
+void dim_measure_tasks_unregister_all(struct dim_measure *m)
+{
+ struct dim_measure_task *pos = NULL;
+ struct dim_measure_task *n = NULL;
+
+ if (m == NULL)
+ return;
+
+ list_for_each_entry_safe(pos, n, &m->task_list, node)
+ task_unregister(pos);
+}
diff --git a/src/monitor/dim_monitor_measure.c b/src/monitor/dim_monitor_measure.c
index f21ed0e..748d5f9 100644
--- a/src/monitor/dim_monitor_measure.c
+++ b/src/monitor/dim_monitor_measure.c
@@ -21,7 +21,9 @@ static struct dim_measure_task *dim_core_tasks[] = {
};
/* the global measurement handle */
-struct dim_measure dim_monitor_handle = { 0 };
+struct dim_measure dim_monitor_handle = {
+ .task_list = LIST_HEAD_INIT(dim_monitor_handle.task_list),
+};
/* lock to prevent trigger multiple measurement */
DEFINE_MUTEX(dim_monitor_measure_lock);
diff --git a/src/monitor/measure_task/dim_monitor_measure_data.c b/src/monitor/measure_task/dim_monitor_measure_data.c
index 5762dc1..029840c 100644
--- a/src/monitor/measure_task/dim_monitor_measure_data.c
+++ b/src/monitor/measure_task/dim_monitor_measure_data.c
@@ -52,5 +52,7 @@ static int module_text_measure(int mode, struct dim_measure *m)
struct dim_measure_task dim_monitor_measure_data = {
.name = "dim_monitor_measure_data",
+ .init = NULL,
+ .destroy = NULL,
.measure = module_text_measure,
};
diff --git a/src/monitor/measure_task/dim_monitor_measure_text.c b/src/monitor/measure_task/dim_monitor_measure_text.c
index de6c77d..fc7dbf7 100644
--- a/src/monitor/measure_task/dim_monitor_measure_text.c
+++ b/src/monitor/measure_task/dim_monitor_measure_text.c
@@ -60,5 +60,7 @@ static int module_text_measure(int mode, struct dim_measure *m)
struct dim_measure_task dim_monitor_measure_text = {
.name = "dim_monitor_measure_text",
+ .init = NULL,
+ .destroy = NULL,
.measure = module_text_measure,
};
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jinlun123123/dim.git
git@gitee.com:jinlun123123/dim.git
jinlun123123
dim
dim
master

搜索帮助