From 630de0c8044062757d7910d6f65fb71e7b98696e Mon Sep 17 00:00:00 2001 From: luckky Date: Thu, 23 Jan 2025 20:37:15 +0800 Subject: [PATCH] hbm_onli_repair: code refactor --- .../{ras-events.c => hbm-events.c} | 28 ++++--------------- .../{ras-events.h => hbm-events.h} | 0 .../hbm_online_repair/hbm_online_repair.c | 2 +- .../ras-non-standard-handler.c | 10 ++----- .../ras-non-standard-handler.h | 2 +- 5 files changed, 9 insertions(+), 33 deletions(-) rename src/plugins/hbm_online_repair/{ras-events.c => hbm-events.c} (93%) rename src/plugins/hbm_online_repair/{ras-events.h => hbm-events.h} (100%) diff --git a/src/plugins/hbm_online_repair/ras-events.c b/src/plugins/hbm_online_repair/hbm-events.c similarity index 93% rename from src/plugins/hbm_online_repair/ras-events.c rename to src/plugins/hbm_online_repair/hbm-events.c index 3158acc..ba68578 100644 --- a/src/plugins/hbm_online_repair/ras-events.c +++ b/src/plugins/hbm_online_repair/hbm-events.c @@ -6,26 +6,18 @@ #include #include #include -#include +#include #include #include #include -#include #include +#include #include #include #include "ras-non-standard-handler.h" #include "logger.h" -/* - * Polling time, if read() doesn't block. Currently, trace_pipe_raw never - * blocks on read(). So, we need to sleep for a while, to avoid spending - * too much CPU cycles. A fix for it is expected for 3.10. - */ -#define POLLING_TIME 3 - -/* Test for a little-endian machine */ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define ENDIAN KBUFFER_ENDIAN_LITTLE #else @@ -43,7 +35,7 @@ static int get_debugfs_dir(char *debugfs_dir, size_t len) return errno; } - do { + while (1) { char *p, *type, *dir; if (!fgets(line, sizeof(line), fp)) break; @@ -66,7 +58,7 @@ static int get_debugfs_dir(char *debugfs_dir, size_t len) debugfs_dir[len - 1] = '\0'; return 0; } - } while(1); + } fclose(fp); log(LOG_INFO, "Can't find debugfs\n"); @@ -121,9 +113,6 @@ struct ras_events *init_trace_instance(void) return ras; } -/* - * Tracing enable/disable code - */ int toggle_ras_event(char *trace_dir, char *group, char *event, int enable) { int fd, rc; @@ -267,13 +256,6 @@ static int read_ras_event_all_cpus(struct ras_events* ras, unsigned n_cpus) return -ENOMEM; } - /* Fix for poll() on the per_cpu trace_pipe and trace_pipe_raw blocks - * indefinitely with the default buffer_percent in the kernel trace system, - * which is introduced by the following change in the kernel. - * https://lore.kernel.org/all/20221020231427.41be3f26@gandalf.local.home/T/#u. - * Set buffer_percent to 0 so that poll() will return immediately - * when the trace data is available in the ras per_cpu trace pipe_raw - */ if (set_buffer_percent(ras, 0)) log(LOG_WARNING, "Set buffer_percent failed\n"); @@ -485,7 +467,7 @@ int handle_ras_events(struct ras_events *ras) { int rc, i; unsigned cpus; - struct tep_handle *pevent = NULL; + struct tep_handle *pevent; pevent = tep_alloc(); if (!pevent) { diff --git a/src/plugins/hbm_online_repair/ras-events.h b/src/plugins/hbm_online_repair/hbm-events.h similarity index 100% rename from src/plugins/hbm_online_repair/ras-events.h rename to src/plugins/hbm_online_repair/hbm-events.h diff --git a/src/plugins/hbm_online_repair/hbm_online_repair.c b/src/plugins/hbm_online_repair/hbm_online_repair.c index 6783485..ada1fbe 100644 --- a/src/plugins/hbm_online_repair/hbm_online_repair.c +++ b/src/plugins/hbm_online_repair/hbm_online_repair.c @@ -5,7 +5,7 @@ #include #include "logger.h" -#include "ras-events.h" +#include "hbm-events.h" #include "non-standard-hbm-repair.h" #define DEFAULT_LOG_LEVEL LOG_INFO diff --git a/src/plugins/hbm_online_repair/ras-non-standard-handler.c b/src/plugins/hbm_online_repair/ras-non-standard-handler.c index 48ffa70..fadfe28 100644 --- a/src/plugins/hbm_online_repair/ras-non-standard-handler.c +++ b/src/plugins/hbm_online_repair/ras-non-standard-handler.c @@ -30,13 +30,8 @@ static int uuid_le(const char *uu, char* uuid) for (i = 0; i < 16; i++) { p += sprintf(p, "%.2x", (unsigned char) uu[le[i]]); - switch (i) { - case 3: - case 5: - case 7: - case 9: + if (i == 3 || i == 5 || i == 7 || i == 9) { *p++ = '-'; - break; } } @@ -45,8 +40,7 @@ static int uuid_le(const char *uu, char* uuid) return 0; } -int ras_non_standard_event_handler(struct trace_seq *s, - struct tep_record *record, +int ras_non_standard_event_handler(struct trace_seq *s, struct tep_record *record, struct tep_event *event, void *context) { int len; diff --git a/src/plugins/hbm_online_repair/ras-non-standard-handler.h b/src/plugins/hbm_online_repair/ras-non-standard-handler.h index 15a37ee..b79973f 100644 --- a/src/plugins/hbm_online_repair/ras-non-standard-handler.h +++ b/src/plugins/hbm_online_repair/ras-non-standard-handler.h @@ -2,7 +2,7 @@ #define __RAS_NON_STANDARD_HANDLER_H #include -#include "ras-events.h" +#include "hbm-events.h" #define BIT(nr) (1UL << (nr)) -- Gitee