Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4045701ybg; Fri, 25 Oct 2019 12:32:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqygVaL5i8eJFParTGgN+tm1bukkbYyr7HZ4LT2v91HFkIIUJWwcOhW2HBWrOMCWgYT823t+ X-Received: by 2002:a17:907:429e:: with SMTP id ny22mr4863997ejb.174.1572031928456; Fri, 25 Oct 2019 12:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572031928; cv=none; d=google.com; s=arc-20160816; b=wKkG4kiOwldX9AG5+aU0tcz5y2EYpJqVpSuE137MyGrLzlJgIbhXMSzNbmVik6/HyS 4VFwXKC1msY5ith5rR6cCZtMyfUKexuWerrM7wySE+PalwP5tPUi4ltMP7TThdXYeVVP ZpL0l1QeEg+E0ntFNzHRsusEopDze6IwTF4NHqdyAgFh9wyF1y6jKrR6x7GAWi9mTC6Q J388wzU4ypp1uyq2RE5jU0Bls4w3jftkKwZ76pKkV4X7sbNCYmCnG5SVojvFVzV2pxZY 9ieC23mIBBTfjEf2mqwksKCFhMCWV7er8uPWEeQ8p3cb0J+ObUqvF7aTG5e7nw778TsC F6cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject; bh=tj+qvzQJ5kAVkAukVOhoj7OR061001iwA9BRBQJsGgo=; b=hwXflktOHc/t1slgjgdEz3XBDqF1eqPhmBYr1fYgJsszUo23VoKVtN1LFY43V4y4zV +quAp99XHw/CRRNfsvqsQU2FWGqzts4gLgQBspnhvJ2ZlMlEahnQJE4+Y6TXgDdGaDfz MzWlRSThnTNvtszdoDnI45c/eb/b9SNlBwRSUSlJvtDDZgZY7zDI8xWn+WMssTuH/XLU cq7lOaiWEAhNsi3VUsaGnhw5XJ1itdx4MJk1UKxhZUqpFV6hTM22w+kw2x30DbNQNYgG eq7lyeeRZMxzimdM+h7W3mH7omx8Hpo596CPOTuvkIZJf539Sck/I5ck4LXK4y/LVG+P 95fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si1808252ejw.226.2019.10.25.12.31.45; Fri, 25 Oct 2019 12:32:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408579AbfJYI75 (ORCPT + 99 others); Fri, 25 Oct 2019 04:59:57 -0400 Received: from mga17.intel.com ([192.55.52.151]:38719 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405717AbfJYI74 (ORCPT ); Fri, 25 Oct 2019 04:59:56 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 01:59:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,228,1569308400"; d="scan'208";a="210337097" Received: from linux.intel.com ([10.54.29.200]) by fmsmga001.fm.intel.com with ESMTP; 25 Oct 2019 01:59:56 -0700 Received: from [10.125.252.238] (abudanko-mobl.ccr.corp.intel.com [10.125.252.238]) by linux.intel.com (Postfix) with ESMTP id 791B458042B; Fri, 25 Oct 2019 01:59:53 -0700 (PDT) Subject: [PATCH v5 3/4] perf/x86/intel: implement LBR callstacks context synchronization From: Alexey Budankov To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Kan Liang , Stephane Eranian , Ian Rogers , Song Liu , linux-kernel References: <6fa20503-b5ad-16c7-260e-5243509176bc@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Fri, 25 Oct 2019 11:59:52 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <6fa20503-b5ad-16c7-260e-5243509176bc@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement intel_pmu_lbr_swap_task_ctx() method updating counters of the events that requested LBR callstack data on a sample. The counter can be zero for the case when task context belongs to a thread that has just come from a block on a futex and the context contains saved (lbr_stack_state == LBR_VALID) LBR register values. For the values to be restored at LBR registers on the next thread's switch-in event it swaps the counter value with the one that is expected to be non zero at the previous equivalent task perf event context. Swap operation type ensures the previous task perf event context stays consistent with the amount of events that requested LBR callstack data on a sample. Signed-off-by: Alexey Budankov --- arch/x86/events/intel/lbr.c | 23 +++++++++++++++++++++++ arch/x86/events/perf_event.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index ea54634eabf3..534c76606049 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -417,6 +417,29 @@ static void __intel_pmu_lbr_save(struct x86_perf_task_context *task_ctx) cpuc->last_log_id = ++task_ctx->log_id; } +void intel_pmu_lbr_swap_task_ctx(struct perf_event_context *prev, + struct perf_event_context *next) +{ + struct x86_perf_task_context *prev_ctx_data, *next_ctx_data; + + swap(prev->task_ctx_data, next->task_ctx_data); + + /* + * Architecture specific synchronization makes sense in + * case both prev->task_ctx_data and next->task_ctx_data + * pointers are allocated. + */ + + prev_ctx_data = next->task_ctx_data; + next_ctx_data = prev->task_ctx_data; + + if (!prev_ctx_data || !next_ctx_data) + return; + + swap(prev_ctx_data->lbr_callstack_users, + next_ctx_data->lbr_callstack_users); +} + void intel_pmu_lbr_sched_task(struct perf_event_context *ctx, bool sched_in) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index 5384317eaa16..930611db8f9a 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -1024,6 +1024,9 @@ void intel_pmu_store_pebs_lbrs(struct pebs_lbr *lbr); void intel_ds_init(void); +void intel_pmu_lbr_swap_task_ctx(struct perf_event_context *prev, + struct perf_event_context *next); + void intel_pmu_lbr_sched_task(struct perf_event_context *ctx, bool sched_in); u64 lbr_from_signext_quirk_wr(u64 val); -- 2.20.1