All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event()
@ 2018-09-20  9:41 Michael Ellerman
  2018-09-20  9:59 ` Madhavan Srinivasan
  2018-10-04  6:14 ` Michael Ellerman
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Ellerman @ 2018-09-20  9:41 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: maddy, paulus

In power7_marked_instr_event() there is a switch case that is missing
a break or an explicit fallthrough, it's not immediately clear which
it should be.

The function determines based on the PMU event code, whether the event
is a "marked" event (which then requires us to configure the PMU in a
certain way). On Power7 there is no specific bit(s) in the event to
tell us that, we just have to know.

Rather than having a full list of every event and whether they are
marked, we pull apart the event code and for events with certain
values of certain fields we can say that those are all marked events.

We take the psel (bits 0-7) of the event, and look at bits 4-7. For a
value of 6 we say that if the entire psel == 0x64 then if the pmc == 3
the event is marked, else not, and otherwise we continue.

It is then that we fallthrough to the 8 case, where we return true if
the unit == 0xd.

The question is should the 6 case also fallthrough and check for
unit == 0xd, or should it return.

Looking at the full list of events we see that there are zero events
where (psel >> 4) == 0x6 and unit == 0xd.

So the answer is it doesn't really matter, there are no valid event
codes that will return a different result whether we fallthrough or
break.

But equally, testing the 6 case events against unit == 0xd is slightly
bogus, as there are no such events. So to make the code clearer, and
avoid any future confusion, have the 6 case break rather than falling
through.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/perf/power7-pmu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/perf/power7-pmu.c b/arch/powerpc/perf/power7-pmu.c
index 7963658dbc22..6dbae9884ec4 100644
--- a/arch/powerpc/perf/power7-pmu.c
+++ b/arch/powerpc/perf/power7-pmu.c
@@ -238,6 +238,7 @@ static int power7_marked_instr_event(u64 event)
 	case 6:
 		if (psel == 0x64)
 			return pmc >= 3;
+		break;
 	case 8:
 		return unit == 0xd;
 	}
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event()
  2018-09-20  9:41 [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event() Michael Ellerman
@ 2018-09-20  9:59 ` Madhavan Srinivasan
  2018-09-20 14:47   ` Segher Boessenkool
  2018-10-04  6:14 ` Michael Ellerman
  1 sibling, 1 reply; 6+ messages in thread
From: Madhavan Srinivasan @ 2018-09-20  9:59 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: maddy, paulus



On Thursday 20 September 2018 03:11 PM, Michael Ellerman wrote:
> In power7_marked_instr_event() there is a switch case that is missing
> a break or an explicit fallthrough, it's not immediately clear which
> it should be.
>
> The function determines based on the PMU event code, whether the event
> is a "marked" event (which then requires us to configure the PMU in a
> certain way). On Power7 there is no specific bit(s) in the event to
> tell us that, we just have to know.
>
> Rather than having a full list of every event and whether they are
> marked, we pull apart the event code and for events with certain
> values of certain fields we can say that those are all marked events.
>
> We take the psel (bits 0-7) of the event, and look at bits 4-7. For a
> value of 6 we say that if the entire psel == 0x64 then if the pmc == 3
> the event is marked, else not, and otherwise we continue.
>
> It is then that we fallthrough to the 8 case, where we return true if
> the unit == 0xd.
>
> The question is should the 6 case also fallthrough and check for
> unit == 0xd, or should it return.
>
> Looking at the full list of events we see that there are zero events
> where (psel >> 4) == 0x6 and unit == 0xd.
>
> So the answer is it doesn't really matter, there are no valid event
> codes that will return a different result whether we fallthrough or
> break.
>
> But equally, testing the 6 case events against unit == 0xd is slightly
> bogus, as there are no such events. So to make the code clearer, and
> avoid any future confusion, have the 6 case break rather than falling
> through.

Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>

Just curious to know, how did you find this. Static code checker compiled
or any specific compiler warnings or just by code read?

Maddy
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>   arch/powerpc/perf/power7-pmu.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/arch/powerpc/perf/power7-pmu.c b/arch/powerpc/perf/power7-pmu.c
> index 7963658dbc22..6dbae9884ec4 100644
> --- a/arch/powerpc/perf/power7-pmu.c
> +++ b/arch/powerpc/perf/power7-pmu.c
> @@ -238,6 +238,7 @@ static int power7_marked_instr_event(u64 event)
>   	case 6:
>   		if (psel == 0x64)
>   			return pmc >= 3;
> +		break;
>   	case 8:
>   		return unit == 0xd;
>   	}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event()
  2018-09-20  9:59 ` Madhavan Srinivasan
@ 2018-09-20 14:47   ` Segher Boessenkool
  2018-09-24  7:03     ` Michael Ellerman
  2018-09-24  7:05     ` Madhavan Srinivasan
  0 siblings, 2 replies; 6+ messages in thread
From: Segher Boessenkool @ 2018-09-20 14:47 UTC (permalink / raw)
  To: Madhavan Srinivasan; +Cc: Michael Ellerman, linuxppc-dev, maddy, paulus

On Thu, Sep 20, 2018 at 03:29:22PM +0530, Madhavan Srinivasan wrote:
> On Thursday 20 September 2018 03:11 PM, Michael Ellerman wrote:
> >In power7_marked_instr_event() there is a switch case that is missing
> >a break or an explicit fallthrough, it's not immediately clear which
> >it should be.

> Just curious to know, how did you find this. Static code checker compiled
> or any specific compiler warnings or just by code read?

Newer GCC warns about suspicious fallthroughs (-Wimplicit-fallthrough,
which is in -Wextra).


Segher

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event()
  2018-09-20 14:47   ` Segher Boessenkool
@ 2018-09-24  7:03     ` Michael Ellerman
  2018-09-24  7:05     ` Madhavan Srinivasan
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2018-09-24  7:03 UTC (permalink / raw)
  To: Segher Boessenkool, Madhavan Srinivasan; +Cc: linuxppc-dev, maddy, paulus

Segher Boessenkool <segher@kernel.crashing.org> writes:

> On Thu, Sep 20, 2018 at 03:29:22PM +0530, Madhavan Srinivasan wrote:
>> On Thursday 20 September 2018 03:11 PM, Michael Ellerman wrote:
>> >In power7_marked_instr_event() there is a switch case that is missing
>> >a break or an explicit fallthrough, it's not immediately clear which
>> >it should be.
>
>> Just curious to know, how did you find this. Static code checker compiled
>> or any specific compiler warnings or just by code read?
>
> Newer GCC warns about suspicious fallthroughs (-Wimplicit-fallthrough,
> which is in -Wextra).

Yeah I actually turned -Wimplicit-fallthrough on manually.

I'm hoping to add that to our CFLAGS once I've merged this fix and
worked out the Kbuild magic to add it to CFLAGS just for arch/powerpc.

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event()
  2018-09-20 14:47   ` Segher Boessenkool
  2018-09-24  7:03     ` Michael Ellerman
@ 2018-09-24  7:05     ` Madhavan Srinivasan
  1 sibling, 0 replies; 6+ messages in thread
From: Madhavan Srinivasan @ 2018-09-24  7:05 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Michael Ellerman, linuxppc-dev, maddy, paulus



On Thursday 20 September 2018 08:17 PM, Segher Boessenkool wrote:
> On Thu, Sep 20, 2018 at 03:29:22PM +0530, Madhavan Srinivasan wrote:
>> On Thursday 20 September 2018 03:11 PM, Michael Ellerman wrote:
>>> In power7_marked_instr_event() there is a switch case that is missing
>>> a break or an explicit fallthrough, it's not immediately clear which
>>> it should be.
>> Just curious to know, how did you find this. Static code checker compiled
>> or any specific compiler warnings or just by code read?
> Newer GCC warns about suspicious fallthroughs (-Wimplicit-fallthrough,
> which is in -Wextra).
>

Nice good to know.

Maddy


> Segher
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: powerpc/perf: Add missing break in power7_marked_instr_event()
  2018-09-20  9:41 [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event() Michael Ellerman
  2018-09-20  9:59 ` Madhavan Srinivasan
@ 2018-10-04  6:14 ` Michael Ellerman
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2018-10-04  6:14 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: maddy, paulus

On Thu, 2018-09-20 at 09:41:11 UTC, Michael Ellerman wrote:
> In power7_marked_instr_event() there is a switch case that is missing
> a break or an explicit fallthrough, it's not immediately clear which
> it should be.
> 
> The function determines based on the PMU event code, whether the event
> is a "marked" event (which then requires us to configure the PMU in a
> certain way). On Power7 there is no specific bit(s) in the event to
> tell us that, we just have to know.
> 
> Rather than having a full list of every event and whether they are
> marked, we pull apart the event code and for events with certain
> values of certain fields we can say that those are all marked events.
> 
> We take the psel (bits 0-7) of the event, and look at bits 4-7. For a
> value of 6 we say that if the entire psel == 0x64 then if the pmc == 3
> the event is marked, else not, and otherwise we continue.
> 
> It is then that we fallthrough to the 8 case, where we return true if
> the unit == 0xd.
> 
> The question is should the 6 case also fallthrough and check for
> unit == 0xd, or should it return.
> 
> Looking at the full list of events we see that there are zero events
> where (psel >> 4) == 0x6 and unit == 0xd.
> 
> So the answer is it doesn't really matter, there are no valid event
> codes that will return a different result whether we fallthrough or
> break.
> 
> But equally, testing the 6 case events against unit == 0xd is slightly
> bogus, as there are no such events. So to make the code clearer, and
> avoid any future confusion, have the 6 case break rather than falling
> through.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>

Applied to powerpc next.

https://git.kernel.org/powerpc/c/db6711b7a17f03921e734e11e3a1e9

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-10-04  6:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-20  9:41 [PATCH] powerpc/perf: Add missing break in power7_marked_instr_event() Michael Ellerman
2018-09-20  9:59 ` Madhavan Srinivasan
2018-09-20 14:47   ` Segher Boessenkool
2018-09-24  7:03     ` Michael Ellerman
2018-09-24  7:05     ` Madhavan Srinivasan
2018-10-04  6:14 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.