Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3468651ybg; Mon, 28 Oct 2019 13:21:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4z9gJI+R8efukqTKrCpQTUQuJcRwOC7+L6E6tBesEOSZeTSMPEWhpUA+4eVXnCL4A3M++ X-Received: by 2002:a17:906:34c8:: with SMTP id h8mr17154873ejb.135.1572294087549; Mon, 28 Oct 2019 13:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572294087; cv=none; d=google.com; s=arc-20160816; b=0/9HLjjqKtM/VSPTAMNBOzhbh1cwx2ZtszSDtlPEK9m2Z1abiIetBkQrtjJHUn5lGt rcri7GyyXh0zzxPPtksyDY1LqyLHDENZfjkkgjYPkQYQ9ACy5KxaezoYzv6mOxJU+Gu0 p8ohYExMpv7zdjFQn1fK34RywfssSq2rinuWzspA8QbzhqHUkA4B+nDdRrPHLKo7NvM2 g+QkIKSsZIDdboaQXomLPWm1DYZkAlD6drWQeKiH6vGecr8uYVGicmrO0S3uhxnTpxVc Bsj+MHG3FFfDcB5rF0cdMV1Rz26SzTu9kPomkcJvqomQB603zjCbD8ZtXhupyddeI1QE gkpg== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=lM8DgQo9z8I1z4K8vKlnlctErUxpXNFfjnpjuArp5RM=; b=CrkRJ9sx4cqNe0XY6ijEY4vKigbmamk6K1hYVaVOfGf0cLRUb7eZ9P75GqHfDVHqfj 8OLIMbbkX6os7oOWfuD2DRJEU0LMRYfWJbwpxfEZQCIMV3KmTpnkG5uL9LByJE/a2xU+ +WEDND14Djeqwd88ZuINcPPN11VU9N+epppADfwu1bU8nyF2rF3m7hwh0gUDwxiHAhhV 5B6xud+vm8JXS2XuCu6dmlmyYt6p14LCsCCZ4dMjTtlMs+IoMBT3VJpZ9vx2WfzQfZEQ uwKjWrWqWw3fHUIwXO0RuXskSDk1Fz3KUAdvkn9MY670Ve/XWZEFz+xNaTXh4JDlcbjM ckyA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k50si7460698ede.224.2019.10.28.13.21.03; Mon, 28 Oct 2019 13:21:27 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389522AbfJ1Mnm (ORCPT + 99 others); Mon, 28 Oct 2019 08:43:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:44683 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389472AbfJ1Mnf (ORCPT ); Mon, 28 Oct 2019 08:43:35 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iP4Mh-0002Lt-Vl; Mon, 28 Oct 2019 13:43:20 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 9F80E1C0081; Mon, 28 Oct 2019 13:43:19 +0100 (CET) Date: Mon, 28 Oct 2019 12:43:19 -0000 From: "tip-bot2 for Alexey Budankov" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel: Implement LBR callstack context synchronization Cc: Alexey Budankov , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Arnaldo Carvalho de Melo , Ian Rogers , Jiri Olsa , Kan Liang , Linus Torvalds , Mark Rutland , Namhyung Kim , Song Liu , Stephane Eranian , Thomas Gleixner , Vince Weaver , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <261ac742-9022-c3f4-5885-1eae7415b091@linux.intel.com> References: <261ac742-9022-c3f4-5885-1eae7415b091@linux.intel.com> MIME-Version: 1.0 Message-ID: <157226659938.29376.5074252162703228441.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 421ca868ea3b7c1ca1a541ed6dff3c101a563b95 Gitweb: https://git.kernel.org/tip/421ca868ea3b7c1ca1a541ed6dff3c101a563b95 Author: Alexey Budankov AuthorDate: Wed, 23 Oct 2019 10:12:54 +03:00 Committer: Ingo Molnar CommitterDate: Mon, 28 Oct 2019 12:51:01 +01:00 perf/x86/intel: Implement LBR callstack context synchronization 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 Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Arnaldo Carvalho de Melo Cc: Ian Rogers Cc: Jiri Olsa Cc: Kan Liang Cc: Linus Torvalds Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Link: https://lkml.kernel.org/r/261ac742-9022-c3f4-5885-1eae7415b091@linux.intel.com Signed-off-by: Ingo Molnar --- 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 ea54634..534c766 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 5384317..930611d 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);