Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3759860ybg; Mon, 28 Oct 2019 18:57:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpgfKmkRDAxJ76FmxGqsZ734DIKnwD3/HaCMXLvYIAo0qoBWnWro5OFyeNXf/E6y98JT6O X-Received: by 2002:a17:906:6844:: with SMTP id a4mr901107ejs.102.1572314221085; Mon, 28 Oct 2019 18:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572314221; cv=none; d=google.com; s=arc-20160816; b=Wueo7XpxpoI1HT/LxipVbUrhEl7QGzXk2i9SKL+xt54CnGbgv6ekBRdqKy7GW/+APk yEYHp3p2clUVp3vZrHa7yEHGKsn8MIaMnYkZ1dgreL2Fx2No/UbmQPTcS7RtbPpv9KM+ LGaxkQ1LwSj7VS9WWKr+wEM5wPkcOW7qykvlGFs9RwUFIjnAVc/RTuwmaw9HelzXi1w+ 7f9pt31iFcHc+yvvtHaHJyYi+mLOQpVjpAQeyxLW5dWvBZUD/E79zwd0VTXP89PrTjn/ Kji3+KIZd4cXlXQ8VO7VwfmDNyS+wBaLoy/nY9R+I9Q1NondUMCoRhjIjmrhRpM36q1F 4BZw== 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=dx7dyFeVWP9sUe7q97JuitPJGjIVCwrdRIf/Wygr7W8=; b=f/KU6u+Tm/LgLWsByLVOQIe1Brpa5JFLjXbE43pywnfc9sz/M+i+5Vdf7mdy6ztEY2 2jXkRDgHnAyKLPnK3WNcvdNebQrqGfRp54PKx7cAKGDzoS4xllt5O5ylRr0+ngFwfUvi zN00AQ+KysInbbYHionBvhK9jnmuiCmn5gcuwTG4h912TYGokoE6xq1QGVLYD+l+wh0c IbNxSUG8mTv2L0zJNy60wTYRGG2CMsZQbLNqQiv0fNtU5FRtVE2r+cMucDxvzyR9zMlq B75qiVnJwUldSc9lQBSnrINFH4A7CmpEY7MDGRGgWNJGEWIDceiTS/dKiF0X7R5Ub1zi ofww== 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 g5si9334459edg.420.2019.10.28.18.56.38; Mon, 28 Oct 2019 18:57:01 -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 S2389502AbfJ1Mnh (ORCPT + 99 others); Mon, 28 Oct 2019 08:43:37 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:44678 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389453AbfJ1Mnd (ORCPT ); Mon, 28 Oct 2019 08:43:33 -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-0002Lq-Lh; Mon, 28 Oct 2019 13:43:19 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 4D0131C047C; 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: Synchronize PMU task contexts on optimized context switches 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: <9c6445a9-bdba-ef03-3859-f1f91198f27a@linux.intel.com> References: <9c6445a9-bdba-ef03-3859-f1f91198f27a@linux.intel.com> MIME-Version: 1.0 Message-ID: <157226659905.29376.4151373731366750163.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: c2b98a8661514f29a44ebd0925cf4b1503beb48c Gitweb: https://git.kernel.org/tip/c2b98a8661514f29a44ebd0925cf4b1503beb48c Author: Alexey Budankov AuthorDate: Wed, 23 Oct 2019 10:13:56 +03:00 Committer: Ingo Molnar CommitterDate: Mon, 28 Oct 2019 12:51:01 +01:00 perf/x86: Synchronize PMU task contexts on optimized context switches Install Intel specific PMU task context synchronization adapter and extend optimized context switch path with PMU specific task context synchronization to fix LBR callstack virtualization on context switches. 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/9c6445a9-bdba-ef03-3859-f1f91198f27a@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/events/intel/core.c | 7 +++++++ kernel/events/core.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index bbf6588..dc64b16 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3820,6 +3820,12 @@ static void intel_pmu_sched_task(struct perf_event_context *ctx, intel_pmu_lbr_sched_task(ctx, sched_in); } +static void intel_pmu_swap_task_ctx(struct perf_event_context *prev, + struct perf_event_context *next) +{ + intel_pmu_lbr_swap_task_ctx(prev, next); +} + static int intel_pmu_check_period(struct perf_event *event, u64 value) { return intel_pmu_has_bts_period(event, value) ? -EINVAL : 0; @@ -3955,6 +3961,7 @@ static __initconst const struct x86_pmu intel_pmu = { .guest_get_msrs = intel_guest_get_msrs, .sched_task = intel_pmu_sched_task, + .swap_task_ctx = intel_pmu_swap_task_ctx, .check_period = intel_pmu_check_period, diff --git a/kernel/events/core.c b/kernel/events/core.c index 0940c88..f48d38b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3204,10 +3204,21 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, raw_spin_lock(&ctx->lock); raw_spin_lock_nested(&next_ctx->lock, SINGLE_DEPTH_NESTING); if (context_equiv(ctx, next_ctx)) { + struct pmu *pmu = ctx->pmu; + WRITE_ONCE(ctx->task, next); WRITE_ONCE(next_ctx->task, task); - swap(ctx->task_ctx_data, next_ctx->task_ctx_data); + /* + * PMU specific parts of task perf context can require + * additional synchronization. As an example of such + * synchronization see implementation details of Intel + * LBR call stack data profiling; + */ + if (pmu->swap_task_ctx) + pmu->swap_task_ctx(ctx, next_ctx); + else + swap(ctx->task_ctx_data, next_ctx->task_ctx_data); /* * RCU_INIT_POINTER here is safe because we've not