Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7490112ybp; Wed, 16 Oct 2019 09:24:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+4WcJHXzF8CFWNLt22SNCGogJqHdfZsq5gQr156WVJ71+i4a4Rv74rlHmf8Ug4GR7/+d8 X-Received: by 2002:a17:906:7f04:: with SMTP id d4mr41562622ejr.178.1571243046717; Wed, 16 Oct 2019 09:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571243046; cv=none; d=google.com; s=arc-20160816; b=cFZW/nEx6664TzTU65lpgbndMDSDD4aKexxWspLkXQqQi9JqnSX69ZhBLprK2tNfmV QoWvY21VDZDW31N/DivXBqLoKxNn0ehSRQGAKV0M5YzRo4DKweTUbayVy7wBPmMo+5IN GMggmdJ/zAwzJES+6zMG/WnQFPN4H5MMamGqku8uWNF707jcmiEqDqNRg82SNRwVFGJb TC0b3Om7eQKm8tFQFpiDmBlm1XPX1/8jNusTlsBcAAVA7D490O90bZ+3IpE7zWKghk9g EnDDF3pK0XOsiHbwwv9j+CROlWhSbq6cPSgGzBg2j6QMLqHgRRreGytY79P8jfRjVJ/l 5hTg== 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=nkRB6IB2djI3Jmx6gwNFBTQnhrThMuBJqp8h/Pio33g=; b=w9+Q7ApGVYXhU3FXlogdbcaq/XvBStxF/3IP/jxO9S5egajQh0tMquV2/Fg7jinlWm Q5L6HwjMmHMTMLS8h7q/pk5o+CGtEwsAWEjudM4TRakay7UD17rBAl0+ClqwTivZHW8M b2Z4LyGUOL63I43BZ/F2k8+WR/vSmohs+Ltk28O2szOS27Hp/SU1iPBmqZW8sTrKoe+j ZygXRihJLJmba5jyNGqbu4etmpSRdTV/7aCwweBTXksY6PD7PVZ7eC4mXPPlhXY6pTaL 6MZ1+B+/BOMb8y/9L4qN9FMm6IBo985QLwaW5U5vUqdae8DMGdWVbozXDsavmtSxhqcO ArlA== 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 d10si15381040ejb.259.2019.10.16.09.23.42; Wed, 16 Oct 2019 09:24:06 -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 S2392355AbfJPO1a (ORCPT + 99 others); Wed, 16 Oct 2019 10:27:30 -0400 Received: from mga04.intel.com ([192.55.52.120]:27470 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbfJPO1a (ORCPT ); Wed, 16 Oct 2019 10:27:30 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2019 07:27:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,304,1566889200"; d="scan'208";a="189693348" Received: from linux.intel.com ([10.54.29.200]) by orsmga008.jf.intel.com with ESMTP; 16 Oct 2019 07:27:28 -0700 Received: from [10.125.252.157] (abudanko-mobl.ccr.corp.intel.com [10.125.252.157]) by linux.intel.com (Postfix) with ESMTP id 6267C580375; Wed, 16 Oct 2019 07:27:26 -0700 (PDT) Subject: [PATCH v3 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: <792a98c7-ed89-6c35-f1d7-98ddc9c1a117@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Wed, 16 Oct 2019 17:27:25 +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: <792a98c7-ed89-6c35-f1d7-98ddc9c1a117@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_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 --- Changes in v3: - replaced assignment with swap at intel_pmu_lbr_sync_task_ctx() --- arch/x86/events/intel/lbr.c | 9 +++++++++ arch/x86/events/perf_event.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index ea54634eabf3..e57734ca59d4 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -417,6 +417,15 @@ 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 *one, + struct x86_perf_task_context *another) +{ + if (!one || !another) + return; + + swap(one->lbr_callstack_users, another->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 a25e6d7eb87b..3e0087c06fc9 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 *one, + struct x86_perf_task_context *another); + 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