summaryrefslogtreecommitdiff
path: root/source/module/monitor_timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/module/monitor_timer.h')
-rw-r--r--source/module/monitor_timer.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/source/module/monitor_timer.h b/source/module/monitor_timer.h
new file mode 100644
index 0000000..e5b4fa2
--- /dev/null
+++ b/source/module/monitor_timer.h
@@ -0,0 +1,73 @@
+#include <linux/hrtimer.h>
+// #include <linux/kprobes.h>
+// #include <linux/ktime.h>
+// #include <linux/list.h>
+// // #include <linux/slab.h> /* for kmalloc */
+// #include <linux/string.h>
+
+// #include <asm/uaccess.h>
+// #include <linux/cdev.h>
+// #include <linux/highmem.h>
+// #include <linux/sched.h>
+// #include <linux/sched/loadavg.h> /* for avenrun, LOAD_* */
+// #include <linux/sched/mm.h>
+// #include <linux/sched/signal.h>
+// #include <linux/stacktrace.h> /* for stack_trace_print */
+
+#define MAX_TIMER_NUM (128) // max timer number
+#define TIMER_MAX_WATCH_NUM (32) // A timer max watch number at once time
+#define MAX_NAME_LEN (15) // max name length
+
+typedef struct {
+ pid_t task_id; // current process id
+ char name[MAX_NAME_LEN + 1]; // name
+ void *ptr; // virtual address
+ int length_byte; // byte
+ long long threshold; // threshold value
+ unsigned char unsigned_flag; // unsigned flag (true: unsigned, false: signed)
+ unsigned char greater_flag; // reverse flag (true: >, false: <)
+ unsigned long time_ns; // timer interval (ns)
+} watch_arg;
+
+typedef struct {
+ pid_t task_id; // current process id
+ char name[MAX_NAME_LEN + 2]; // name, last char automatically add '\0'
+ void *kptr; // kernel address + offset
+ int length_byte; // byte
+ long long threshold; // threshold value
+ unsigned char unsigned_flag; // unsigned flag (true: unsigned, false: signed)
+ unsigned char greater_flag; // reverse flag (true: >, false: <)
+} kernel_watch_arg;
+
+typedef struct {
+ unsigned long long time_ns; // hrTimer time interval (ns)
+ struct hrtimer hr_timer; // hrTimer
+ ktime_t kt; // hrTimer time
+ unsigned sentinel; // sentinel
+ kernel_watch_arg
+ k_watch_args[TIMER_MAX_WATCH_NUM]; // all watched kernel_watch_arg
+} kernel_watch_timer;
+
+// Global variable
+kernel_watch_timer kernel_wtimer_list[MAX_TIMER_NUM] = {
+ 0}; // all kernel_watch_timer
+int kernel_wtimer_num = 0; // current kernel_watch_timer number
+
+EXPORT_SYMBOL(kernel_wtimer_list); // export kernel_watch_timer_list
+EXPORT_SYMBOL(kernel_wtimer_num); // export kernel_watch_timer_num
+
+unsigned char del_all_kwarg_by_pid(pid_t pid);
+
+#define TIMER_START(timer) \
+ (hrtimer_start(&timer->hr_timer, timer->kt, HRTIMER_MODE_REL))
+#define TIMER_CANCEL(timer) (hrtimer_cancel(&timer->hr_timer))
+
+// for timer
+kernel_watch_timer *get_timer(unsigned long long time_ns);
+unsigned char timer_add_watch(kernel_watch_timer *timer,
+ kernel_watch_arg k_watch_arg);
+unsigned char timer_del_watch_by_pid(kernel_watch_timer *timer, pid_t pid);
+
+enum hrtimer_restart check_variable_cb(struct hrtimer *timer); // callback
+void start_all_hrTimer(void);
+void cancel_all_hrTimer(void); \ No newline at end of file