Re: Efficient x86 and x86_64 NOP microbenchmarks

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mathieu Desnoyers
Date: Wednesday, August 13, 2008 - 1:01 pm

* Andi Kleen (andi@firstfloor.org) wrote:

I agree that the custom call scheme could let you know the mcount call
site addresses at link time, so you could replace the call instructions
with nops (at link time, so you actually don't know much about the
exact hardware the kernel will be running on, which makes it harder to
choose the best nop). To me, it seems that doing this at link time,
as you propose, is the best approach, as it won't impact the system
bootup time as much as the current ftrace scheme.

However, I disagree with you on one point : if you use nops which are
made of multiple instructions smaller than 5 bytes, enabling the tracer
(patching all the sites in a stop_machine()) still present the risk of
having a preempted thread with a return IP pointing directly in the
middle of what will become a 5-bytes call instruction. When the thread
will be scheduled again after the stop_machine, an illegal instruction
fault (or any random effect) will occur.

Therefore, building a table of mcount call sites in a ELF section,
declaring _single_ 5-bytes nop instruction in the instruction stream
that would fit for all target architectures in lieue of mcount call, so
it can be later patched-in with the 5-bytes call at runtime seems like a
good way to go.

Mathieu

P.S. : It would be good to have a look at the alternative.c lock prefix
vs preemption race I identified a few weeks ago. Actually, this
currently existing cpu hotplug bug is related to the preemption issue I
just explained here. ref. http://lkml.org/lkml/2008/7/30/265,
especially:

"As a general rule, never try to combine smaller instructions into a
bigger one, except in the case of adding a lock-prefix to an instruction :
this case insures that the non-lock prefixed instruction is still
valid after the change has been done. We could however run into a nasty
non-synchronized atomic instruction use in SMP mode if a thread happens
to be scheduled out right after the lock prefix. Hopefully the
alternative code uses the refrigerator... (hrm, it doesn't).

Actually, alternative.c lock-prefix modification is O.K. for spinlocks
because they execute with preemption off, but not for other atomic
operations which may execute with preemption on."



-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Thu Aug 7, 11:20 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Thu Aug 7, 11:47 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Thu Aug 7, 1:42 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Jeremy Fitzhardinge, (Thu Aug 7, 2:11 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Thu Aug 7, 2:29 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Roland McGrath, (Thu Aug 7, 3:26 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Thu Aug 7, 6:21 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Thu Aug 7, 6:24 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Thu Aug 7, 6:56 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Sam Ravnborg, (Thu Aug 7, 9:54 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Peter Zijlstra, (Fri Aug 8, 12:22 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 4:31 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Fri Aug 8, 10:22 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 10:36 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Fri Aug 8, 10:46 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 11:13 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Peter Zijlstra, (Fri Aug 8, 11:15 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Fri Aug 8, 11:21 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 11:41 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Linus Torvalds, (Fri Aug 8, 12:04 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Fri Aug 8, 12:05 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Jeremy Fitzhardinge, (Fri Aug 8, 12:08 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 4:38 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Andi Kleen, (Fri Aug 8, 5:23 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 5:30 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 5:36 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Jeremy Fitzhardinge, (Fri Aug 8, 5:47 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Linus Torvalds, (Fri Aug 8, 5:51 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 5:51 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Roland McGrath, (Fri Aug 8, 5:53 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Andi Kleen, (Fri Aug 8, 6:13 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Andi Kleen, (Fri Aug 8, 6:19 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 6:25 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 6:30 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Andi Kleen, (Fri Aug 8, 6:55 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 7:03 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Andi Kleen, (Fri Aug 8, 7:23 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Fri Aug 8, 9:12 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Abhishek Sagar, (Sat Aug 9, 2:48 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Sat Aug 9, 6:01 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Abhishek Sagar, (Sat Aug 9, 8:01 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Sat Aug 9, 8:37 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Abhishek Sagar, (Sat Aug 9, 10:14 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Rusty Russell, (Sun Aug 10, 7:41 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Mon Aug 11, 5:33 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Mon Aug 11, 11:21 am)
Re: [PATCH 0/5] ftrace: to kill a daemon, Steven Rostedt, (Mon Aug 11, 12:28 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Tue Aug 12, 11:31 pm)
Re: [PATCH 0/5] ftrace: to kill a daemon, Mathieu Desnoyers, (Wed Aug 13, 8:38 am)
Efficient x86 and x86_64 NOP microbenchmarks, Mathieu Desnoyers, (Wed Aug 13, 10:52 am)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Linus Torvalds, (Wed Aug 13, 11:27 am)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Andi Kleen, (Wed Aug 13, 11:41 am)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Avi Kivity, (Wed Aug 13, 11:45 am)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Andi Kleen, (Wed Aug 13, 11:51 am)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Avi Kivity, (Wed Aug 13, 11:56 am)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Mathieu Desnoyers, (Wed Aug 13, 12:16 pm)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Mathieu Desnoyers, (Wed Aug 13, 12:30 pm)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Andi Kleen, (Wed Aug 13, 12:37 pm)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Mathieu Desnoyers, (Wed Aug 13, 1:01 pm)
[RFC PATCH] x86 alternatives : fix LOCK_PREFIX race with p ..., Mathieu Desnoyers, (Wed Aug 13, 4:41 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Wed Aug 13, 6:13 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Wed Aug 13, 6:22 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Wed Aug 13, 6:49 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Wed Aug 13, 8:35 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 8:18 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 9:58 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 10:04 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 10:05 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 10:28 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 10:30 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 10:43 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 10:46 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 10:49 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 10:55 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 11:09 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 11:53 am)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 12:29 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 12:49 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Mathieu Desnoyers, (Thu Aug 14, 1:31 pm)
Re: [RFC PATCH] x86 alternatives : fix LOCK_PREFIX race wi ..., Jeremy Fitzhardinge, (Thu Aug 14, 2:46 pm)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Steven Rostedt, (Fri Aug 15, 2:34 pm)
Re: Efficient x86 and x86_64 NOP microbenchmarks, Andi Kleen, (Fri Aug 15, 2:51 pm)