From 40efa27bc9a912611234aba59708ba3e580f695b Mon Sep 17 00:00:00 2001 From: zy Date: Mon, 27 Nov 2023 20:51:25 -0500 Subject: [PATCH] ioctl --- source/module/monitor_kernel.c | 7 +++---- source/module/monitor_kernel.h | 5 ++++- source/module/monitor_kernel_lib.c | 8 +++----- source/module/monitor_timer.c | 2 +- source/ucli/ucli.cc | 3 ++- source/ucli/ucli.h | 3 +++ 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/source/module/monitor_kernel.c b/source/module/monitor_kernel.c index 23648ab..2d49e2b 100644 --- a/source/module/monitor_kernel.c +++ b/source/module/monitor_kernel.c @@ -10,7 +10,6 @@ #define DEVICE_NAME "variable_monitor" -//!todo check name // for character device static dev_t dev_num; static struct cdev *watch_cdev; @@ -57,9 +56,9 @@ static long device_ioctl(struct file *file, unsigned int ioctl_num, printk(KERN_INFO "variable_monitor fun: %s with ioctl_num %d\n", __FUNCTION__, ioctl_num); - //!todo check style + //! todo check style switch (ioctl_num) { - case 0: + case IOCTL_WATCH_VARIABLE: // copy watch_arg if (copy_from_user(&warg, (watch_arg *)ioctl_param, sizeof(warg))) { return -EACCES; @@ -72,7 +71,7 @@ static long device_ioctl(struct file *file, unsigned int ioctl_num, // start watch variable start_watch_variable(warg); break; - case 1: + case IOCTL_DUMP_LOG: printk(KERN_INFO "variable_monitor ioctl_num 1\n"); ret = copy_from_user(&dump_param, (ioctl_dump_param *)ioctl_param, sizeof(ioctl_dump_param)); diff --git a/source/module/monitor_kernel.h b/source/module/monitor_kernel.h index dce9913..a7b435a 100644 --- a/source/module/monitor_kernel.h +++ b/source/module/monitor_kernel.h @@ -3,6 +3,9 @@ #include "monitor_timer.h" #include "monitor_trace.h" +#define IOCTL_WATCH_VARIABLE 0 +#define IOCTL_DUMP_LOG 1 + extern mm_tree mm_tree_struct; extern struct diag_variant_buffer load_monitor_variant_buffer; // global buffer @@ -14,4 +17,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); // that is for test \ No newline at end of file +int diag_test(int nid); // 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 554bc4d..9bebcfb 100644 --- a/source/module/monitor_kernel_lib.c +++ b/source/module/monitor_kernel_lib.c @@ -129,7 +129,7 @@ void diag_task_info_work(struct work_struct *work) { if (k_watch_timer->threshold_num <= 0) // if no threshold reached return; - printk(KERN_INFO "diag_task_info_work\n"); + // printk(KERN_INFO "diag_task_info_work\n"); struct task_struct *g, *p; // g: task group; p: task unsigned long flags; @@ -149,7 +149,6 @@ void diag_task_info_work(struct work_struct *work) { kwarg = &k_watch_timer->k_watch_args[k_watch_timer->threshold_buffer[i]]; k_w_arg2threshold(kwarg, &vm_record.threshold_record[i]); } - // !todo 调整输出 printk(KERN_INFO "-------------------------------------\n"); printk(KERN_INFO "-----------variable monitor----------\n"); printk(KERN_INFO "超出阈值:%lld\n", vm_record.tv); @@ -192,7 +191,7 @@ void diag_task_info_work(struct work_struct *work) { } } while_each_thread(g, p); - printk("-------------------------------------\n"); + printk(KERN_INFO "-------------------------------------\n"); return; } /** @@ -229,7 +228,6 @@ void monitor_exit(void) { * * @param warg: uapi watch_arg * @return int 0 is success - * !todo: adjust printk */ int start_watch_variable(watch_arg warg) { void *kptr; @@ -413,7 +411,7 @@ int diag_test(int nid) { } } while_each_thread(g, p); - printk("-------------------------------------\n"); + printk(KERN_INFO "-------------------------------------\n"); return 0; } \ No newline at end of file diff --git a/source/module/monitor_timer.c b/source/module/monitor_timer.c index ac7d5e3..2eb768f 100644 --- a/source/module/monitor_timer.c +++ b/source/module/monitor_timer.c @@ -146,7 +146,7 @@ void start_all_hrTimer(void) { timer = &(kernel_wtimer_list[i]); TIMER_START(timer); } - printk("HrTimer start,module keep %d hrtimer for now\n", kernel_wtimer_num); + printk(KERN_INFO "HrTimer start,module keep %d hrtimer for now\n", kernel_wtimer_num); } /// @brief cancel hrTimer diff --git a/source/ucli/ucli.cc b/source/ucli/ucli.cc index e34812c..1f830d9 100644 --- a/source/ucli/ucli.cc +++ b/source/ucli/ucli.cc @@ -82,7 +82,8 @@ static void do_dump(const char *arg) { .user_buf = variant_buf, }; - ret = diag_call_ioctl(1, (long)&dump_param); // !todo arg -> #define + ret = diag_call_ioctl(IOCTL_DUMP_LOG, + (long)&dump_param); // !todo arg -> #define if (ret == 0) { do_extract(variant_buf, len); } diff --git a/source/ucli/ucli.h b/source/ucli/ucli.h index ac5b67c..64bece2 100644 --- a/source/ucli/ucli.h +++ b/source/ucli/ucli.h @@ -6,6 +6,9 @@ #include // size_t +#define IOCTL_WATCH_VARIABLE 0 +#define IOCTL_DUMP_LOG 1 + #define DEVICE "/dev/variable_monitor" #define CGROUP_NAME_LEN 32 // max length of cgroup name