Re: [PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-10-07 Thread Peter Zijlstra
On Tue, Oct 07, 2014 at 02:59:20AM +, Liang, Kan wrote:
> > On Wed, Sep 10, 2014 at 10:09:05AM -0400, kan.li...@intel.com wrote:
> > > @@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct
> > perf_event_context *ctx, bool sched_in)
> > >   }
> > >  }
> > >
> > > +static inline bool branch_user_callstack(unsigned br_sel) {
> > > + return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK); }
> > > +
> > >  void intel_pmu_lbr_enable(struct perf_event *event)  {
> > >   struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
> > > + struct x86_perf_task_context *task_ctx;
> > >
> > >   if (!x86_pmu.lbr_nr)
> > >   return;
> > > @@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event
> > *event)
> > >   }
> > >   cpuc->br_sel = event->hw.branch_reg.reg;
> > >
> > > + task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
> > > + if (task_ctx && branch_user_callstack(cpuc->br_sel))
> > > + task_ctx->lbr_callstack_users++;
> > > +
> > 
> > Does it make sense to flip those conditions to avoid a potentially useless
> > dereference?
> 
> I'm not quite sure I understand your meaning here.
> But lbr_callstack_users is an indicator for save/restore the LBR stack on 
> context switch.
> Here, we only change the lbr_callstack_users, when it's LBR call stack and 
> has space for saving LBR stack.
> 
> Should I change the code as below?
> +   if (branch_user_callstack(cpuc->br_sel) && event->ctx &&
> +   (task_ctx = event->ctx->task_ctx_data))
> +   task_ctx->lbr_callstack_users++;

Yes, that avoids the ctx->task_ctx_data deref when
!branch_user_callstack().
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-10-07 Thread Peter Zijlstra
On Tue, Oct 07, 2014 at 02:59:20AM +, Liang, Kan wrote:
  On Wed, Sep 10, 2014 at 10:09:05AM -0400, kan.li...@intel.com wrote:
   @@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct
  perf_event_context *ctx, bool sched_in)
 }
}
  
   +static inline bool branch_user_callstack(unsigned br_sel) {
   + return (br_sel  X86_BR_USER)  (br_sel  X86_BR_CALL_STACK); }
   +
void intel_pmu_lbr_enable(struct perf_event *event)  {
 struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
   + struct x86_perf_task_context *task_ctx;
  
 if (!x86_pmu.lbr_nr)
 return;
   @@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event
  *event)
 }
 cpuc-br_sel = event-hw.branch_reg.reg;
  
   + task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
   + if (task_ctx  branch_user_callstack(cpuc-br_sel))
   + task_ctx-lbr_callstack_users++;
   +
  
  Does it make sense to flip those conditions to avoid a potentially useless
  dereference?
 
 I'm not quite sure I understand your meaning here.
 But lbr_callstack_users is an indicator for save/restore the LBR stack on 
 context switch.
 Here, we only change the lbr_callstack_users, when it's LBR call stack and 
 has space for saving LBR stack.
 
 Should I change the code as below?
 +   if (branch_user_callstack(cpuc-br_sel)  event-ctx 
 +   (task_ctx = event-ctx-task_ctx_data))
 +   task_ctx-lbr_callstack_users++;

Yes, that avoids the ctx-task_ctx_data deref when
!branch_user_callstack().
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-10-06 Thread Liang, Kan

> 
> On Wed, Sep 10, 2014 at 10:09:05AM -0400, kan.li...@intel.com wrote:
> > @@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct
> perf_event_context *ctx, bool sched_in)
> > }
> >  }
> >
> > +static inline bool branch_user_callstack(unsigned br_sel) {
> > +   return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK); }
> > +
> >  void intel_pmu_lbr_enable(struct perf_event *event)  {
> > struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
> > +   struct x86_perf_task_context *task_ctx;
> >
> > if (!x86_pmu.lbr_nr)
> > return;
> > @@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event
> *event)
> > }
> > cpuc->br_sel = event->hw.branch_reg.reg;
> >
> > +   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
> > +   if (task_ctx && branch_user_callstack(cpuc->br_sel))
> > +   task_ctx->lbr_callstack_users++;
> > +
> 
> Does it make sense to flip those conditions to avoid a potentially useless
> dereference?

I'm not quite sure I understand your meaning here.
But lbr_callstack_users is an indicator for save/restore the LBR stack on 
context switch.
Here, we only change the lbr_callstack_users, when it's LBR call stack and has 
space for saving LBR stack.

Should I change the code as below?
+   if (branch_user_callstack(cpuc->br_sel) && event->ctx &&
+   (task_ctx = event->ctx->task_ctx_data))
+   task_ctx->lbr_callstack_users++;

Kan

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-10-06 Thread Liang, Kan

 
 On Wed, Sep 10, 2014 at 10:09:05AM -0400, kan.li...@intel.com wrote:
  @@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct
 perf_event_context *ctx, bool sched_in)
  }
   }
 
  +static inline bool branch_user_callstack(unsigned br_sel) {
  +   return (br_sel  X86_BR_USER)  (br_sel  X86_BR_CALL_STACK); }
  +
   void intel_pmu_lbr_enable(struct perf_event *event)  {
  struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
  +   struct x86_perf_task_context *task_ctx;
 
  if (!x86_pmu.lbr_nr)
  return;
  @@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event
 *event)
  }
  cpuc-br_sel = event-hw.branch_reg.reg;
 
  +   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
  +   if (task_ctx  branch_user_callstack(cpuc-br_sel))
  +   task_ctx-lbr_callstack_users++;
  +
 
 Does it make sense to flip those conditions to avoid a potentially useless
 dereference?

I'm not quite sure I understand your meaning here.
But lbr_callstack_users is an indicator for save/restore the LBR stack on 
context switch.
Here, we only change the lbr_callstack_users, when it's LBR call stack and has 
space for saving LBR stack.

Should I change the code as below?
+   if (branch_user_callstack(cpuc-br_sel)  event-ctx 
+   (task_ctx = event-ctx-task_ctx_data))
+   task_ctx-lbr_callstack_users++;

Kan

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-09-24 Thread Peter Zijlstra
On Wed, Sep 10, 2014 at 10:09:05AM -0400, kan.li...@intel.com wrote:
> @@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
> *ctx, bool sched_in)
>   }
>  }
>  
> +static inline bool branch_user_callstack(unsigned br_sel)
> +{
> + return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK);
> +}
> +
>  void intel_pmu_lbr_enable(struct perf_event *event)
>  {
>   struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
> + struct x86_perf_task_context *task_ctx;
>  
>   if (!x86_pmu.lbr_nr)
>   return;
> @@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
>   }
>   cpuc->br_sel = event->hw.branch_reg.reg;
>  
> + task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
> + if (task_ctx && branch_user_callstack(cpuc->br_sel))
> + task_ctx->lbr_callstack_users++;
> +

Does it make sense to flip those conditions to avoid a potentially
useless dereference?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-09-24 Thread Peter Zijlstra
On Wed, Sep 10, 2014 at 10:09:05AM -0400, kan.li...@intel.com wrote:
 @@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
 *ctx, bool sched_in)
   }
  }
  
 +static inline bool branch_user_callstack(unsigned br_sel)
 +{
 + return (br_sel  X86_BR_USER)  (br_sel  X86_BR_CALL_STACK);
 +}
 +
  void intel_pmu_lbr_enable(struct perf_event *event)
  {
   struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
 + struct x86_perf_task_context *task_ctx;
  
   if (!x86_pmu.lbr_nr)
   return;
 @@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
   }
   cpuc-br_sel = event-hw.branch_reg.reg;
  
 + task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
 + if (task_ctx  branch_user_callstack(cpuc-br_sel))
 + task_ctx-lbr_callstack_users++;
 +

Does it make sense to flip those conditions to avoid a potentially
useless dereference?
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-09-10 Thread kan . liang
From: Kan Liang 

When enabling/disabling an event, check if the event uses the LBR
callstack feature, adjust the LBR callstack usage count accordingly.
Later patch will use the usage count to decide if LBR stack should
be saved/restored.

Signed-off-by: Yan, Zheng 
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c 
b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 3a63a25..8c6da0f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
*ctx, bool sched_in)
}
 }
 
+static inline bool branch_user_callstack(unsigned br_sel)
+{
+   return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK);
+}
+
 void intel_pmu_lbr_enable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
@@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
}
cpuc->br_sel = event->hw.branch_reg.reg;
 
+   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
+   if (task_ctx && branch_user_callstack(cpuc->br_sel))
+   task_ctx->lbr_callstack_users++;
+
cpuc->lbr_users++;
if (cpuc->lbr_users == 1)
perf_sched_cb_enable(event->ctx->pmu);
@@ -228,10 +238,15 @@ void intel_pmu_lbr_enable(struct perf_event *event)
 void intel_pmu_lbr_disable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
 
+   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
+   if (task_ctx && branch_user_callstack(cpuc->br_sel))
+   task_ctx->lbr_callstack_users--;
+
cpuc->lbr_users--;
WARN_ON_ONCE(cpuc->lbr_users < 0);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-09-10 Thread kan . liang
From: Kan Liang kan.li...@intel.com

When enabling/disabling an event, check if the event uses the LBR
callstack feature, adjust the LBR callstack usage count accordingly.
Later patch will use the usage count to decide if LBR stack should
be saved/restored.

Signed-off-by: Yan, Zheng zheng.z@intel.com
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c 
b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 3a63a25..8c6da0f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
*ctx, bool sched_in)
}
 }
 
+static inline bool branch_user_callstack(unsigned br_sel)
+{
+   return (br_sel  X86_BR_USER)  (br_sel  X86_BR_CALL_STACK);
+}
+
 void intel_pmu_lbr_enable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
@@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
}
cpuc-br_sel = event-hw.branch_reg.reg;
 
+   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
+   if (task_ctx  branch_user_callstack(cpuc-br_sel))
+   task_ctx-lbr_callstack_users++;
+
cpuc-lbr_users++;
if (cpuc-lbr_users == 1)
perf_sched_cb_enable(event-ctx-pmu);
@@ -228,10 +238,15 @@ void intel_pmu_lbr_enable(struct perf_event *event)
 void intel_pmu_lbr_disable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
 
+   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
+   if (task_ctx  branch_user_callstack(cpuc-br_sel))
+   task_ctx-lbr_callstack_users--;
+
cpuc-lbr_users--;
WARN_ON_ONCE(cpuc-lbr_users  0);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-09-09 Thread kan . liang
From: Kan Liang 

When enabling/disabling an event, check if the event uses the LBR
callstack feature, adjust the LBR callstack usage count accordingly.
Later patch will use the usage count to decide if LBR stack should
be saved/restored.

Signed-off-by: Yan, Zheng 
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c 
b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 3a63a25..8c6da0f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
*ctx, bool sched_in)
}
 }
 
+static inline bool branch_user_callstack(unsigned br_sel)
+{
+   return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK);
+}
+
 void intel_pmu_lbr_enable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
@@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
}
cpuc->br_sel = event->hw.branch_reg.reg;
 
+   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
+   if (task_ctx && branch_user_callstack(cpuc->br_sel))
+   task_ctx->lbr_callstack_users++;
+
cpuc->lbr_users++;
if (cpuc->lbr_users == 1)
perf_sched_cb_enable(event->ctx->pmu);
@@ -228,10 +238,15 @@ void intel_pmu_lbr_enable(struct perf_event *event)
 void intel_pmu_lbr_disable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
 
+   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
+   if (task_ctx && branch_user_callstack(cpuc->br_sel))
+   task_ctx->lbr_callstack_users--;
+
cpuc->lbr_users--;
WARN_ON_ONCE(cpuc->lbr_users < 0);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V5 08/16] perf, x86: track number of events that use LBR callstack

2014-09-09 Thread kan . liang
From: Kan Liang kan.li...@intel.com

When enabling/disabling an event, check if the event uses the LBR
callstack feature, adjust the LBR callstack usage count accordingly.
Later patch will use the usage count to decide if LBR stack should
be saved/restored.

Signed-off-by: Yan, Zheng zheng.z@intel.com
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c 
b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 3a63a25..8c6da0f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
*ctx, bool sched_in)
}
 }
 
+static inline bool branch_user_callstack(unsigned br_sel)
+{
+   return (br_sel  X86_BR_USER)  (br_sel  X86_BR_CALL_STACK);
+}
+
 void intel_pmu_lbr_enable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
@@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
}
cpuc-br_sel = event-hw.branch_reg.reg;
 
+   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
+   if (task_ctx  branch_user_callstack(cpuc-br_sel))
+   task_ctx-lbr_callstack_users++;
+
cpuc-lbr_users++;
if (cpuc-lbr_users == 1)
perf_sched_cb_enable(event-ctx-pmu);
@@ -228,10 +238,15 @@ void intel_pmu_lbr_enable(struct perf_event *event)
 void intel_pmu_lbr_disable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
 
+   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
+   if (task_ctx  branch_user_callstack(cpuc-br_sel))
+   task_ctx-lbr_callstack_users--;
+
cpuc-lbr_users--;
WARN_ON_ONCE(cpuc-lbr_users  0);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 08/16] perf, x86: track number of events that use LBR callstack

2014-07-07 Thread Yan, Zheng
When enabling/disabling an event, check if the event uses the LBR
callstack feature, adjust the LBR callstack usage count accordingly.
Later patch will use the usage count to decide if LBR stack should
be saved/restored.

Signed-off-by: Yan, Zheng 
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c 
b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 909f70a..9ae1875 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
*ctx, bool sched_in)
}
 }
 
+static inline bool branch_user_callstack(unsigned br_sel)
+{
+   return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK);
+}
+
 void intel_pmu_lbr_enable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
@@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
}
cpuc->br_sel = event->hw.branch_reg.reg;
 
+   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
+   if (task_ctx && branch_user_callstack(cpuc->br_sel))
+   task_ctx->lbr_callstack_users++;
+
cpuc->lbr_users++;
if (cpuc->lbr_users == 1)
perf_sched_cb_enable(event->ctx->pmu);
@@ -228,10 +238,15 @@ void intel_pmu_lbr_enable(struct perf_event *event)
 void intel_pmu_lbr_disable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
 
+   task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL;
+   if (task_ctx && branch_user_callstack(cpuc->br_sel))
+   task_ctx->lbr_callstack_users--;
+
cpuc->lbr_users--;
WARN_ON_ONCE(cpuc->lbr_users < 0);
 
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 08/16] perf, x86: track number of events that use LBR callstack

2014-07-07 Thread Yan, Zheng
When enabling/disabling an event, check if the event uses the LBR
callstack feature, adjust the LBR callstack usage count accordingly.
Later patch will use the usage count to decide if LBR stack should
be saved/restored.

Signed-off-by: Yan, Zheng zheng.z@intel.com
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c 
b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 909f70a..9ae1875 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -204,9 +204,15 @@ void intel_pmu_lbr_sched_task(struct perf_event_context 
*ctx, bool sched_in)
}
 }
 
+static inline bool branch_user_callstack(unsigned br_sel)
+{
+   return (br_sel  X86_BR_USER)  (br_sel  X86_BR_CALL_STACK);
+}
+
 void intel_pmu_lbr_enable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
@@ -220,6 +226,10 @@ void intel_pmu_lbr_enable(struct perf_event *event)
}
cpuc-br_sel = event-hw.branch_reg.reg;
 
+   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
+   if (task_ctx  branch_user_callstack(cpuc-br_sel))
+   task_ctx-lbr_callstack_users++;
+
cpuc-lbr_users++;
if (cpuc-lbr_users == 1)
perf_sched_cb_enable(event-ctx-pmu);
@@ -228,10 +238,15 @@ void intel_pmu_lbr_enable(struct perf_event *event)
 void intel_pmu_lbr_disable(struct perf_event *event)
 {
struct cpu_hw_events *cpuc = __get_cpu_var(cpu_hw_events);
+   struct x86_perf_task_context *task_ctx;
 
if (!x86_pmu.lbr_nr)
return;
 
+   task_ctx = event-ctx ? event-ctx-task_ctx_data : NULL;
+   if (task_ctx  branch_user_callstack(cpuc-br_sel))
+   task_ctx-lbr_callstack_users--;
+
cpuc-lbr_users--;
WARN_ON_ONCE(cpuc-lbr_users  0);
 
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/