Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5197438ybg; Mon, 21 Oct 2019 23:01:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcb34ot6S8ojUNoXCi7lL/VPsUvLZcJFpLxRQ/5MwjCOZQGKviSMgk2DV78AS7HH49Gg04 X-Received: by 2002:a17:906:3b4e:: with SMTP id h14mr6590635ejf.111.1571724093374; Mon, 21 Oct 2019 23:01:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571724093; cv=none; d=google.com; s=arc-20160816; b=JYlPPYnJreka1E23k3cvbtyDAAQoLoOSH3y9W4uPzWTj9NCC9TOqbRaq7PM4PPrvQM HSMaivrEo4FFN0aU9tyE3qniVBQcTAT4lWhpJC+BI/QQGSTJWFYez/0oheXi0NJqVfQd AOyLs9AIzWieYrioKDJpRRVvYAcdedkGukEtebGzOD5Lb6BaGGxI4pohQ/uq7Lzq7E69 Iryu/EvJGJr9xD5bBYSkw36H7PngRIcP6BEbe1FXjEBcBG8eQnuY8rMcOfi5/bw8UrPG WcCNkIZJ9xhcXK8PfaIqOy5VYOu3lQMcgLnVrVN2i6jYHQ6Jw65hOpKc8ZB0l1njSZrV ANHg== 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=WaUlEjPSvRmZmq+pXU5HHIKnC08BxSNXkSY11vvdAqg=; b=y0BqnSY8IVdTA8fIZlAHv4nbjbwf66+HeHKiZCa7N/byCLvyM1m19sIWHbVF9g5qPn Lry+EgMPakPEEiol1V4CXSEIhgfrUz0Z25MAZbp5mOB3xSQksbyQ1ZP7qWPhljnoeMkT 1VrKTUdM99QConof5wcRQBoPsH8UVxiVw0sxWf+CuqBt6u/rbnMjv9bF3vgz3ZpiNHMG zjGuO5DldZaca0PFiDajbDh0o0o5XTgeNfBYpv4VOsBgzFSPu5QfwFKkEk21TC/paHGX RMEnH3XIxCVXSGTY6fcw2Xuc7foSG1kYEv1EvVLjZxvXv1wmgulxkH4QnCjt78y6Ivsl strA== 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 d44si4609954ede.149.2019.10.21.23.01.10; Mon, 21 Oct 2019 23:01:33 -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 S2387523AbfJVGAI (ORCPT + 99 others); Tue, 22 Oct 2019 02:00:08 -0400 Received: from mga17.intel.com ([192.55.52.151]:54929 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730705AbfJVGAH (ORCPT ); Tue, 22 Oct 2019 02:00:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Oct 2019 23:00:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,326,1566889200"; d="scan'208";a="187778623" Received: from linux.intel.com ([10.54.29.200]) by orsmga007.jf.intel.com with ESMTP; 21 Oct 2019 23:00:06 -0700 Received: from [10.249.230.171] (abudanko-mobl.ccr.corp.intel.com [10.249.230.171]) by linux.intel.com (Postfix) with ESMTP id 3197558029D; Mon, 21 Oct 2019 23:00:02 -0700 (PDT) Subject: [PATCH v4 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: Organization: Intel Corp. Message-ID: <2bd6306a-9086-60b8-b5c9-4e16f39950d4@linux.intel.com> Date: Tue, 22 Oct 2019 09:00:01 +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: 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_sync_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 | 6 ++++++ arch/x86/events/perf_event.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index ea54634eabf3..3cf58bcb88af 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -417,6 +417,12 @@ 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_sync_task_ctx(struct x86_perf_task_context *prev, + struct x86_perf_task_context *next) +{ + swap(prev->lbr_callstack_users, next->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 be78f2765f74..0474ec6f4771 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_sync_task_ctx(struct x86_perf_task_context *prev, + struct x86_perf_task_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