kretprobe_example.c (58e16d792a6a8c6b750f637a4649967fcac853dc) | kretprobe_example.c (d85eaa9411472a99de4b5732cb59c8bae629d5f1) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * kretprobe_example.c 4 * 5 * Here's a sample kernel module showing the use of return probes to 6 * report the return value and total time taken for probed function 7 * to run. 8 * --- 34 unchanged lines hidden (view full) --- 43 44 if (!current->mm) 45 return 1; /* Skip kernel threads */ 46 47 data = (struct my_data *)ri->data; 48 data->entry_stamp = ktime_get(); 49 return 0; 50} | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * kretprobe_example.c 4 * 5 * Here's a sample kernel module showing the use of return probes to 6 * report the return value and total time taken for probed function 7 * to run. 8 * --- 34 unchanged lines hidden (view full) --- 43 44 if (!current->mm) 45 return 1; /* Skip kernel threads */ 46 47 data = (struct my_data *)ri->data; 48 data->entry_stamp = ktime_get(); 49 return 0; 50} |
51NOKPROBE_SYMBOL(entry_handler); |
|
51 52/* 53 * Return-probe handler: Log the return value and duration. Duration may turn 54 * out to be zero consistently, depending upon the granularity of time 55 * accounting on the platform. 56 */ 57static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) 58{ 59 unsigned long retval = regs_return_value(regs); 60 struct my_data *data = (struct my_data *)ri->data; 61 s64 delta; 62 ktime_t now; 63 64 now = ktime_get(); 65 delta = ktime_to_ns(ktime_sub(now, data->entry_stamp)); 66 pr_info("%s returned %lu and took %lld ns to execute\n", 67 func_name, retval, (long long)delta); 68 return 0; 69} | 52 53/* 54 * Return-probe handler: Log the return value and duration. Duration may turn 55 * out to be zero consistently, depending upon the granularity of time 56 * accounting on the platform. 57 */ 58static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) 59{ 60 unsigned long retval = regs_return_value(regs); 61 struct my_data *data = (struct my_data *)ri->data; 62 s64 delta; 63 ktime_t now; 64 65 now = ktime_get(); 66 delta = ktime_to_ns(ktime_sub(now, data->entry_stamp)); 67 pr_info("%s returned %lu and took %lld ns to execute\n", 68 func_name, retval, (long long)delta); 69 return 0; 70} |
71NOKPROBE_SYMBOL(ret_handler); |
|
70 71static struct kretprobe my_kretprobe = { 72 .handler = ret_handler, 73 .entry_handler = entry_handler, 74 .data_size = sizeof(struct my_data), 75 /* Probe up to 20 instances concurrently. */ 76 .maxactive = 20, 77}; --- 29 unchanged lines hidden --- | 72 73static struct kretprobe my_kretprobe = { 74 .handler = ret_handler, 75 .entry_handler = entry_handler, 76 .data_size = sizeof(struct my_data), 77 /* Probe up to 20 instances concurrently. */ 78 .maxactive = 20, 79}; --- 29 unchanged lines hidden --- |