Re: [PATCH V4 09/16] perf, x86: Save/resotre LBR stack during context switch
From: Peter Zijlstra
Date: Wed Jul 02 2014 - 06:50:18 EST
On Mon, Jun 30, 2014 at 04:50:46PM +0800, Yan, Zheng wrote:
> void intel_pmu_lbr_sched_task(struct perf_event_context *ctx, bool sched_in)
> {
> struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
> + struct x86_perf_task_context *task_ctx;
>
> if (!x86_pmu.lbr_nr)
> return;
>
> /*
> + * If LBR callstack feature is enabled and the stack was saved when
> + * the task was scheduled out, restore the stack. Otherwise flush
> + * the LBR stack.
> */
> + task_ctx = ctx ? ctx->task_ctx_data : NULL;
> if (sched_in) {
> + if (task_ctx &&
> + task_ctx->lbr_callstack_users > 0 &&
> + task_ctx->lbr_stack_state == LBR_VALID)
> + __intel_pmu_lbr_restore(task_ctx);
> + else
> + intel_pmu_lbr_reset();
> +
> cpuc->lbr_context = ctx;
> + return;
> + }
> +
> + /* schedule out */
> + if (task_ctx) {
> + if (task_ctx->lbr_callstack_users)
> + __intel_pmu_lbr_save(task_ctx);
> + else
> + task_ctx->lbr_stack_state = LBR_NONE;
> }
> }
I can't say that's pretty..
How about something like:
task_ctx = ctx->task_ctx_data; /* XXX I don't think ctx can ever be NULL here */
if (task_ctx) {
if (sched_in)
intel_pmu_lbr_restore(task_ctx);
else
intel_pmu_lbr_save(task_ctx);
return;
}
if (sched_in)
intel_pmu_lbr_reset();
And then push all the callstack_users and state nonsense into the
save/restore functions.
Attachment:
pgpmNavlCEQ4Q.pgp
Description: PGP signature