Commit 0a01640
ftrace: Optimize the function tracer list loop
There is lots of places that perform:
op = rcu_dereference_raw(ftrace_control_list);
while (op != &ftrace_list_end) {
Add a helper macro to do this, and also optimize for a single
entity. That is, gcc will optimize a loop for either no iterations
or more than one iteration. But usually only a single callback
is registered to the function tracer, thus the optimized case
should be a single pass. to do this we now do:
op = rcu_dereference_raw(list);
do {
[...]
} while (likely(op = rcu_dereference_raw((op)->next)) &&
unlikely((op) != &ftrace_list_end));
An op is always registered (ftrace_list_end when no callbacks is
registered), thus when a single callback is registered, the link
list looks like:
top => callback => ftrace_list_end => NULL.
The likely(op = op->next) still must be performed due to the race
of removing the callback, where the first op assignment could
equal ftrace_list_end. In that case, the op->next would be NULL.
But this is unlikely (only happens in a race condition when
removing the callback).
But it is very likely that the next op would be ftrace_list_end,
unless more than one callback has been registered. This tells
gcc what the most common case is and makes the fast path with
the least amount of branches.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>1 parent 9640388 commit 0a01640
1 file changed
+26
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
114 | 134 | | |
115 | 135 | | |
116 | 136 | | |
| |||
132 | 152 | | |
133 | 153 | | |
134 | 154 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | 155 | | |
145 | 156 | | |
146 | 157 | | |
| |||
149 | 160 | | |
150 | 161 | | |
151 | 162 | | |
152 | | - | |
153 | | - | |
| 163 | + | |
154 | 164 | | |
155 | | - | |
156 | | - | |
| 165 | + | |
157 | 166 | | |
158 | 167 | | |
159 | 168 | | |
| |||
4104 | 4113 | | |
4105 | 4114 | | |
4106 | 4115 | | |
4107 | | - | |
4108 | | - | |
| 4116 | + | |
4109 | 4117 | | |
4110 | 4118 | | |
4111 | 4119 | | |
4112 | | - | |
4113 | | - | |
4114 | | - | |
| 4120 | + | |
4115 | 4121 | | |
4116 | 4122 | | |
4117 | 4123 | | |
| |||
4139 | 4145 | | |
4140 | 4146 | | |
4141 | 4147 | | |
4142 | | - | |
4143 | | - | |
| 4148 | + | |
4144 | 4149 | | |
4145 | 4150 | | |
4146 | | - | |
4147 | | - | |
| 4151 | + | |
4148 | 4152 | | |
4149 | 4153 | | |
4150 | 4154 | | |
| |||
0 commit comments