This commit is contained in:
zy
2023-11-23 00:29:21 -05:00
parent 1ba029a6b8
commit ac287cdb63
5 changed files with 85 additions and 5 deletions

View File

@@ -229,6 +229,7 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
k_w_arg2threshold(kwarg, &vm_record.threshold_record[i]);
}
rcu_read_lock();
diag_variant_buffer_spin_lock(&load_monitor_variant_buffer, flags);
diag_variant_buffer_reserve(&load_monitor_variant_buffer,
sizeof(variable_monitor_record));
@@ -237,6 +238,8 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
diag_variant_buffer_seal(&load_monitor_variant_buffer);
diag_variant_buffer_spin_unlock(&load_monitor_variant_buffer, flags);
rcu_read_unlock();
do_each_thread(g, p) {
if (p->__state == TASK_RUNNING || __task_contributes_to_load(p) ||
p->__state == TASK_IDLE || 1) {
@@ -262,8 +265,6 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
}
while_each_thread(g, p);
rcu_read_unlock();
// print_task_stack();
// restart timer after 5s
hrtimer_forward(timer, timer->base->get_time(), ktime_set(5, 0)); //! todo
@@ -273,4 +274,64 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
hrtimer_forward(timer, timer->base->get_time(), k_watch_timer->kt);
}
return HRTIMER_RESTART; // restart timer
}
static void test(struct task_struct *p, variable_monitor_task *tsk_info, unsigned long *flags){
unsigned int nr_bt;
printk(KERN_INFO "diag_tsk\n");
diag_task_brief(p, &tsk_info->task); // task brief
// printk("1\n");
diag_task_user_stack(p, &tsk_info->user_stack); // user stack
diag_task_raw_stack(p, &tsk_info->raw_stack); // raw 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
put_task_struct(p);
diag_variant_buffer_spin_lock(&load_monitor_variant_buffer, flags);
diag_variant_buffer_reserve(&load_monitor_variant_buffer,sizeof(variable_monitor_task));
diag_variant_buffer_write_nolock(&load_monitor_variant_buffer, &tsk_info,
sizeof(variable_monitor_task));
diag_variant_buffer_seal(&load_monitor_variant_buffer);
diag_variant_buffer_spin_unlock(&load_monitor_variant_buffer, flags);
}
static int diag_test(int nid){
struct task_struct *tsk;
struct task_struct *leader;
variable_monitor_task tsk_info;
// unsigned int nr_bt;
int ret;
unsigned long flags;
pid_t id = (pid_t)nid;
rcu_read_lock();
tsk = NULL;
if (orig_find_task_by_vpid)
tsk = orig_find_task_by_vpid(id);
if (!tsk) {
ret = -EINVAL;
rcu_read_unlock();
return ret;
}
leader = tsk->group_leader;
if (leader == NULL || leader->exit_state == EXIT_ZOMBIE){
ret = -EINVAL;
rcu_read_unlock();
return ret;
}
get_task_struct(tsk);
rcu_read_unlock();
// test(tsk, &tsk_info);
put_task_struct(tsk);
// test2(&tsk_info, &flags);
return 0;
}