Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7476869ybp; Wed, 16 Oct 2019 09:12:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3t6wXcXxg7caNnPgB31Kngsf31RlqewOg7CKtQLw/SVcEOGpZiBAkvpqRlOzAH8Dcld5Z X-Received: by 2002:a17:906:3c4:: with SMTP id c4mr2873068eja.302.1571242364281; Wed, 16 Oct 2019 09:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571242364; cv=none; d=google.com; s=arc-20160816; b=AzEL8gOUbBmynDHBpjIJGxhaGGoa9mVrF6IV7Rvb7/Cyer4mS/bXKZxW08U0xM5jrA tv/OzzkunfH7NMXfS0F5gB2rOCRJenhFLLCgth3fHPqasjqvDCTQTGBJ72T42tL61+0G 9BFzULaDy9o/I1WX60SdUCZlTDrHfVhbrajBZEZVnlBKkq1720QTJF97RJrFGOUS501G w701sKVq0E2jZ4pxj36ARCPmhShJD0kra2Jl1aMnrpFqod58YbWJ8h/0AjTEyG5qYgjI Hm6s9b7iYDMaJhRJz2XWl4ipr3lzbLdjv+iYjH0LDnkP/1VkEUptb1RgSAM/UbZoiTqJ HiQA== 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=fOZBZ+0+KEsdVgO6WTHwwrVfpCMMyNQ7fPr1woJUp2w=; b=hzRGHV50uJmBHcMtyIapGcbg1MbgCz+DbvSiBloiKfrHS0ptzMR6EUVBIdgRLGZ2AA n8fUzFkcfwNlRUa8xNWIJwLv8I+K/JdJu/r9kBvG/UsawtmtZ+MYAK2ScuFo8kcVDnIr ng0FsWikOMmw+mSdHxhe/+Jum2TmgxQObM2MD1rFNpmI1815q7lkY1NOYR1LL6QlCdzv fozu+57wdj7XRltkc7Aj6tP5Hc3YBanyJpGH6i9qsWhaw5cTEDtUizR5ohKlienf4Gd0 MaZ83D23O90MVY/AqyC5an7PpEjibyMxgTAn8h1Mrrn9gfLdc3fCzj9qrMy8TP/STuYO srUw== 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 o2si14986146ejm.367.2019.10.16.09.12.21; Wed, 16 Oct 2019 09:12:44 -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 S2393781AbfJPOHK (ORCPT + 99 others); Wed, 16 Oct 2019 10:07:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:58440 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726824AbfJPOHJ (ORCPT ); Wed, 16 Oct 2019 10:07:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2019 07:07:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,304,1566889200"; d="scan'208";a="395905023" Received: from linux.intel.com ([10.54.29.200]) by fmsmga005.fm.intel.com with ESMTP; 16 Oct 2019 07:07:08 -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 195D3580375; Wed, 16 Oct 2019 07:07:05 -0700 (PDT) Subject: Re: [PATCH v2 3/4] perf/x86/intel: implement LBR callstacks context synchronization From: Alexey Budankov To: "Liang, Kan" , Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Stephane Eranian , Ian Rogers , Song Liu , linux-kernel References: <5964c7e9-ab6f-c0d0-3dca-31196606e337@linux.intel.com> <79b0e201-479e-0e35-4ef4-3f6410ee28e4@linux.intel.com> <56c5408c-a217-18f3-8a0d-c0bb0886f2d3@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Wed, 16 Oct 2019 17:07:05 +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: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.10.2019 16:39, Alexey Budankov wrote: > On 16.10.2019 15:20, Liang, Kan wrote: >> >> >> On 10/16/2019 5:50 AM, Alexey Budankov wrote: >>> >>> Implement intel_pmu_lbr_sync_task_ctx() method that updates counter >>> 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 copies the counter value that is expected to be >>> non zero from the previous equivalent task perf event context. >>> >>> Signed-off-by: Alexey Budankov >>> --- >>>   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..152a3f8b516a 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; >>> + >>> +    one->lbr_callstack_users = another->lbr_callstack_users; >> >> We may want to swap here? > > Well, in this particular case lbr_callstack_users has to stay consistent > with the amount of events in task perf event context that requested > LBR callstack. Tested swap version and it also fixes the initial issue. After more code revising swap looks like the correct operation here. Nice catch. Thanks! ~Alexey > > ~Alexey > >> >> Thanks, >> Kan >> >>> +} >>> + >>>   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); >>> >> >