Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6384758rwd; Mon, 5 Jun 2023 17:55:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6MrLBRAegg0RRll018LVpUoP6Oz6gr2BpTKhxgIi1Fnf+gJ1q6EzRouiS/A++WH+nI0SJa X-Received: by 2002:a05:6870:8804:b0:19f:14a7:b5f5 with SMTP id n4-20020a056870880400b0019f14a7b5f5mr635993oam.18.1686012926019; Mon, 05 Jun 2023 17:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686012925; cv=none; d=google.com; s=arc-20160816; b=lbcen+kSO6mlknw6t5NJ/xhcJ6QmJQQ/Q2Wpg5l0yXqTQbaNaZJb18qis+LLE0vDBJ 9th7ZX+Pt6cw2nwJWx9Dzcx7fO+YifZn0SqJ6cRLa2u0UAmGD/jagUH5ql8qGli+KqUs SE0O15RNMKYrwnx0LcyZgSfceSHtf6yg3BF6Sssri7GA24nt2O6v2jCYR3MtXZLmoObk Jkf71Y+EzJWJewYxAW9txeKyAA1cKWm9KeZfe9EONWTSAYGbB1RIEMA5RjqiVHIDdNXr GgqbAr5X1pBjTdyZj0vS30AZU8QxePi6Nt1kYj9HVQaHuuP2EnaSp33ETUVIMZVeRQ+J AcJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=dlErdsND5IUqaRyiwQrIkx4Lw2unyX0BKHF40RtKB/Q=; b=qrOPEcWR4AGDTybW/OW9vApe3UKamtDolNEMmIuSNGHPEN2R7TsztywLLZlYro8SEG ZKJW0g6WuKFAGJ9/ePlwEYyji7LdWZavK3pInVVFIP1pAANy59cxdUXKSOi7HKLXC0lc 67lKSHF37P95JwyikELfOQ8q6rA0ZkX3tHUysSKICRq6mwH/8xY1MUfNSjokKcB7LObs F4FwrdKC58yOn9+hQ3XbO02e7QWyd6Sy7cwW4w+F4bwaF1e9D2ZFfjg9K+zAU8c8Xvj8 6qpwhwMuQlJ1GTDYRDLBK/RSKLhfd6wtogF/hF+yp3Tc5bgFv/VwvGWZFWrpisbEDBoB moWA== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10-20020a633e0a000000b0053fd39c7f6csi6264169pga.646.2023.06.05.17.55.12; Mon, 05 Jun 2023 17:55:25 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjFEXt3 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Jun 2023 19:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjFEXt1 (ORCPT ); Mon, 5 Jun 2023 19:49:27 -0400 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85B6CEC; Mon, 5 Jun 2023 16:49:26 -0700 (PDT) Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-bad102ce9eeso6052893276.0; Mon, 05 Jun 2023 16:49:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686008965; x=1688600965; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yY5d/V8MfrMaTZ9YnTPCdi3pO6uRZ4QgR85u/BK5vQ8=; b=IJx6+gdTbz1Va3yGo3fNO5DinNs9XWr6SR7m63cid3lS1BmYpivzyF4B0+ljd9CGwd 0rUfXcY3YAKNplQgyrYH7RGzSAQrgW8mYudiTcHksWQvSQgodhJqK73el5XirQwBYYiA mBY/5m+tud1v/dffbpzlaO955VzTSiZ5CJx8Phnz9BanHgkHdbqc7lOwyVWdUrre8Z2I bQJET0JWLxieYItPeGVo5GRChD/G+PUIx7jkru8Pjrlne7cepciH+TllrQfhQnZ5Yny3 bWQH7an3vFFz3sGEsDB5MJGxm+ZjApLKtfZd5XRZVrpeXml+HGzaGaKntYr4ETxf88Xo C2sg== X-Gm-Message-State: AC+VfDyQedfNZYIuzdg/lL96FMIftJYCTcCR4MmiqWL0RibOvB3Q+GHT +J+XmhgLuP5F7t1H8E1Jxop5lwj3Qx2r5vTyu14= X-Received: by 2002:a25:2fd7:0:b0:bad:74d:f9ed with SMTP id v206-20020a252fd7000000b00bad074df9edmr156488ybv.2.1686008965638; Mon, 05 Jun 2023 16:49:25 -0700 (PDT) MIME-Version: 1.0 References: <20230531040428.501523-1-anshuman.khandual@arm.com> <20230531040428.501523-9-anshuman.khandual@arm.com> In-Reply-To: From: Namhyung Kim Date: Mon, 5 Jun 2023 16:49:14 -0700 Message-ID: Subject: Re: [PATCH V11 08/10] arm64/perf: Add struct brbe_regset helper functions To: Anshuman Khandual 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Sun, Jun 4, 2023 at 8:15 PM Anshuman Khandual wrote: > > > > 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 ? Say nr_stored = 40 and nr_live = 20, wouldn't it copy stored[0] to stored[20]? Then stored[20:39] will be lost. Also I'm not sure "-1" is correct. > > > > > 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 ? I guess normally the live buffer is full, then it can skip the copy and use the buffer directly for IRQ, right? Thanks, Namhyung