kwarg: true_value

This commit is contained in:
zy
2023-12-06 03:17:10 -05:00
parent 590326282f
commit 1a45d3e409
3 changed files with 35 additions and 34 deletions

View File

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

View File

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

View File

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