Skip to content

Commit 7b68621

Browse files
committed
ftrace: Clean up the recursion code a bit
In trace_test_and_set_recursion(), current->trace_recursion is placed into a variable, and that variable should be used for the processing, as there's no reason to dereference current multiple times. On trace_clear_recursion(), current->trace_recursion is modified and there's no reason to copy it over to a variable. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 60602cb commit 7b68621

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

‎include/linux/trace_recursion.h‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ extern void ftrace_record_recursion(unsigned long ip, unsigned long parent_ip);
162162
static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsigned long pip,
163163
int start, int max)
164164
{
165-
unsigned int val = current->trace_recursion;
165+
unsigned int val = READ_ONCE(current->trace_recursion);
166166
int bit;
167167

168168
/* A previous recursion check was made */
@@ -176,18 +176,15 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
176176
* a switch between contexts. Allow for a single recursion.
177177
*/
178178
bit = TRACE_TRANSITION_BIT;
179-
if (trace_recursion_test(bit)) {
179+
if (val & (1 << bit)) {
180180
do_ftrace_record_recursion(ip, pip);
181181
return -1;
182182
}
183-
trace_recursion_set(bit);
184-
barrier();
185-
return bit + 1;
183+
} else {
184+
/* Normal check passed, clear the transition to allow it again */
185+
val &= ~(1 << TRACE_TRANSITION_BIT);
186186
}
187187

188-
/* Normal check passed, clear the transition to allow it again */
189-
trace_recursion_clear(TRACE_TRANSITION_BIT);
190-
191188
val |= 1 << bit;
192189
current->trace_recursion = val;
193190
barrier();
@@ -197,17 +194,12 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
197194

198195
static __always_inline void trace_clear_recursion(int bit)
199196
{
200-
unsigned int val = current->trace_recursion;
201-
202197
if (!bit)
203198
return;
204199

205-
bit--;
206-
bit = 1 << bit;
207-
val &= ~bit;
208-
209200
barrier();
210-
current->trace_recursion = val;
201+
bit--;
202+
trace_recursion_clear(bit);
211203
}
212204

213205
/**

0 commit comments

Comments
 (0)