Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1354327rwo; Wed, 2 Aug 2023 12:38:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlHVznul57AloqjzRdMmDrWwL5ZthjaP5lxDKs3/CtuByPPfA7f9qAN9PFqegYmwZSiqjOUu X-Received: by 2002:a05:6a00:13a8:b0:687:3f06:5939 with SMTP id t40-20020a056a0013a800b006873f065939mr11008877pfg.32.1691005119744; Wed, 02 Aug 2023 12:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691005119; cv=none; d=google.com; s=arc-20160816; b=w6w2DXYJZOAGNI0oP4c4h7AOLvDKGJBfxUeHfP0oyIgar+UyzIKb0KAjAhaIkryWJs rlRUEq8m9nzVOJhKgMand8UnnIpwMcaw2Up4ULxTvew0fj4y1aqlg7Ucip90wfWuUs1N Xcompd2UAENl+0F48DfbezNG5uRrVPTWHKh2dF0JoZ+2iBWeGy81+yZqUtbjWmWYz64l RPac+zSi53y4RguPzVCX6iZeZ6fX9dCJ2AHM4PUKYjb3MQGLBdNwDCtHhha0XP0FIs4Y TZgOfRGNhVUcToB8wYyuKuNF2drBnkfjmVpHLPOG9TAk3F/CcJm4mKc/FEZsTY4qmw+S 0Yjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=KmDdWGcGQmmIRGCW7EcGq6nijhDR44vxgYgqFUIflus=; fh=HDytX8ftdAnxyb0A5Lu5FUBCGn+FKIvGrC4jgt21OHw=; b=ZVUTiO9T6rICpY69mQuEHGJXVrohjRlOHK/6zBEY9jlRRvPrFAVG7D8drMJZBjK0qe YzrZEupUmM4LiS5ojC8u6udehND4rvNxstTs/P0zph5q9eBN+6RP7GwGIpJkEgcve+ZU jcZWqoGTPSbMOqm2nVFa7bN1jikeme8ZKjzo3TkLErT1fKk4IR7gyAoMVlPLxENAcr0K RY8YpAKLyWikNEeFuxWe0CUxUY6ZSfIMDmT6ge0v2tONPeTcRCkymZnQ8p9+aB7bgqIU CkosG3MeBdXsuOs2SleGFUbZhTN6mUDf/0OXBmcnoCO7zNhwe1kCjSuDjbsijWk5uwk8 2lwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Tnffh/Sx"; 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 s80-20020a632c53000000b00563e6fb302fsi11137976pgs.725.2023.08.02.12.38.27; Wed, 02 Aug 2023 12:38:39 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Tnffh/Sx"; 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 S231833AbjHBTQd (ORCPT + 99 others); Wed, 2 Aug 2023 15:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjHBTQb (ORCPT ); Wed, 2 Aug 2023 15:16:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03545E7D; Wed, 2 Aug 2023 12:16:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 73C2B61ADB; Wed, 2 Aug 2023 19:16:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE9D8C433C8; Wed, 2 Aug 2023 19:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691003789; bh=XBtPzjHQlXNIEQFLxSA/ttht8PBVws+eh+Spm9Nkkoo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Tnffh/SxD2Pjn+liTTmM1Pvc2lh1VRW6FzrlIqRiNgNSaC5W+VxiiYVzIISQ2Q6kO Gscg6nPQ3PIPDBk4PTi24qW6Y45kUbIA/fKa+sglBgFHYPwVxtmZAFNPLrLBhZ54ih od5C4emkLRQ5qa2W+Y/KaOY0L31r8affvuO6j1j1OEQMcZ5Y4dEoqZ+KZAL332oHPL gfWJCa6CCVTJAOfCYQDWfIx5Id/0KcgtqyKqOvgMtJbko4sLlP8gxBZopaqcE9xO/8 KETQ/yBbUDD+lHfyE32XFHLQGGRCevdmBvyvxti1LshHX5xhkgRRqwBdGIH49F+8vO +Igzi7c09aB5A== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qRHKd-001T2k-Ap; Wed, 02 Aug 2023 20:16:27 +0100 Date: Wed, 02 Aug 2023 20:16:17 +0100 Message-ID: <86il9x5k72.wl-maz@kernel.org> From: Marc Zyngier To: Rajnesh Kanwal Cc: anshuman.khandual@arm.com, acme@kernel.org, broonie@kernel.org, catalin.marinas@arm.com, james.clark@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mark.rutland@arm.com, mingo@redhat.com, peterz@infradead.org, robh@kernel.org, suzuki.poulose@arm.com, will@kernel.org, atishp@rivosinc.com Subject: Re: [PATCH V13 - RESEND 09/10] arm64/perf: Implement branch records save on task sched out In-Reply-To: <20230802115931.12212-1-rkanwal@rivosinc.com> References: <20230711082455.215983-10-anshuman.khandual@arm.com> <20230802115931.12212-1-rkanwal@rivosinc.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: rkanwal@rivosinc.com, anshuman.khandual@arm.com, acme@kernel.org, broonie@kernel.org, catalin.marinas@arm.com, james.clark@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mark.rutland@arm.com, mingo@redhat.com, peterz@infradead.org, robh@kernel.org, suzuki.poulose@arm.com, will@kernel.org, atishp@rivosinc.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 Wed, 02 Aug 2023 12:59:31 +0100, Rajnesh Kanwal wrote: > > >diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c > >index 203cd4f350d5..2177632befa6 100644 > >--- a/drivers/perf/arm_brbe.c > >+++ b/drivers/perf/arm_brbe.c > >@@ -165,6 +165,36 @@ static int stitch_stored_live_entries(struct brbe_regset *stored, > > return min(nr_live + nr_stored, nr_max); > > } > > > >+static int brbe_branch_save(struct brbe_regset *live, int nr_hw_entries) > >+{ > >+ u64 brbfcr = read_sysreg_s(SYS_BRBFCR_EL1); > >+ int nr_live; > >+ > >+ write_sysreg_s(brbfcr | BRBFCR_EL1_PAUSED, SYS_BRBFCR_EL1); > >+ isb(); > >+ > >+ nr_live = capture_brbe_regset(live, nr_hw_entries); > >+ > >+ write_sysreg_s(brbfcr & ~BRBFCR_EL1_PAUSED, SYS_BRBFCR_EL1); > >+ isb(); > >+ > >+ return nr_live; > >+} > >+ > >+void armv8pmu_branch_save(struct arm_pmu *arm_pmu, void *ctx) > >+{ > >+ struct arm64_perf_task_context *task_ctx = ctx; > >+ struct brbe_regset live[BRBE_MAX_ENTRIES]; > >+ int nr_live, nr_store, nr_hw_entries; > >+ > >+ nr_hw_entries = brbe_get_numrec(arm_pmu->reg_brbidr); > >+ nr_live = brbe_branch_save(live, nr_hw_entries); > >+ nr_store = task_ctx->nr_brbe_records; > >+ nr_store = stitch_stored_live_entries(task_ctx->store, live, nr_store, > >+ nr_live, nr_hw_entries); > >+ task_ctx->nr_brbe_records = nr_store; > >+} > > Asking out-of-curiosity. Have you thought about virtualization use > case. Current LBR implementation create an event for the guest > and save/restore happens using the sched_task callback. (Correct me > if I am wrong). Given you are only saving and processing those saved > entries, how do you plan to expose the entries to the guest? Two possibilities: - either we perform a full save/restore of the registers so that host and guest have isolated states - or we trap all BRBE accesses and piggy-back on the perf framework for that, much like we already do for the PMU. M. -- Without deviation from the norm, progress is not possible.