rm user_stack

This commit is contained in:
zy
2023-11-27 03:17:38 -05:00
parent 8731f63566
commit 308734c364
5 changed files with 144 additions and 139 deletions

View File

@@ -78,7 +78,7 @@ static void diag_tsk(struct task_struct *p, variable_monitor_task *tsk_info) {
unsigned int nr_bt;
// printk(KERN_INFO "diag_tsk\n");
diag_task_brief(p, &tsk_info->task); // task brief
diag_task_user_stack(p, &tsk_info->user_stack); // user stack
// diag_task_user_stack(p, &tsk_info->user_stack); // user stack
nr_bt = diag_task_kern_stack(p, &tsk_info->kern_stack); // kernel stack
dump_proc_chains_argv(1, p, &mm_tree_struct,
&tsk_info->proc_chains); // proc chains

View File

@@ -229,31 +229,31 @@ static inline void __save_stack_trace_user(struct stack_trace *trace) {
}
}
static void perfect_save_stack_trace_user(struct stack_trace *trace) {
/*
* Trace user stack if we are not a kernel thread
*/
if (current->mm) {
__save_stack_trace_user(trace);
}
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = ULONG_MAX;
}
// static void perfect_save_stack_trace_user(struct stack_trace *trace) {
// /*
// * Trace user stack if we are not a kernel thread
// */
// if (current->mm) {
// __save_stack_trace_user(trace);
// }
// if (trace->nr_entries < trace->max_entries)
// trace->entries[trace->nr_entries++] = ULONG_MAX;
// }
/**
* @brief save stack trace | current task
*
* @param backtrace
*/
static void diagnose_save_stack_trace_user(unsigned long *backtrace) {
struct stack_trace trace;
// static void diagnose_save_stack_trace_user(unsigned long *backtrace) {
// struct stack_trace trace;
memset(&trace, 0, sizeof(trace));
memset(backtrace, 0, BACKTRACE_DEPTH * sizeof(unsigned long));
trace.max_entries = BACKTRACE_DEPTH;
trace.entries = backtrace;
perfect_save_stack_trace_user(&trace);
}
// memset(&trace, 0, sizeof(trace));
// memset(backtrace, 0, BACKTRACE_DEPTH * sizeof(unsigned long));
// trace.max_entries = BACKTRACE_DEPTH;
// trace.entries = backtrace;
// perfect_save_stack_trace_user(&trace);
// }
/**
* @brief save stack trace | not current task
@@ -262,25 +262,25 @@ static void diagnose_save_stack_trace_user(unsigned long *backtrace) {
* @param backtrace
*/
static void diagnose_save_stack_trace_user_remote(struct task_struct *tsk,
unsigned long *backtrace) {
struct stack_trace trace;
// static void diagnose_save_stack_trace_user_remote(struct task_struct *tsk,
// unsigned long *backtrace) {
// struct stack_trace trace;
memset(&trace, 0, sizeof(trace));
memset(backtrace, 0, BACKTRACE_DEPTH * sizeof(unsigned long));
trace.max_entries = BACKTRACE_DEPTH;
trace.entries = backtrace;
// memset(&trace, 0, sizeof(trace));
// memset(backtrace, 0, BACKTRACE_DEPTH * sizeof(unsigned long));
// trace.max_entries = BACKTRACE_DEPTH;
// trace.entries = backtrace;
/*
* Trace user stack if we are not a kernel thread
*/
if (tsk->mm) {
// printk(KERN_INFO "save_stack_trace_user_remote %d mm\n", tsk->pid);
save_stack_trace_user_remote(tsk, &trace);
}
if (trace.nr_entries < trace.max_entries)
trace.entries[trace.nr_entries++] = ULONG_MAX;
}
// /*
// * Trace user stack if we are not a kernel thread
// */
// if (tsk->mm) {
// // printk(KERN_INFO "save_stack_trace_user_remote %d mm\n", tsk->pid);
// save_stack_trace_user_remote(tsk, &trace);
// }
// if (trace.nr_entries < trace.max_entries)
// trace.entries[trace.nr_entries++] = ULONG_MAX;
// }
static int diagnose_task_raw_stack_remote(struct task_struct *tsk, void *to,
void __user *from, unsigned long n) {
@@ -382,47 +382,47 @@ void diag_task_brief(struct task_struct *tsk, task_detail *detail) {
detail->cgroup_cpuset[CGROUP_NAME_LEN - 1] = 0; // cgroup cpuset name
}
void diag_task_user_stack(struct task_struct *tsk, user_stack_detail *detail) {
struct pt_regs *regs;
unsigned long sp, ip, bp;
struct task_struct *leader;
// void diag_task_user_stack(struct task_struct *tsk, user_stack_detail *detail) {
// struct pt_regs *regs;
// unsigned long sp, ip, bp;
// struct task_struct *leader;
if (!detail) {
return;
}
// if (!detail) {
// return;
// }
detail->stack[0] = 0;
if (!tsk || !tsk->mm) {
return;
}
// detail->stack[0] = 0;
// if (!tsk || !tsk->mm) {
// return;
// }
leader = tsk->group_leader;
if (!leader || !leader->mm || leader->exit_state == EXIT_ZOMBIE) {
return;
}
// leader = tsk->group_leader;
// if (!leader || !leader->mm || leader->exit_state == EXIT_ZOMBIE) {
// return;
// }
sp = 0;
ip = 0;
bp = 0;
regs = task_pt_regs(tsk);
if (regs) {
sp = regs->sp;
ip = regs->ip;
bp = regs->bp;
}
detail->regs = *regs;
detail->sp = sp;
detail->ip = ip;
detail->bp = bp;
// sp = 0;
// ip = 0;
// bp = 0;
// regs = task_pt_regs(tsk);
// if (regs) {
// sp = regs->sp;
// ip = regs->ip;
// bp = regs->bp;
// }
// detail->regs = *regs;
// detail->sp = sp;
// detail->ip = ip;
// detail->bp = bp;
if (tsk == current) {
// printk(KERN_INFO "diag_task_user_stack %d current\n", tsk->pid);
diagnose_save_stack_trace_user(detail->stack);
} else {
// printk(KERN_INFO "diag_task_user_stack %d no current\n", tsk->pid);
diagnose_save_stack_trace_user_remote(tsk, detail->stack);
}
}
// if (tsk == current) {
// // printk(KERN_INFO "diag_task_user_stack %d current\n", tsk->pid);
// diagnose_save_stack_trace_user(detail->stack);
// } else {
// // printk(KERN_INFO "diag_task_user_stack %d no current\n", tsk->pid);
// diagnose_save_stack_trace_user_remote(tsk, detail->stack);
// }
// }
/**
* @brief diag task kernel stack | -> to orig_stack_trace_save_tsk

View File

@@ -62,13 +62,13 @@ typedef struct {
unsigned long stack[BACKTRACE_DEPTH];
} kern_stack_detail; // kernel stack
typedef struct {
struct pt_regs regs;
unsigned long ip;
unsigned long bp;
unsigned long sp;
unsigned long stack[BACKTRACE_DEPTH];
} user_stack_detail; // user stack
// typedef struct {
// struct pt_regs regs;
// unsigned long ip;
// unsigned long bp;
// unsigned long sp;
// unsigned long stack[BACKTRACE_DEPTH];
// } user_stack_detail; // user stack
typedef struct {
struct pt_regs regs;
@@ -91,7 +91,7 @@ typedef struct {
unsigned long id;
unsigned long long tv;
task_detail task; // brief
user_stack_detail user_stack; // user stack
// user_stack_detail user_stack; // user stack
kern_stack_detail kern_stack; // kernel stack
proc_chains_detail proc_chains; // process chains argv
raw_stack_detail raw_stack;
@@ -107,8 +107,8 @@ extern struct diag_variant_buffer load_monitor_variant_buffer; // Global buffer
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_user_stack(struct task_struct *tsk,
// user_stack_detail *detail); // get task user stack
void diag_task_raw_stack(struct task_struct *tsk,
raw_stack_detail *detail); // get task raw stack
unsigned int

View File

@@ -15,46 +15,49 @@ static int task_info_extract(void *buf, unsigned int len, void *) {
struct load_monitor_cpu_run *cpu_run;
static int seq = 0;
if (len == 0) return 0;
if (len == 0)
return 0;
et_type = (int *)buf;
switch (*et_type) {
case 0:
if (len < sizeof(variable_monitor_record)) break;
vm_record = (variable_monitor_record *)buf;
printf("超出阈值:%d\n", vm_record->tv);
for (int i = 0; i < vm_record->threshold_num; i++) {
printf("\t: pid: %d, name: %s, ptr: %p, threshold:%d\n",
vm_record->threshold_record[i].task_id,
vm_record->threshold_record[i]
.name, // Assuming name is a null-terminated string
vm_record->threshold_record[i].ptr,
vm_record->threshold_record[i].threshold);
}
case 0:
if (len < sizeof(variable_monitor_record))
break;
case 1:
if (len < sizeof(variable_monitor_task)) break;
tsk_info = (variable_monitor_task *)buf;
seq++;
vm_record = (variable_monitor_record *)buf;
printf("##CGROUP:[%s] %d [%03d] 采样命中[%s]\n",
tsk_info->task.cgroup_buf, tsk_info->task.pid, seq,
tsk_info->task.state == 0 ? "R" : "D");
printk_task_brief(&tsk_info->task);
diag_printf_raw_stack(tsk_info->task.tgid, tsk_info->task.container_tgid,
tsk_info->task.comm, &tsk_info->raw_stack);
diag_printf_kern_stack(&tsk_info->kern_stack);
printf("#* 0xffffffffffffff %s (UNKNOWN)\n", tsk_info->task.comm);
diag_printf_proc_chains(&tsk_info->proc_chains);
printf("##\n");
printf("超出阈值:%d\n", vm_record->tv);
for (int i = 0; i < vm_record->threshold_num; i++) {
printf("\t: pid: %d, name: %s, ptr: %p, threshold:%d\n",
vm_record->threshold_record[i].task_id,
vm_record->threshold_record[i]
.name, // Assuming name is a null-terminated string
vm_record->threshold_record[i].ptr,
vm_record->threshold_record[i].threshold);
}
break;
case 1:
if (len < sizeof(variable_monitor_task))
break;
default:
break;
tsk_info = (variable_monitor_task *)buf;
seq++;
printf("##CGROUP:[%s] %d [%03d] 采样命中[%s]\n",
tsk_info->task.cgroup_buf, tsk_info->task.pid, seq,
tsk_info->task.state == 0 ? "R" : "D");
printk_task_brief(&tsk_info->task);
diag_printf_raw_stack(tsk_info->task.tgid, tsk_info->task.container_tgid,
tsk_info->task.comm, &tsk_info->raw_stack);
diag_printf_kern_stack(&tsk_info->kern_stack);
printf("#* 0xffffffffffffff %s (UNKNOWN)\n", tsk_info->task.comm);
diag_printf_proc_chains(&tsk_info->proc_chains);
printf("##\n");
break;
default:
break;
}
return 0;
@@ -75,26 +78,26 @@ static void do_dump(const char *arg) {
struct diag_ioctl_dump_param dump_param = {
.user_ptr_len = &len,
.user_buf_len = 5 * 1024 * 1024,
.user_buf_len = 50 * 1024 * 1024,
.user_buf = variant_buf,
};
ret = diag_call_ioctl(1, (long)&dump_param); // !todo arg -> #define
ret = diag_call_ioctl(1, (long)&dump_param); // !todo arg -> #define
if (ret == 0) {
do_extract(variant_buf, len);
}
}
int main(int argc, char *argv[]) {
static const struct option long_options[] = {
{"help", no_argument, 0, 0},
{"report", no_argument, 0, 0},
// {"pid", required_argument, 0, 0},
{0, 0, 0, 0}};
static const struct option long_options[] = {{"help", no_argument, 0, 0},
{"report", no_argument, 0, 0},
{"pid", required_argument, 0, 0},
{0, 0, 0, 0}};
int c;
if (argc <= 1) {
// do something default
do_dump(optarg ? optarg : "");
return 0;
}
@@ -106,16 +109,18 @@ int main(int argc, char *argv[]) {
break;
}
option_index = 1;
switch (option_index) {
case 0: // help
// usage_pupil();
break;
case 1: // report
do_dump(optarg ? optarg : "");
break;
default:
// usage_pupil();
break;
case 0: // help
// usage_pupil();
break;
case 1: // report
do_dump(optarg ? optarg : "");
break;
default:
// usage_pupil();
break;
}
}

View File

@@ -61,13 +61,13 @@ typedef struct {
unsigned long stack[BACKTRACE_DEPTH];
} kern_stack_detail;
typedef struct {
struct pt_regs regs;
unsigned long ip;
unsigned long bp;
unsigned long sp;
unsigned long stack[BACKTRACE_DEPTH];
} user_stack_detail;
// typedef struct {
// struct pt_regs regs;
// unsigned long ip;
// unsigned long bp;
// unsigned long sp;
// unsigned long stack[BACKTRACE_DEPTH];
// } user_stack_detail;
typedef struct {
struct pt_regs regs;
@@ -90,7 +90,7 @@ typedef struct {
unsigned long id;
unsigned long long tv;
task_detail task; // brief
user_stack_detail user_stack; // user stack
// user_stack_detail user_stack; // user stack
kern_stack_detail kern_stack; // kernel stack
proc_chains_detail proc_chains; // process chains argv
raw_stack_detail raw_stack;