Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5090111rwd; Sun, 4 Jun 2023 20:35:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kBYwC4Cmdmk02NUHhyp4tEMfz7HDeqPDf95Z+Y8leZ6tJbN3pmIRz1p2s120FsBoKCRB+ X-Received: by 2002:a05:6358:e48c:b0:127:afd3:b78f with SMTP id by12-20020a056358e48c00b00127afd3b78fmr25540617rwb.19.1685936129764; Sun, 04 Jun 2023 20:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685936129; cv=none; d=google.com; s=arc-20160816; b=GLMsi9kikbZ7uDxKt0KaEbiNworhYCvE2gRaGuTVtesu6BeWkgrRaOAJsZ+nxSDb3n bWCEyeSbjejCK4MDfkQEYZvbqk2uvP95uNQC873D5uf++AlclzQPxnzlhbmJaz1aTLqq 23YzO4LmqJrWgGTuF21r3zyKrD4extfnBhxthKvY0RS9ZNzt7THJAC3QS1k7c7QlUJQk 4P3mZiHjSO6sEMxrMyTJZytIgiNMCHVXJtPUPenPdFj2W64RbeXy77EfbpfHGz2ECT38 2MhdPgJeWwEfkzryu67P+e55beJwvjj98pyTKnsMtRWrVT2/q5G6Nsd0Ui+r7zz3eMOB 5JLA== 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=WyMlt6UoQIrI/7CFbyOTp/sV7qA9DN8R0cvmDXrnoLg=; b=vt4CJLBtdX9SYk4w+a7qHRtIoca5wxBML0ImUrJOxgcLlfposcdHfDuu6QJRPXAj0Q rPJ417d1bIIhAi4TD4VsJ2ZZ63NuBU9hfz1hPVUDf9zPoHkkqRxfIOHyXKZVitFTUzJC +HbVJcHjuZUsIRUrtOXyo3NExB8NKxTCqCCJ0AlDu4NL8farCKpL/v45MGdkdcHQ6RZ0 /OVa4qzhzKNNALi3Y2RAC8dNBcmd6uLgvnhf4QfxT0T4xqHlbOXpu3M7vkazw8S2sfLL V28pY1eEN5kb8UktNlQjmoiObbeD1o70Ciz0v/uCHZfhThh4/QS+pO2m8kHAMD0egBQb 1TSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a63d00b000000b00518f82d7053si4967695pgf.493.2023.06.04.20.35.17; Sun, 04 Jun 2023 20:35:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232607AbjFEDPC (ORCPT + 99 others); Sun, 4 Jun 2023 23:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232600AbjFEDO7 (ORCPT ); Sun, 4 Jun 2023 23:14:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 115FFA9; Sun, 4 Jun 2023 20:14:58 -0700 (PDT) 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 504A1D75; Sun, 4 Jun 2023 20:15:43 -0700 (PDT) Received: from [10.162.41.6] (a077893.blr.arm.com [10.162.41.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 45FE03F663; Sun, 4 Jun 2023 20:14:52 -0700 (PDT) Message-ID: Date: Mon, 5 Jun 2023 08:44:50 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH V11 08/10] arm64/perf: Add struct brbe_regset helper functions Content-Language: en-US To: Namhyung Kim Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@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 References: <20230531040428.501523-1-anshuman.khandual@arm.com> <20230531040428.501523-9-anshuman.khandual@arm.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/2/23 08:10, Namhyung Kim wrote: > On Tue, May 30, 2023 at 9:15 PM 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 >> --- > > [SNIP] >> + >> +static inline void copy_brbe_regset(struct brbe_regset *src, int src_idx, >> + struct brbe_regset *dst, int dst_idx) >> +{ >> + dst[dst_idx].brbinf = src[src_idx].brbinf; >> + dst[dst_idx].brbsrc = src[src_idx].brbsrc; >> + dst[dst_idx].brbtgt = src[src_idx].brbtgt; >> +} >> + >> +/* >> + * 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 reocords. Unless the live buffer is detetcted 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_total, nr_excess, nr_last, i; >> + >> + nr_total = nr_stored + nr_live; >> + nr_excess = nr_total - nr_max; >> + >> + /* Stored branch records in stitched buffer */ >> + if (nr_live == nr_max) >> + nr_stored = 0; >> + else if (nr_excess > 0) >> + nr_stored -= nr_excess; >> + >> + /* Stitched buffer branch records length */ >> + if (nr_total > nr_max) >> + nr_last = nr_max; >> + else >> + nr_last = nr_total; >> + >> + /* Move stored branch records */ >> + for (i = 0; i < nr_stored; i++) >> + copy_brbe_regset(stored, i, stored, nr_last - nr_stored - 1 + i); > > I'm afraid it can overwrite some entries if nr_live is small > and nr_stored is big. Why not use memmove()? nr_stored is first adjusted with nr_excess if both live and stored entries combined exceed the maximum branch records in the HW. I am wondering how it can override ? > > Also I think it'd be simpler if you copy store to live. > It'll save copying live in the IRQ but it will copy the > whole content to store again for the sched switch. But how that is better than the current scheme ?