Skip to content

Commit 0cb91a2

Browse files
Andi KleenAndi Kleen
authored andcommitted
[PATCH] i386: Account spinlocks to the caller during profiling for !FP kernels
This ports the algorithm from x86-64 (with improvements) to i386. Previously this only worked for frame pointer enabled kernels. But spinlocks have a very simple stack frame that can be manually analyzed. Do this. Signed-off-by: Andi Kleen <ak@suse.de>
1 parent c16b63e commit 0cb91a2

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

arch/i386/kernel/time.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,33 @@ static int set_rtc_mmss(unsigned long nowtime)
130130

131131
int timer_ack;
132132

133-
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
134133
unsigned long profile_pc(struct pt_regs *regs)
135134
{
136135
unsigned long pc = instruction_pointer(regs);
137136

138-
if (!user_mode_vm(regs) && in_lock_functions(pc))
137+
#ifdef CONFIG_SMP
138+
if (!user_mode_vm(regs) && in_lock_functions(pc)) {
139+
#ifdef CONFIG_FRAME_POINTER
139140
return *(unsigned long *)(regs->ebp + 4);
140-
141+
#else
142+
unsigned long *sp;
143+
if ((regs->xcs & 3) == 0)
144+
sp = (unsigned long *)&regs->esp;
145+
else
146+
sp = (unsigned long *)regs->esp;
147+
/* Return address is either directly at stack pointer
148+
or above a saved eflags. Eflags has bits 22-31 zero,
149+
kernel addresses don't. */
150+
if (sp[0] >> 22)
151+
return sp[0];
152+
if (sp[1] >> 22)
153+
return sp[1];
154+
#endif
155+
}
156+
#endif
141157
return pc;
142158
}
143159
EXPORT_SYMBOL(profile_pc);
144-
#endif
145160

146161
/*
147162
* This is the same as the above, except we _also_ save the current

include/asm-i386/ptrace.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ static inline int user_mode_vm(struct pt_regs *regs)
8080
return ((regs->xcs & 3) | (regs->eflags & VM_MASK)) != 0;
8181
}
8282
#define instruction_pointer(regs) ((regs)->eip)
83-
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
8483
extern unsigned long profile_pc(struct pt_regs *regs);
85-
#else
86-
#define profile_pc(regs) instruction_pointer(regs)
87-
#endif
8884
#endif /* __KERNEL__ */
8985

9086
#endif

kernel/spinlock.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*
88
* This file contains the spinlock/rwlock implementations for the
99
* SMP and the DEBUG_SPINLOCK cases. (UP-nondebug inlines them)
10+
*
11+
* Note that some architectures have special knowledge about the
12+
* stack frames of these functions in their profile_pc. If you
13+
* change anything significant here that could change the stack
14+
* frame contact the architecture maintainers.
1015
*/
1116

1217
#include <linux/linkage.h>

0 commit comments

Comments
 (0)