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 28593C00528 for ; Wed, 2 Aug 2023 12:00:05 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7q7NyuZDY8zLbtQc3f+y1tcrlmIRV5dMyc4yaCZwZyM=; b=xoOh/wseI5sv0p WePu/1fcO8eoaAD5HzTbGOQ0N71/iXvNQknE7NeXvO0EJ1RplEvT97mHY/MHl/aGuYmT5v4ikSrCn Ej+sU2mQ2yyNpHNu770sqFSCcbKihCWHzW667cKIRVHKDAMFWHlesmOTSMDqbtsNBtE3Mdo+Ymqz7 9+RWwMeGJeY1o+FfsQ0cx8DBcGr6Rydp1fbCgPkOho+o2ssdjLa3v25BQ2qDEmyHyaWZmLmkG/zPo 3lcnXhpTEIyTw3SNXtN/1CtF007h3v/R57OSZlY4IClA1vC5fvWflzDvVPGcmc2/MqCYLPRTZOZJw q83JaZdUrARJ6UW8uj1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRAVu-004r5H-1l; Wed, 02 Aug 2023 11:59:38 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRAVr-004r4d-1K for linux-arm-kernel@lists.infradead.org; Wed, 02 Aug 2023 11:59:37 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso72273155e9.0 for ; Wed, 02 Aug 2023 04:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690977572; x=1691582372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bp5xBL2+ZyetnS6R/9E4VPAMDlUiJg//neyQGE8mAn8=; b=xDAla6uTyC2qwpkOA3lcBp7p6CRW+qzxhUfu1bcdl5YZMnW/kZWFZUfpHkBNzYsxG8 R2NU+tBQ5sqURKvVW/500rdx4qZ+X0OS2T5IDCA5BwmV+yU+Y+3m6RIhb+jwCWsRtugA Pgz4cv4ld7P74eDFrQMLH0h4Y0tRzDW4G+HrTqoHurHdZhFu0lgntnigIkxnpVXMOqia sz06gmuwQaDPzlMjBk9vlIkNaJIudhLZiY/rDt7Gerx2BJpW16ZphJ9cv5TcIisOkByx WFS1ZFbfbw2W55BXL2yTBQBFwIG71MldYmUpZp5dpY6MYkkmXIhbYYTynVx5KyYo6oyM fcfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690977572; x=1691582372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bp5xBL2+ZyetnS6R/9E4VPAMDlUiJg//neyQGE8mAn8=; b=afEWoLzj1gz+8T49NXR1UtFKBiXhswUrDvoKH0xegYy6Rjl6S9l56rTNeo/gml7RUh ffQmKAlKToKBdCJ/fLvtJsBWoDPLDxpVjamL5gqa+vaz3A6/4lw4R8SQbbj0g1185KJx ODr923rkXuHcgW+T5lFAq5querX1LeiD21BFWLfIT1m10CJN96HcOvx11N6C1CN3XjZ3 MBlmSa2dg3scQJmXvD9QNHy+B6esBwCDyfxzVGrU8vSSvKz7GdPyUV1gDKP/ml2H4hmg q1ORycQ7IBZ3eq5ExKSsKO11YHqvgZ3Oc/G6WzvtiVrE5tYu8MDKXf3sk0VwPiabXMvU R62g== X-Gm-Message-State: ABy/qLasp9xlNgOQaxTHD66s8cb7LMjXFlA9S96i6mdK7BU0h7tPAWFE 5G/oGsW/QouUiAcTHNMhM27d7A== X-Google-Smtp-Source: APBJJlHXTDoc9PC8kQ7qJTabUhxGNnHLykNg77MkUglnWffppm7AHP8+coyKULDEiciGu67SwJb4NA== X-Received: by 2002:a05:600c:219a:b0:3fe:2108:eb8e with SMTP id e26-20020a05600c219a00b003fe2108eb8emr4601718wme.34.1690977572714; Wed, 02 Aug 2023 04:59:32 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id n16-20020a1c7210000000b003fe1630a8f0sm1502871wmc.24.2023.08.02.04.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 04:59:32 -0700 (PDT) From: Rajnesh Kanwal To: anshuman.khandual@arm.com Cc: 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, maz@kernel.org, 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 Date: Wed, 2 Aug 2023 12:59:31 +0100 Message-Id: <20230802115931.12212-1-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711082455.215983-10-anshuman.khandual@arm.com> References: <20230711082455.215983-10-anshuman.khandual@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230802_045935_667847_24E8833F X-CRM114-Status: GOOD ( 10.89 ) 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 >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? Thanks Rajnesh >+ > /* > * Generic perf branch filters supported on BRBE > * >diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c >index 408974d5c57b..aa3c7b3dcdd6 100644 >--- a/drivers/perf/arm_pmuv3.c >+++ b/drivers/perf/arm_pmuv3.c >@@ -923,9 +923,19 @@ static int armv8pmu_user_event_idx(struct perf_event *event) > static void armv8pmu_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in) > { > struct arm_pmu *armpmu = to_arm_pmu(pmu_ctx->pmu); >+ void *task_ctx = pmu_ctx ? pmu_ctx->task_ctx_data : NULL; > >- if (sched_in && armpmu->has_branch_stack) >- armv8pmu_branch_reset(); >+ if (armpmu->has_branch_stack) { >+ /* Save branch records in task_ctx on sched out */ >+ if (task_ctx && !sched_in) { >+ armv8pmu_branch_save(armpmu, task_ctx); >+ return; >+ } >+ >+ /* Reset branch records on sched in */ >+ if (sched_in) >+ armv8pmu_branch_reset(); >+ } > } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel