Re: [PATCH v2 4/7] perf, x86: Save/resotre LBR stack during contextswitch

From: Peter Zijlstra
Date: Thu Jul 04 2013 - 08:44:17 EST


On Mon, Jul 01, 2013 at 03:23:04PM +0800, Yan, Zheng wrote:
> From: "Yan, Zheng" <zheng.z.yan@xxxxxxxxx>
>
> When the LBR call stack is enabled, it is necessary to save/restore
> the LBR stack on context switch. The solution is saving/restoring
> the LBR stack to/from task's perf event context.
>
> If there are cpu-wide events that use LBR, do not save/restore the
> LBR stack on context switches, flush it instead.

Again inadequate changelog; it fails to explain wtf this is:

> + if (event->ctx->task &&
> + branch_user_callstack(event->hw.branch_reg.reg)) {
> + struct x86_perf_event_context *task_ctx = (void *)event->ctx;
> + /*
> + * Reset the LBR stack if the call stack is not
> + * continuous enabled
> + */
> + if (task_ctx->lbr_callstack_users == 0 &&
> + task_ctx->lbr_stack_gen + 1 < event->ctx->sched_gen)
> + intel_pmu_lbr_reset();
> +
> + task_ctx->lbr_callstack_users++;
> + task_ctx->lbr_stack_gen = event->ctx->sched_gen;
> + }
> }

And what this parent_ctx nonsense is about:

> +void intel_pmu_lbr_init_context(struct perf_event_context *child_ctx,
> + struct perf_event_context *parent_ctx)
> +{
> + struct x86_perf_event_context *task_ctx, *parent_task_ctx;
> +
> + if (!x86_pmu.lbr_nr)
> + return;
> +
> + task_ctx = (struct x86_perf_event_context *)child_ctx;
> + parent_task_ctx = (struct x86_perf_event_context *)parent_ctx;
> +
> + if (parent_task_ctx->lbr_callstack_users)
> + __intel_pmu_lbr_save(task_ctx);
> + else
> + task_ctx->lbr_stack_saved = false;
> +}
--
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/