summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorzy <[email protected]>2023-12-06 03:17:10 -0500
committerzy <[email protected]>2023-12-06 03:17:10 -0500
commit1a45d3e409edf39c496d20c91a089adf96cc6a50 (patch)
tree1187b468da42f9bfedab22d8f63d26592cfd9c16 /source
parent590326282f075adcb780d79e1156b65536cfac1c (diff)
kwarg: true_value
Diffstat (limited to 'source')
-rw-r--r--source/module/monitor_kernel_lib.c66
-rw-r--r--source/module/monitor_timer.h1
-rw-r--r--source/module/monitor_trace.h2
3 files changed, 35 insertions, 34 deletions
diff --git a/source/module/monitor_kernel_lib.c b/source/module/monitor_kernel_lib.c
index 3634a7b..bc261a7 100644
--- a/source/module/monitor_kernel_lib.c
+++ b/source/module/monitor_kernel_lib.c
@@ -30,37 +30,35 @@ static unsigned char w_arg2k_w_arg(void *kptr, watch_arg warg,
k_watch_arg->threshold = warg.threshold;
k_watch_arg->is_unsigned = warg.is_unsigned;
k_watch_arg->above_threshold = warg.above_threshold;
+ k_watch_arg->true_value = 0;
return 0;
}
-// static long long convert_to_longlong(void *ptr, int size, char isUnsigned) {
-// // ptr is null
-// if (!ptr) {
-// return 0;
-// }
-// switch (size) {
-// case 1: // 8-bit integer.
-// if (isUnsigned) {
-// return (long long)(*(uint8_t*)ptr);
-// } else {
-// return (long long)(*(int8_t*)ptr);
-// }
-// case 2: // 16-bit integer.
-// if (isUnsigned) {
-// return (long long)(*(uint16_t*)ptr);
-// } else {
-// return (long long)(*(int16_t*)ptr);
-// }
-// case 4: // 32-bit integer.
-// if (isUnsigned) {
-// return (long long)(*(uint32_t*)ptr);
-// } else {
-// return (long long)(*(int32_t*)ptr);
-// }
-// default:
-// return 0;
-// }
-// }
+static long long convert_to_longlong(void *ptr, int size, char isUnsigned) {
+ long long ret = 0;
+ // ptr is null
+ if (!ptr) {
+ return 0;
+ }
+ switch (size) {
+ case 1: // 8-bit integer.
+ ret = isUnsigned ? (*(unsigned char *)ptr) : (*(char *)ptr);
+ break;
+ case 2: // 16-bit integer.
+ ret = isUnsigned ? (*(unsigned short *)ptr) : (*(short *)ptr);
+ break;
+ case 4: // 32-bit integer.
+ ret = isUnsigned ? (*(unsigned int *)ptr) : (*(int *)ptr);
+ break;
+ case 8:
+ ret = isUnsigned ? (*(unsigned long long *)ptr) : (*(long long *)ptr);
+ break;
+ default:
+ ret = 0;
+ break;
+ }
+ return ret;
+}
/**
* @brief kernel_watch_arg to threshold
@@ -76,8 +74,7 @@ static void k_w_arg2threshold(kernel_watch_arg *k_watch_arg,
threshold->ptr = k_watch_arg->ptr;
threshold->threshold = k_watch_arg->threshold;
// read true value
- // threshold->true_value = convert_to_longlong(k_watch_arg->ptr,
- // k_watch_arg->length_byte, k_watch_arg->is_unsigned);
+ threshold->true_value = k_watch_arg->true_value;
}
static void init_mm_tree(mm_tree *mm_tree) {
@@ -186,13 +183,13 @@ void diag_task_info_work(struct work_struct *work) {
printk(KERN_INFO "threshold exceeded, Timestamp %lld:\n", vm_record.tv);
for (i = 0; i < vm_record.threshold_num; i++) {
- printk(KERN_INFO "\t: pid: %d, name: %s, ptr: %p, threshold:%lld\n",
+ printk(KERN_INFO "\t: pid: %d, name: %s, ptr: %p, threshold:%lld, true_value:%lld\n",
vm_record.threshold_record[i].task_id,
vm_record.threshold_record[i]
.name, // Assuming name is a null-terminated string
vm_record.threshold_record[i].ptr,
- vm_record.threshold_record[i].threshold);
- // vm_record.threshold_record[i].true_value);
+ vm_record.threshold_record[i].threshold,
+ vm_record.threshold_record[i].true_value);
}
rcu_read_lock();
@@ -349,6 +346,9 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
if (read_and_compare(kwarg->kptr, kwarg->length_byte,
kwarg->above_threshold, kwarg->is_unsigned,
kwarg->threshold)) {
+ // printk(KERN_INFO "threshold reached\n");
+ kwarg->true_value = convert_to_longlong(kwarg->kptr, kwarg->length_byte,
+ kwarg->is_unsigned);
k_watch_timer->threshold_buffer[j] = i;
j++;
}
diff --git a/source/module/monitor_timer.h b/source/module/monitor_timer.h
index 43c2e10..3fec723 100644
--- a/source/module/monitor_timer.h
+++ b/source/module/monitor_timer.h
@@ -23,6 +23,7 @@ typedef struct {
void *kptr; // kernel address + offset
int length_byte; // byte
long long threshold; // threshold value
+ long long true_value; // target true value | available after reach threshold
unsigned char is_unsigned; // unsigned flag (true: unsigned, false: signed)
unsigned char above_threshold; // reverse flag (true: >, false: <)
} kernel_watch_arg;
diff --git a/source/module/monitor_trace.h b/source/module/monitor_trace.h
index 1878077..98edf9c 100644
--- a/source/module/monitor_trace.h
+++ b/source/module/monitor_trace.h
@@ -28,7 +28,7 @@ typedef struct {
char name[MAX_NAME_LEN + 1]; // name
void *ptr; // virtual address
long long threshold; // threshold value
- // long long true_value; // target true value
+ long long true_value; // target true value
} threshold;
typedef struct {