perf/x86: filter branches for PEBS event
Subsystems (2)
PATCH 1/1 perf/x86: filter branches for PEBS event
From: Kan Liang <[email protected]>
For supporting Intel LBR branches filtering, Intel LBR sharing logic mechanism is introduced from commit b36817e88630 ("perf/x86: Add Intel LBR sharing logic"). It modifies __intel_shared_reg_get_constraints to config lbr_sel, which is finally used to set LBR_SELECT. However, the intel_shared_regs_constraints is called after intel_pebs_constraints. The PEBS event will return immediately after intel_pebs_constraints. So it's impossible to filter branches for PEBS event.
This patch move intel_shared_regs_constraints for branch_reg ahead of intel_pebs_constraints.intel_shared_regs_constraints for branch_reg doesn't modify event->hw, so it's safe to be called before intel_pebs_constraints. intel_shared_regs_constraints for branch_reg also special case when it returns &emptyconstraint. It put constraints for extra_reg. This patch remove it. Because it will never get constraints for extra_reg if return is &emptyconstraint.
--- arch/x86/kernel/cpu/perf_event_intel.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +12 -22
@@ -1587,25 +1587,14 @@ __intel_shared_reg_put_constraints(struct cpu_hw_events *cpuc,static struct event_constraint *intel_shared_regs_constraints (struct cpu_hw_events *cpuc, -struct perf_event *event) +struct perf_event *event, +struct hw_perf_event_extra *reg) { -struct event_constraint *c =NULL , *d; -struct hw_perf_event_extra *xreg, *breg; +struct event_constraint *c =NULL ; + +if (reg->idx !=EXTRA_REG_NONE ) + c =__intel_shared_reg_get_constraints (cpuc, event, reg); - xreg = &event->hw.extra_reg; -if (xreg->idx !=EXTRA_REG_NONE ) { - c =__intel_shared_reg_get_constraints (cpuc, event, xreg); -if (c == &emptyconstraint) -return c; - } - breg = &event->hw.branch_reg; -if (breg->idx !=EXTRA_REG_NONE ) { - d =__intel_shared_reg_get_constraints (cpuc, event, breg); -if (d == &emptyconstraint) { -__intel_shared_reg_put_constraints (cpuc, xreg); - c = d; - } - }return c; }
@@ -1629,17 +1618,18 @@ x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)static struct event_constraint *intel_get_event_constraints (struct cpu_hw_events *cpuc,struct perf_event *event) { -struct event_constraint *c; +struct event_constraint *c, *d; c =intel_bts_constraints (event);if (c)return c; - c =intel_pebs_constraints (event); -if (c) -return c; + c =intel_shared_regs_constraints (cpuc, event, &event->hw.branch_reg); + d =intel_pebs_constraints (event); +if (d || c) +return (d) ? (d) : (c); - c =intel_shared_regs_constraints (cpuc, event); + c =intel_shared_regs_constraints (cpuc, event, &event->hw.extra_reg);if (c)return c;
Signature · 1 line
1.8.3.2
Quoted 75 lines · On Thu, Mar 26, 2015 at 11:13 AM, <[email protected]> wrote:
From: Kan Liang <[email protected]>
For supporting Intel LBR branches filtering, Intel LBR sharing logic mechanism is introduced from commit
b36817e88630("perf/x86: Add Intel LBR sharing logic"). It modifies__intel_shared_reg_get_constraintsto configlbr_sel, which is finally used to setLBR_SELECT. However, theintel_shared_regs_constraintsis called afterintel_pebs_constraints. The PEBS event will return immediately afterintel_pebs_constraints. So it's impossible to filter branches for PEBS event.This patch move
intel_shared_regs_constraintsforbranch_regahead ofintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regdoesn't modifyevent->hw, so it's safe to be called beforeintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regalso special case when it returns &emptyconstraint. It put constraints forextra_reg. This patch remove it. Because it will never get constraints forextra_regif return is &emptyconstraint.Signed-off-by Kan Liang <[email protected]>--- arch/x86/kernel/cpu/perf_event_intel.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)arch/x86/kernel/cpu/perf_event_intel.c +7
-21@@ -1587,25 +1587,14 @@ __intel_shared_reg_put_constraints(struct cpu_hw_events *cpuc,static struct event_constraint *intel_shared_regs_constraints (struct cpu_hw_events *cpuc, -struct perf_event *event) +struct perf_event *event, +struct hw_perf_event_extra *reg) { -struct event_constraint *c =NULL , *d; -struct hw_perf_event_extra *xreg, *breg; +struct event_constraint *c =NULL ; + +if (reg->idx !=EXTRA_REG_NONE ) + c =__intel_shared_reg_get_constraints (cpuc, event, reg); - xreg = &event->hw.extra_reg; -if (xreg->idx !=EXTRA_REG_NONE ) { - c =__intel_shared_reg_get_constraints (cpuc, event, xreg); -if (c == &emptyconstraint) -return c; - } - breg = &event->hw.branch_reg; -if (breg->idx !=EXTRA_REG_NONE ) { - d =__intel_shared_reg_get_constraints (cpuc, event, breg); -if (d == &emptyconstraint) { -__intel_shared_reg_put_constraints (cpuc, xreg); - c = d; - } - }return c; }@@ -1629,17 +1618,18 @@ x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)static struct event_constraint *intel_get_event_constraints (struct cpu_hw_events *cpuc,struct perf_event *event) { -struct event_constraint *c; +struct event_constraint *c, *d; c =intel_bts_constraints (event);if (c)return c; - c =intel_pebs_constraints (event); -if (c) -return c;
arch/x86/kernel/cpu/perf_event_intel.c x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) · line 1635
Quoted 10 lines
arch/x86/kernel/cpu/perf_event_intel.c +5
-1+ c =intel_shared_regs_constraints (cpuc, event, &event->hw.branch_reg); + d =intel_pebs_constraints (event); +if (d || c) +return (d) ? (d) : (c); - c =intel_shared_regs_constraints (cpuc, event); + c =intel_shared_regs_constraints (cpuc, event, &event->hw.extra_reg);if (c)return c;
You are addressing one of the problems of this routine. But I think there is a more serious
issue which is not addressed here. The intel_shared_regs_constraints() assumes that
the associated event is necessarily unconstrained:
__intel_shared_reg_get_constraints()
{
struct event_constraint *c = &emptyconstraint; ...
}
This is true for offcore_response, but for LBR this may not always be the case. I may want to use LBR on the L1D_PEND_MISS event and it would need to be on counter 2. But I believe that the current code could place it on counter 0 simply because you return if shared_reg_get_constraint() is successful, but it looks only at the LBR constraint not the event constraint. I think in the presence
of LBR, you always need to call share_get_reg() and x86_get_event_constraint(). This is to ensure that both the shared constraint AND the event constraint are satisfied (and of course, in case one fails, the other needs to be released).
Quoted 3 lines
--
1.8.3.2
Quoted 109 lines
Subject: Re: [PATCH 1/1] perf/x86: filter branches for PEBS event
Quoted 4 lines · On Thu, Mar 26, 2015 at 11:13 AM, <[email protected]> wrote:
From: Kan Liang <[email protected]>
For supporting Intel LBR branches filtering, Intel LBR sharing logic mechanism is introduced from commit
b36817e88630("perf/x86: AddIntel
arch/x86/kernel/cpu/perf_event_intel.c x86_get_event_constraints(struct
Quoted 62 lines
LBR sharing logic"). It modifies
__intel_shared_reg_get_constraintsto configlbr_sel, which is finally used to setLBR_SELECT. However, theintel_shared_regs_constraintsis called afterintel_pebs_constraints. The PEBS event will return immediately afterintel_pebs_constraints. So it's impossible to filter branches for PEBS event.This patch move
intel_shared_regs_constraintsforbranch_regahead ofintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regdoesn't modifyevent->hw, so it's safe to be called beforeintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regalso special case when it returns &emptyconstraint. It put constraints forextra_reg. This patch remove it. Because it will never get constraints forextra_regif return is &emptyconstraint.Signed-off-by Kan Liang <[email protected]>--- arch/x86/kernel/cpu/perf_event_intel.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)arch/x86/kernel/cpu/perf_event_intel.c +7
-17@@ -1587,25 +1587,14 @@ __intel_shared_reg_put_constraints(structcpu_hw_events *cpuc, static struct event_constraint * intel_shared_regs_constraints(struct cpu_hw_events *cpuc, - struct perf_event *event) + struct perf_event *event, + struct hw_perf_event_extra *reg) { - struct event_constraint *c = NULL, *d; -struct hw_perf_event_extra *xreg, *breg; + struct event_constraint *c = NULL; + +if (reg->idx !=EXTRA_REG_NONE ) + c =__intel_shared_reg_get_constraints (cpuc, event, + reg); - xreg = &event->hw.extra_reg; -if (xreg->idx !=EXTRA_REG_NONE ) { - c =__intel_shared_reg_get_constraints (cpuc, event, xreg); -if (c == &emptyconstraint) -return c; - } - breg = &event->hw.branch_reg; -if (breg->idx !=EXTRA_REG_NONE ) { - d =__intel_shared_reg_get_constraints (cpuc, event, breg); -if (d == &emptyconstraint) { -__intel_shared_reg_put_constraints (cpuc, xreg); - c = d; - } - }return c; }@@ -1629,17 +1618,18 @@ x86_get_event_constraints(struct
cpu_hw_eventsQuoted 16 lines
arch/x86/kernel/cpu/perf_event_intel.c +0
-0*cpuc, struct perf_event *event) static struct event_constraint *
intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event){arch/x86/kernel/cpu/perf_event_intel.c +2
-4-struct event_constraint *c; +struct event_constraint *c, *d; c =intel_bts_constraints (event);if (c)return c; - c =intel_pebs_constraints (event); -if (c) -return c; + c = intel_shared_regs_constraints(cpuc, event, &event-hw.branch_reg);
arch/x86/kernel/cpu/perf_event_intel.c x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) · line 1634
Quoted 9 lines
arch/x86/kernel/cpu/perf_event_intel.c +5
-1+ d =intel_pebs_constraints (event); +if (d || c) +return (d) ? (d) : (c); - c =intel_shared_regs_constraints (cpuc, event); + c =intel_shared_regs_constraints (cpuc, event, + &event->hw.extra_reg);if (c)return c;You are addressing one of the problems of this routine. But I think there is a more serious issue which is not addressed here. The
intel_shared_regs_constraints()assumes that the associated event is necessarily unconstrained:
__intel_shared_reg_get_constraints(){ struct event_constraint *c = &emptyconstraint;...
}
Quoted 6 lines
This is true for
offcore_response, but for LBR this may not always be the case.
I may want to use LBR on theL1D_PEND_MISSevent and it would need to be on counter 2. But I believe that the current code could place it on counter 0 simply because you return ifshared_reg_get_constraint()is successful, but it looks only at the LBR constraint not the event constraint.
I didn’t change __intel_shared_reg_get_constraints and its input. So using LBR on the L1D_PEND_MISS event, it would return NULL.
/* * need to call x86_get_event_constraint() * to check if associated event has constraints */ c = NULL;
Since it's not PEBS, intel_pebs_constraints will also return NULL. So it will not return. It will continue to check extra_reg and finally check if associated event has constraints.
Quoted 7 lines
I
think in the presence of LBR, you always need to callshare_get_reg()andx86_get_event_constraint().
This is to ensure that both the shared constraint AND the event constraint are satisfied (and of course, in case one fails, the other needs to be released).
The patch doesn't change the behavior for non-PEBS event.
Thanks,
Kan
Quoted 4 lines
Quoted 4 lines
--
1.8.3.2
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 126 lines · Kan
Quoted 109 lines
Subject: Re: [PATCH 1/1] perf/x86: filter branches for PEBS event
Quoted 4 lines · On Thu, Mar 26, 2015 at 11:13 AM, <[email protected]> wrote:
From: Kan Liang <[email protected]>
For supporting Intel LBR branches filtering, Intel LBR sharing logic mechanism is introduced from commit
b36817e88630("perf/x86: AddIntel
arch/x86/kernel/cpu/perf_event_intel.c x86_get_event_constraints(struct
Quoted 62 lines
LBR sharing logic"). It modifies
__intel_shared_reg_get_constraintsto configlbr_sel, which is finally used to setLBR_SELECT. However, theintel_shared_regs_constraintsis called afterintel_pebs_constraints. The PEBS event will return immediately afterintel_pebs_constraints. So it's impossible to filter branches for PEBS event.This patch move
intel_shared_regs_constraintsforbranch_regahead ofintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regdoesn't modifyevent->hw, so it's safe to be called beforeintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regalso special case when it returns &emptyconstraint. It put constraints forextra_reg. This patch remove it. Because it will never get constraints forextra_regif return is &emptyconstraint.Signed-off-by Kan Liang <[email protected]>--- arch/x86/kernel/cpu/perf_event_intel.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)arch/x86/kernel/cpu/perf_event_intel.c +7
-17@@ -1587,25 +1587,14 @@ __intel_shared_reg_put_constraints(structcpu_hw_events *cpuc, static struct event_constraint * intel_shared_regs_constraints(struct cpu_hw_events *cpuc, - struct perf_event *event) + struct perf_event *event, + struct hw_perf_event_extra *reg) { - struct event_constraint *c = NULL, *d; -struct hw_perf_event_extra *xreg, *breg; + struct event_constraint *c = NULL; + +if (reg->idx !=EXTRA_REG_NONE ) + c =__intel_shared_reg_get_constraints (cpuc, event, + reg); - xreg = &event->hw.extra_reg; -if (xreg->idx !=EXTRA_REG_NONE ) { - c =__intel_shared_reg_get_constraints (cpuc, event, xreg); -if (c == &emptyconstraint) -return c; - } - breg = &event->hw.branch_reg; -if (breg->idx !=EXTRA_REG_NONE ) { - d =__intel_shared_reg_get_constraints (cpuc, event, breg); -if (d == &emptyconstraint) { -__intel_shared_reg_put_constraints (cpuc, xreg); - c = d; - } - }return c; }@@ -1629,17 +1618,18 @@ x86_get_event_constraints(struct
cpu_hw_eventsQuoted 16 lines
arch/x86/kernel/cpu/perf_event_intel.c +0
-0*cpuc, struct perf_event *event) static struct event_constraint *
intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event){arch/x86/kernel/cpu/perf_event_intel.c +2
-4-struct event_constraint *c; +struct event_constraint *c, *d; c =intel_bts_constraints (event);if (c)return c; - c =intel_pebs_constraints (event); -if (c) -return c; + c = intel_shared_regs_constraints(cpuc, event, &event-hw.branch_reg);
arch/x86/kernel/cpu/perf_event_intel.c x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) · line 1634
Quoted 9 lines
arch/x86/kernel/cpu/perf_event_intel.c +5
-1+ d =intel_pebs_constraints (event); +if (d || c) +return (d) ? (d) : (c); - c =intel_shared_regs_constraints (cpuc, event); + c =intel_shared_regs_constraints (cpuc, event, + &event->hw.extra_reg);if (c)return c;You are addressing one of the problems of this routine. But I think there is a more serious issue which is not addressed here. The
intel_shared_regs_constraints()assumes that the associated event is necessarily unconstrained:
__intel_shared_reg_get_constraints(){ struct event_constraint *c = &emptyconstraint;...
}Quoted 6 lines
This is true for
offcore_response, but for LBR this may not always be the case.
I may want to use LBR on theL1D_PEND_MISSevent and it would need to be on counter 2. But I believe that the current code could place it on counter 0 simply because you return ifshared_reg_get_constraint()is successful, but it looks only at the LBR constraint not the event constraint.I didn’t change
__intel_shared_reg_get_constraintsand its input. So using LBR on theL1D_PEND_MISSevent, it would return NULL./* * need to call x86_get_event_constraint() * to check if associated event has constraints */ c = NULL;Since it's not PEBS,
intel_pebs_constraintswill also return NULL. So it will not return. It will continue to checkextra_regand finally check if associated event has constraints.
Quoted 9 lines
Quoted 7 lines
I
think in the presence of LBR, you always need to callshare_get_reg()andx86_get_event_constraint().
This is to ensure that both the shared constraint AND the event constraint are satisfied (and of course, in case one fails, the other needs to be released).The patch doesn't change the behavior for non-PEBS event.
I know that. I was commenting in general on the function. I think it still has the problem I mention. And it needs to be fixed.
Quoted 6 lines
Thanks,
KanQuoted 4 lines
Quoted 4 lines
--
1.8.3.2
Peter Zijlstra
maintainerQuoted 10 lines · Stephane Eranian
You are addressing one of the problems of this routine. But I think there is a more serious issue which is not addressed here. The
intel_shared_regs_constraints()assumes that the associated event is necessarily unconstrained:
__intel_shared_reg_get_constraints(){ struct event_constraint *c = &emptyconstraint;...
}
emptyconstraint != unconstrained.
Note how that function only returns emptyconstraint if its rejecting the event, otherwise it returns NULL such that we continue calling x86_get_event_constraint().
Quoted 9 lines
This is true for
offcore_response, but for LBR this may not always be the case. I may want to use LBR on theL1D_PEND_MISSevent and it would need to be on counter 2.But I believe that the current code could place it on counter 0 simply because you return if
shared_reg_get_constraint()is successful, but it looks only at the LBR constraint not the event constraint. I think in the presence of LBR, you always need to callshare_get_reg()andx86_get_event_constraint().
Which, I think it does.
Quoted 12 lines · Peter Zijlstra
Quoted 10 lines · Stephane Eranian
You are addressing one of the problems of this routine. But I think there is a more serious issue which is not addressed here. The
intel_shared_regs_constraints()assumes that the associated event is necessarily unconstrained:
__intel_shared_reg_get_constraints(){ struct event_constraint *c = &emptyconstraint;...
}
Quoted 6 lines
emptyconstraint != unconstrained.
Note how that function only returns emptyconstraint if its rejecting the event, otherwise it returns NULL such that we continue calling
x86_get_event_constraint().
Ah, yes, I had forgotten about that. Then everything is fine.
Quoted 11 lines
Quoted 9 lines
This is true for
offcore_response, but for LBR this may not always be the case. I may want to use LBR on theL1D_PEND_MISSevent and it would need to be on counter 2.But I believe that the current code could place it on counter 0 simply because you return if
shared_reg_get_constraint()is successful, but it looks only at the LBR constraint not the event constraint. I think in the presence of LBR, you always need to callshare_get_reg()andx86_get_event_constraint().Which, I think it does.
Indeed.
Peter Zijlstra
maintainerQuoted 2 lines · On Thu, Mar 26, 2015 at 02:13:23PM -0400, [email protected] wrote:
This patch move
intel_shared_regs_constraintsforbranch_regahead ofintel_pebs_constraints.
Why not all shared regs?
Quoted 6 lines
intel_shared_regs_constraintsforbranch_regdoesn't modifyevent->hw, so it's safe to be called beforeintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regalso special case when it returns &emptyconstraint. It put constraints forextra_reg. This patch remove it. Because it will never get constraints forextra_regif return is &emptyconstraint.
-ENOPARSE.
Quoted 7 lines · On Thu, Mar 26, 2015 at 02:13:23PM -0400, [email protected] wrote:
Quoted 2 lines
This patch move
intel_shared_regs_constraintsforbranch_regahead ofintel_pebs_constraints.Why not all shared regs?
Yes, all shared regs can also be moved ahead.
The patch is named for modifying the branch filter. I didn't want to change other codes. So I keep them unchanged.
I will do it in next version.
Quoted 9 lines
Quoted 7 lines
intel_shared_regs_constraintsforbranch_regdoesn't modifyevent->hw, so it's safe to be called beforeintel_pebs_constraints.intel_shared_regs_constraintsforbranch_regalso special case when it returns &emptyconstraint. It put constraints forextra_reg. This patch remove it. Because it will never get constraints forextra_regif return is &emptyconstraint.
-ENOPARSE.
Will remove the description, since it doesn't need in next version.
Thanks,
Kan