/proc work
This commit is contained in:
@@ -6,6 +6,7 @@ variable_monitor-objs := module/monitor_kernel.o \
|
||||
module/monitor_mem.o \
|
||||
module/monitor_timer.o \
|
||||
module/monitor_trace.o \
|
||||
module/monitor_proc.o \
|
||||
buffer/trace_buffer.o \
|
||||
buffer/variant_buffer.o \
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ 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
|
||||
switch (ioctl_num) {
|
||||
case IOCTL_WATCH_VARIABLE:
|
||||
// copy watch_arg
|
||||
@@ -67,7 +66,8 @@ static long device_ioctl(struct file *file, unsigned int ioctl_num,
|
||||
"time_ns=%ld, threshold=%lld\n",
|
||||
warg.task_id, warg.name, warg.ptr, warg.length_byte, warg.time_ns,
|
||||
warg.threshold);
|
||||
warg.time_ns = warg.time_ns == 0 ? 10000 : warg.time_ns; // default 10us
|
||||
warg.time_ns =
|
||||
warg.time_ns == 0 ? def_interval_ns : warg.time_ns; // default 10us
|
||||
// start watch variable
|
||||
start_watch_variable(warg);
|
||||
break;
|
||||
@@ -143,6 +143,9 @@ int init_module(void) {
|
||||
printk(KERN_INFO "dev number: %d\n", dev_num);
|
||||
printk(KERN_INFO "path: /dev/%s %d\n", DEVICE_NAME, dev_num);
|
||||
|
||||
// proc
|
||||
monitor_proc_init();
|
||||
|
||||
// orig_X | buffer
|
||||
monitor_init();
|
||||
|
||||
@@ -154,6 +157,9 @@ void cleanup_module(void) {
|
||||
// clear all watch | free buffer
|
||||
monitor_exit();
|
||||
|
||||
// proc
|
||||
monitor_proc_exit();
|
||||
|
||||
// unmount
|
||||
device_destroy(watch_class, dev_num);
|
||||
class_destroy(watch_class);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "monitor_kallsyms.h"
|
||||
#include "monitor_mem.h"
|
||||
#include "monitor_proc.h"
|
||||
#include "monitor_timer.h"
|
||||
#include "monitor_trace.h"
|
||||
|
||||
@@ -7,15 +8,20 @@
|
||||
#define IOCTL_WATCH_VARIABLE 0
|
||||
#define IOCTL_DUMP_LOG 1
|
||||
|
||||
// default value
|
||||
extern int def_interval_ns;
|
||||
extern int dump_reset_sec;
|
||||
|
||||
extern mm_tree mm_tree_struct;
|
||||
extern struct diag_variant_buffer load_monitor_variant_buffer; // global buffer
|
||||
|
||||
int monitor_init(void); // monitor init
|
||||
int monitor_init(void); // monitor init
|
||||
void monitor_exit(void); // monitor exit
|
||||
|
||||
int start_watch_variable(watch_arg warg); // for open
|
||||
void clear_watch(pid_t pid); // for release
|
||||
void clear_watch(pid_t pid); // for release
|
||||
|
||||
enum hrtimer_restart check_variable_cb(struct hrtimer *timer); // hrtimer callback
|
||||
enum hrtimer_restart
|
||||
check_variable_cb(struct hrtimer *timer); // hrtimer callback
|
||||
|
||||
int diag_test(int nid); // for test
|
||||
int diag_test(int nid); // for test
|
||||
@@ -304,7 +304,8 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
|
||||
{
|
||||
k_watch_timer->threshold_num = j;
|
||||
// restart timer after 5s
|
||||
hrtimer_forward(timer, timer->base->get_time(), ktime_set(5, 0)); //! todo
|
||||
hrtimer_forward(timer, timer->base->get_time(),
|
||||
ktime_set(dump_reset_sec, 0)); //! todo
|
||||
// highpri_wq
|
||||
queue_work(system_highpri_wq, &k_watch_timer->wk);
|
||||
} else {
|
||||
|
||||
87
source/module/monitor_proc.c
Normal file
87
source/module/monitor_proc.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "monitor_proc.h"
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
char *proc_dir = "variable_monitor";
|
||||
int def_interval_ns = DEFAULT_INTERVAL_NS;
|
||||
int dump_reset_sec = DEFAULT_DUMP_RESET_SEC;
|
||||
|
||||
static ssize_t read_proc(struct file *file, char __user *buf, size_t count,
|
||||
loff_t *offset, int *var) {
|
||||
char temp_buf[32];
|
||||
size_t len = sprintf(temp_buf, "%d\n", *var);
|
||||
|
||||
return simple_read_from_buffer(buf, count, offset, temp_buf, len);
|
||||
}
|
||||
|
||||
static ssize_t write_proc(struct file *file, const char __user *buf,
|
||||
size_t count, loff_t *offset, int *var) {
|
||||
char temp_buf[32];
|
||||
if (count > sizeof(temp_buf) - 1)
|
||||
return -EINVAL;
|
||||
|
||||
if (copy_from_user(temp_buf, buf, count))
|
||||
return -EFAULT;
|
||||
|
||||
temp_buf[count] = '\0';
|
||||
sscanf(temp_buf, "%d", var);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t read_proc_def_interval_ns(struct file *file, char __user *buf,
|
||||
size_t count, loff_t *offset) {
|
||||
return read_proc(file, buf, count, offset, &def_interval_ns);
|
||||
}
|
||||
|
||||
static ssize_t read_proc_dump_reset_sec(struct file *file, char __user *buf,
|
||||
size_t count, loff_t *offset) {
|
||||
return read_proc(file, buf, count, offset, &dump_reset_sec);
|
||||
}
|
||||
|
||||
static ssize_t write_proc_def_interval_ns(struct file *file,
|
||||
const char __user *buf, size_t count,
|
||||
loff_t *offset) {
|
||||
return write_proc(file, buf, count, offset, &def_interval_ns);
|
||||
}
|
||||
|
||||
static ssize_t write_proc_dump_reset_sec(struct file *file,
|
||||
const char __user *buf, size_t count,
|
||||
loff_t *offset) {
|
||||
return write_proc(file, buf, count, offset, &dump_reset_sec);
|
||||
}
|
||||
|
||||
static const struct proc_ops proc_def_interval_ns_ops = {
|
||||
.proc_read = read_proc_def_interval_ns,
|
||||
.proc_write = write_proc_def_interval_ns,
|
||||
};
|
||||
|
||||
static const struct proc_ops proc_dump_reset_sec_ops = {
|
||||
.proc_read = read_proc_dump_reset_sec,
|
||||
.proc_write = write_proc_dump_reset_sec,
|
||||
};
|
||||
|
||||
int monitor_proc_init(void) {
|
||||
struct proc_dir_entry *dir;
|
||||
|
||||
dir = proc_mkdir(proc_dir, NULL);
|
||||
if (!dir) {
|
||||
pr_err("variable_monitor: failed to create /proc directory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
proc_create("def_interval_ns", 0666, dir, &proc_def_interval_ns_ops);
|
||||
proc_create("dump_reset_sec", 0666, dir, &proc_dump_reset_sec_ops);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int monitor_proc_exit(void) {
|
||||
remove_proc_entry("def_interval_ns", NULL);
|
||||
remove_proc_entry("dump_reset_sec", NULL);
|
||||
remove_proc_entry(proc_dir, NULL);
|
||||
return 0;
|
||||
}
|
||||
13
source/module/monitor_proc.h
Normal file
13
source/module/monitor_proc.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef MODULE_MONITOR_PROC_H
|
||||
#define MODULE_MONITOR_PROC_H
|
||||
|
||||
#define DEFAULT_INTERVAL_NS 10000 // 10us
|
||||
#define DEFAULT_DUMP_RESET_SEC 5 // 5s
|
||||
|
||||
extern int def_interval_ns;
|
||||
extern int dump_reset_sec;
|
||||
|
||||
int monitor_proc_init(void);
|
||||
int monitor_proc_exit(void);
|
||||
|
||||
#endif // MODULE_MONITOR_PROC_H
|
||||
@@ -20,7 +20,6 @@ struct elf_file {
|
||||
std::string filename;
|
||||
int type;
|
||||
|
||||
// TODO get builid from elf header or build hash for elf
|
||||
elf_file(const std::string &name) : filename(name), type(NATIVE_TYPE) {
|
||||
elf_read_error = 0;
|
||||
eh_frame_hdr_offset = 0;
|
||||
@@ -30,7 +29,6 @@ struct elf_file {
|
||||
|
||||
elf_file() :type(NATIVE_TYPE) {}
|
||||
|
||||
// TODO get builid from elf header or build hash for elf
|
||||
void reset(const std::string &name) {
|
||||
filename = name;
|
||||
elf_read_error = 0;
|
||||
|
||||
Reference in New Issue
Block a user