* [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
@ 2007-11-20 3:36 Kumar Gala
2007-11-20 17:54 ` Scott Wood
0 siblings, 1 reply; 24+ messages in thread
From: Kumar Gala @ 2007-11-20 3:36 UTC (permalink / raw)
To: linuxppc-dev
isel (Integer Select) is a new user space instruction in the
PowerISA 2.04 spec. Not all processors implement it so lets emulate
to ensure code built with isel will run everywhere.
---
arch/powerpc/kernel/traps.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
In my git tree for 2.6.25.
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 59c464e..cad6484 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -622,6 +622,9 @@ static void parse_fpe(struct pt_regs *regs)
#define INST_POPCNTB 0x7c0000f4
#define INST_POPCNTB_MASK 0xfc0007fe
+#define INST_ISEL 0x7c00001e
+#define INST_ISEL_MASK 0xfc00003e
+
static int emulate_string_inst(struct pt_regs *regs, u32 instword)
{
u8 rT = (instword >> 21) & 0x1f;
@@ -707,6 +710,23 @@ static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
return 0;
}
+static int emulate_isel(struct pt_regs *regs, u32 instword)
+{
+ u8 rT = (instword >> 21) & 0x1f;
+ u8 rA = (instword >> 16) & 0x1f;
+ u8 rB = (instword >> 11) & 0x1f;
+ u8 BC = (instword >> 6) & 0x1f;
+ u8 bit;
+ unsigned long tmp;
+
+ tmp = (rA == 0) ? 0 : regs->gpr[rA];
+ bit = (regs->ccr >> (31 - BC)) & 0x1;
+
+ regs->gpr[rT] = bit ? tmp : regs->gpr[rB];
+
+ return 0;
+}
+
static int emulate_instruction(struct pt_regs *regs)
{
u32 instword;
@@ -749,6 +769,11 @@ static int emulate_instruction(struct pt_regs *regs)
return emulate_popcntb_inst(regs, instword);
}
+ /* Emulate isel (Integer Select) instruction */
+ if ((instword & INST_ISEL_MASK) == INST_ISEL) {
+ return emulate_isel(regs, instword);
+ }
+
return -EINVAL;
}
--
1.5.3.4
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-20 3:36 [PATCH] [POWERPC] Emulate isel (Integer Select) instruction Kumar Gala
@ 2007-11-20 17:54 ` Scott Wood
2007-11-20 21:01 ` Kumar Gala
0 siblings, 1 reply; 24+ messages in thread
From: Scott Wood @ 2007-11-20 17:54 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
> isel (Integer Select) is a new user space instruction in the
> PowerISA 2.04 spec. Not all processors implement it so lets emulate
> to ensure code built with isel will run everywhere.
Given that the instruction is meant to be a performance enhancement,
we should probably warn the first few times it's emulated, so the user
knows they should change their toolchain setup if possible.
-Scott
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-20 17:54 ` Scott Wood
@ 2007-11-20 21:01 ` Kumar Gala
2007-11-21 9:12 ` Benjamin Herrenschmidt
2007-11-21 13:09 ` Geert Uytterhoeven
0 siblings, 2 replies; 24+ messages in thread
From: Kumar Gala @ 2007-11-20 21:01 UTC (permalink / raw)
To: Scott Wood; +Cc: linuxppc-dev
On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
> On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
>> isel (Integer Select) is a new user space instruction in the
>> PowerISA 2.04 spec. Not all processors implement it so lets emulate
>> to ensure code built with isel will run everywhere.
>
> Given that the instruction is meant to be a performance enhancement,
> we should probably warn the first few times it's emulated, so the user
> knows they should change their toolchain setup if possible.
The same is true of mcrxr, popcntb, and possibly string ld/st.
Feel free to submit a patch that warns about their usage.
- k
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-20 21:01 ` Kumar Gala
@ 2007-11-21 9:12 ` Benjamin Herrenschmidt
2007-11-21 14:19 ` Kumar Gala
2007-11-21 13:09 ` Geert Uytterhoeven
1 sibling, 1 reply; 24+ messages in thread
From: Benjamin Herrenschmidt @ 2007-11-21 9:12 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
On Tue, 2007-11-20 at 15:01 -0600, Kumar Gala wrote:
> > Given that the instruction is meant to be a performance enhancement,
> > we should probably warn the first few times it's emulated, so the
> user
> > knows they should change their toolchain setup if possible.
>
> The same is true of mcrxr, popcntb, and possibly string ld/st.
>
> Feel free to submit a patch that warns about their usage.
At least we should keep counters... best would be per-task counters
in /proc but that sounds harder :-)
I remember in the early days of powerpc, it wasn't uncommon to have apps
with issues because they used 601 only bits on 603/4 that had to be
emulated (such as old POWER opcodes). On MacOS, we used to have a
system-wide counter of the number of emulated instructions we could use
to detect these things.
Ben.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-20 21:01 ` Kumar Gala
2007-11-21 9:12 ` Benjamin Herrenschmidt
@ 2007-11-21 13:09 ` Geert Uytterhoeven
2007-11-21 14:22 ` Kumar Gala
` (4 more replies)
1 sibling, 5 replies; 24+ messages in thread
From: Geert Uytterhoeven @ 2007-11-21 13:09 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
[-- Attachment #1: Type: TEXT/PLAIN, Size: 3610 bytes --]
On Tue, 20 Nov 2007, Kumar Gala wrote:
> On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
> > On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
> >> isel (Integer Select) is a new user space instruction in the
> >> PowerISA 2.04 spec. Not all processors implement it so lets emulate
> >> to ensure code built with isel will run everywhere.
> >
> > Given that the instruction is meant to be a performance enhancement,
> > we should probably warn the first few times it's emulated, so the user
> > knows they should change their toolchain setup if possible.
>
> The same is true of mcrxr, popcntb, and possibly string ld/st.
>
> Feel free to submit a patch that warns about their usage.
Something like this?
Probably we also want it for:
- arch/powerpc/kernel/align.c
o emulate_dcbz()
o emulate_multiple()
o emulate_fp_pair()
o emulate_spe()
- arch/powerpc/kernel/softemu8xx.c
o Soft_emulate_8xx()
- arch/powerpc/kernel/traps.c
o SoftwareEmulation()
- arch/powerpc/kernel/vecemu.c
o emulate_altivec()
Question: do we want it for emulate_single_step(), too?
So far my Debian userland didn't trigger any of them on the PS3, I had to
write an explicit test ;-)
---
arch/powerpc/kernel/traps.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -707,6 +707,14 @@ static int emulate_popcntb_inst(struct p
return 0;
}
+#define WARN_EMULATE(type) \
+ do { \
+ static unsigned int count; \
+ if (count++ < 10) \
+ pr_warning("%s used emulated %s instruction\n", \
+ current->comm, type); \
+ } while (0)
+
static int emulate_instruction(struct pt_regs *regs)
{
u32 instword;
@@ -721,31 +729,38 @@ static int emulate_instruction(struct pt
/* Emulate the mfspr rD, PVR. */
if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
+ WARN_EMULATE("mfpvr");
rd = (instword >> 21) & 0x1f;
regs->gpr[rd] = mfspr(SPRN_PVR);
return 0;
}
/* Emulating the dcba insn is just a no-op. */
- if ((instword & INST_DCBA_MASK) == INST_DCBA)
+ if ((instword & INST_DCBA_MASK) == INST_DCBA) {
+ WARN_EMULATE("dcba");
return 0;
+ }
/* Emulate the mcrxr insn. */
if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
int shift = (instword >> 21) & 0x1c;
unsigned long msk = 0xf0000000UL >> shift;
+ WARN_EMULATE("mcrxr");
regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
regs->xer &= ~0xf0000000UL;
return 0;
}
/* Emulate load/store string insn. */
- if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
+ if ((instword & INST_STRING_GEN_MASK) == INST_STRING) {
+ WARN_EMULATE("string");
return emulate_string_inst(regs, instword);
+ }
/* Emulate the popcntb (Population Count Bytes) instruction. */
if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) {
+ WARN_EMULATE("popcntb");
return emulate_popcntb_inst(regs, instword);
}
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 9:12 ` Benjamin Herrenschmidt
@ 2007-11-21 14:19 ` Kumar Gala
0 siblings, 0 replies; 24+ messages in thread
From: Kumar Gala @ 2007-11-21 14:19 UTC (permalink / raw)
To: benh; +Cc: linuxppc-dev
On Nov 21, 2007, at 3:12 AM, Benjamin Herrenschmidt wrote:
>
> On Tue, 2007-11-20 at 15:01 -0600, Kumar Gala wrote:
>>> Given that the instruction is meant to be a performance enhancement,
>>> we should probably warn the first few times it's emulated, so the
>> user
>>> knows they should change their toolchain setup if possible.
>>
>> The same is true of mcrxr, popcntb, and possibly string ld/st.
>>
>> Feel free to submit a patch that warns about their usage.
>
> At least we should keep counters... best would be per-task counters
> in /proc but that sounds harder :-)
>
> I remember in the early days of powerpc, it wasn't uncommon to have
> apps
> with issues because they used 601 only bits on 603/4 that had to be
> emulated (such as old POWER opcodes). On MacOS, we used to have a
> system-wide counter of the number of emulated instructions we could
> use
> to detect these things.
I think having some form of per insn group counters would be useful as
well. I know it would be helpful to debug user problems if they are
doing a lot of FP emu or the like and don't know it.
- k
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 13:09 ` Geert Uytterhoeven
@ 2007-11-21 14:22 ` Kumar Gala
2007-11-21 14:33 ` Geert Uytterhoeven
2007-11-21 16:50 ` Geert Uytterhoeven
2007-11-21 21:31 ` Paul Mackerras
` (3 subsequent siblings)
4 siblings, 2 replies; 24+ messages in thread
From: Kumar Gala @ 2007-11-21 14:22 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
On Nov 21, 2007, at 7:09 AM, Geert Uytterhoeven wrote:
> On Tue, 20 Nov 2007, Kumar Gala wrote:
>> On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
>>> On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
>>>> isel (Integer Select) is a new user space instruction in the
>>>> PowerISA 2.04 spec. Not all processors implement it so lets
>>>> emulate
>>>> to ensure code built with isel will run everywhere.
>>>
>>> Given that the instruction is meant to be a performance enhancement,
>>> we should probably warn the first few times it's emulated, so the
>>> user
>>> knows they should change their toolchain setup if possible.
>>
>> The same is true of mcrxr, popcntb, and possibly string ld/st.
>>
>> Feel free to submit a patch that warns about their usage.
>
> Something like this?
>
> Probably we also want it for:
>
> - arch/powerpc/kernel/align.c
> o emulate_dcbz()
> o emulate_multiple()
> o emulate_fp_pair()
> o emulate_spe()
>
> - arch/powerpc/kernel/softemu8xx.c
> o Soft_emulate_8xx()
>
> - arch/powerpc/kernel/traps.c
> o SoftwareEmulation()
You missed math_emu.
> - arch/powerpc/kernel/vecemu.c
> o emulate_altivec()
I'm not sure I would concern this one emulation, there isn't much you
can do about the denorm fixup.
How about some per processor counters in sysfs under the processor.
> Question: do we want it for emulate_single_step(), too?
What do you mean, we should could the emulation, the emulate single
step just is for handling if you are doing debug while hitting an
emulated insn.
> So far my Debian userland didn't trigger any of them on the PS3, I
> had to
> write an explicit test ;-)
> ---
> arch/powerpc/kernel/traps.c | 19 +++++++++++++++++--
> 1 files changed, 17 insertions(+), 2 deletions(-)
>
> --- a/arch/powerpc/kernel/traps.c
> +++ b/arch/powerpc/kernel/traps.c
> @@ -707,6 +707,14 @@ static int emulate_popcntb_inst(struct p
> return 0;
> }
>
> +#define WARN_EMULATE(type) \
> + do { \
> + static unsigned int count; \
> + if (count++ < 10) \
> + pr_warning("%s used emulated %s instruction\n", \
> + current->comm, type); \
> + } while (0)
> +
> static int emulate_instruction(struct pt_regs *regs)
> {
> u32 instword;
> @@ -721,31 +729,38 @@ static int emulate_instruction(struct pt
>
> /* Emulate the mfspr rD, PVR. */
> if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
> + WARN_EMULATE("mfpvr");
> rd = (instword >> 21) & 0x1f;
> regs->gpr[rd] = mfspr(SPRN_PVR);
> return 0;
> }
>
> /* Emulating the dcba insn is just a no-op. */
> - if ((instword & INST_DCBA_MASK) == INST_DCBA)
> + if ((instword & INST_DCBA_MASK) == INST_DCBA) {
> + WARN_EMULATE("dcba");
> return 0;
> + }
>
> /* Emulate the mcrxr insn. */
> if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
> int shift = (instword >> 21) & 0x1c;
> unsigned long msk = 0xf0000000UL >> shift;
>
> + WARN_EMULATE("mcrxr");
> regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
> regs->xer &= ~0xf0000000UL;
> return 0;
> }
>
> /* Emulate load/store string insn. */
> - if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
> + if ((instword & INST_STRING_GEN_MASK) == INST_STRING) {
> + WARN_EMULATE("string");
> return emulate_string_inst(regs, instword);
> + }
>
> /* Emulate the popcntb (Population Count Bytes) instruction. */
> if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) {
> + WARN_EMULATE("popcntb");
> return emulate_popcntb_inst(regs, instword);
> }
>
This looks good as a start.
- k
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 14:22 ` Kumar Gala
@ 2007-11-21 14:33 ` Geert Uytterhoeven
2007-11-21 15:34 ` Kumar Gala
2007-11-21 16:50 ` Geert Uytterhoeven
1 sibling, 1 reply; 24+ messages in thread
From: Geert Uytterhoeven @ 2007-11-21 14:33 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2359 bytes --]
On Wed, 21 Nov 2007, Kumar Gala wrote:
> On Nov 21, 2007, at 7:09 AM, Geert Uytterhoeven wrote:
> > On Tue, 20 Nov 2007, Kumar Gala wrote:
> > > On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
> > > > On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
> > > > > isel (Integer Select) is a new user space instruction in the
> > > > > PowerISA 2.04 spec. Not all processors implement it so lets emulate
> > > > > to ensure code built with isel will run everywhere.
> > > >
> > > > Given that the instruction is meant to be a performance enhancement,
> > > > we should probably warn the first few times it's emulated, so the user
> > > > knows they should change their toolchain setup if possible.
> > >
> > > The same is true of mcrxr, popcntb, and possibly string ld/st.
> > >
> > > Feel free to submit a patch that warns about their usage.
> >
> > Something like this?
> >
> > Probably we also want it for:
> >
> > - arch/powerpc/kernel/align.c
> > o emulate_dcbz()
> > o emulate_multiple()
> > o emulate_fp_pair()
> > o emulate_spe()
> >
> > - arch/powerpc/kernel/softemu8xx.c
> > o Soft_emulate_8xx()
> >
> > - arch/powerpc/kernel/traps.c
> > o SoftwareEmulation()
>
> You missed math_emu.
>
> > - arch/powerpc/kernel/vecemu.c
> > o emulate_altivec()
>
> I'm not sure I would concern this one emulation, there isn't much you can do
> about the denorm fixup.
>
> How about some per processor counters in sysfs under the processor.
Good idea!
> > Question: do we want it for emulate_single_step(), too?
>
> What do you mean, we should could the emulation, the emulate single step just
> is for handling if you are doing debug while hitting an emulated insn.
I mean: should these be counted?
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 14:33 ` Geert Uytterhoeven
@ 2007-11-21 15:34 ` Kumar Gala
0 siblings, 0 replies; 24+ messages in thread
From: Kumar Gala @ 2007-11-21 15:34 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
On Nov 21, 2007, at 8:33 AM, Geert Uytterhoeven wrote:
> On Wed, 21 Nov 2007, Kumar Gala wrote:
>> On Nov 21, 2007, at 7:09 AM, Geert Uytterhoeven wrote:
>>> On Tue, 20 Nov 2007, Kumar Gala wrote:
>>>> On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
>>>>> On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
>>>>>> isel (Integer Select) is a new user space instruction in the
>>>>>> PowerISA 2.04 spec. Not all processors implement it so lets
>>>>>> emulate
>>>>>> to ensure code built with isel will run everywhere.
>>>>>
>>>>> Given that the instruction is meant to be a performance
>>>>> enhancement,
>>>>> we should probably warn the first few times it's emulated, so
>>>>> the user
>>>>> knows they should change their toolchain setup if possible.
>>>>
>>>> The same is true of mcrxr, popcntb, and possibly string ld/st.
>>>>
>>>> Feel free to submit a patch that warns about their usage.
>>>
>>> Something like this?
>>>
>>> Probably we also want it for:
>>>
>>> - arch/powerpc/kernel/align.c
>>> o emulate_dcbz()
>>> o emulate_multiple()
>>> o emulate_fp_pair()
>>> o emulate_spe()
>>>
>>> - arch/powerpc/kernel/softemu8xx.c
>>> o Soft_emulate_8xx()
>>>
>>> - arch/powerpc/kernel/traps.c
>>> o SoftwareEmulation()
>>
>> You missed math_emu.
>>
>>> - arch/powerpc/kernel/vecemu.c
>>> o emulate_altivec()
>>
>> I'm not sure I would concern this one emulation, there isn't much
>> you can do
>> about the denorm fixup.
>>
>> How about some per processor counters in sysfs under the processor.
>
> Good idea!
>
>>> Question: do we want it for emulate_single_step(), too?
>>
>> What do you mean, we should could the emulation, the emulate single
>> step just
>> is for handling if you are doing debug while hitting an emulated
>> insn.
>
> I mean: should these be counted?
the number of emulated single steps insn? not sure I follow. I think
we should count regardless if we go through emulate_single_step().
- k
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 14:22 ` Kumar Gala
2007-11-21 14:33 ` Geert Uytterhoeven
@ 2007-11-21 16:50 ` Geert Uytterhoeven
2007-11-21 19:22 ` Kumar Gala
1 sibling, 1 reply; 24+ messages in thread
From: Geert Uytterhoeven @ 2007-11-21 16:50 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1328 bytes --]
On Wed, 21 Nov 2007, Kumar Gala wrote:
> On Nov 21, 2007, at 7:09 AM, Geert Uytterhoeven wrote:
> > On Tue, 20 Nov 2007, Kumar Gala wrote:
> > > On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
> > > > Given that the instruction is meant to be a performance enhancement,
> > > > we should probably warn the first few times it's emulated, so the user
> > > > knows they should change their toolchain setup if possible.
> > >
> > > The same is true of mcrxr, popcntb, and possibly string ld/st.
> > >
> > > Feel free to submit a patch that warns about their usage.
>
> How about some per processor counters in sysfs under the processor.
Per processor? That means it has to be per_cpu, which sounds a bit like
overkill to me.
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 16:50 ` Geert Uytterhoeven
@ 2007-11-21 19:22 ` Kumar Gala
0 siblings, 0 replies; 24+ messages in thread
From: Kumar Gala @ 2007-11-21 19:22 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
On Nov 21, 2007, at 10:50 AM, Geert Uytterhoeven wrote:
> On Wed, 21 Nov 2007, Kumar Gala wrote:
>> On Nov 21, 2007, at 7:09 AM, Geert Uytterhoeven wrote:
>>> On Tue, 20 Nov 2007, Kumar Gala wrote:
>>>> On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
>>>>> Given that the instruction is meant to be a performance
>>>>> enhancement,
>>>>> we should probably warn the first few times it's emulated, so
>>>>> the user
>>>>> knows they should change their toolchain setup if possible.
>>>>
>>>> The same is true of mcrxr, popcntb, and possibly string ld/st.
>>>>
>>>> Feel free to submit a patch that warns about their usage.
>>
>> How about some per processor counters in sysfs under the processor.
>
> Per processor? That means it has to be per_cpu, which sounds a bit
> like
> overkill to me.
I can probably live with global, not sure that would work with sysfs.
- k
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 13:09 ` Geert Uytterhoeven
2007-11-21 14:22 ` Kumar Gala
@ 2007-11-21 21:31 ` Paul Mackerras
2007-11-21 21:36 ` Paul Mackerras
` (2 subsequent siblings)
4 siblings, 0 replies; 24+ messages in thread
From: Paul Mackerras @ 2007-11-21 21:31 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
Geert Uytterhoeven writes:
> @@ -721,31 +729,38 @@ static int emulate_instruction(struct pt
>
> /* Emulate the mfspr rD, PVR. */
> if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
> + WARN_EMULATE("mfpvr");
mfpvr is a bit different from the others in that it is actually a
privileged instruction, so I don't think it helps to warn about it.
Also, I think the warnings should be optional.
Paul.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 13:09 ` Geert Uytterhoeven
2007-11-21 14:22 ` Kumar Gala
2007-11-21 21:31 ` Paul Mackerras
@ 2007-11-21 21:36 ` Paul Mackerras
2007-11-21 21:41 ` Scott Wood
2007-11-21 21:38 ` Paul Mackerras
2007-11-27 14:56 ` Geert Uytterhoeven
4 siblings, 1 reply; 24+ messages in thread
From: Paul Mackerras @ 2007-11-21 21:36 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
Geert Uytterhoeven writes:
> +#define WARN_EMULATE(type) \
> + do { \
> + static unsigned int count; \
> + if (count++ < 10) \
> + pr_warning("%s used emulated %s instruction\n", \
> + current->comm, type); \
Thinking about this a bit more, if an instruction gets emulated 10
times then I don't care, since it's probably only cost me 10
microseconds or so. If it gets emulated a million times then I might
want to look at it. So in fact this approach doesn't give me the
information I need to know whether there is a real problem or not.
Paul.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 13:09 ` Geert Uytterhoeven
` (2 preceding siblings ...)
2007-11-21 21:36 ` Paul Mackerras
@ 2007-11-21 21:38 ` Paul Mackerras
2007-11-27 14:56 ` Geert Uytterhoeven
4 siblings, 0 replies; 24+ messages in thread
From: Paul Mackerras @ 2007-11-21 21:38 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
Geert Uytterhoeven writes:
> Question: do we want it for emulate_single_step(), too?
No, because that's not emulating an instruction.
Paul.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 21:36 ` Paul Mackerras
@ 2007-11-21 21:41 ` Scott Wood
2007-11-21 21:48 ` Kim Phillips
0 siblings, 1 reply; 24+ messages in thread
From: Scott Wood @ 2007-11-21 21:41 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Geert Uytterhoeven, linuxppc-dev
Paul Mackerras wrote:
> Geert Uytterhoeven writes:
>
>> +#define WARN_EMULATE(type) \
>> + do { \
>> + static unsigned int count; \
>> + if (count++ < 10) \
>> + pr_warning("%s used emulated %s instruction\n", \
>> + current->comm, type); \
>
> Thinking about this a bit more, if an instruction gets emulated 10
> times then I don't care, since it's probably only cost me 10
> microseconds or so. If it gets emulated a million times then I might
> want to look at it. So in fact this approach doesn't give me the
> information I need to know whether there is a real problem or not.
Maybe print the first time, then when it's happened 10 times, then 100,
then 1000, etc.
-Scott
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 21:41 ` Scott Wood
@ 2007-11-21 21:48 ` Kim Phillips
0 siblings, 0 replies; 24+ messages in thread
From: Kim Phillips @ 2007-11-21 21:48 UTC (permalink / raw)
To: Scott Wood; +Cc: Geert Uytterhoeven, linuxppc-dev, Paul Mackerras
On Wed, 21 Nov 2007 15:41:00 -0600
Scott Wood <scottwood@freescale.com> wrote:
> Paul Mackerras wrote:
> > Geert Uytterhoeven writes:
> >
> >> +#define WARN_EMULATE(type) \
> >> + do { \
> >> + static unsigned int count; \
> >> + if (count++ < 10) \
> >> + pr_warning("%s used emulated %s instruction\n", \
> >> + current->comm, type); \
> >
> > Thinking about this a bit more, if an instruction gets emulated 10
> > times then I don't care, since it's probably only cost me 10
> > microseconds or so. If it gets emulated a million times then I might
> > want to look at it. So in fact this approach doesn't give me the
> > information I need to know whether there is a real problem or not.
>
> Maybe print the first time, then when it's happened 10 times, then 100,
> then 1000, etc.
>
or just use printk_ratelimit().
Kim
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-21 13:09 ` Geert Uytterhoeven
` (3 preceding siblings ...)
2007-11-21 21:38 ` Paul Mackerras
@ 2007-11-27 14:56 ` Geert Uytterhoeven
2007-11-27 15:23 ` Olof Johansson
4 siblings, 1 reply; 24+ messages in thread
From: Geert Uytterhoeven @ 2007-11-27 14:56 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
[-- Attachment #1: Type: TEXT/PLAIN, Size: 10848 bytes --]
On Wed, 21 Nov 2007, Geert Uytterhoeven wrote:
> On Tue, 20 Nov 2007, Kumar Gala wrote:
> > On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
> > > On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
> > >> isel (Integer Select) is a new user space instruction in the
> > >> PowerISA 2.04 spec. Not all processors implement it so lets emulate
> > >> to ensure code built with isel will run everywhere.
> > >
> > > Given that the instruction is meant to be a performance enhancement,
> > > we should probably warn the first few times it's emulated, so the user
> > > knows they should change their toolchain setup if possible.
> >
> > The same is true of mcrxr, popcntb, and possibly string ld/st.
> >
> > Feel free to submit a patch that warns about their usage.
>
> Something like this?
New version below.
Do we want it in sysfs? Or should we use debugfs instead?
Subject: powerpc: Keep track of emulated instructions
From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
powerpc: Keep track of emulated instructions
Counters for the various classes of emulated instructions are available under
/sys/devices/system/cpu/cpu*/emulated/.
Optionally, rate-limited warnings can be printed to the console when
instructions are emulated.
Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
---
arch/powerpc/Kconfig.debug | 10 ++++++
arch/powerpc/kernel/align.c | 17 ++++++++--
arch/powerpc/kernel/sysfs.c | 64 ++++++++++++++++++++++++++++++++++++++++-
arch/powerpc/kernel/traps.c | 17 +++++++++-
include/asm-powerpc/emulator.h | 60 ++++++++++++++++++++++++++++++++++++++
5 files changed, 161 insertions(+), 7 deletions(-)
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -284,4 +284,14 @@ config PPC_EARLY_DEBUG_CPM_ADDR
platform probing is done, all platforms selected must
share the same address.
+config DEBUG_WARN_EMULATED
+ bool "Warn if emulated instructions are used"
+ depends on DEBUG_KERNEL && SYSFS
+ help
+ This option will cause messages to be printed if an instruction is
+ emulated.
+ Counters for emulated instruction usages are always available under
+ /sys/devices/system/cpu/cpu*/emulated/, irrespective of the state
+ of this option.
+
endmenu
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -24,6 +24,7 @@
#include <asm/system.h>
#include <asm/cache.h>
#include <asm/cputable.h>
+#include <asm/emulator.h>
struct aligninfo {
unsigned char len;
@@ -696,8 +697,10 @@ int fix_alignment(struct pt_regs *regs)
areg = dsisr & 0x1f; /* register to update */
#ifdef CONFIG_SPE
- if ((instr >> 26) == 0x4)
+ if ((instr >> 26) == 0x4) {
+ WARN_EMULATE(spe);
return emulate_spe(regs, reg, instr);
+ }
#endif
instr = (dsisr >> 10) & 0x7f;
@@ -731,17 +734,21 @@ int fix_alignment(struct pt_regs *regs)
/* A size of 0 indicates an instruction we don't support, with
* the exception of DCBZ which is handled as a special case here
*/
- if (instr == DCBZ)
+ if (instr == DCBZ) {
+ WARN_EMULATE(dcbz);
return emulate_dcbz(regs, addr);
+ }
if (unlikely(nb == 0))
return 0;
/* Load/Store Multiple instructions are handled in their own
* function
*/
- if (flags & M)
+ if (flags & M) {
+ WARN_EMULATE(multiple);
return emulate_multiple(regs, addr, reg, nb,
flags, instr, swiz);
+ }
/* Verify the address of the operand */
if (unlikely(user_mode(regs) &&
@@ -758,8 +765,10 @@ int fix_alignment(struct pt_regs *regs)
}
/* Special case for 16-byte FP loads and stores */
- if (nb == 16)
+ if (nb == 16) {
+ WARN_EMULATE(fp_pair);
return emulate_fp_pair(regs, addr, reg, flags);
+ }
/* If we are loading, get the data from user space, else
* get it from register values
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -19,6 +19,7 @@
#include <asm/lppaca.h>
#include <asm/machdep.h>
#include <asm/smp.h>
+#include <asm/emulator.h>
static DEFINE_PER_CPU(struct cpu, cpu_devices);
@@ -291,12 +292,68 @@ static struct sysdev_attribute pa6t_attr
};
+#define SYSFS_EMULATED_SETUP(type) \
+DEFINE_PER_CPU(atomic_long_t, emulated_ ## type); \
+static ssize_t show_emulated_ ## type (struct sys_device *dev, \
+ char *buf) \
+{ \
+ struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
+ \
+ return sprintf(buf, "%lu\n", \
+ atomic_long_read(&per_cpu(emulated_ ## type, \
+ cpu->sysdev.id))); \
+} \
+ \
+static struct sysdev_attribute emulated_ ## type ## _attr = { \
+ .attr = { .name = #type, .mode = 0400 }, \
+ .show = show_emulated_ ## type, \
+};
+
+SYSFS_EMULATED_SETUP(dcba);
+SYSFS_EMULATED_SETUP(dcbz);
+SYSFS_EMULATED_SETUP(fp_pair);
+SYSFS_EMULATED_SETUP(mcrxr);
+SYSFS_EMULATED_SETUP(mfpvr);
+SYSFS_EMULATED_SETUP(multiple);
+SYSFS_EMULATED_SETUP(popcntb);
+SYSFS_EMULATED_SETUP(spe);
+SYSFS_EMULATED_SETUP(string);
+#ifdef CONFIG_MATH_EMULATION
+SYSFS_EMULATED_SETUP(math);
+#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
+SYSFS_EMULATED_SETUP(8xx);
+#endif
+
+static struct attribute *emulated_attrs[] = {
+ &emulated_dcba_attr.attr,
+ &emulated_dcbz_attr.attr,
+ &emulated_fp_pair_attr.attr,
+ &emulated_mcrxr_attr.attr,
+ &emulated_mfpvr_attr.attr,
+ &emulated_multiple_attr.attr,
+ &emulated_popcntb_attr.attr,
+ &emulated_spe_attr.attr,
+ &emulated_string_attr.attr,
+#ifdef CONFIG_MATH_EMULATION
+ &emulated_math_attr.attr,
+#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
+ &emulated_8xx_attr.attr,
+#endif
+ NULL
+};
+
+static struct attribute_group emulated_attr_group = {
+ .attrs = emulated_attrs,
+ .name = "emulated"
+};
+
+
static void register_cpu_online(unsigned int cpu)
{
struct cpu *c = &per_cpu(cpu_devices, cpu);
struct sys_device *s = &c->sysdev;
struct sysdev_attribute *attrs, *pmc_attrs;
- int i, nattrs;
+ int i, nattrs, res;
if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
cpu_has_feature(CPU_FTR_SMT))
@@ -339,6 +396,11 @@ static void register_cpu_online(unsigned
if (cpu_has_feature(CPU_FTR_DSCR))
sysdev_create_file(s, &attr_dscr);
+
+ res = sysfs_create_group(&s->kobj, &emulated_attr_group);
+ if (res)
+ pr_warning("Cannot create emulated sysfs group for cpu %u\n",
+ cpu);
}
#ifdef CONFIG_HOTPLUG_CPU
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -53,6 +53,7 @@
#include <asm/processor.h>
#endif
#include <asm/kexec.h>
+#include <asm/emulator.h>
#ifdef CONFIG_DEBUGGER
int (*__debugger)(struct pt_regs *regs);
@@ -721,31 +722,38 @@ static int emulate_instruction(struct pt
/* Emulate the mfspr rD, PVR. */
if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
+ WARN_EMULATE(mfpvr);
rd = (instword >> 21) & 0x1f;
regs->gpr[rd] = mfspr(SPRN_PVR);
return 0;
}
/* Emulating the dcba insn is just a no-op. */
- if ((instword & INST_DCBA_MASK) == INST_DCBA)
+ if ((instword & INST_DCBA_MASK) == INST_DCBA) {
+ WARN_EMULATE(dcba);
return 0;
+ }
/* Emulate the mcrxr insn. */
if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
int shift = (instword >> 21) & 0x1c;
unsigned long msk = 0xf0000000UL >> shift;
+ WARN_EMULATE(mcrxr);
regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
regs->xer &= ~0xf0000000UL;
return 0;
}
/* Emulate load/store string insn. */
- if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
+ if ((instword & INST_STRING_GEN_MASK) == INST_STRING) {
+ WARN_EMULATE(string);
return emulate_string_inst(regs, instword);
+ }
/* Emulate the popcntb (Population Count Bytes) instruction. */
if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) {
+ WARN_EMULATE(popcntb);
return emulate_popcntb_inst(regs, instword);
}
@@ -929,6 +937,8 @@ void SoftwareEmulation(struct pt_regs *r
#ifdef CONFIG_MATH_EMULATION
errcode = do_mathemu(regs);
+ if (errcode >= 0)
+ WARN_EMULATE(math);
switch (errcode) {
case 0:
@@ -950,6 +960,9 @@ void SoftwareEmulation(struct pt_regs *r
#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
errcode = Soft_emulate_8xx(regs);
+ if (errcode >= 0)
+ WARN_EMULATE(8xx);
+
switch (errcode) {
case 0:
emulate_single_step(regs);
--- /dev/null
+++ b/include/asm-powerpc/emulator.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2007 Sony Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _ASM_POWERPC_EMULATOR_H
+#define _ASM_POWERPC_EMULATOR_H
+
+#include <linux/kernel.h>
+#include <linux/percpu.h>
+
+#include <asm/atomic.h>
+
+DECLARE_PER_CPU(atomic_long_t, emulated_dcba);
+DECLARE_PER_CPU(atomic_long_t, emulated_dcbz);
+DECLARE_PER_CPU(atomic_long_t, emulated_fp_pair);
+DECLARE_PER_CPU(atomic_long_t, emulated_mcrxr);
+DECLARE_PER_CPU(atomic_long_t, emulated_mfpvr);
+DECLARE_PER_CPU(atomic_long_t, emulated_multiple);
+DECLARE_PER_CPU(atomic_long_t, emulated_popcntb);
+DECLARE_PER_CPU(atomic_long_t, emulated_spe);
+DECLARE_PER_CPU(atomic_long_t, emulated_string);
+#ifdef CONFIG_MATH_EMULATION
+DECLARE_PER_CPU(atomic_long_t, emulated_math);
+#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
+DECLARE_PER_CPU(atomic_long_t, emulated_8xx);
+#endif
+
+#ifdef CONFIG_DEBUG_WARN_EMULATED
+static inline void do_warn_emulate(const char *type)
+{
+ if (printk_ratelimit())
+ pr_warning("%s used emulated %s instruction\n", current->comm,
+ type);
+}
+#else
+static inline void do_warn_emulate(const char *type) {}
+#endif
+
+#define WARN_EMULATE(type) \
+ do { \
+ atomic_long_inc(&per_cpu(emulated_ ## type, \
+ raw_smp_processor_id())); \
+ do_warn_emulate(#type); \
+ } while (0)
+
+
+#endif /* _ASM_POWERPC_EMULATOR_H */
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-27 14:56 ` Geert Uytterhoeven
@ 2007-11-27 15:23 ` Olof Johansson
2007-11-28 10:49 ` Geert Uytterhoeven
0 siblings, 1 reply; 24+ messages in thread
From: Olof Johansson @ 2007-11-27 15:23 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
On Tue, Nov 27, 2007 at 03:56:53PM +0100, Geert Uytterhoeven wrote:
> On Wed, 21 Nov 2007, Geert Uytterhoeven wrote:
> > On Tue, 20 Nov 2007, Kumar Gala wrote:
> > > On Nov 20, 2007, at 11:54 AM, Scott Wood wrote:
> > > > On Mon, Nov 19, 2007 at 09:36:57PM -0600, Kumar Gala wrote:
> > > >> isel (Integer Select) is a new user space instruction in the
> > > >> PowerISA 2.04 spec. Not all processors implement it so lets emulate
> > > >> to ensure code built with isel will run everywhere.
> > > >
> > > > Given that the instruction is meant to be a performance enhancement,
> > > > we should probably warn the first few times it's emulated, so the user
> > > > knows they should change their toolchain setup if possible.
> > >
> > > The same is true of mcrxr, popcntb, and possibly string ld/st.
> > >
> > > Feel free to submit a patch that warns about their usage.
> >
> > Something like this?
>
> New version below.
>
> Do we want it in sysfs? Or should we use debugfs instead?
I like this, and I'd say it's useful to have in sysfs. Few production
systems enable debugfs, and this is something that could be useful to
have access to there.
> Subject: powerpc: Keep track of emulated instructions
>
> From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
>
> powerpc: Keep track of emulated instructions
>
> Counters for the various classes of emulated instructions are available under
> /sys/devices/system/cpu/cpu*/emulated/.
> Optionally, rate-limited warnings can be printed to the console when
> instructions are emulated.
>
> Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
> ---
> arch/powerpc/Kconfig.debug | 10 ++++++
> arch/powerpc/kernel/align.c | 17 ++++++++--
> arch/powerpc/kernel/sysfs.c | 64 ++++++++++++++++++++++++++++++++++++++++-
> arch/powerpc/kernel/traps.c | 17 +++++++++-
> include/asm-powerpc/emulator.h | 60 ++++++++++++++++++++++++++++++++++++++
This name stood out as being a bit too generic, emulator could mean
system support for running under some sort of emulator as well. How
about emulated_ops.h?
> +config DEBUG_WARN_EMULATED
> + bool "Warn if emulated instructions are used"
> + depends on DEBUG_KERNEL && SYSFS
> + help
> + This option will cause messages to be printed if an instruction is
> + emulated.
> + Counters for emulated instruction usages are always available under
> + /sys/devices/system/cpu/cpu*/emulated/, irrespective of the state
> + of this option.
How about making it a sysctl instead, so it can be flipped at runtime
(but default off)?
-Olof
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-27 15:23 ` Olof Johansson
@ 2007-11-28 10:49 ` Geert Uytterhoeven
2007-11-29 15:13 ` Geert Uytterhoeven
0 siblings, 1 reply; 24+ messages in thread
From: Geert Uytterhoeven @ 2007-11-28 10:49 UTC (permalink / raw)
To: Olof Johansson; +Cc: linuxppc-dev
[-- Attachment #1: Type: TEXT/PLAIN, Size: 11545 bytes --]
On Tue, 27 Nov 2007, Olof Johansson wrote:
> On Tue, Nov 27, 2007 at 03:56:53PM +0100, Geert Uytterhoeven wrote:
> > include/asm-powerpc/emulator.h | 60 ++++++++++++++++++++++++++++++++++++++
>
> This name stood out as being a bit too generic, emulator could mean
> system support for running under some sort of emulator as well. How
> about emulated_ops.h?
Changed.
> > +config DEBUG_WARN_EMULATED
> > + bool "Warn if emulated instructions are used"
> > + depends on DEBUG_KERNEL && SYSFS
> > + help
> > + This option will cause messages to be printed if an instruction is
> > + emulated.
> > + Counters for emulated instruction usages are always available under
> > + /sys/devices/system/cpu/cpu*/emulated/, irrespective of the state
> > + of this option.
>
> How about making it a sysctl instead, so it can be flipped at runtime
> (but default off)?
Converted to a sysctl.
Subject: powerpc: Keep track of emulated instructions
From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
powerpc: Keep track of emulated instructions
Counters for the various classes of emulated instructions are available under
/sys/devices/system/cpu/cpu*/emulated/.
Optionally (controlled by /proc/sys/kernel/cpu_emulation_warnings),
rate-limited warnings can be printed to the console when instructions are
emulated.
Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
---
arch/powerpc/kernel/align.c | 17 ++++--
arch/powerpc/kernel/sysfs.c | 100 ++++++++++++++++++++++++++++++++++++-
arch/powerpc/kernel/traps.c | 24 ++++++++
include/asm-powerpc/emulated_ops.h | 52 +++++++++++++++++++
4 files changed, 186 insertions(+), 7 deletions(-)
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -24,6 +24,7 @@
#include <asm/system.h>
#include <asm/cache.h>
#include <asm/cputable.h>
+#include <asm/emulated_ops.h>
struct aligninfo {
unsigned char len;
@@ -696,8 +697,10 @@ int fix_alignment(struct pt_regs *regs)
areg = dsisr & 0x1f; /* register to update */
#ifdef CONFIG_SPE
- if ((instr >> 26) == 0x4)
+ if ((instr >> 26) == 0x4) {
+ WARN_EMULATE(spe);
return emulate_spe(regs, reg, instr);
+ }
#endif
instr = (dsisr >> 10) & 0x7f;
@@ -731,17 +734,21 @@ int fix_alignment(struct pt_regs *regs)
/* A size of 0 indicates an instruction we don't support, with
* the exception of DCBZ which is handled as a special case here
*/
- if (instr == DCBZ)
+ if (instr == DCBZ) {
+ WARN_EMULATE(dcbz);
return emulate_dcbz(regs, addr);
+ }
if (unlikely(nb == 0))
return 0;
/* Load/Store Multiple instructions are handled in their own
* function
*/
- if (flags & M)
+ if (flags & M) {
+ WARN_EMULATE(multiple);
return emulate_multiple(regs, addr, reg, nb,
flags, instr, swiz);
+ }
/* Verify the address of the operand */
if (unlikely(user_mode(regs) &&
@@ -758,8 +765,10 @@ int fix_alignment(struct pt_regs *regs)
}
/* Special case for 16-byte FP loads and stores */
- if (nb == 16)
+ if (nb == 16) {
+ WARN_EMULATE(fp_pair);
return emulate_fp_pair(regs, addr, reg, flags);
+ }
/* If we are loading, get the data from user space, else
* get it from register values
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -8,6 +8,7 @@
#include <linux/nodemask.h>
#include <linux/cpumask.h>
#include <linux/notifier.h>
+#include <linux/sysctl.h>
#include <asm/current.h>
#include <asm/processor.h>
@@ -19,6 +20,7 @@
#include <asm/lppaca.h>
#include <asm/machdep.h>
#include <asm/smp.h>
+#include <asm/emulated_ops.h>
static DEFINE_PER_CPU(struct cpu, cpu_devices);
@@ -291,12 +293,101 @@ static struct sysdev_attribute pa6t_attr
};
+#define SYSFS_EMULATED_SETUP(type) \
+DEFINE_PER_CPU(atomic_long_t, emulated_ ## type); \
+static ssize_t show_emulated_ ## type (struct sys_device *dev, \
+ char *buf) \
+{ \
+ struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
+ \
+ return sprintf(buf, "%lu\n", \
+ atomic_long_read(&per_cpu(emulated_ ## type, \
+ cpu->sysdev.id))); \
+} \
+ \
+static struct sysdev_attribute emulated_ ## type ## _attr = { \
+ .attr = { .name = #type, .mode = 0400 }, \
+ .show = show_emulated_ ## type, \
+};
+
+SYSFS_EMULATED_SETUP(dcba);
+SYSFS_EMULATED_SETUP(dcbz);
+SYSFS_EMULATED_SETUP(fp_pair);
+SYSFS_EMULATED_SETUP(mcrxr);
+SYSFS_EMULATED_SETUP(mfpvr);
+SYSFS_EMULATED_SETUP(multiple);
+SYSFS_EMULATED_SETUP(popcntb);
+SYSFS_EMULATED_SETUP(spe);
+SYSFS_EMULATED_SETUP(string);
+#ifdef CONFIG_MATH_EMULATION
+SYSFS_EMULATED_SETUP(math);
+#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
+SYSFS_EMULATED_SETUP(8xx);
+#endif
+
+static struct attribute *emulated_attrs[] = {
+ &emulated_dcba_attr.attr,
+ &emulated_dcbz_attr.attr,
+ &emulated_fp_pair_attr.attr,
+ &emulated_mcrxr_attr.attr,
+ &emulated_mfpvr_attr.attr,
+ &emulated_multiple_attr.attr,
+ &emulated_popcntb_attr.attr,
+ &emulated_spe_attr.attr,
+ &emulated_string_attr.attr,
+#ifdef CONFIG_MATH_EMULATION
+ &emulated_math_attr.attr,
+#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
+ &emulated_8xx_attr.attr,
+#endif
+ NULL
+};
+
+static struct attribute_group emulated_attr_group = {
+ .attrs = emulated_attrs,
+ .name = "emulated"
+};
+
+int sysctl_warn_emulated;
+
+#ifdef CONFIG_SYSCTL
+static ctl_table warn_emulated_ctl_table[]={
+ {
+ .procname = "cpu_emulation_warnings",
+ .data = &sysctl_warn_emulated,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec,
+ },
+ {}
+};
+
+static ctl_table warn_emulated_sysctl_root[] = {
+ {
+ .ctl_name = CTL_KERN,
+ .procname = "kernel",
+ .mode = 0555,
+ .child = warn_emulated_ctl_table,
+ },
+ {}
+};
+
+static inline void warn_emulated_sysctl_register(void)
+{
+ int res = register_sysctl_table(warn_emulated_sysctl_root);
+ printk("@@@ register_sysctl_table() returned %d\n", res);
+}
+#else /* !CONFIG_SYSCTL */
+static inline void warn_emulated_sysctl_register(void) {}
+#endif /* !CONFIG_SYSCTL */
+
+
static void register_cpu_online(unsigned int cpu)
{
struct cpu *c = &per_cpu(cpu_devices, cpu);
struct sys_device *s = &c->sysdev;
struct sysdev_attribute *attrs, *pmc_attrs;
- int i, nattrs;
+ int i, nattrs, res;
if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
cpu_has_feature(CPU_FTR_SMT))
@@ -339,6 +430,11 @@ static void register_cpu_online(unsigned
if (cpu_has_feature(CPU_FTR_DSCR))
sysdev_create_file(s, &attr_dscr);
+
+ res = sysfs_create_group(&s->kobj, &emulated_attr_group);
+ if (res)
+ pr_warning("Cannot create emulated sysfs group for cpu %u\n",
+ cpu);
}
#ifdef CONFIG_HOTPLUG_CPU
@@ -560,6 +656,8 @@ static int __init topology_init(void)
register_cpu_online(cpu);
}
+ warn_emulated_sysctl_register();
+
return 0;
}
subsys_initcall(topology_init);
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -53,6 +53,7 @@
#include <asm/processor.h>
#endif
#include <asm/kexec.h>
+#include <asm/emulated_ops.h>
#ifdef CONFIG_DEBUGGER
int (*__debugger)(struct pt_regs *regs);
@@ -707,6 +708,13 @@ static int emulate_popcntb_inst(struct p
return 0;
}
+void do_warn_emulate(const char *type)
+{
+ if (printk_ratelimit())
+ pr_warning("%s used emulated %s instruction\n", current->comm,
+ type);
+}
+
static int emulate_instruction(struct pt_regs *regs)
{
u32 instword;
@@ -721,31 +729,38 @@ static int emulate_instruction(struct pt
/* Emulate the mfspr rD, PVR. */
if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
+ WARN_EMULATE(mfpvr);
rd = (instword >> 21) & 0x1f;
regs->gpr[rd] = mfspr(SPRN_PVR);
return 0;
}
/* Emulating the dcba insn is just a no-op. */
- if ((instword & INST_DCBA_MASK) == INST_DCBA)
+ if ((instword & INST_DCBA_MASK) == INST_DCBA) {
+ WARN_EMULATE(dcba);
return 0;
+ }
/* Emulate the mcrxr insn. */
if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
int shift = (instword >> 21) & 0x1c;
unsigned long msk = 0xf0000000UL >> shift;
+ WARN_EMULATE(mcrxr);
regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
regs->xer &= ~0xf0000000UL;
return 0;
}
/* Emulate load/store string insn. */
- if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
+ if ((instword & INST_STRING_GEN_MASK) == INST_STRING) {
+ WARN_EMULATE(string);
return emulate_string_inst(regs, instword);
+ }
/* Emulate the popcntb (Population Count Bytes) instruction. */
if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) {
+ WARN_EMULATE(popcntb);
return emulate_popcntb_inst(regs, instword);
}
@@ -929,6 +944,8 @@ void SoftwareEmulation(struct pt_regs *r
#ifdef CONFIG_MATH_EMULATION
errcode = do_mathemu(regs);
+ if (errcode >= 0)
+ WARN_EMULATE(math);
switch (errcode) {
case 0:
@@ -950,6 +967,9 @@ void SoftwareEmulation(struct pt_regs *r
#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
errcode = Soft_emulate_8xx(regs);
+ if (errcode >= 0)
+ WARN_EMULATE(8xx);
+
switch (errcode) {
case 0:
emulate_single_step(regs);
--- /dev/null
+++ b/include/asm-powerpc/emulated_ops.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2007 Sony Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _ASM_POWERPC_EMULATED_OPS_H
+#define _ASM_POWERPC_EMULATED_OPS_H
+
+#include <linux/percpu.h>
+
+#include <asm/atomic.h>
+
+DECLARE_PER_CPU(atomic_long_t, emulated_dcba);
+DECLARE_PER_CPU(atomic_long_t, emulated_dcbz);
+DECLARE_PER_CPU(atomic_long_t, emulated_fp_pair);
+DECLARE_PER_CPU(atomic_long_t, emulated_mcrxr);
+DECLARE_PER_CPU(atomic_long_t, emulated_mfpvr);
+DECLARE_PER_CPU(atomic_long_t, emulated_multiple);
+DECLARE_PER_CPU(atomic_long_t, emulated_popcntb);
+DECLARE_PER_CPU(atomic_long_t, emulated_spe);
+DECLARE_PER_CPU(atomic_long_t, emulated_string);
+#ifdef CONFIG_MATH_EMULATION
+DECLARE_PER_CPU(atomic_long_t, emulated_math);
+#elif defined(CONFIG_8XX_MINIMAL_FPEMU)
+DECLARE_PER_CPU(atomic_long_t, emulated_8xx);
+#endif
+
+extern int sysctl_warn_emulated;
+extern void do_warn_emulate(const char *type);
+
+#define WARN_EMULATE(type) \
+ do { \
+ atomic_long_inc(&per_cpu(emulated_ ## type, \
+ raw_smp_processor_id())); \
+ if (sysctl_warn_emulated) \
+ do_warn_emulate(#type); \
+ } while (0)
+
+
+#endif /* _ASM_POWERPC_EMULATED_OPS_H */
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-28 10:49 ` Geert Uytterhoeven
@ 2007-11-29 15:13 ` Geert Uytterhoeven
2007-12-14 8:12 ` Olof Johansson
0 siblings, 1 reply; 24+ messages in thread
From: Geert Uytterhoeven @ 2007-11-29 15:13 UTC (permalink / raw)
To: Olof Johansson; +Cc: linuxppc-dev
[-- Attachment #1: Type: TEXT/PLAIN, Size: 975 bytes --]
On Wed, 28 Nov 2007, Geert Uytterhoeven wrote:
> +static inline void warn_emulated_sysctl_register(void)
> +{
> + int res = register_sysctl_table(warn_emulated_sysctl_root);
^^^^^^^^^^
> + printk("@@@ register_sysctl_table() returned %d\n", res);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +}
Woops, that part shouldn't have been there...
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-12-14 8:12 ` Olof Johansson
@ 2007-12-14 8:08 ` Kumar Gala
2007-12-14 8:17 ` Olof Johansson
2007-12-14 8:16 ` Olof Johansson
1 sibling, 1 reply; 24+ messages in thread
From: Kumar Gala @ 2007-12-14 8:08 UTC (permalink / raw)
To: Olof Johansson; +Cc: Geert Uytterhoeven, linuxppc-dev
On Dec 14, 2007, at 2:12 AM, Olof Johansson wrote:
> On Thu, Nov 29, 2007 at 04:13:14PM +0100, Geert Uytterhoeven wrote:
>> On Wed, 28 Nov 2007, Geert Uytterhoeven wrote:
>>> +static inline void warn_emulated_sysctl_register(void)
>>> +{
>>> + int res = register_sysctl_table(warn_emulated_sysctl_root);
>> ^^^^^^^^^^
>>> + printk("@@@ register_sysctl_table() returned %d\n", res);
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>> +}
>>
>> Woops, that part shouldn't have been there...
>
> Care to resubmit a clean patch under a fresh subject? Paul didn't
> chime
> in but hopefully he can pick it up for 2.6.25.
I'd say wait for Paul to pickup my 2.6.25 request. Than the base will
have the isel emulation as well.
- k
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-11-29 15:13 ` Geert Uytterhoeven
@ 2007-12-14 8:12 ` Olof Johansson
2007-12-14 8:08 ` Kumar Gala
2007-12-14 8:16 ` Olof Johansson
0 siblings, 2 replies; 24+ messages in thread
From: Olof Johansson @ 2007-12-14 8:12 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
On Thu, Nov 29, 2007 at 04:13:14PM +0100, Geert Uytterhoeven wrote:
> On Wed, 28 Nov 2007, Geert Uytterhoeven wrote:
> > +static inline void warn_emulated_sysctl_register(void)
> > +{
> > + int res = register_sysctl_table(warn_emulated_sysctl_root);
> ^^^^^^^^^^
> > + printk("@@@ register_sysctl_table() returned %d\n", res);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > +}
>
> Woops, that part shouldn't have been there...
Care to resubmit a clean patch under a fresh subject? Paul didn't chime
in but hopefully he can pick it up for 2.6.25.
Thanks,
Olof
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-12-14 8:12 ` Olof Johansson
2007-12-14 8:08 ` Kumar Gala
@ 2007-12-14 8:16 ` Olof Johansson
1 sibling, 0 replies; 24+ messages in thread
From: Olof Johansson @ 2007-12-14 8:16 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linuxppc-dev
On Fri, Dec 14, 2007 at 02:12:10AM -0600, Olof Johansson wrote:
> Care to resubmit a clean patch under a fresh subject? Paul didn't chime
> in but hopefully he can pick it up for 2.6.25.
Next time I will take the time to re-read the whole thread. :)
Seems like the open question was how to warn only for excessive
amounts of emulated ops. Maybe a simple count/threshold per process
(+ printk_ratelimit)? Warning on every power of 10 occurrances was also
suggested, either works for me.
-Olof
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] [POWERPC] Emulate isel (Integer Select) instruction
2007-12-14 8:08 ` Kumar Gala
@ 2007-12-14 8:17 ` Olof Johansson
0 siblings, 0 replies; 24+ messages in thread
From: Olof Johansson @ 2007-12-14 8:17 UTC (permalink / raw)
To: Kumar Gala; +Cc: Geert Uytterhoeven, linuxppc-dev
On Fri, Dec 14, 2007 at 02:08:14AM -0600, Kumar Gala wrote:
> I'd say wait for Paul to pickup my 2.6.25 request. Than the base will
> have the isel emulation as well.
It was spotting the isel patch in your queue that made me go back and
look at the thread. :)
-Olof
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2007-12-14 8:12 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-20 3:36 [PATCH] [POWERPC] Emulate isel (Integer Select) instruction Kumar Gala
2007-11-20 17:54 ` Scott Wood
2007-11-20 21:01 ` Kumar Gala
2007-11-21 9:12 ` Benjamin Herrenschmidt
2007-11-21 14:19 ` Kumar Gala
2007-11-21 13:09 ` Geert Uytterhoeven
2007-11-21 14:22 ` Kumar Gala
2007-11-21 14:33 ` Geert Uytterhoeven
2007-11-21 15:34 ` Kumar Gala
2007-11-21 16:50 ` Geert Uytterhoeven
2007-11-21 19:22 ` Kumar Gala
2007-11-21 21:31 ` Paul Mackerras
2007-11-21 21:36 ` Paul Mackerras
2007-11-21 21:41 ` Scott Wood
2007-11-21 21:48 ` Kim Phillips
2007-11-21 21:38 ` Paul Mackerras
2007-11-27 14:56 ` Geert Uytterhoeven
2007-11-27 15:23 ` Olof Johansson
2007-11-28 10:49 ` Geert Uytterhoeven
2007-11-29 15:13 ` Geert Uytterhoeven
2007-12-14 8:12 ` Olof Johansson
2007-12-14 8:08 ` Kumar Gala
2007-12-14 8:17 ` Olof Johansson
2007-12-14 8:16 ` Olof Johansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).