This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
block_hist_kprobes.c
153 lines (129 loc) · 3.55 KB
/
block_hist_kprobes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <linux/kprobes.h>
#include <linux/module.h>
#include <linux/file.h>
#include <linux/dcache.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <linux/cpu.h>
#include "../latency_tracker.h"
#include "block_hist.h"
#include "../wrapper/percpu-defs.h"
static
int entry_new_sync_write(struct kretprobe_instance *p, struct pt_regs *regs)
{
struct task_struct* task = current;
struct kprobe_key_t kprobe_key;
enum latency_tracker_event_in_ret ret;
if (!latency_tracker_get_tracking_on(tracker))
return 0;
kprobe_key.pid = task->pid;
kprobe_key.type = KEY_FS;
ret = latency_tracker_event_in(tracker, &kprobe_key, sizeof(kprobe_key),
0, NULL);
if (ret == LATENCY_TRACKER_FULL) {
skip_cnt++;
//printk("latency_tracker block: no more free events, consider "
// "increasing the max_events parameter\n");
} else if (ret) {
printk("latency_tracker block: error adding event\n");
}
return 0;
}
static
int exit_new_sync_write(struct kretprobe_instance *p, struct pt_regs *regs)
{
struct kprobe_key_t key;
struct latency_tracker_event *s;
if (!latency_tracker_get_tracking_on(tracker))
return 0;
key.pid = current->pid;
key.type = KEY_FS;
s = latency_tracker_get_event_by_key(tracker, &key, sizeof(key), NULL);
if (!s)
goto end;
update_hist(s, IO_FS_WRITE,
lttng_this_cpu_ptr(&live_hist));
update_hist(s, IO_FS_WRITE,
lttng_this_cpu_ptr(¤t_hist));
latency_tracker_unref_event(s);
end:
latency_tracker_event_out(tracker, NULL, &key, sizeof(key), 0, 0);
return 0;
}
static
struct kretprobe probe_new_sync_write = {
.entry_handler = entry_new_sync_write,
.handler = exit_new_sync_write,
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0))
.kp.symbol_name = "do_sync_write",
#else
.kp.symbol_name = "new_sync_write",
#endif
};
static
int entry_new_sync_read(struct kretprobe_instance *p, struct pt_regs *regs)
{
struct task_struct* task = current;
struct kprobe_key_t kprobe_key;
enum latency_tracker_event_in_ret ret;
if (!latency_tracker_get_tracking_on(tracker))
return 0;
kprobe_key.pid = task->pid;
kprobe_key.type = KEY_FS;
ret = latency_tracker_event_in(tracker, &kprobe_key, sizeof(kprobe_key),
0, NULL);
if (ret == LATENCY_TRACKER_FULL) {
skip_cnt++;
//printk("latency_tracker block: no more free events, consider "
// "increasing the max_events parameter\n");
} else if (ret) {
printk("latency_tracker block: error adding event\n");
}
return 0;
}
static
int exit_new_sync_read(struct kretprobe_instance *p, struct pt_regs *regs)
{
struct kprobe_key_t key;
struct latency_tracker_event *s;
if (!latency_tracker_get_tracking_on(tracker))
return 0;
key.pid = current->pid;
key.type = KEY_FS;
s = latency_tracker_get_event_by_key(tracker, &key, sizeof(key), NULL);
if (!s)
goto end;
update_hist(s, IO_FS_READ,
lttng_this_cpu_ptr(&live_hist));
update_hist(s, IO_FS_READ,
lttng_this_cpu_ptr(¤t_hist));
latency_tracker_unref_event(s);
end:
latency_tracker_event_out(tracker, NULL, &key, sizeof(key), 0, 0);
return 0;
}
static
struct kretprobe probe_new_sync_read = {
.entry_handler = entry_new_sync_read,
.handler = exit_new_sync_read,
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0))
.kp.symbol_name = "do_sync_read",
#else
.kp.symbol_name = "new_sync_read",
#endif
};
int setup_kprobes(void)
{
int ret;
ret = register_kretprobe(&probe_new_sync_write);
WARN_ON(ret);
ret = register_kretprobe(&probe_new_sync_read);
WARN_ON(ret);
return 0;
}
void remove_kprobes(void)
{
unregister_kretprobe(&probe_new_sync_write);
unregister_kretprobe(&probe_new_sync_read);
}