@@ -9,9 +9,10 @@ Fprobe - Function entry/exit probe
9
9
Introduction
10
10
============
11
11
12
- Fprobe is a function entry/exit probe mechanism based on ftrace.
13
- Instead of using ftrace full feature, if you only want to attach callbacks
14
- on function entry and exit, similar to the kprobes and kretprobes, you can
12
+ Fprobe is a function entry/exit probe based on the function-graph tracing
13
+ feature in ftrace.
14
+ Instead of tracing all functions, if you want to attach callbacks on specific
15
+ function entry and exit, similar to the kprobes and kretprobes, you can
15
16
use fprobe. Compared with kprobes and kretprobes, fprobe gives faster
16
17
instrumentation for multiple functions with single handler. This document
17
18
describes how to use fprobe.
@@ -91,12 +92,14 @@ The prototype of the entry/exit callback function are as follows:
91
92
92
93
.. code-block :: c
93
94
94
- int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs , void *entry_data);
95
+ int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs , void *entry_data);
95
96
96
- void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs , void *entry_data);
97
+ void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs , void *entry_data);
97
98
98
- Note that the @entry_ip is saved at function entry and passed to exit handler.
99
- If the entry callback function returns !0, the corresponding exit callback will be cancelled.
99
+ Note that the @entry_ip is saved at function entry and passed to exit
100
+ handler.
101
+ If the entry callback function returns !0, the corresponding exit callback
102
+ will be cancelled.
100
103
101
104
@fp
102
105
This is the address of `fprobe ` data structure related to this handler.
@@ -112,19 +115,28 @@ If the entry callback function returns !0, the corresponding exit callback will
112
115
This is the return address that the traced function will return to,
113
116
somewhere in the caller. This can be used at both entry and exit.
114
117
115
- @regs
116
- This is the `pt_regs ` data structure at the entry and exit. Note that
117
- the instruction pointer of @regs may be different from the @entry_ip
118
- in the entry_handler. If you need traced instruction pointer, you need
119
- to use @entry_ip. On the other hand, in the exit_handler, the instruction
120
- pointer of @regs is set to the current return address.
118
+ @fregs
119
+ This is the `ftrace_regs ` data structure at the entry and exit. This
120
+ includes the function parameters, or the return values. So user can
121
+ access thos values via appropriate `ftrace_regs_* ` APIs.
121
122
122
123
@entry_data
123
124
This is a local storage to share the data between entry and exit handlers.
124
125
This storage is NULL by default. If the user specify `exit_handler ` field
125
126
and `entry_data_size ` field when registering the fprobe, the storage is
126
127
allocated and passed to both `entry_handler ` and `exit_handler `.
127
128
129
+ Entry data size and exit handlers on the same function
130
+ ======================================================
131
+
132
+ Since the entry data is passed via per-task stack and it has limited size,
133
+ the entry data size per probe is limited to `15 * sizeof(long) `. You also need
134
+ to take care that the different fprobes are probing on the same function, this
135
+ limit becomes smaller. The entry data size is aligned to `sizeof(long) ` and
136
+ each fprobe which has exit handler uses a `sizeof(long) ` space on the stack,
137
+ you should keep the number of fprobes on the same function as small as
138
+ possible.
139
+
128
140
Share the callbacks with kprobes
129
141
================================
130
142
@@ -165,8 +177,8 @@ This counter counts up when;
165
177
- fprobe fails to take ftrace_recursion lock. This usually means that a function
166
178
which is traced by other ftrace users is called from the entry_handler.
167
179
168
- - fprobe fails to setup the function exit because of the shortage of rethook
169
- (the shadow stack for hooking the function return.)
180
+ - fprobe fails to setup the function exit because of failing to allocate the
181
+ data buffer from the per-task shadow stack.
170
182
171
183
The `fprobe::nmissed ` field counts up in both cases. Therefore, the former
172
184
skips both of entry and exit callback and the latter skips the exit
0 commit comments