oprofile for 2.5.39
A message that is not in the archive (sent off-list or not yet received): [email protected]
John Levon <[email protected]> writes:
Can you explain what you need the context switch hook for ? I don't think it's a good idea to put a hook at such a critical place. 2.4 oprofile worked without such a hook, no ?
-Andi
Quoted 1 line · Andi Kleen
Can you explain what you need the context switch hook for ?
Hmm, I tried to explain this in comments in the patch ...
Quoted 1 line
I don't think it's a good idea to put a hook at such a critical place.
... but I obviously didn't do a very good job.
We need a context to look up the EIP against when we process each sample in buffer_sync.c. We could just log current at sample time along with EIP/event, but why would it be preferrable to just logging the same information once when it's needed ?
Basically it's a matter of :
task_struct * EIP/Event EIP/Event EIP/Event EIP/Event ....
versus
task_struct */EIP/Event task_struct */EIP/Event task_struct */EIP/Event task_struct */EIP/Event task_struct */EIP/Event ....
Where task_struct is the same as the previous entry for the vast majority of entries.
Quoted 1 line
2.4 oprofile worked without such a hook, no ?
Sure, but it was ugly as hell (and worked completely differently)
regards
john
Signature · 2 lines
"When your name is Winner, that's it. You don't need a nickname." - Loser Lane
Quoted 9 lines
Basically it's a matter of :
task_struct * EIP/Event EIP/Event EIP/Event EIP/Event ....
I think you can easily do that by keeping state per cpu in the NMI handler.
if (current == __get_cpu_var(oprofile_cpustate)) {
/* log current */
__get_cpu_var(oprofile_cpustate) = current;
} else {
/* do nothing */
}
/* log EIP */[or when you are an module use an cache line padded array indexed with smp_processor_id - per cpu data doesn't work from modules]
This is even more efficient because when the NMI rate is lower than the task switch frequency (which is not unlikely) then you'll avoid many useless task_struct loggings.
-Andi
Quoted 4 lines
I think you can easily do that by keeping state per cpu in the NMI handler.
if (current == __get_cpu_var(oprofile_cpustate)) {
^^
Should be != of course.
-Andi
Quoted 6 lines
/* log current */
__get_cpu_var(oprofile_cpustate) = current;
} else {
/* do nothing */
}
/* log EIP */Quoted 2 lines · Andi Kleen
I think you can easily do that by keeping state per cpu in the NMI handler.
You're quite right, it's simpler as well.
I had a distinct memory of not doing this because it wouldn't work originally, but I forget what the reasoning was.
Quoted 1 line
smp_processor_id- per cpu data doesn't work from modules]
yes, which was why I don't use it already.
[Are there any advantages to per_cpu stuff over hand-coding, other than readability ??]
thanks
john
Signature · 2 lines
"When your name is Winner, that's it. You don't need a nickname." - Loser Lane
Quoted 3 lines
[Are there any advantages to
per_cpustuff over hand-coding, other than readability ??]
As well as allocating the areas on separate cachelines and packing it all together so you dont waste 1 cacheline minus a small amount times NR_CPUS of memory, on NUMA boxes we will allocate the areas from local memory.
Oh yeah we can also do some tricks to make the address generation slightly quicker (eg we will probably dedicate r13 to be a pointer to the start of the per cpu area on ppc64).
Anton
Quoted 2 lines · Andi Kleen
smp_processor_id
Using smp_processor_id() is usually a bug.
Please default to using get_cpu()/put_cpu().
- It pins the caller onto that CPU if the kernel is preemptive.
- You may not sleep inside get_cpu/put_cpu.
- If you do something which might sleep inside get_cpu/put_cpu, you get might_sleep() warnings.
Probably, smp_processor_id() needs to be renamed to something which is hard to type.
Quoted 1 line · Andrew Morton
Using
smp_processor_id()is usually a bug.
Well, this is in-interrupt code.
Quoted 2 lines
- If you do something which might sleep inside get_cpu/put_cpu, you get
might_sleep()warnings.
Certainly handy (but I don't see it's useful in this particular code, really)
regards
john
Signature · 2 lines
"When your name is Winner, that's it. You don't need a nickname." - Loser Lane