From ba633b50bc6bcff0b85c382f0a0e62e4c92651c4 Mon Sep 17 00:00:00 2001 From: zy Date: Mon, 20 Nov 2023 02:12:21 -0500 Subject: [PATCH] diag_task_kern_stack void -> unsigned int; adjust print --- source/module/monitor_kernel_lib.c | 31 +++++++++++++++++++----------- source/module/monitor_trace.c | 4 ++-- source/module/monitor_trace.h | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/source/module/monitor_kernel_lib.c b/source/module/monitor_kernel_lib.c index 69570d1..1821b00 100644 --- a/source/module/monitor_kernel_lib.c +++ b/source/module/monitor_kernel_lib.c @@ -1,6 +1,7 @@ #include "monitor_kernel.h" #include +#include // #include // #include @@ -55,24 +56,32 @@ static int init_buffer(unsigned int buf_size) { } void diag_tsk(struct task_struct *p, variable_monitor_task *tsk_info,unsigned long *flags) { - + int i; + unsigned int nr_bt; printk(KERN_INFO "diag_tsk\n"); diag_task_brief(p, &tsk_info->task); // task brief - printk("1\n"); + // printk("1\n"); diag_task_user_stack(p, &tsk_info->user_stack); // user stack - printk("2\n"); - diag_task_kern_stack(p, &tsk_info->kern_stack); // kernel stack - printk("3\n"); + // printk("2\n"); + nr_bt = diag_task_kern_stack(p, &tsk_info->kern_stack); // kernel stack + // printk("pid: %d, kernel stack.stack\n", p->pid); + // for (i = 0; i < nr_bt; i++) { + // printk("%lx\n", tsk_info->kern_stack.stack[i]); + // } + // printk("pid: %d, stack_trace_print\n", p->pid); + stack_trace_print(tsk_info->kern_stack.stack, nr_bt, 0); /* 打印栈 */ + + // printk("3\n"); dump_proc_chains_argv(1, p, &mm_tree_struct, &tsk_info->proc_chains); // proc chains - printk("4\n"); + // printk("4\n"); diag_variant_buffer_spin_lock(&load_monitor_variant_buffer, *flags); diag_variant_buffer_reserve(&load_monitor_variant_buffer, sizeof(variable_monitor_task)); - printk("5\n"); + // printk("5\n"); diag_variant_buffer_write_nolock(&load_monitor_variant_buffer, tsk_info, sizeof(variable_monitor_task)); - printk("6\n"); + // printk("6\n"); diag_variant_buffer_seal(&load_monitor_variant_buffer); diag_variant_buffer_spin_unlock(&load_monitor_variant_buffer, *flags); } @@ -206,7 +215,7 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) { static variable_monitor_record vm_record = {0}; vm_record.id = event_id; - vm_record.et_type = 1; //! todo event type + vm_record.et_type = 0; //! todo event type vm_record.tv = ktime_get_real(); vm_record.threshold_num = j; @@ -228,8 +237,8 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) { do_each_thread(g, p) { if (p->__state == TASK_RUNNING || __task_contributes_to_load(p) || - p->__state == TASK_IDLE) { - tsk_info.et_type = 2; //! todo event type + p->__state == TASK_IDLE || 1) { + tsk_info.et_type = 1; //! todo event type tsk_info.id = event_id; tsk_info.tv = vm_record.tv; diag_tsk(p, &tsk_info, &flags); diff --git a/source/module/monitor_trace.c b/source/module/monitor_trace.c index 2590383..9583068 100644 --- a/source/module/monitor_trace.c +++ b/source/module/monitor_trace.c @@ -322,8 +322,8 @@ void diag_task_user_stack(struct task_struct *tsk, user_stack_detail *detail) { } } -void diag_task_kern_stack(struct task_struct *tsk, kern_stack_detail *detail) { - orig_stack_trace_save_tsk(tsk, detail->stack, BACKTRACE_DEPTH, 0); +unsigned int diag_task_kern_stack(struct task_struct *tsk, kern_stack_detail *detail) { + return orig_stack_trace_save_tsk(tsk, detail->stack, BACKTRACE_DEPTH, 0); } void dump_proc_chains_argv(int style, struct task_struct *tsk, mm_tree *mm_tree, diff --git a/source/module/monitor_trace.h b/source/module/monitor_trace.h index 652ccb4..7930a04 100644 --- a/source/module/monitor_trace.h +++ b/source/module/monitor_trace.h @@ -94,7 +94,7 @@ void diag_task_brief(struct task_struct *tsk, task_detail *detail); // get task brief void diag_task_user_stack(struct task_struct *tsk, user_stack_detail *detail); // get task user stack -void diag_task_kern_stack(struct task_struct *tsk, +unsigned int diag_task_kern_stack(struct task_struct *tsk, kern_stack_detail *detail); // get task kernel stack void dump_proc_chains_argv( int style, struct task_struct *tsk, mm_tree *mm_tree,