diff --git a/source/lib/internal/kernel_module/Makefile b/source/lib/internal/kernel_module/Makefile index f9200491dde05ec382083bea2f64307a97172b89..265d84e1e24073940a39b8a53eed96d4afa1a13f 100644 --- a/source/lib/internal/kernel_module/Makefile +++ b/source/lib/internal/kernel_module/Makefile @@ -33,9 +33,6 @@ endif ifneq ($(findstring mmaptrace,$(TARGET_LIST)),) sysak-objs += modules/mmaptrace/mmaptrace.o endif -ifneq ($(findstring loadtask,$(TARGET_LIST)),) -sysak-objs += modules/loadtask/loadtask.o -endif ifneq ($(findstring iosdiag,$(TARGET_LIST)),) ifneq ($(wildcard $(MODULE_SRC)/modules/iosdiag/include/$(KERNEL_VERSION)),) sysak-objs += modules/iosdiag/iosdiag.o modules/iosdiag/rq_hang.o modules/iosdiag/virtio_blk.o modules/iosdiag/nvme.o modules/iosdiag/scsi.o diff --git a/source/lib/internal/kernel_module/modules/loadtask/loadtask.c b/source/lib/internal/kernel_module/modules/loadtask/loadtask.c deleted file mode 100644 index dd2416ca184fb520462852bdc1ee0f25bb75ea5f..0000000000000000000000000000000000000000 --- a/source/lib/internal/kernel_module/modules/loadtask/loadtask.c +++ /dev/null @@ -1,133 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/proc.h" -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) -#include -#include -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) -static void *orig_tasklist_lock; -void (*orig_get_avenrun)(unsigned long *loads, unsigned long offset, int shift); -#ifdef CONFIG_RICH_CONTAINER -int *orig_sysctl_rich_container_enable; -bool (*orig_child_cpuacct)(struct task_struct *tsk); -static void (*orig_get_avenrun_r)(unsigned long *loads, unsigned long offset, - int shift); -static void (*orig_get_cgroup_avenrun)(struct task_struct *tsk, - unsigned long *loads, unsigned long offset, - int shift, bool running); -static inline bool orig_in_rich_container(struct task_struct *tsk) -{ - if (*orig_sysctl_rich_container_enable == 0) - return false; - - return (task_active_pid_ns(tsk) != &init_pid_ns) && orig_child_cpuacct(tsk); -} -#else -static inline void (*orig_get_avenrun_r)(unsigned long *loads, unsigned long offset, - int shift) { } -static inline void (*orig_get_cgroup_avenrun)(struct task_struct *tsk, - unsigned long *loads, unsigned long offset, - int shift, bool running) { } -static inline bool orig_in_rich_container(struct task_struct *tsk) -{ - return false; -} -#endif -#endif - -static int loadtask_show(struct seq_file *m, void *v) -{ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) - unsigned long avnrun[3], avnrun_r[3]; - - rcu_read_lock(); - if (orig_in_rich_container(current)) { - struct task_struct *init_tsk; - - read_lock(orig_tasklist_lock); - init_tsk = task_active_pid_ns(current)->child_reaper; - get_task_struct(init_tsk); - read_unlock(orig_tasklist_lock); - orig_get_cgroup_avenrun(init_tsk, avnrun, FIXED_1/200, 0, false); - orig_get_cgroup_avenrun(init_tsk, avnrun_r, FIXED_1/200, 0, true); - put_task_struct(init_tsk); - } else { - orig_get_avenrun(avnrun, FIXED_1/200, 0); - orig_get_avenrun_r(avnrun_r, FIXED_1/200, 0); - } - rcu_read_unlock(); - - seq_printf(m, "loadavg: %lu.%02lu %lu.%02lu %lu.%02lu\n", - LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]), - LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]), - LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2])); - seq_printf(m, "loadavg_r: %lu.%02lu %lu.%02lu %lu.%02lu\n", - LOAD_INT(avnrun_r[0]), LOAD_FRAC(avnrun_r[0]), - LOAD_INT(avnrun_r[1]), LOAD_FRAC(avnrun_r[1]), - LOAD_INT(avnrun_r[2]), LOAD_FRAC(avnrun_r[2])); - seq_printf(m, "loadavg_d: %lu.%02lu %lu.%02lu %lu.%02lu\n", - LOAD_INT(avnrun[0] - avnrun_r[0]), LOAD_FRAC(avnrun[0] - avnrun_r[0]), - LOAD_INT(avnrun[1] - avnrun_r[1]), LOAD_FRAC(avnrun[1] - avnrun_r[1]), - LOAD_INT(avnrun[2] - avnrun_r[2]), LOAD_FRAC(avnrun[2] - avnrun_r[2])); -#endif - return 0; -} - -DEFINE_PROC_ATTRIBUTE_RO(loadtask); - -int loadtask_init(void) -{ - struct proc_dir_entry *parent_dir; - struct proc_dir_entry *entry_print; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) - orig_tasklist_lock = (void *)kallsyms_lookup_name("tasklist_lock"); - if (!orig_tasklist_lock) - return -1; - orig_get_avenrun = (void *)kallsyms_lookup_name("get_avenrun"); - if (!orig_get_avenrun) - return -1; -#ifdef CONFIG_RICH_CONTAINER - orig_get_avenrun_r = (void *)kallsyms_lookup_name("get_avenrun_r"); - if (!orig_get_avenrun_r) - return -1; - orig_get_cgroup_avenrun = (void *)kallsyms_lookup_name("get_cgroup_avenrun"); - if (!orig_get_cgroup_avenrun) - return -1; - orig_sysctl_rich_container_enable= (void *)kallsyms_lookup_name("sysctl_rich_container_enable"); - if (!orig_sysctl_rich_container_enable) - return -1; -#endif - orig_child_cpuacct = (void *)kallsyms_lookup_name("child_cpuacct"); - if (!orig_child_cpuacct) - return -1; -#endif - parent_dir = sysak_proc_mkdir("loadtask"); - if (!parent_dir) { - goto failed_root; - } - - entry_print = proc_create("loadavg", 0444, parent_dir, &loadtask_fops); - if(!entry_print) - goto failed; - return 0; - -failed: - sysak_remove_proc_entry("loadtask"); -failed_root: - return -1; -} - -int loadtask_exit(void) -{ - return 0; -} \ No newline at end of file diff --git a/source/lib/internal/kernel_module/sysak_mods.c b/source/lib/internal/kernel_module/sysak_mods.c index de2d940a7ee63a85938c00a7b004e52e265f024b..8368472180ed04e23e4e6076c8e7f739483ce9da 100644 --- a/source/lib/internal/kernel_module/sysak_mods.c +++ b/source/lib/internal/kernel_module/sysak_mods.c @@ -57,14 +57,6 @@ int __attribute__((weak)) mmaptrace_exit(void) { return 0; } -int __attribute__((weak)) loadtask_init(void) -{ - return 0; -} -int __attribute__((weak)) loadtask_exit(void) -{ - return 0; -} int __attribute__((weak)) disk_hang_init(void) { return 0; @@ -81,7 +73,6 @@ struct sysak_module sysak_modules[] = { { "task_ctl", task_ctl_init, task_ctl_exit}, { "schedtrace", schedtrace_init, schedtrace_exit}, { "mmap_trace", mmaptrace_init, mmaptrace_exit}, - { "loadtask", loadtask_init, loadtask_exit}, { "iosdiag", disk_hang_init, disk_hang_exit}, }; diff --git a/source/tools/detect/loadtask/Makefile b/source/tools/detect/loadtask/Makefile index 24de920d1f19974879cd34317cafb9098dadb878..5ae9f8b26949f36281266d8756a0cc9d3ae92199 100644 --- a/source/tools/detect/loadtask/Makefile +++ b/source/tools/detect/loadtask/Makefile @@ -1,5 +1,4 @@ target := loadtask -DEPEND := "prev{-s modin};post{-e modun}" include $(SRC)/mk/sh.mk diff --git a/source/tools/detect/loadtask/loadtask.sh b/source/tools/detect/loadtask/loadtask.sh index 269fdac69f99c937380d61fe36038b17dc98779a..b4f7d1de318d4297989d826a2e99dc3c019df5f0 100755 --- a/source/tools/detect/loadtask/loadtask.sh +++ b/source/tools/detect/loadtask/loadtask.sh @@ -20,7 +20,6 @@ usage() { echo " -k, terminate running ${selftaskname} which started previously" echo " -g, default collect cpu perf flamegraph by cpu_flamegraph tool" echo " -r datafile, read datafile created by '-f datafile' or by default(datafile directory /var/log/sysak/loadtask/) and show result" - echo " -e, rmmod loadtask.ko" } uninterrupt_cnt=0 @@ -191,9 +190,24 @@ current_analyse() { load_proc=`cat /proc/loadavg` load_proc="load_proc: $load_proc" echo "$load_proc" >> $tmpfile - if [ "$summary" == "true" ];then - if [ -f "/proc/sysak/loadtask/loadavg" ]; then - cat /proc/sysak/loadtask/loadavg >> $tmpfile + if [ "$summary" == "true" ];then + if [ -f "/sys/fs/cgroup/cpuacct/cpuacct.proc_stat" ]; then + load_1=`echo $load_proc | awk -F " " '{print$2}'` + load_5=`echo $load_proc | awk -F " " '{print$3}'` + load_15=`echo $load_proc | awk -F " " '{print$4}'` + + r_count=`cat /sys/fs/cgroup/cpuacct/cpuacct.proc_stat | grep nr_running | awk -F " " '{print$2}'` + d_count=`cat /sys/fs/cgroup/cpuacct/cpuacct.proc_stat | grep nr_uninterruptible | awk -F " " '{print$2}'` + + loadavg_r_1=$(echo "$r_count/($r_count+$d_count)*$load_1" | bc | awk '{printf "%.2f\n", $0}') + loadavg_r_5=$(echo "$r_count/($r_count+$d_count)*$load_5" | bc | awk '{printf "%.2f\n", $0}') + loadavg_r_15=$(echo "$r_count/($r_count+$d_count)*$load_15" | bc | awk '{printf "%.2f\n", $0}') + loadavg_d_1=$(echo "$load_1-$loadavg_r_1" | bc | awk '{printf "%.2f\n", $0}') + loadavg_d_5=$(echo "$load_5-$loadavg_r_5" | bc | awk '{printf "%.2f\n", $0}') + loadavg_d_15=$(echo "$load_15-$loadavg_r_15" | bc | awk '{printf "%.2f\n", $0}') + + echo "loadavg_r: $loadavg_r_1 $loadavg_r_5 $loadavg_r_15" >> $tmpfile + echo "loadavg_d: $loadavg_d_1 $loadavg_d_5 $loadavg_d_15" >> $tmpfile fi fi load=`cat /proc/loadavg | awk '{print $1}'` @@ -398,7 +412,7 @@ selftaskname="`cat /proc/$$/status | grep -w "Name" | awk -F" " '{print $2}'`" parsed_datafile="" tmp_parsed_datafile=${loadtask_dir}.parsedlog -while getopts 'm:f:i:t:r:deskgh' OPT; do +while getopts 'm:f:i:t:r:dskgh' OPT; do case $OPT in "h") usage @@ -435,10 +449,6 @@ while getopts 'm:f:i:t:r:deskgh' OPT; do "g") is_cpuflamegraph="true" ;; - "e") - echo "rmmod loadtask.ko" - exit 0 - ;; *) usage exit -1