From 7503e2a1893c04629cc0dc3f0a8a501cd176484a Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Wed, 23 Feb 2022 19:04:17 +0800 Subject: [PATCH 1/8] lib/Makefile: Fix make clean failed in container When we do 'make clean' it will do: make -C $(KERNEL_BUILD_PATH) M=$(MODULE_SRC) clean It will be ok if we are in host; but if we we use a container, this command will fail and interrupt subsequent other "clean" steps, which lead the 'make clean' command to be incomplete. Signed-off-by: Hailong Liu --- source/lib/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/lib/Makefile b/source/lib/Makefile index 3a5ed826..b957459b 100644 --- a/source/lib/Makefile +++ b/source/lib/Makefile @@ -13,6 +13,8 @@ ifeq ($(BUILD_LIBBPF), YES) endif clean: +ifeq ($(BUILD_KERNEL_MODULE), YES) make -C internal/kernel_module clean +endif make -C internal/ebpf/libbpf/src clean -- Gitee From 1db7e66c5a5e82d15b2685eaf58fa44abb25c21d Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Thu, 24 Feb 2022 22:24:44 +0800 Subject: [PATCH 2/8] sched/runlatency: Fix rmmod failed by "-d" When use 'sysak -e', 'sysak -p $pid', then 'sysak -d' will fail for romoving the sysak moudle failed. It is becase lkm missed the put_moudle paring with get_moulde. Signed-off-by: Hailong Liu --- .../monitor/sched/runlatency/runlatency.c | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/source/tools/monitor/sched/runlatency/runlatency.c b/source/tools/monitor/sched/runlatency/runlatency.c index 26403ba0..cb619f4f 100644 --- a/source/tools/monitor/sched/runlatency/runlatency.c +++ b/source/tools/monitor/sched/runlatency/runlatency.c @@ -24,6 +24,7 @@ static void usage(char *prog) " Usage: %s [OPTIONS]\n" " Options:\n" " -f the output file\n" + " -p set the pid we monitor, used with -e or separately\n" " -r read the result to file or stdout, default stdout\n" " -d disable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" " -e enable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" @@ -35,20 +36,17 @@ static void usage(char *prog) char *cmdstr[3]; -int switch_func(int opt, int enable, int arg) +int switch_func(int opt, int enable, int pid) { FILE *fp; int param[3], ret, index = 0; int optalign; char cmd[MAX_CMD_LEN] = {0}; - optalign = opt & OPT_MASK; if (optalign & OPT_LAT) - param[2] = arg; - else - param[2] = enable; + param[2] = (enable != 0) ? pid:-1; param[0] = param[1] = enable; while (index < MAX_CMD) { @@ -61,16 +59,15 @@ int switch_func(int opt, int enable, int arg) perror(cmd); return ret; } - optalign = optalign; - index++; } + index++; } } bool ready[MAX_CMD] = {false}; int retno[MAX_CMD] = {0}; -static int not_ready(bool ready[], int retno[]) +static int all_ready(bool ready[], int retno[]) { int i, ret = MAX_CMD; @@ -89,11 +86,11 @@ static int not_ready(bool ready[], int retno[]) int main(int argc, char *argv[]) { char *refile = NULL; - int pid = -1, ret = 0, i, will_switch, enable; - int c, option_index, en_opt, dis_opt; + int pid = -1, ret = 0, i, will_switch = 0, enable = -1; + int c, option_index, opt_mask; opterr = 0; - dis_opt = en_opt = OPT_MASK; + opt_mask = 0; cmdstr[0] = firq; cmdstr[1] = fsch; @@ -118,26 +115,33 @@ int main(int argc, char *argv[]) refile = optarg; break; case 'r': - if (!not_ready(ready, retno)) + if (!all_ready(ready, retno)) return -1; pasre_dump(refile);//do something break; case 'p': pid = atoi(optarg); + will_switch = 1; + opt_mask |= OPT_LAT; break; case 'e': - if (!not_ready(ready, retno)) + if (!all_ready(ready, retno)) return -1; if (optarg) - en_opt = atoi(optarg); + opt_mask = atoi(optarg); + else + opt_mask = OPT_MASK & (~OPT_LAT); + will_switch = 1; enable = 1; break; case 'd': - if (!not_ready(ready, retno)) + if (!all_ready(ready, retno)) return -1; if (optarg) - dis_opt = atoi(optarg); + opt_mask = atoi(optarg); + else + opt_mask = OPT_MASK; will_switch = 1; enable = 0; break; @@ -149,7 +153,7 @@ int main(int argc, char *argv[]) } } if (will_switch) - ret = switch_func(dis_opt, enable, pid); + ret = switch_func(opt_mask, enable, pid); return ret; } -- Gitee From e2fb547e3a183560276163e8d989360c42c56b49 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Fri, 25 Feb 2022 11:10:32 +0800 Subject: [PATCH 3/8] sched/runlatency: Fix the issue of recording results Signed-off-by: Hailong Liu --- .../monitor/sched/runlatency/json_dump.c | 10 +++++-- .../tools/monitor/sched/runlatency/parser.h | 2 +- .../monitor/sched/runlatency/runlatency.c | 29 ++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/source/tools/monitor/sched/runlatency/json_dump.c b/source/tools/monitor/sched/runlatency/json_dump.c index 904666c1..abc46c09 100644 --- a/source/tools/monitor/sched/runlatency/json_dump.c +++ b/source/tools/monitor/sched/runlatency/json_dump.c @@ -46,7 +46,7 @@ int clear_file(char *path) return size; } -int pasre_dump(char *file) +int parse_dump(char *file) { char *s; int ret; @@ -56,11 +56,17 @@ int pasre_dump(char *file) if (s == NULL) { return -ENOMEM; } + if (file) { outf = fopen(file, "a+"); - if (!outf) + if (!outf) { + ret = errno; fprintf(stderr, "%s :fopen %s\n", strerror(errno), file); + goto failed; + } + } else { + goto failed; } ret = read_file(IRQOFF_FILE, s); if (ret < 0) { diff --git a/source/tools/monitor/sched/runlatency/parser.h b/source/tools/monitor/sched/runlatency/parser.h index 57baa7bc..bb190053 100644 --- a/source/tools/monitor/sched/runlatency/parser.h +++ b/source/tools/monitor/sched/runlatency/parser.h @@ -3,5 +3,5 @@ int parser_irqoff(char *stream, int size, FILE *file); int parser_nosch(char *stream, int size, FILE *file); int parser_runq(char *stream, int size, FILE *file); -int pasre_dump(char *file); +int parse_dump(char *file); #endif diff --git a/source/tools/monitor/sched/runlatency/runlatency.c b/source/tools/monitor/sched/runlatency/runlatency.c index cb619f4f..69ded760 100644 --- a/source/tools/monitor/sched/runlatency/runlatency.c +++ b/source/tools/monitor/sched/runlatency/runlatency.c @@ -23,11 +23,15 @@ static void usage(char *prog) const char *str = " Usage: %s [OPTIONS]\n" " Options:\n" - " -f the output file\n" - " -p set the pid we monitor, used with -e or separately\n" - " -r read the result to file or stdout, default stdout\n" - " -d disable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" - " -e enable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" + " -p set the pid we monitor, used with -e or separately\n" + " -r [outfile] read result to outfile, if not point,to stdout\n" + " -d [mask] disable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" + " -e [mask]enable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" + "for example:\n" + " sysak runlatency -e -p 78953 #enable all runaltency monitor for task 78953\n" + " sleep 20 #Sampling for 20 seconds 20\n" + " sysak runlatency -r ./my.json #record the sampling result to my.json\n" + " sysak runlatency -d #close all runaltency monitor\n" ; fprintf(stderr, str, prog); @@ -69,18 +73,18 @@ int retno[MAX_CMD] = {0}; static int all_ready(bool ready[], int retno[]) { - int i, ret = MAX_CMD; + int i, ready_cnt = 0; for (i = 0; i < MAX_CMD; i++) { if (ready[i]) { - ret--; + ready_cnt++; } else { fprintf(stderr, "%s: access() %s\n", strerror(retno[i]), cmdstr[i]); } } - return ret; + return (ready_cnt == MAX_CMD); } int main(int argc, char *argv[]) @@ -105,19 +109,18 @@ int main(int argc, char *argv[]) } } for (;;) { - c = getopt_long(argc, argv, "f:p:e::d::hr", + c = getopt_long(argc, argv, "p:e::d::rh", NULL /*long_options*/, &option_index); if (c == -1) break; switch (c) { - case 'f': - refile = optarg; - break; case 'r': if (!all_ready(ready, retno)) return -1; - pasre_dump(refile);//do something + if (argc > optind) /* for -r xxx.log */ + refile = argv[optind]; + parse_dump(refile);//do something break; case 'p': pid = atoi(optarg); -- Gitee From d05e17cc93f3a997895619dedf3a3a89df77f4ed Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Sun, 27 Feb 2022 21:37:01 +0800 Subject: [PATCH 4/8] runlatency: Fix leak of module_put when info OVERFLOW When the array of info overflowed, info->pid set to -1; and then we use *-d* , module_put will be skiped for info->pid == input(-1). Signed-off-by: Hailong Liu --- .../lib/internal/kernel_module/modules/sched/trace_runqlat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c index c3d86bd4..acec400c 100644 --- a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c +++ b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c @@ -387,8 +387,11 @@ static ssize_t trace_pid_store(void *priv, const char __user *buf, size_t count) local_irq_disable(); arch_spin_lock(&info->lock); - if (info->pid == pid) + if (info->pid == pid) { + if (pid == INVALID_PID) + sysak_module_put(&runqlat_ref); goto unlock; + } if (pid != INVALID_PID) { -- Gitee From f65f6553d91ee933075cd0bf9c207e312b42b211 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Mon, 28 Feb 2022 09:37:55 +0800 Subject: [PATCH 5/8] runlatency: Add target task's pid,comm,cpu to result Add the task we are monitoring to the result, provide a better interface for sysom. Signed-off-by: Hailong Liu --- .../modules/sched/trace_runqlat.c | 56 ++++++++++++++++--- .../tools/monitor/sched/runlatency/parser.c | 2 +- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c index acec400c..30e64b3c 100644 --- a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c +++ b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c @@ -29,7 +29,8 @@ #define MAX_TRACE_ENTRY_TASKS \ (MAX_TRACE_ENTRIES * PER_TRACE_ENTRY_TASKS) -#define THRESHOLD_DEFAULT (20 * 1000 * 1000UL) +/* 20ms */ +#define THRESHOLD_DEFAULT (20*1000*1000UL) #define INVALID_PID -1 #define INVALID_CPU -1 @@ -57,6 +58,9 @@ struct task_entry { }; struct trace_entry { + int cpu; + pid_t pid; + char comm[TASK_COMM_LEN]; u64 latency; u64 rq_start; unsigned int nr_tasks; @@ -66,6 +70,7 @@ struct trace_entry { struct runqlat_info { int cpu; /* The target CPU */ pid_t pid; /* Trace this pid only */ + char comm[TASK_COMM_LEN]; /* target task's comm */ u64 rq_start; u64 run_start; u64 threshold; @@ -203,6 +208,9 @@ static bool record_task_commit(struct runqlat_info *info, u64 latency) if (latency >= info->threshold) { trace->latency = latency; trace->rq_start = info->rq_start; + trace->cpu = info->cpu; + trace->pid = info->pid; + strncpy(trace->comm, info->comm, TASK_COMM_LEN); info->nr_trace++; if (unlikely(info->nr_trace >= MAX_TRACE_ENTRIES)) { pr_info("BUG: MAX_TRACE_ENTRIES too low!"); @@ -374,9 +382,31 @@ static int trace_pid_show(struct seq_file *m, void *ptr) return 0; } +static struct task_struct *loc_find_get_task_by_vpid(int nr) +{ + struct pid * pid_obj; + struct task_struct *task; + + rcu_read_lock(); + pid_obj = find_vpid(nr); + if (!pid_obj) + goto fail; + + task = pid_task(pid_obj, PIDTYPE_PID); + if (!task) + goto fail; + + get_task_struct(task); + rcu_read_unlock(); + return task; +fail: + rcu_read_unlock(); + return NULL; +} static ssize_t trace_pid_store(void *priv, const char __user *buf, size_t count) { int pid; + struct task_struct *task = NULL; struct runqlat_info *info = priv; if (kstrtoint_from_user(buf, count, 0, &pid)) @@ -401,12 +431,19 @@ static ssize_t trace_pid_store(void *priv, const char __user *buf, size_t count) MAX_TRACE_ENTRIES * sizeof(struct trace_entry) + MAX_TRACE_ENTRY_TASKS * sizeof(struct task_entry)); sysak_module_get(&runqlat_ref); - } else + } else { sysak_module_put(&runqlat_ref); - + } runqlat_info_reset(info); smp_wmb(); info->pid = pid; + task = loc_find_get_task_by_vpid(pid); + if (task) { + strncpy(info->comm, task->comm, TASK_COMM_LEN); + put_task_struct(task); + } else { + strncpy(info->comm, "NULL", 5); + } unlock: arch_spin_unlock(&info->lock); local_irq_enable(); @@ -420,7 +457,7 @@ static int threshold_show(struct seq_file *m, void *ptr) { struct runqlat_info *info = m->private; - seq_printf(m, "%llu\n", info->threshold); + seq_printf(m, "%llu ns\n", info->threshold); return 0; } @@ -453,14 +490,17 @@ static int runqlat_show(struct seq_file *m, void *ptr) for (i = 0; i < info->nr_trace; i++) { struct trace_entry *entry = info->trace_entries + i; - seq_printf(m, "%*clatency(us):%llu\trunqlen:%d\trqstart(us):%llu\n", 2, ' ', - entry->latency / 1000, entry->nr_tasks, - entry->rq_start / 1000); + seq_printf(m, "%*ccpu:%d\tcommand:%s\tpid:%d\tlatency:%llums\tSTAMP:%llu\trunqlen:%d\n", + 5, ' ', entry->cpu, + entry->comm, entry->pid, + entry->latency/(1000*1000), + entry->rq_start, + entry->nr_tasks); for (j = 0; j < entry->nr_tasks; j++) { struct task_entry *task = entry->entries + j; - seq_printf(m, "%*cCOMM:%s\tPID:%d\tRUNTIME(us):%llu\n", + seq_printf(m, "%*ctask:%s %d\tRUNTIME(us):%llu\n", 6, ' ', task->comm, task->pid, task->runtime / 1000); } diff --git a/source/tools/monitor/sched/runlatency/parser.c b/source/tools/monitor/sched/runlatency/parser.c index 971dd248..028c900a 100644 --- a/source/tools/monitor/sched/runlatency/parser.c +++ b/source/tools/monitor/sched/runlatency/parser.c @@ -253,7 +253,7 @@ static char* body_runq(char* beg, FILE *file) s = head_args(s, root); arr = cJSON_CreateArray(); - cJSON_AddItemToObject(root, "que", arr); + cJSON_AddItemToObject(root, "private", arr); while (*s != '\n') { cJSON *cell = cJSON_CreateObject(); s = head_args(s, cell); -- Gitee From bd8cfc2e04dd458a14b454e4bedd49c6885bd508 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Mon, 28 Feb 2022 14:19:09 +0800 Subject: [PATCH 6/8] runlatency: Add threshold options for runlatency This change provides a options for user to choice a self defined thresholds for runlatency monitor. Signed-off-by: Hailong Liu --- .../kernel_module/modules/sched/noschedule.c | 2 +- .../modules/sched/trace_irqoff.c | 6 +- .../modules/sched/trace_runqlat.c | 2 +- .../tools/monitor/sched/runlatency/parser.c | 2 +- .../tools/monitor/sched/runlatency/parser.h | 2 + .../monitor/sched/runlatency/runlatency.c | 83 ++++++++++++++----- 6 files changed, 71 insertions(+), 26 deletions(-) diff --git a/source/lib/internal/kernel_module/modules/sched/noschedule.c b/source/lib/internal/kernel_module/modules/sched/noschedule.c index 5043eba3..849a9818 100644 --- a/source/lib/internal/kernel_module/modules/sched/noschedule.c +++ b/source/lib/internal/kernel_module/modules/sched/noschedule.c @@ -347,7 +347,7 @@ static void tracepoint_lookup(struct tracepoint *tp, void *priv) static int threshold_show(struct seq_file *m, void *ptr) { - seq_printf(m, "%llu\n", duration_threshold); + seq_printf(m, "%llu ms\n", duration_threshold/(1000*1000)); return 0; } diff --git a/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c b/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c index b70c470a..a55fcac1 100644 --- a/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c +++ b/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c @@ -423,9 +423,9 @@ static int trace_latency_show(struct seq_file *m, void *v) static ssize_t trace_latency_store(void *priv, const char __user *buf, size_t count) { - unsigned long latency; + u64 latency; - if (kstrtoul_from_user(buf, count, 0, &latency)) + if (kstrtou64_from_user(buf, count, 0, &latency)) return -EINVAL; if (latency == 0) { @@ -439,7 +439,7 @@ static ssize_t trace_latency_store(void *priv, const char __user *buf, size_t co } else if (latency < (sampling_period << 1) / (1000 * 1000UL)) return -EINVAL; - trace_irqoff_latency = latency * 1000 * 1000UL; + trace_irqoff_latency = latency; return count; } diff --git a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c index 30e64b3c..ac76a9b5 100644 --- a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c +++ b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c @@ -457,7 +457,7 @@ static int threshold_show(struct seq_file *m, void *ptr) { struct runqlat_info *info = m->private; - seq_printf(m, "%llu ns\n", info->threshold); + seq_printf(m, "%llu ms\n", info->threshold/(1000*1000)); return 0; } diff --git a/source/tools/monitor/sched/runlatency/parser.c b/source/tools/monitor/sched/runlatency/parser.c index 028c900a..4b7ad141 100644 --- a/source/tools/monitor/sched/runlatency/parser.c +++ b/source/tools/monitor/sched/runlatency/parser.c @@ -41,7 +41,7 @@ static char* accepts(char* s, char c1, char c2) return s + 1; } -static bool isdigits(char *s) +bool isdigits(char *s) { while (*s != '\0') { if (isdigit(*s) == 0) { diff --git a/source/tools/monitor/sched/runlatency/parser.h b/source/tools/monitor/sched/runlatency/parser.h index bb190053..adee4e5a 100644 --- a/source/tools/monitor/sched/runlatency/parser.h +++ b/source/tools/monitor/sched/runlatency/parser.h @@ -1,7 +1,9 @@ #ifndef _PARSER_H #define _PARSER_H +#include int parser_irqoff(char *stream, int size, FILE *file); int parser_nosch(char *stream, int size, FILE *file); int parser_runq(char *stream, int size, FILE *file); int parse_dump(char *file); +bool isdigits(char *s); #endif diff --git a/source/tools/monitor/sched/runlatency/runlatency.c b/source/tools/monitor/sched/runlatency/runlatency.c index 69ded760..8aa7498b 100644 --- a/source/tools/monitor/sched/runlatency/runlatency.c +++ b/source/tools/monitor/sched/runlatency/runlatency.c @@ -14,19 +14,25 @@ #define MAX_CMD 3 #define MAX_CMD_LEN 128 -char *firq = "/proc/sysak/runlatency/irqoff/enable"; -char *fsch = "/proc/sysak/runlatency/nosch/enable"; -char *flat = "/proc/sysak/runlatency/runqlat/pid"; +bool ready[MAX_CMD] = {false}; +int retno[MAX_CMD] = {0}; +char *enable_files[] = {"/proc/sysak/runlatency/irqoff/enable", + "/proc/sysak/runlatency/nosch/enable", + "/proc/sysak/runlatency/runqlat/pid"}; +char *trsh_files[] = {"/proc/sysak/runlatency/irqoff/latency", + "/proc/sysak/runlatency/nosch/threshold", + "/proc/sysak/runlatency/runqlat/threshold"}; static void usage(char *prog) { const char *str = - " Usage: %s [OPTIONS]\n" + " Usage: %s -e [-p pid], [-t t1 t2 t3]\n" " Options:\n" - " -p set the pid we monitor, used with -e or separately\n" - " -r [outfile] read result to outfile, if not point,to stdout\n" - " -d [mask] disable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" - " -e [mask]enable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" + " -p set the pid we monitor, used with -e or separately\n" + " -t set thresh:latirq=thresh1, nosched=thresh2, runq=thresh3 \n" + " -r [outfile] read result to outfile, if not point,to stdout\n" + " -d [mask] disable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" + " -e [mask]enable the monitor, 7-all, 1-irq, 2-nosched, 4-runlat, default=7\n" "for example:\n" " sysak runlatency -e -p 78953 #enable all runaltency monitor for task 78953\n" " sleep 20 #Sampling for 20 seconds 20\n" @@ -38,8 +44,6 @@ static void usage(char *prog) exit(EXIT_FAILURE); } -char *cmdstr[3]; - int switch_func(int opt, int enable, int pid) { FILE *fp; @@ -55,7 +59,7 @@ int switch_func(int opt, int enable, int pid) param[0] = param[1] = enable; while (index < MAX_CMD) { if (optalign & (1 << index)) { - snprintf(cmd, MAX_CMD_LEN, "echo %d > %s",param[index], cmdstr[index]); + snprintf(cmd, MAX_CMD_LEN, "echo %d > %s",param[index], enable_files[index]); /* fprintf(stderr, "debug_cmd:%s\n", cmd); */ fp = popen(cmd, "r"); if (!fp) { @@ -66,10 +70,28 @@ int switch_func(int opt, int enable, int pid) } index++; } + + return 0; } -bool ready[MAX_CMD] = {false}; -int retno[MAX_CMD] = {0}; +int set_thresh(unsigned long *thresh) +{ + FILE *fp; + int i = 0, ret; + char cmd[MAX_CMD_LEN] = {0}; + + for (; i < MAX_CMD; i++) { + snprintf(cmd, MAX_CMD_LEN, "echo %llu > %s", + thresh[i]*1000*1000, trsh_files[i]); + fp = popen(cmd, "r"); + if (!fp) { + ret = errno; + perror(cmd); + return ret; + } + } + return 0; +} static int all_ready(bool ready[], int retno[]) { @@ -80,7 +102,7 @@ static int all_ready(bool ready[], int retno[]) ready_cnt++; } else { fprintf(stderr, "%s: access() %s\n", - strerror(retno[i]), cmdstr[i]); + strerror(retno[i]), enable_files[i]); } } @@ -92,15 +114,14 @@ int main(int argc, char *argv[]) char *refile = NULL; int pid = -1, ret = 0, i, will_switch = 0, enable = -1; int c, option_index, opt_mask; + bool will_thresh = false; + unsigned long thresh[MAX_CMD] = {0}; opterr = 0; opt_mask = 0; - cmdstr[0] = firq; - cmdstr[1] = fsch; - cmdstr[2] = flat; for (i = 0; i < MAX_CMD; i++) { - if (access(cmdstr[i], F_OK)) { + if (access(enable_files[i], F_OK)) { retno[i] = errno; ready[i] = false; } else { @@ -109,7 +130,7 @@ int main(int argc, char *argv[]) } } for (;;) { - c = getopt_long(argc, argv, "p:e::d::rh", + c = getopt_long(argc, argv, "p:e::d::trh", NULL /*long_options*/, &option_index); if (c == -1) @@ -122,6 +143,25 @@ int main(int argc, char *argv[]) refile = argv[optind]; parse_dump(refile);//do something break; + case 't': + if (!all_ready(ready, retno)) + return -1; + if (argc > optind + 2) { /* -t follows 3 arguments */ + for (i = 0; i < MAX_CMD; i++) { + if (isdigits(argv[i+optind])) + thresh[i] = strtoul(argv[i+optind], NULL, 10); + else + break; + } + if (i >= MAX_CMD) + will_thresh = true; + else + printf("-t must follows 3 digitals\n"); + } else { + printf("\"-t\" must follows 3 digitals\n"); + usage("sysak runlatency"); + } + break; case 'p': pid = atoi(optarg); will_switch = 1; @@ -157,6 +197,9 @@ int main(int argc, char *argv[]) } if (will_switch) ret = switch_func(opt_mask, enable, pid); - + if (ret) + return ret; + if (will_thresh) + ret = set_thresh(thresh); return ret; } -- Gitee From 8e488357957bf25237a6084bd214cabf522ece71 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Mon, 28 Feb 2022 15:48:01 +0800 Subject: [PATCH 7/8] runlatency: Unified adaptation for all output formats. Make sure all the output formats are the same. Signed-off-by: Hailong Liu --- source/lib/internal/kernel_module/modules/sched/noschedule.c | 5 ++--- .../lib/internal/kernel_module/modules/sched/trace_irqoff.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/source/lib/internal/kernel_module/modules/sched/noschedule.c b/source/lib/internal/kernel_module/modules/sched/noschedule.c index 849a9818..9bae2649 100644 --- a/source/lib/internal/kernel_module/modules/sched/noschedule.c +++ b/source/lib/internal/kernel_module/modules/sched/noschedule.c @@ -543,12 +543,11 @@ static int stack_trace_show(struct seq_file *m, void *ptr) struct stack_entry *entry; entry = cpu_stack_trace->stack_entries + i; - seq_printf(m, "%*ccpu:%d\tCOMM: %s\tPID:%d\tDURATION:%lluus\tSTAMP:%llu\n", + seq_printf(m, "%*ccpu:%d\tcommand:%s\tpid:%d\tlatency:%lluus\tSTAMP:%llu\n", 5, ' ', cpu, cpu_stack_trace->comms[i], cpu_stack_trace->pids[i], cpu_stack_trace->duration[i] / (1000UL), - cpu_stack_trace->stamp[i] - ); + cpu_stack_trace->stamp[i]); seq_print_stack_trace(m, entry); seq_putc(m, '\n'); diff --git a/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c b/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c index a55fcac1..5602be1a 100644 --- a/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c +++ b/source/lib/internal/kernel_module/modules/sched/trace_irqoff.c @@ -387,12 +387,12 @@ static void trace_latency_show_one(struct seq_file *m, void *v, bool hardirq) for (i = 0; i < nr_irqoff_trace; i++) { struct irqoff_trace *trace = stack_trace->trace + i; - seq_printf(m, "%*ccpu:%d\tCOMMAND:%s\tPID:%d\tLATENCY:%lu%s\tSTAMP:%llu\n", + seq_printf(m, "%*ccpu:%d\tcommand:%s\tpid:%d\tlatency:%lu%s\tSTAMP:%llu\n", 5, ' ', cpu, stack_trace->comms[i], stack_trace->pids[i], stack_trace->latency[i].nsecs / (1000 * 1000UL), stack_trace->latency[i].more ? "+ms" : "ms", - stack_trace->stamp[i] / 1000UL); + stack_trace->stamp[i]); seq_print_stack_trace(m, trace); seq_putc(m, '\n'); -- Gitee From f19617bee0adb3d5b1ff6998233c9b8fd79f7f07 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Mon, 28 Feb 2022 17:09:40 +0800 Subject: [PATCH 8/8] runlatency: Don't recored the tasks' info in run queue Task's in run queue is not nesseary for now; what's more, it has a large overhead. Signed-off-by: Hailong Liu --- .../kernel_module/modules/sched/trace_runqlat.c | 9 --------- source/tools/monitor/sched/runlatency/parser.c | 10 +--------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c index ac76a9b5..828c36d0 100644 --- a/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c +++ b/source/lib/internal/kernel_module/modules/sched/trace_runqlat.c @@ -496,15 +496,6 @@ static int runqlat_show(struct seq_file *m, void *ptr) entry->latency/(1000*1000), entry->rq_start, entry->nr_tasks); - - for (j = 0; j < entry->nr_tasks; j++) { - struct task_entry *task = entry->entries + j; - - seq_printf(m, "%*ctask:%s %d\tRUNTIME(us):%llu\n", - 6, ' ', task->comm, task->pid, - task->runtime / 1000); - } - seq_putc(m, '\n'); } arch_spin_unlock(&info->lock); local_irq_enable(); diff --git a/source/tools/monitor/sched/runlatency/parser.c b/source/tools/monitor/sched/runlatency/parser.c index 4b7ad141..aa9636ed 100644 --- a/source/tools/monitor/sched/runlatency/parser.c +++ b/source/tools/monitor/sched/runlatency/parser.c @@ -250,16 +250,8 @@ static char* body_runq(char* beg, FILE *file) root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "mode", "runq"); - s = head_args(s, root); - arr = cJSON_CreateArray(); - cJSON_AddItemToObject(root, "private", arr); - while (*s != '\n') { - cJSON *cell = cJSON_CreateObject(); - s = head_args(s, cell); - cJSON_AddItemToArray(arr, cell); - } - + out = cJSON_Print(root); if (!file) printf("%s\n", out); -- Gitee