This commit is contained in:
zy
2023-11-27 20:51:25 -05:00
parent e560158cbc
commit 40efa27bc9
6 changed files with 16 additions and 12 deletions

View File

@@ -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));

View File

@@ -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
int diag_test(int nid); // for test

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -6,6 +6,9 @@
#include <cstddef> // 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