summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/module/monitor_kernel.c1
-rw-r--r--source/module/monitor_kernel_lib.c4
-rw-r--r--source/module/monitor_mem.c4
-rw-r--r--source/module/monitor_mem.h2
-rw-r--r--source/module/monitor_timer.h4
-rw-r--r--source/uapi/monitor_user.c14
-rw-r--r--source/uapi/monitor_user.h16
-rw-r--r--source/uapi/monitor_user_sw.h165
8 files changed, 201 insertions, 9 deletions
diff --git a/source/module/monitor_kernel.c b/source/module/monitor_kernel.c
index fd26828..2e6e35c 100644
--- a/source/module/monitor_kernel.c
+++ b/source/module/monitor_kernel.c
@@ -67,6 +67,7 @@ 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
// start watch variable
start_watch_variable(warg);
break;
diff --git a/source/module/monitor_kernel_lib.c b/source/module/monitor_kernel_lib.c
index f7032f1..2d12ef6 100644
--- a/source/module/monitor_kernel_lib.c
+++ b/source/module/monitor_kernel_lib.c
@@ -29,7 +29,7 @@ static unsigned char w_arg2k_w_arg(void *kptr, watch_arg warg,
k_watch_arg->length_byte = warg.length_byte;
k_watch_arg->threshold = warg.threshold;
k_watch_arg->unsigned_flag = warg.unsigned_flag;
- k_watch_arg->greater_flag = warg.greater_flag;
+ k_watch_arg->above_threshold = warg.above_threshold;
return 0;
}
@@ -296,7 +296,7 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
// check all watched kernel_watch_arg
for (i = 0; i < k_watch_timer->sentinel; i++) {
kwarg = &k_watch_timer->k_watch_args[i];
- if (read_and_compare(kwarg->kptr, kwarg->length_byte, kwarg->greater_flag,
+ if (read_and_compare(kwarg->kptr, kwarg->length_byte, kwarg->above_threshold,
kwarg->unsigned_flag, kwarg->threshold)) {
k_watch_timer->threshold_buffer[j] = i;
j++;
diff --git a/source/module/monitor_mem.c b/source/module/monitor_mem.c
index 17375a0..e2dc096 100644
--- a/source/module/monitor_mem.c
+++ b/source/module/monitor_mem.c
@@ -161,7 +161,7 @@ static int func_indices[2][9] = {{0, 0, 1, 0, 2, 0, 0, 0, 3},
/// @brief read k_arg->kptr and compare with threshold
/// @param k_arg
/// @return result of compare
-unsigned char read_and_compare(void *ptr, int len, unsigned char greater_flag,
+unsigned char read_and_compare(void *ptr, int len, unsigned char above_threshold,
unsigned char is_unsigned, long long threshold) {
unsigned char result = 0;
@@ -177,7 +177,7 @@ unsigned char read_and_compare(void *ptr, int len, unsigned char greater_flag,
// %d \n", k_arg->name, *(int *)ptr,
// threshold, result);
- if (greater_flag)
+ if (above_threshold)
return result;
else
return !result;
diff --git a/source/module/monitor_mem.h b/source/module/monitor_mem.h
index 391c609..394d900 100644
--- a/source/module/monitor_mem.h
+++ b/source/module/monitor_mem.h
@@ -23,5 +23,5 @@ void *convert_user_space_ptr(pid_t pid, unsigned long kaddr);
void free_page_list(pid_t task_id);
void free_all_page_list(void);
-unsigned char read_and_compare(void *ptr, int len, unsigned char greater_flag,
+unsigned char read_and_compare(void *ptr, int len, unsigned char above_threshold,
unsigned char is_unsigned, long long threshold);
diff --git a/source/module/monitor_timer.h b/source/module/monitor_timer.h
index 3253ba9..3db413e 100644
--- a/source/module/monitor_timer.h
+++ b/source/module/monitor_timer.h
@@ -12,7 +12,7 @@ typedef struct {
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 char above_threshold; // reverse flag (true: >, false: <)
unsigned long time_ns; // timer interval (ns)
} watch_arg;
@@ -24,7 +24,7 @@ typedef struct {
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 char above_threshold; // reverse flag (true: >, false: <)
} kernel_watch_arg;
typedef struct {
diff --git a/source/uapi/monitor_user.c b/source/uapi/monitor_user.c
index 9305675..1a90008 100644
--- a/source/uapi/monitor_user.c
+++ b/source/uapi/monitor_user.c
@@ -42,3 +42,17 @@ int cancel_watch() {
file_desc = -1;
return 0;
}
+
+void init_watch_arg(watch_arg *wg, char *name, void *ptr,
+ int length_byte, long long threshold,
+ unsigned char unsigned_flag,
+ unsigned char above_threshold, unsigned long time_ns){
+ wg->task_id = getpid();
+ strncpy(wg->name, name, (MAX_NAME_LEN + 1));
+ wg->ptr = ptr;
+ wg->length_byte = length_byte;
+ wg->threshold = threshold;
+ wg->unsigned_flag = unsigned_flag;
+ wg->above_threshold = above_threshold;
+ wg->time_ns = time_ns;
+}
diff --git a/source/uapi/monitor_user.h b/source/uapi/monitor_user.h
index f4d9df1..257217f 100644
--- a/source/uapi/monitor_user.h
+++ b/source/uapi/monitor_user.h
@@ -1,7 +1,13 @@
+#ifndef UAPI_MONITOR_H
+#define UAPI_MONITOR_H
// monitor_interface.h
+#include "monitor_user_sw.h"
+#include <string.h>
#include <sys/types.h>
+#include <unistd.h>
#define MAX_NAME_LEN (15) // max name length
+
typedef struct {
pid_t task_id; // current process id
char name[MAX_NAME_LEN + 1]; // name
@@ -9,12 +15,18 @@ typedef struct {
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 char above_threshold; // reverse flag (true: >, false: <)
unsigned long time_ns; // timer interval (ns)
} watch_arg;
+void init_watch_arg(watch_arg *wg, char *name, void *ptr, int length_byte,
+ long long threshold, unsigned char unsigned_flag,
+ unsigned char above_threshold, unsigned long time_ns);
+
// start watch
int start_watch(watch_arg w_arg);
// cancel watch
-int cancel_watch(void); \ No newline at end of file
+int cancel_watch(void);
+
+#endif \ No newline at end of file
diff --git a/source/uapi/monitor_user_sw.h b/source/uapi/monitor_user_sw.h
new file mode 100644
index 0000000..15c19e5
--- /dev/null
+++ b/source/uapi/monitor_user_sw.h
@@ -0,0 +1,165 @@
+#ifndef UAPI_MONITOR_SW_H
+#define UAPI_MONITOR_SW_H
+
+#define SWATCH_CHAR(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(char); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 0; \
+ w_arg.above_threshold = 0; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_CHAR_LESS(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(char); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 0; \
+ w_arg.above_threshold = 1; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_UCHAR(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(unsigned char); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 1; \
+ w_arg.above_threshold = 0; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_UCHAR_LESS(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(unsigned char); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 1; \
+ w_arg.above_threshold = 1; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_INT(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg = {0}; \
+ init_watch_arg(&w_arg, name, ptr, sizeof(int), threshold, 0, 1, 0); \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_INT_LESS(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(int); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 0; \
+ w_arg.above_threshold = 1; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_UINT(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(unsigned int); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 1; \
+ w_arg.above_threshold = 0; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_UINT_LESS(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(unsigned int); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 1; \
+ w_arg.above_threshold = 1; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_LONG(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(long); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 0; \
+ w_arg.above_threshold = 0; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_LONG_LESS(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(long); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 0; \
+ w_arg.above_threshold = 1; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_ULONG(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(unsigned long); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 1; \
+ w_arg.above_threshold = 0; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#define SWATCH_ULONG_LESS(name, ptr, threshold) \
+ do { \
+ watch_arg w_arg; \
+ w_arg.task_id = getpid(); \
+ strncpy(w_arg.name, name, MAX_NAME_LEN); \
+ w_arg.ptr = ptr; \
+ w_arg.length_byte = sizeof(unsigned long); \
+ w_arg.threshold = threshold; \
+ w_arg.unsigned_flag = 1; \
+ w_arg.above_threshold = 1; \
+ w_arg.time_ns = 0; \
+ start_watch(w_arg); \
+ } while (0)
+
+#endif \ No newline at end of file