diff options
| author | zy <[email protected]> | 2023-12-05 00:48:37 -0500 |
|---|---|---|
| committer | zy <[email protected]> | 2023-12-05 00:48:37 -0500 |
| commit | 6accd46ac7f3163fc069fe3943035198702ec3a8 (patch) | |
| tree | 97b15a874409b8d641b680de16bcd974fdacd6db /source | |
| parent | 16beb60e94aef6ed5258f6821afb41492f067d0d (diff) | |
IOCTL_PID
Diffstat (limited to 'source')
| -rw-r--r-- | source/module/monitor_kernel.c | 6 | ||||
| -rw-r--r-- | source/module/monitor_kernel.h | 6 | ||||
| -rw-r--r-- | source/module/monitor_kernel_lib.c | 40 |
3 files changed, 28 insertions, 24 deletions
diff --git a/source/module/monitor_kernel.c b/source/module/monitor_kernel.c index bf0d872..53b056c 100644 --- a/source/module/monitor_kernel.c +++ b/source/module/monitor_kernel.c @@ -89,10 +89,10 @@ static long device_ioctl(struct file *file, unsigned int ioctl_num, } // printk(KERN_INFO "copy_to_user_variant_buffer \n"); break; - case 2: - printk(KERN_INFO "variable_monitor ioctl_num 2\n"); + case IOCTL_PID: + printk(KERN_INFO "variable_monitor PID\n"); ret = copy_from_user(&wpid, (ioctl_pid *)ioctl_param, sizeof(ioctl_pid)); - diag_test(wpid.pid); + diag_pid(wpid.pid); break; default: break; diff --git a/source/module/monitor_kernel.h b/source/module/monitor_kernel.h index d262ff6..f20665f 100644 --- a/source/module/monitor_kernel.h +++ b/source/module/monitor_kernel.h @@ -4,9 +4,13 @@ #include "monitor_timer.h" #include "monitor_trace.h" +#include <linux/ioctl.h> // for ioctl + // ioctl +#define IOCTL_MAGIC_NUMBER 'k' #define IOCTL_WATCH_VARIABLE 0 #define IOCTL_DUMP_LOG 1 +#define IOCTL_PID _IOWR(IOCTL_MAGIC_NUMBER, 2, int) // default value extern int def_interval_ns; @@ -24,4 +28,4 @@ void clear_watch(pid_t pid); // for release enum hrtimer_restart check_variable_cb(struct hrtimer *timer); // hrtimer callback -int diag_test(int nid); // for test
\ No newline at end of file +int diag_pid(int pid); // for test
\ No newline at end of file diff --git a/source/module/monitor_kernel_lib.c b/source/module/monitor_kernel_lib.c index f485a1d..c2d937b 100644 --- a/source/module/monitor_kernel_lib.c +++ b/source/module/monitor_kernel_lib.c @@ -366,37 +366,37 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) { return HRTIMER_RESTART; // restart timer } -int diag_test(int nid) { - struct task_struct *g, *p; // g: task group; p: task +int diag_pid(int pid) { + struct task_struct *tsk; + int ret; unsigned long flags; unsigned long event_id = get_cycles(); static variable_monitor_task tsk_info = {0}; static variable_monitor_record vm_record = {0}; - vm_record.tv = ktime_get_real(); + pid_t id = (pid_t)pid; + 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; + } rcu_read_unlock(); - do_each_thread(g, p) { - if (p->__state == TASK_RUNNING || __task_contributes_to_load(p) || - p->__state == TASK_IDLE) { - - get_task_struct(p); - - tsk_info.et_type = VARIABLE_MONITOR_TASK_TYPE; - tsk_info.id = event_id; - tsk_info.tv = vm_record.tv; - - diag_tsk(p, &tsk_info); + get_task_struct(tsk); // count +1 - put_task_struct(p); + tsk_info.et_type = VARIABLE_MONITOR_TASK_TYPE; + tsk_info.id = event_id; + tsk_info.tv = vm_record.tv; + diag_tsk(tsk, &tsk_info); + put_task_struct(tsk); // count -1 - push_tskinfo_2_buffer(&tsk_info, &flags); - } - } - while_each_thread(g, p); - printk(KERN_INFO "-------------------------------------\n"); + push_tskinfo_2_buffer(&tsk_info, &flags); // push to buffer return 0; }
\ No newline at end of file |
