diff --git a/source/lib/internal/kernel_module/common/proc.h b/source/lib/internal/kernel_module/common/proc.h index fdc0e52376e7478295adc863c7830ac2cc433e61..cbf17a9915c05609e5e6630658d229197e4acba5 100644 --- a/source/lib/internal/kernel_module/common/proc.h +++ b/source/lib/internal/kernel_module/common/proc.h @@ -106,7 +106,6 @@ int __weak kstrtobool_from_user(const char __user *s, size_t count, bool *res) #define DEFINE_PROC_ATTRIBUTE_RO(name) \ DEFINE_PROC_ATTRIBUTE(name, NULL) #endif -#endif extern struct proc_dir_entry *sysak_proc_mkdir(const char *name); @@ -123,4 +122,4 @@ extern int sysak_remove_proc_subtree(const char *name); extern int sysak_proc_init(void); extern void sysak_proc_exit(void); -#endif \ No newline at end of file +#endif diff --git a/source/tools/monitor/sched/runlatency/Makefile b/source/tools/monitor/sched/runlatency/Makefile index 6a58b3a5ece546dfb4ae837da8a53425d6927491..d1fd7933c20fe7e5173ec5d8de8246bbdd9dbcb3 100644 --- a/source/tools/monitor/sched/runlatency/Makefile +++ b/source/tools/monitor/sched/runlatency/Makefile @@ -1 +1,7 @@ -include $(SRC)/mk/sub.mk +target := runlatency +DEPEND := "prev{-e modin};post{-d modun}" +mods := runlatency.o json_dump.o parser.o +EXTRA_CFLAGS += -I ./include +EXTRA_LDFLAGS += -lsysak + +include $(SRC)/mk/csrc.mk diff --git a/source/tools/monitor/sched/runlatency/json_dump/src/json_dump.c b/source/tools/monitor/sched/runlatency/json_dump.c similarity index 60% rename from source/tools/monitor/sched/runlatency/json_dump/src/json_dump.c rename to source/tools/monitor/sched/runlatency/json_dump.c index 011d0d34895826721f95dc15eab7d4a89065d085..904666c1eaa9420639332ebf8bc471b990b472f3 100644 --- a/source/tools/monitor/sched/runlatency/json_dump/src/json_dump.c +++ b/source/tools/monitor/sched/runlatency/json_dump.c @@ -5,11 +5,12 @@ #include #include #include +#include #include "parser.h" -#define IRQOFF_FILE "/proc/runlatency/irqoff/latency" -#define NOSCH_FILE "/proc/runlatency/nosch/stack_trace" -#define RUNQ_FILE "/proc/runlatency/runqlat/runqlat" +#define IRQOFF_FILE "/proc/sysak/runlatency/irqoff/latency" +#define NOSCH_FILE "/proc/sysak/runlatency/nosch/stack_trace" +#define RUNQ_FILE "/proc/sysak/runlatency/runqlat/runqlat" #define STREAM_SIZE (128 * 1024) @@ -19,6 +20,8 @@ int read_file(char* path, char* s) int size; if (fd < 0) { + fprintf(stderr, "%s :open %s\n", + strerror(errno), path); return fd; } @@ -33,6 +36,8 @@ int clear_file(char *path) int size; if (fd < 0) { + fprintf(stderr, "%s :open %s\n", + strerror(errno), path); return fd; } @@ -41,29 +46,35 @@ int clear_file(char *path) return size; } -int main(void) +int pasre_dump(char *file) { char *s; int ret; + FILE *outf = NULL; s = malloc(STREAM_SIZE); if (s == NULL) { return -ENOMEM; } - + if (file) { + outf = fopen(file, "a+"); + if (!outf) + fprintf(stderr, "%s :fopen %s\n", + strerror(errno), file); + } ret = read_file(IRQOFF_FILE, s); if (ret < 0) { goto failed; } s[ret] = '\0'; - parser_irqoff(s, ret); + parser_irqoff(s, ret, outf); ret = read_file(NOSCH_FILE, s); if (ret < 0) { goto failed; } s[ret] = '\0'; - parser_nosch(s, ret); + parser_nosch(s, ret, outf); clear_file(NOSCH_FILE); ret = read_file(RUNQ_FILE, s); @@ -71,13 +82,17 @@ int main(void) goto failed; } s[ret] = '\0'; - parser_runq(s, ret); + parser_runq(s, ret, outf); clear_file(RUNQ_FILE); free(s); + if (outf) + fclose(outf); return 0; failed: free(s); + if (outf) + fclose(outf); return ret; } diff --git a/source/tools/monitor/sched/runlatency/json_dump/Makefile b/source/tools/monitor/sched/runlatency/json_dump/Makefile deleted file mode 100644 index 6a58b3a5ece546dfb4ae837da8a53425d6927491..0000000000000000000000000000000000000000 --- a/source/tools/monitor/sched/runlatency/json_dump/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(SRC)/mk/sub.mk diff --git a/source/tools/monitor/sched/runlatency/json_dump/include/parser.h b/source/tools/monitor/sched/runlatency/json_dump/include/parser.h deleted file mode 100644 index 199be029f86a468360ec363d2b9d138629881031..0000000000000000000000000000000000000000 --- a/source/tools/monitor/sched/runlatency/json_dump/include/parser.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _PARSER_H -#define _PARSER_H -int parser_irqoff(char *stream, int size); -int parser_nosch(char *stream, int size); -int parser_runq(char *stream, int size); -#endif diff --git a/source/tools/monitor/sched/runlatency/json_dump/src/Makefile b/source/tools/monitor/sched/runlatency/json_dump/src/Makefile deleted file mode 100644 index ee4f738657c64f11038f546de7b49496245af4c0..0000000000000000000000000000000000000000 --- a/source/tools/monitor/sched/runlatency/json_dump/src/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -target := rt_json_dump -mods := json_dump.o parser.o - -EXTRA_CFLAGS += -I ../include -EXTRA_LDFLAGS += -lsysak - -include $(SRC)/mk/csrc.mk diff --git a/source/tools/monitor/sched/runlatency/json_dump/src/parser.c b/source/tools/monitor/sched/runlatency/parser.c similarity index 85% rename from source/tools/monitor/sched/runlatency/json_dump/src/parser.c rename to source/tools/monitor/sched/runlatency/parser.c index 9bd749b3cee1db154a33c11f12161d9d592b6b7a..971dd248aaa3900972b75c8341be147923229bac 100644 --- a/source/tools/monitor/sched/runlatency/json_dump/src/parser.c +++ b/source/tools/monitor/sched/runlatency/parser.c @@ -157,7 +157,7 @@ static char* stack_get(char* beg, cJSON *parent) return s + 1; // enter + 1 } -static char* body_irqoff(char* beg, enum IRQOFF stat) +static char* body_irqoff(char* beg, enum IRQOFF stat, FILE *file) { char *s; cJSON *root; @@ -178,13 +178,16 @@ static char* body_irqoff(char* beg, enum IRQOFF stat) s = stack_get(s, root); out = cJSON_Print(root); - printf("%s\n", out); + if (!file) + printf("%s\n", out); + else + fprintf(file, "%s\n", out); free(out); cJSON_Delete(root); return s; } -int parser_irqoff(char *stream, int size) +int parser_irqoff(char *stream, int size, FILE *file) { char *sBeg, *sCursor; enum IRQOFF stat = HARD_IRQ; @@ -195,18 +198,18 @@ int parser_irqoff(char *stream, int size) sBeg = sCursor; while (sBeg[1] != 's') { - sBeg = body_irqoff(sBeg, stat); + sBeg = body_irqoff(sBeg, stat, file); } stat = SOFT_IRQ; sBeg = accept(sBeg, '\n'); while (sBeg[0] != '\0') { - sBeg = body_irqoff(sBeg, stat); + sBeg = body_irqoff(sBeg, stat, file); } return 0; } -static char* body_nosch(char* beg) +static char* body_nosch(char* beg, FILE *file) { char *s; cJSON *root; @@ -219,24 +222,27 @@ static char* body_nosch(char* beg) s = stack_get(s, root); out = cJSON_Print(root); - printf("%s\n", out); + if (!file) + printf("%s\n", out); + else + fprintf(file, "%s\n", out); free(out); cJSON_Delete(root); return s; } -int parser_nosch(char *stream, int size) +int parser_nosch(char *stream, int size, FILE *file) { char *sBeg; sBeg = stream; while (sBeg[0] != '\0') { - sBeg = body_nosch(sBeg); + sBeg = body_nosch(sBeg, file); } return 0; } -static char* body_runq(char* beg) +static char* body_runq(char* beg, FILE *file) { char *s = beg; cJSON *root, *arr; @@ -255,19 +261,22 @@ static char* body_runq(char* beg) } out = cJSON_Print(root); - printf("%s\n", out); + if (!file) + printf("%s\n", out); + else + fprintf(file, "%s\n", out); free(out); cJSON_Delete(root); return s + 1; } -int parser_runq(char *stream, int size) +int parser_runq(char *stream, int size, FILE *file) { char *sBeg; sBeg = stream; while (sBeg[0] != '\0') { - sBeg = body_runq(sBeg); + sBeg = body_runq(sBeg, file); } return 0; } diff --git a/source/tools/monitor/sched/runlatency/parser.h b/source/tools/monitor/sched/runlatency/parser.h new file mode 100644 index 0000000000000000000000000000000000000000..57baa7bcdb885fa8c8fcf00b3d72a18f40cd1e27 --- /dev/null +++ b/source/tools/monitor/sched/runlatency/parser.h @@ -0,0 +1,7 @@ +#ifndef _PARSER_H +#define _PARSER_H +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); +#endif diff --git a/source/tools/monitor/sched/runlatency/runlatency.c b/source/tools/monitor/sched/runlatency/runlatency.c new file mode 100644 index 0000000000000000000000000000000000000000..26403ba03d30e0186b05c32ab3f9d5848135ec10 --- /dev/null +++ b/source/tools/monitor/sched/runlatency/runlatency.c @@ -0,0 +1,155 @@ +#include +#include +#include +#include +#include +#include +#include +#include "parser.h" + +#define OPT_MASK 0x7 +#define OPT_IRQ 0x1 +#define OPT_SCH 0x2 +#define OPT_LAT 0x4 +#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"; + +static void usage(char *prog) +{ + const char *str = + " Usage: %s [OPTIONS]\n" + " Options:\n" + " -f the output file\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" + ; + + fprintf(stderr, str, prog); + exit(EXIT_FAILURE); +} + +char *cmdstr[3]; + +int switch_func(int opt, int enable, int arg) +{ + 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[0] = param[1] = enable; + while (index < MAX_CMD) { + if (optalign & (1 << index)) { + snprintf(cmd, MAX_CMD_LEN, "echo %d > %s",param[index], cmdstr[index]); + /* fprintf(stderr, "debug_cmd:%s\n", cmd); */ + fp = popen(cmd, "r"); + if (!fp) { + ret = errno; + perror(cmd); + return ret; + } + optalign = optalign; + index++; + } + } +} + +bool ready[MAX_CMD] = {false}; +int retno[MAX_CMD] = {0}; + +static int not_ready(bool ready[], int retno[]) +{ + int i, ret = MAX_CMD; + + for (i = 0; i < MAX_CMD; i++) { + if (ready[i]) { + ret--; + } else { + fprintf(stderr, "%s: access() %s\n", + strerror(retno[i]), cmdstr[i]); + } + } + + return ret; +} + +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; + + opterr = 0; + dis_opt = en_opt = OPT_MASK; + + cmdstr[0] = firq; + cmdstr[1] = fsch; + cmdstr[2] = flat; + for (i = 0; i < MAX_CMD; i++) { + if (access(cmdstr[i], F_OK)) { + retno[i] = errno; + ready[i] = false; + } else { + retno[i] = 0; + ready[i] = true; + } + } + for (;;) { + c = getopt_long(argc, argv, "f:p:e::d::hr", + NULL /*long_options*/, &option_index); + + if (c == -1) + break; + switch (c) { + case 'f': + refile = optarg; + break; + case 'r': + if (!not_ready(ready, retno)) + return -1; + pasre_dump(refile);//do something + break; + case 'p': + pid = atoi(optarg); + break; + case 'e': + if (!not_ready(ready, retno)) + return -1; + if (optarg) + en_opt = atoi(optarg); + will_switch = 1; + enable = 1; + break; + case 'd': + if (!not_ready(ready, retno)) + return -1; + if (optarg) + dis_opt = atoi(optarg); + will_switch = 1; + enable = 0; + break; + case 'h': + usage("sysak runlatency"); + break; + default: + usage("sysak runlatency"); + } + } + if (will_switch) + ret = switch_func(dis_opt, enable, pid); + + return ret; +} diff --git a/source/tools/monitor/sched/runlatency/sh/Makefile b/source/tools/monitor/sched/runlatency/sh/Makefile deleted file mode 100644 index 255d37a638c3deb400972cf129ceaa3ee4defbeb..0000000000000000000000000000000000000000 --- a/source/tools/monitor/sched/runlatency/sh/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -target := runlatency -DEPEND := "prev{-e modin};post{-d modun}" - -include $(SRC)/mk/sh.mk diff --git a/source/tools/monitor/sched/runlatency/sh/runlatency.sh b/source/tools/monitor/sched/runlatency/sh/runlatency.sh deleted file mode 100755 index 5c6d9625821285fbd9d1911571b021992d155f7a..0000000000000000000000000000000000000000 --- a/source/tools/monitor/sched/runlatency/sh/runlatency.sh +++ /dev/null @@ -1,67 +0,0 @@ -WORK_PATH=`dirname $0`/ -pid=-1 - -runlatency_enable() { - echo 1 > /proc/sysak/runlatency/irqoff/enable - echo 1 > /proc/sysak/runlatency/nosch/enable - echo $pid > /proc/sysak/runlatency/runqlat/pid -} - -runlatency_disable() { - echo 0 > /proc/sysak/runlatency/irqoff/enable - echo 0 > /proc/sysak/runlatency/nosch/enable - echo -1 > /proc/sysak/runlatency/runqlat/pid -} - -runlatency_report() { - - if [ -z "$outfile" ]; then - $WORK_PATH/rt_json_dump - else - $WORK_PATH/rt_json_dump >>$outfile - fi -} - -usage() { - echo "$0 -e|d" - echo " -e, enable" - echo " -d, disable" - echo " -r, report, default stdout if no outfile specified" - echo " -f, outfile for report" -} - -while getopts 'p:f:edrh' OPT; do - case $OPT in - "h") - usage - exit 0 - ;; - "p") - pid=$OPTARG - ;; - "e") - runlatency_enable - exit 0 - ;; - "d") - runlatency_disable - exit 0 - ;; - "r") - report="true" - ;; - "f") - outfile=$OPTARG - ;; - *) - echo this - usage - exit -1 - ;; - esac -done - -if [ $report = "true" ];then - runlatency_report -fi -