Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3557915imw; Mon, 18 Jul 2022 10:10:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vEA2x6sZlnmcPVd5DSBw2elRJ6dxoebiU9JiMNsHZbSxu+iCnIUElCV50WoqQ5AEhVTruE X-Received: by 2002:a17:906:6a0a:b0:72b:60b8:d2e7 with SMTP id qw10-20020a1709066a0a00b0072b60b8d2e7mr25259163ejc.607.1658164245814; Mon, 18 Jul 2022 10:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658164245; cv=none; d=google.com; s=arc-20160816; b=KmGJA5D9kKPdO/sRGaujTlYXom054TWjSY8nBoQ81bnpnFZTktuFJgC+He+wa938IA X/tJUg8kAkM0wsxEI5VfPrqOHgx5h1m0I0ppaanL0LiqHyyf8mQSAG7VtrL9KBqDxJAy +grjHg3hEWf/iKI43Lf4FwKAua+MxvvBZqOZpm+XaI3W26+XcaoIQ5ARMF7AE3YLwVkY atvHdiUsLIVKaCXfgrP4sL/v6GopP4Yv1+MZXbqrFtZ7u1yankOOmwKXbyoYhzXdIMwD 7RiCfKQW7xpThA97l7sZ6+hYfR1y/vJPcU59ku6sqAw2/JlYuWL+1VvsL38kqqoI8Mxc R05g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H7ChdRBKS+9A003EiQbM2SMDrKCCYQePnInXhSsyMB0=; b=CBNMH7IfSG/6rPSM2fqeJiAjC6d9a6ladiYvdRI4J3RM3MFdbfCzlLjMf8YAFkMqEA /+A99IVr/ii68ReoxAfAJM9vgtUxwt+Uxx7Mtp3SW95q+jkrlWojlAzKaWClMGyvs4Ny MHv1ZbUkDTAlhK1XgrR7N8NDS2m3+FXS8dv5WZU7q0vX9IhPF5Onne+gqVNYYIEju0oU TMFeI+4hOnkZBeVReSaMqlBg04pRArswO8eUSSXz171ytZ0zT8wY/4VevmbsNJIAJL6G PXTne28bMBF0CAqvunBJsGz7GTRvSlscYjcgEWtfwkHZOXFULbFfJrpHxrRxJsbmasbS rU1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=2V7H54kc; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf28-20020a1709077f1c00b00722e1c6efe2si14780502ejc.426.2022.07.18.10.10.20; Mon, 18 Jul 2022 10:10:45 -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=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=2V7H54kc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235040AbiGRRFw (ORCPT + 99 others); Mon, 18 Jul 2022 13:05:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235625AbiGRRFr (ORCPT ); Mon, 18 Jul 2022 13:05:47 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACF192BB1A for ; Mon, 18 Jul 2022 10:05:46 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id b10so1434286pjq.5 for ; Mon, 18 Jul 2022 10:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H7ChdRBKS+9A003EiQbM2SMDrKCCYQePnInXhSsyMB0=; b=2V7H54kc+3zNv1TcuveEZhkWNgIt1ocwR1qZtOLzfciyvULmAUYAVdSYvDM/LMqPW7 B2K1L+wSiEDZFuMDMucw3/YkGg89OijRh8dtnIplDxavoLr+HLhF1RSyQXxCnRG/72Tf KHeNwRoBhGw0rXQdnYIWadk5aSrZwLj7I/0cV0ZkgQrHx0ezw5iLQkZg1Uak7Z5I0sqE qFLiHdxohtP+MR29CMLuGTlZRid3ndTvwyv2IFhPeeJPuBbWKdNqbpz4KKb8bRDh9SWd v8nTz6wqG+l9bP6qNs15D6dX6qH+nOrr4SmzAUcKI22h5JluwKsyWFI5ud4IQSpY+eeR W4Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H7ChdRBKS+9A003EiQbM2SMDrKCCYQePnInXhSsyMB0=; b=GKI0/4YhsEzxmyf0Q4K+6QBAOn5EKlLnj50/8Zw9s6RXatvjYOSSRBMxpA7X+9hci3 H1z8mmNki8qn6BTjBaOJsHtuK7S1CF8831HKnT5qcnrDDdzpxZxST680SE7lU0FsLG1L C2WF11/pFj3gyzmHNoqG7oTg6oSncToKY+L36i67yaPfUOo0e88Kl/3ksimCmbcyIM9Z n8cBG/kviOUW/aqeKQccPE0uee0nELvydBsi112xKzQq3BAaoOuBpSjOj0ZaMr1KSw3m GdSbDG/TXJ4K2Fjdxp2wVO1g99+/JkcYC3gLRAAzay3YYb+nGYETdCDdM8olbuojh7oA txBQ== X-Gm-Message-State: AJIora/ci7AhZqlZD4t1DInUtQWmrHozhiHSxT5HCFVrhd/5kim/R3rQ 4ZQKyqYJPO6ZmQg+oM3/pMDbmer0iGpiQQ== X-Received: by 2002:a17:902:a413:b0:156:15b:524a with SMTP id p19-20020a170902a41300b00156015b524amr30012463plq.106.1658163945893; Mon, 18 Jul 2022 10:05:45 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id r10-20020a170902be0a00b0016bc947c5b7sm9733402pls.38.2022.07.18.10.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 10:05:45 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Anup Patel , Atish Patra , Guo Ren , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: [RFC 2/9] RISC-V: Define a helper function to return counter width Date: Mon, 18 Jul 2022 10:01:58 -0700 Message-Id: <20220718170205.2972215-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718170205.2972215-1-atishp@rivosinc.com> References: <20220718170205.2972215-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 The virtual hardware counters need to have the same width as the logical hardware counters for simplicity. However, there shouldn't be mapping between virtual hardware counters and logical hardware counters. As we don't support hetergeneous harts or counters with different width as of now, the implementation relies on the counter width of the first available programmable counter. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 25 +++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 1723af68ffa1..5d0eef3ef136 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -250,6 +250,31 @@ static bool pmu_sbi_ctr_is_fw(int cidx) return (info->type == SBI_PMU_CTR_TYPE_FW) ? true : false; } +/* + * Returns the counter width of a programmable counter + * As we don't support heterneous CPUs yet, it is okay to just + * return the counter width of the first programmable counter. + */ +int riscv_pmu_sbi_hpmc_width(void) +{ + int i; + union sbi_pmu_ctr_info *info; + + if (!rvpmu) + return -EINVAL; + + for (i = 0; i < rvpmu->num_counters; i++) { + info = &pmu_ctr_list[i]; + if (!info) + continue; + if (info->type == SBI_PMU_CTR_TYPE_HW) + return info->width; + } + + return 0; +} +EXPORT_SYMBOL(riscv_pmu_sbi_hpmc_width); + static int pmu_sbi_ctr_get_idx(struct perf_event *event) { struct hw_perf_event *hwc = &event->hw; diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h index fc47167e000c..6fee211c27b5 100644 --- a/include/linux/perf/riscv_pmu.h +++ b/include/linux/perf/riscv_pmu.h @@ -72,6 +72,7 @@ static inline void riscv_pmu_legacy_skip_init(void) {}; struct riscv_pmu *riscv_pmu_alloc(void); #ifdef CONFIG_RISCV_PMU_SBI int riscv_pmu_sbi_get_num_hw_ctrs(void); +int riscv_pmu_sbi_hpmc_width(void); #endif #endif /* CONFIG_RISCV_PMU */ -- 2.25.1