Re: [PATCH 09/12] perf_events: add hook to flush branch_stack oncontext switch (v2)

From: Stephane Eranian
Date: Wed Dec 07 2011 - 13:26:03 EST


On Mon, Dec 5, 2011 at 1:37 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> On Fri, 2011-10-14 at 14:37 +0200, Stephane Eranian wrote:
>> + Â Â Â Â Â Â Â /*
>> + Â Â Â Â Â Â Â Â* check if the context has at least one
>> + Â Â Â Â Â Â Â Â* event using PERF_SAMPLE_BRANCH_STACK
>> + Â Â Â Â Â Â Â Â*/
>> + Â Â Â Â Â Â Â if (cpuctx->ctx.nr_branch_stack > 0
>> + Â Â Â Â Â Â Â Â Â && pmu->flush_branch_stack) {
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â pmu = cpuctx->ctx.pmu;
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â perf_ctx_lock(cpuctx, cpuctx->task_ctx);
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â perf_pmu_disable(pmu);
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â pmu->flush_branch_stack();
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â perf_pmu_enable(pmu);
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â perf_ctx_unlock(cpuctx, cpuctx->task_ctx);
>> + Â Â Â Â Â Â Â }
>> + Â Â Â }
>
> (what whitespace looks funny)
>
> So all PMUs not supporting this branch stuff will fail to create a
> has_branch_stack() event, right? Thus all ctx with !0 nr_branch_stack
> support it. Doesn't this make the test for pmu->flush_branch_stack
> redundant?
>
>
No, nr_branch_stack counts the number of active events with
branch_stack. It's like the ctx->nr_cgroups. Processors which
do not support branch_stack will always have this field to 0.
It's not because a processor supports branch_stack that we
need to call flush_branch_stack(), i.e., we use a lazy approach.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/