Re: [PATCH 2/3-REVISED] x86: Implement prctl PR_GET_TSC andPR_SET_TSC

From: Arjan van de Ven
Date: Mon Apr 14 2008 - 00:03:52 EST


On Mon, 14 Apr 2008 00:24:18 +0200 (CEST)
Erik Bosman <ejbosman@xxxxxxxx> wrote:

>
> (I have made it non-configurable and it does not touch
> kernel/seccomp.c anymore. I only changed ifdef/endifs)
>
> This patch implements the PR_GET_TSC and PR_SET_TSC prctl()
> commands on the x86 platform (both 32 and 64 bit.) These
> commands control the ability to read the timestamp counter
> from userspace (the RDTSC instruction.)
>
> While the RDTSC instuction is a useful profiling tool,
> it is also the source of some non-determinism in ring-3.
> For deterministic replay applications it is useful to be
> able to trap and emulate (and record the outcome of) this
> instruction.
>
> This patch uses code earlier used to disable the timestamp
> counter for the SECCOMP framework. A side-effect of this
> patch is that the SECCOMP environment will now also disable
> the timestamp counter on x86_64 due to the addition of the
> TIF_NOTSC define on this platform.
>
> The code which enables/disables the RDTSC instruction during
> context switches is in the __switch_to_xtra function, which
> already handles other unusual conditions, so normal
> performance should not have to suffer from this change.
>
> Signed-off-by: Erik Bosman <ejbosman@xxxxxxxx>


I like this a whole lot more than the previous version; in fact
I like how it gets rid of various ifdefs. It's a bit unfortunate that
it duplicates for 32/64 bit but this code isn't unified yet, and at least
your 2 functions are identical, making it not hard to deal with in the unification.
(so .. not your fault you did all the right things)


Acked-by: Arjan van de Ven <arjan@xxxxxxxxxxxxxxx>



Btw one other reason I like this general approach is that we can now start to get
apps to ask for the tsc to be enabled when they use it, and then we can just say
"no" on systems without reliable tsc...
(obviously we can't do that right away but we should try to migrate to that approach)


--
If you want to reach me at my work email, use arjan@xxxxxxxxxxxxxxx
For development, discussion and tips for power savings,
visit http://www.lesswatts.org
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/