From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14546EB64D7 for ; Wed, 21 Jun 2023 13:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gSqpsatc/zLY4dwDwlzKmGUHN5T3I+nt+/EtmygcTSg=; b=WLPTbzZoatNsAV VNikIbJ2z4jz9/8IRCPyUG1FlYAqfDt0XMlOm7S/k1jjmaXn6QdzQcAyoY1CFtvir9XHBk73i9eNM V+VhHjgWomy8Vb5j4nl57cDIRbHVuGPtSB0ABE5PQWNfhPEjr0BekHhKXMjAwwr1kqk5jLWXEerub lAqp6R4MtzZFA9hgCsa6mNJmuISzEI3UwXLumz2Czx1pyLCTEsui0j+8qQQOh96l2dEFbhLlylMvN aJ10xYacE7Fxv/A4DkzcJJHLdBXTeoyI7pZMXjqbXuuajKfdT9d3HDLYlPnofJ4oBiyDOTb43b2Ro aYRBu7YYGn18EjK5Op+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBxgF-00EeQA-1R; Wed, 21 Jun 2023 13:15:27 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBxgB-00EeOa-1C for linux-arm-kernel@lists.infradead.org; Wed, 21 Jun 2023 13:15:25 +0000 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 F12081042; Wed, 21 Jun 2023 06:16:04 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.27.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAF0C3F64C; Wed, 21 Jun 2023 06:15:18 -0700 (PDT) Date: Wed, 21 Jun 2023 14:15:15 +0100 From: Mark Rutland To: Anshuman Khandual Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, Mark Brown , James Clark , Rob Herring , Marc Zyngier , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org Subject: Re: [PATCH V12 08/10] arm64/perf: Add struct brbe_regset helper functions Message-ID: References: <20230615133239.442736-1-anshuman.khandual@arm.com> <20230615133239.442736-9-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230615133239.442736-9-anshuman.khandual@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230621_061523_525679_21DA633A X-CRM114-Status: GOOD ( 35.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Anshuman, Thanks, this is looking much better; I just a have a couple of minor comments. With those fixed up: Acked-by: Mark Rutland Mark. On Thu, Jun 15, 2023 at 07:02:37PM +0530, Anshuman Khandual wrote: > The primary abstraction level for fetching branch records from BRBE HW has > been changed as 'struct brbe_regset', which contains storage for all three > BRBE registers i.e BRBSRC, BRBTGT, BRBINF. Whether branch record processing > happens in the task sched out path, or in the PMU IRQ handling path, these > registers need to be extracted from the HW. Afterwards both live and stored > sets need to be stitched together to create final branch records set. This > adds required helper functions for such operations. > > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Mark Rutland > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Tested-by: James Clark > Signed-off-by: Anshuman Khandual > --- > drivers/perf/arm_brbe.c | 127 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 127 insertions(+) > > diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c > index 4729cb49282b..f6693699fade 100644 > --- a/drivers/perf/arm_brbe.c > +++ b/drivers/perf/arm_brbe.c > @@ -44,6 +44,133 @@ static void select_brbe_bank(int bank) > isb(); > } > > +static bool __read_brbe_regset(struct brbe_regset *entry, int idx) > +{ > + entry->brbinf = get_brbinf_reg(idx); > + > + /* > + * There are no valid entries anymore on the buffer. > + * Abort the branch record processing to save some > + * cycles and also reduce the capture/process load > + * for the user space as well. > + */ This comment refers to the process of handling multiple entries, though it's only handling one entry, and I don't think we need to mention saving cycles here. Could we please delete this comment entirely? The comment above capture_brbe_regset() already explains that we read until the first invalid entry. > + if (brbe_invalid(entry->brbinf)) > + return false; > + > + entry->brbsrc = get_brbsrc_reg(idx); > + entry->brbtgt = get_brbtgt_reg(idx); > + return true; > +} > + > +/* > + * This scans over BRBE register banks and captures individual branch records > + * [BRBSRC, BRBTGT, BRBINF] into a pre-allocated 'struct brbe_regset' buffer, > + * until an invalid one gets encountered. The caller for this function needs > + * to ensure BRBE is an appropriate state before the records can be captured. > + */ Could we simplify this to: /* * Read all BRBE entries in HW until the first invalid entry. * * The caller must ensure that the BRBE is not concurrently modifying these * entries. */ > +static int capture_brbe_regset(int nr_hw_entries, struct brbe_regset *buf) > +{ > + int idx = 0; > + > + select_brbe_bank(BRBE_BANK_IDX_0); > + while (idx < nr_hw_entries && idx < BRBE_BANK0_IDX_MAX) { > + if (!__read_brbe_regset(&buf[idx], idx)) > + return idx; > + idx++; > + } > + > + select_brbe_bank(BRBE_BANK_IDX_1); > + while (idx < nr_hw_entries && idx < BRBE_BANK1_IDX_MAX) { > + if (!__read_brbe_regset(&buf[idx], idx)) > + return idx; > + idx++; > + } > + return idx; > +} > + > +/* > + * This function concatenates branch records from stored and live buffer > + * up to maximum nr_max records and the stored buffer holds the resultant > + * buffer. The concatenated buffer contains all the branch records from > + * the live buffer but might contain some from stored buffer considering > + * the maximum combined length does not exceed 'nr_max'. > + * > + * Stored records Live records > + * ------------------------------------------------^ > + * | S0 | L0 | Newest | > + * --------------------------------- | > + * | S1 | L1 | | > + * --------------------------------- | > + * | S2 | L2 | | > + * --------------------------------- | > + * | S3 | L3 | | > + * --------------------------------- | > + * | S4 | L4 | nr_max > + * --------------------------------- | > + * | | L5 | | > + * --------------------------------- | > + * | | L6 | | > + * --------------------------------- | > + * | | L7 | | > + * --------------------------------- | > + * | | | | > + * --------------------------------- | > + * | | | Oldest | > + * ------------------------------------------------V > + * > + * > + * S0 is the newest in the stored records, where as L7 is the oldest in > + * the live records. Unless the live buffer is detected as being full > + * thus potentially dropping off some older records, L7 and S0 records > + * are contiguous in time for a user task context. The stitched buffer > + * here represents maximum possible branch records, contiguous in time. > + * > + * Stored records Live records > + * ------------------------------------------------^ > + * | L0 | L0 | Newest | > + * --------------------------------- | > + * | L0 | L1 | | > + * --------------------------------- | > + * | L2 | L2 | | > + * --------------------------------- | > + * | L3 | L3 | | > + * --------------------------------- | > + * | L4 | L4 | nr_max > + * --------------------------------- | > + * | L5 | L5 | | > + * --------------------------------- | > + * | L6 | L6 | | > + * --------------------------------- | > + * | L7 | L7 | | > + * --------------------------------- | > + * | S0 | | | > + * --------------------------------- | > + * | S1 | | Oldest | > + * ------------------------------------------------V > + * | S2 | <----| > + * ----------------- | > + * | S3 | <----| Dropped off after nr_max > + * ----------------- | > + * | S4 | <----| > + * ----------------- > + */ > +static int stitch_stored_live_entries(struct brbe_regset *stored, > + struct brbe_regset *live, > + int nr_stored, int nr_live, > + int nr_max) > +{ > + int nr_move = min(nr_stored, nr_max - nr_live); > + > + /* Move the tail of the buffer to make room for the new entries */ > + memmove(&stored[nr_live], &stored[0], nr_move * sizeof(*stored)); > + > + /* Copy the new entries into the head of the buffer */ > + memcpy(&stored[0], &live[0], nr_live * sizeof(*stored)); > + > + /* Return the number of entries in the stitched buffer */ > + return min(nr_live + nr_stored, nr_max); > +} > + > /* > * Generic perf branch filters supported on BRBE > * > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel