From fed999f492f240fd43676a773a2709a7ba68ad06 Mon Sep 17 00:00:00 2001 From: aurelianliu Date: Thu, 10 Oct 2024 14:49:17 +0800 Subject: [PATCH] get more info for performance Signed-off-by: aurelianliu --- ops/os_stat/ops-run | 2 +- ops/os_stat/os_stat/data_aware.c | 143 ++++++++++++++++++------------- ops/os_stat/os_stat/syms.c | 1 - ops/os_stat/os_stat/sysctl.c | 4 +- ops/os_stat/os_stat_user/main.c | 30 +++++-- 5 files changed, 110 insertions(+), 70 deletions(-) diff --git a/ops/os_stat/ops-run b/ops/os_stat/ops-run index 717f3c7..df80a56 100755 --- a/ops/os_stat/ops-run +++ b/ops/os_stat/ops-run @@ -24,7 +24,7 @@ function include_link() ln -sf include_private include elif [ ! -z "$res_6_6" ]; then rm include - ln -sf include_tk5 include + ln -sf include_6_6 include elif [ ! -z "res_4_14" ]; then rm include ln -sf include_tk3 include diff --git a/ops/os_stat/os_stat/data_aware.c b/ops/os_stat/os_stat/data_aware.c index f201024..30f476f 100644 --- a/ops/os_stat/os_stat/data_aware.c +++ b/ops/os_stat/os_stat/data_aware.c @@ -400,9 +400,11 @@ void stat_func_exit(struct kret_data *data) void sys_get_latency(struct func_latency (*data)[PRINT_SYSCALL_NUM]) { - int i, j, k, cpu; + int i, j, k, cpu, busy = 0; unsigned long syscall_max[PRINT_SYSCALL_NUM][2] = {0}; unsigned long func_num = 0, func_time = 0, func_block_time = 0; + int nid, idle_cur = 0, idle_smt = 0, target; + size_t len_tmp = sizeof(struct func_latency); if (!data) return; @@ -433,7 +435,7 @@ void sys_get_latency(struct func_latency (*data)[PRINT_SYSCALL_NUM]) func_block_time += stat_pagefault_time_block[cpu]; } - for (i = 0; i < PRINT_SYSCALL_NUM - 1; i++) { + for (i = 0; i < PRINT_SYSCALL_NUM - 5; i++) { (*data)[i].nr = syscall_max[i][0]; (*data)[i].num = syscall_max[i][1]; (*data)[i].latency = 0; @@ -455,8 +457,58 @@ void sys_get_latency(struct func_latency (*data)[PRINT_SYSCALL_NUM]) (*data)[i].latency = func_time / func_num; (*data)[i].block_latency = func_block_time / func_num; } - strcpy((*data)[i].func, "do_page_fault"); + strcpy((*data)[i++].func, "do_page_fault"); + + j = 0; + for_each_node(nid) { + (*data)[i].nr = nid; + (*data)[i].num = (stat_mem_node[nid] * PAGE_SIZE) >> 10; + (*data)[i].latency = nr_node_ids; + (*data)[i].block_latency = 0; + strcpy((*data)[i].func, "alloc pages"); + i++; + if (j++ >= 1) + break; + } + memset(nr_running_per_node, 0, nr_node_ids * sizeof(int)); + memset(idle_cpu_stat, 0, nr_cpu_ids * sizeof(int)); + for_each_possible_cpu(cpu) { + nid = cpu_to_node(cpu); + idle_smt = 0; + idle_cur = 0; + for_each_cpu(target, cpu_smt_mask(cpu)){ + if (idle_cpu_stat[target] == 0) +#ifdef TK5 + nr_running_per_node[nid] += per_cpu(*runqueues, target).nr_running; +#else + nr_running_per_node[nid] += cpu_rq(target)->nr_running; +#endif + if (target == cpu) + idle_cur = idle_cpu(target); + else + idle_smt += idle_cpu(target); + } + if (!idle_cur && !idle_smt) { + idle_cpu_stat[cpu] = 1; + busy++; + } + if (idle_cur || idle_smt) + idle_cpu_stat[cpu] = 2; + if (idle_cur && idle_smt) + idle_cpu_stat[cpu] = 3; + } + j = 0; + for_each_node(nid) { + (*data)[i].nr = nid; + (*data)[i].num = nr_running_per_node[nid]; + (*data)[i].latency = busy; + (*data)[i].block_latency = 0; + strcpy((*data)[i].func, "rq running per node"); + i++; + if (++j > 1) + break; + } return; } @@ -544,7 +596,11 @@ int sysctl_numa_enable_handler(struct ctl_table *table, int write, int sysctl_get_total_data_handler(struct ctl_table *table, int write, +#ifdef TK5 + void *buffer, size_t *lenp, loff_t *ppos) +#else void __user *buffer, size_t *lenp, loff_t *ppos) +#endif { int i, j, k, busy = 0, cpu_num = 0; unsigned long nr = 0, nr1 = 0, nr_total = 0, nr_num = 0; @@ -561,7 +617,6 @@ int sysctl_get_total_data_handler(struct ctl_table *table, int write, memset(nr_running_per_node, 0, nr_node_ids * sizeof(int)); memset(idle_cpu_stat, 0, nr_cpu_ids * sizeof(int)); memset(idle_cpu_stat_char, 0, nr_cpu_ids * sizeof(int)); - memset(stat_sys_num_tmp, 0, 3 * NR_syscalls * sizeof(unsigned long)); pr_info("----------rq running-------------"); for_each_possible_cpu(cpu) { @@ -627,59 +682,6 @@ int sysctl_get_total_data_handler(struct ctl_table *table, int write, nr_num = 1; pr_info("all cpu total: num:%8ld, idle:%8ld, %4ld%%", nr_num, nr_total, nr_total * 100 / nr_num); - pr_info("----------memory-------------"); - for_each_node(nid) - pr_info("numa nodes alloed from: node:%d, %ld(K)", nid, (stat_mem_node[nid] * PAGE_SIZE) >> 10); - - for_each_possible_cpu(cpu) { - func_num += stat_pagefault_num[cpu]; - func_time += stat_pagefault_time[cpu]; - func_block_time += stat_pagefault_time_block[cpu]; - } - if (func_num == 0) - func_num = 1; - pr_info("page fault: num:%ld, time:%ld, ave:%ld", func_num, func_time, func_time / func_num); - - pr_info("----------syscall-------------"); - for(i = 0; i < NR_syscalls; i++) { - for_each_possible_cpu(cpu) { - stat_sys_num_tmp[i] += stat_sys_num[cpu][i]; - stat_sys_time_tmp[i] += stat_sys_time[cpu][i]; - stat_sys_time_tmp_block[i] += stat_sys_time_block[cpu][i]; - } - for (j = 0; j < PRINT_SYSCALL_NUM; j++) { - if (stat_sys_num_tmp[i] > syscall_max[j][1]) { - for (k = PRINT_SYSCALL_NUM - 1; k > j; k--) { - syscall_max[k][0] = syscall_max[k - 1][0]; - syscall_max[k][1] = syscall_max[k - 1][1]; - } - syscall_max[j][0] = i; - syscall_max[j][1] = stat_sys_num_tmp[i]; - break; - } - } - } - for (j = 0; j < PRINT_SYSCALL_NUM; j++) { - if (syscall_max[j][1] > 0) - pr_info("syscall, nr:%4ld:%32pF, num:%8ld, time:%10ld(us), ave:%8ld(ns), block time:%10ld(us), ave:%8ld(ns)", - syscall_max[j][0], stat_sys_call_table[syscall_max[j][0]], syscall_max[j][1], - stat_sys_time_tmp[syscall_max[j][0]] / 1000, - stat_sys_time_tmp[syscall_max[j][0]] / syscall_max[j][1], - stat_sys_time_tmp_block[syscall_max[j][0]] / 1000, - stat_sys_time_tmp_block[syscall_max[j][0]] / syscall_max[j][1]); - } - func_num = 0; - func_time = 0; - for_each_possible_cpu(cpu) { - func_num += stat_func_num[cpu]; - func_time += stat_func_time[cpu]; - func_block_time += stat_pagefault_time_block[cpu]; - } - if (func_num == 0) - func_num = 1; - - pr_info("stat func:%s, num:%ld, time:%ld(us), ave: %ld(ns), block time:%ld(us), ave: %ld(ns)", - func_name_new, func_num, func_time / 1000, func_time / func_num, func_block_time / 1000, func_block_time / func_num); /*----------clean data-------------*/ if (sysctl_module_debug == 1) { memset(stat_sys_num[0], 0, 3 * nr_cpu_ids * NR_syscalls * sizeof(unsigned long)); @@ -707,16 +709,35 @@ int sysctl_get_data_handler(struct ctl_table *table, int write, copy_to_user(buffer, data, len); #endif -#if 1 - int i; - pr_info("------%s, %d------", __func__, __LINE__); - for (i = 0; i < PRINT_SYSCALL_NUM; i++) { +#if 0 + int i, j; + for (i = 0; i < PRINT_SYSCALL_NUM - 5; i++) { pr_info("nr:%4ld, num:%8ld, ave:%8ld(ns), total:%8ld, block ave:%8ld(ns), total:%8ld, func:%s\n", data[i].nr, data[i].num, data[i].latency, data[i].num * data[i].latency, data[i].block_latency, data[i].num * data[i].block_latency, data[i].func); } + pr_info("--------memory-----------\n"); + pr_info("num :%8ld, ave latency:%8ld(ns), block ave latency:%8ld(ns), %s\n", data[i].num, data[i].latency, data[i].block_latency, data[i].func); + i++; + j = 0; + for (;i < PRINT_SYSCALL_NUM - 2; i++) { + pr_info("node:%8ld, mem:%8ld(k), %s\n", data[i].nr, data[i].num, data[i].func); + j++; + if (j >= nr_node_ids) { + i++; + break; + } + } + pr_info("--------rq running num-----------\n"); + j = 0; + for (;i < PRINT_SYSCALL_NUM; i++) { + pr_info("node:%8ld, nr running:%8ld, busy:%ld, %s\n", data[i].nr, data[i].num, data[i].latency, data[i].func); + j++; + if (j >= nr_node_ids) + break; + } #endif return 0; } diff --git a/ops/os_stat/os_stat/syms.c b/ops/os_stat/os_stat/syms.c index 5d4881e..6824731 100644 --- a/ops/os_stat/os_stat/syms.c +++ b/ops/os_stat/os_stat/syms.c @@ -17,7 +17,6 @@ struct rq __percpu *p_runqueues; #ifdef TK5 sys_call_ptr_t *p_sys_call_table[NR_syscalls+1]; -sys_call_ptr_t *p_sys_call_table[NR_syscalls+1]; struct mutex *p_module_mutex; #else sys_call_ptr_t *p_sys_call_table[__NR_syscall_max+1]; diff --git a/ops/os_stat/os_stat/sysctl.c b/ops/os_stat/os_stat/sysctl.c index 17dc6a1..2a10fb1 100644 --- a/ops/os_stat/os_stat/sysctl.c +++ b/ops/os_stat/os_stat/sysctl.c @@ -104,8 +104,8 @@ static struct ctl_table os_aware_table[] = { }, { .procname = "data", - .data = &sysctl_module_data, - .maxlen = sizeof(unsigned int), + .data = &sysctl_data, + .maxlen = sizeof(sysctl_data), .mode = 0444, .proc_handler = sysctl_get_data_handler, .extra1 = SYSCTL_ZERO, diff --git a/ops/os_stat/os_stat_user/main.c b/ops/os_stat/os_stat_user/main.c index 9390421..a79a5d3 100644 --- a/ops/os_stat/os_stat_user/main.c +++ b/ops/os_stat/os_stat_user/main.c @@ -41,7 +41,7 @@ int enable_block_stat(int block) char buf[4] = {'1'}, ret, fd; if (block == 0) - return; + return 0; fd = open("/proc/sys/os_aware/enable_stat_block", O_RDWR); if (fd < 0) { @@ -279,7 +279,7 @@ int process_func_pointer(char *name, char *parent_name) int main(int argc,char *argv[]) { - int fd, ret, i, func_ret; + int fd, ret, i, func_ret, j; struct func_latency data[PRINT_SYSCALL_NUM]; struct func_latency func_data; char buf[4] = {'1'}; @@ -289,6 +289,7 @@ int main(int argc,char *argv[]) int print = 1; int delay = 5; int block = 0; + int nr_node = 0; if (argc > 1) strcpy(name, argv[1]); @@ -329,10 +330,29 @@ int main(int argc,char *argv[]) printf("--------syscall stat-----------\n"); if (ret > 0) { - for (i = 0; i < PRINT_SYSCALL_NUM - 1; i ++) + for (i = 0; i < PRINT_SYSCALL_NUM - 5; i++) printf("nr:%4ld, num:%8ld, ave latency:%8ld(ns), block ave latency:%8ld(ns) %s\n", data[i].nr, data[i].num, data[i].latency, data[i].block_latency, data[i].func); - printf("--------page fault stat-----------\n"); - printf("num:%8ld, ave latency:%8ld(ns), block ave latency:%8ld(ns), %s\n", data[i].num, data[i].latency, data[i].block_latency, data[i].func); + printf("--------memory-----------\n"); + printf("num :%8ld, ave latency:%8ld(ns), block ave latency:%8ld(ns), %s\n", data[i].num, data[i].latency, data[i].block_latency, data[i].func); + i++; + j = 0; + for (;i < PRINT_SYSCALL_NUM - 2; i++) { + printf("node:%8ld, mem:%8ld(k), %s\n", data[i].nr, data[i].num, data[i].func); + j++; + nr_node = data[i].latency; + if (j >= nr_node) { + i++; + break; + } + } + printf("--------rq running num-----------\n"); + j = 0; + for (;i < PRINT_SYSCALL_NUM; i++) { + printf("node:%8ld, nr running:%8ld, busy:%ld, %s\n", data[i].nr, data[i].num, data[i].latency, data[i].func); + j++; + if (j >= nr_node) + break; + } } close(fd); disable_sys_stat(); -- Gitee