Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp53155rdb; Wed, 29 Nov 2023 19:58:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeZ9UkxEqbAbxku7BOs7SxBaoAKsnsNiEiCawYKUfDE8nEoaTg0f0dsYeAAMmAriqLUdrK X-Received: by 2002:a17:903:2285:b0:1cf:b81f:ed44 with SMTP id b5-20020a170903228500b001cfb81fed44mr18695689plh.29.1701316726494; Wed, 29 Nov 2023 19:58:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701316726; cv=none; d=google.com; s=arc-20160816; b=dLaF8yyAz2rm6W4c+MwcNGALdwAKzv0YFWMmK5rnhT9mrEm8hx7H0em4+FHVtgvxcg DioUjRJOeFYMWgt19JSy19CFjzDT0Bt1C85/ZeHCrSW7zXuB+KvLZpBEna0h3WTWa0aN Rf1ezw0W3AafvAfo41boyhDaWFLHQY3aISmB1TRi/pNs/CsRBww+ry20CWpi0Y1zWMuH e4mA7urwW4wZxhhq9F+vO/EvoqTzEm8WV6rCCqQAkBu/aex95LNtBm9v4dkxnQIjr835 ng5UBmAaEhqBVXxs7V/wvlkHRDmbDu5gkqWRRw7u1VaP8MQrV7bN5NYPcvkQ6qCh880q jWmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=2Yk8RzYixFVINwEFonEyEv8vKdd0UlOCwETIYwrK2OI=; fh=pE2uB+Pj5ycJqeAHmrQX21zOyGN5AMkM6doeLbKSOMs=; b=X5mxRkdl/TnhfOKiAR7+RrjDpsaNkts1zYpL+QMPa0+02ohFWq8iFxRLv377eeYNSi pNRgKZ3ZnZfz+kBztGN6/w07/455fNFmnbw94nP3NfCVEu9Ydbap5+eCw5vmh7G0ZJ6H g5HzFqHeG/ONQWHkfvJILaT7BC9UvhQDJ1K4nKk0MkW0yLTqkAQ/xelWNBpzacWVnNK5 HmeingAApDCE+VsVh6/NxnCF2/Yz7qCeoLG+jg3B3fFJxVxFJYuWQLNNsy5wtImSt8GR /QFF0lvL0wXpt8peUf6PnkPrCj8HfItlfRu/5VNk3qbXkQq+C3A+nAor0tjva8RBeS4n 0j+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id p2-20020a170902eac200b001cc1194e9d3si271545pld.217.2023.11.29.19.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 19:58:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 9B364801B39B; Wed, 29 Nov 2023 19:58:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231640AbjK3D61 (ORCPT + 99 others); Wed, 29 Nov 2023 22:58:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjK3D6Z (ORCPT ); Wed, 29 Nov 2023 22:58:25 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92C25D5C; Wed, 29 Nov 2023 19:58:31 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F3EB31042; Wed, 29 Nov 2023 19:59:17 -0800 (PST) Received: from [10.162.41.8] (a077893.blr.arm.com [10.162.41.8]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D6A143F5A1; Wed, 29 Nov 2023 19:58:26 -0800 (PST) Message-ID: Date: Thu, 30 Nov 2023 09:28:23 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [V14 3/8] drivers: perf: arm_pmuv3: Enable branch stack sampling framework Content-Language: en-US To: James Clark Cc: Mark Brown , Rob Herring , Marc Zyngier , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com References: <20231114051329.327572-1-anshuman.khandual@arm.com> <20231114051329.327572-4-anshuman.khandual@arm.com> <5f281bb8-9d74-041f-4311-6d68b5ee271d@arm.com> From: Anshuman Khandual In-Reply-To: <5f281bb8-9d74-041f-4311-6d68b5ee271d@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 19:58:43 -0800 (PST) On 11/14/23 22:40, James Clark wrote: > > On 14/11/2023 05:13, Anshuman Khandual wrote: > [...] >> diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c >> index d712a19e47ac..76f1376ae594 100644 >> --- a/drivers/perf/arm_pmu.c >> +++ b/drivers/perf/arm_pmu.c >> @@ -317,6 +317,15 @@ armpmu_del(struct perf_event *event, int flags) >> struct hw_perf_event *hwc = &event->hw; >> int idx = hwc->idx; >> >> + if (has_branch_stack(event)) { >> + WARN_ON_ONCE(!hw_events->brbe_users); >> + hw_events->brbe_users--; >> + if (!hw_events->brbe_users) { >> + hw_events->brbe_context = NULL; >> + hw_events->brbe_sample_type = 0; >> + } >> + } >> + >> armpmu_stop(event, PERF_EF_UPDATE); >> hw_events->events[idx] = NULL; >> armpmu->clear_event_idx(hw_events, event); >> @@ -333,6 +342,22 @@ armpmu_add(struct perf_event *event, int flags) >> struct hw_perf_event *hwc = &event->hw; >> int idx; >> >> + if (has_branch_stack(event)) { >> + /* >> + * Reset branch records buffer if a new task event gets >> + * scheduled on a PMU which might have existing records. >> + * Otherwise older branch records present in the buffer >> + * might leak into the new task event. >> + */ >> + if (event->ctx->task && hw_events->brbe_context != event->ctx) { >> + hw_events->brbe_context = event->ctx; >> + if (armpmu->branch_reset) >> + armpmu->branch_reset(); > What about a per-thread event following a per-cpu event? Doesn't that > also need to branch_reset()? If hw_events->brbe_context was already > previously assigned, once the per-thread event is switched in it skips > this reset following a per-cpu event on the same core. Right, guess it is real a possibility. How about folding in something like .. diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 76f1376ae594..15bb80823ae6 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -343,6 +343,22 @@ armpmu_add(struct perf_event *event, int flags) int idx; if (has_branch_stack(event)) { + /* + * Reset branch records buffer if a new CPU bound event + * gets scheduled on a PMU. Otherwise existing branch + * records present in the buffer might just leak into + * such events. + * + * Also reset current 'hw_events->brbe_context' because + * any previous task bound event now would have lost an + * opportunity for continuous branch records. + */ + if (!event->ctx->task) { + hw_events->brbe_context = NULL; + if (armpmu->branch_reset) + armpmu->branch_reset(); + } + /* * Reset branch records buffer if a new task event gets * scheduled on a PMU which might have existing records.