From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5BB2246A70; Fri, 27 Jun 2025 17:41:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 264B040697; Fri, 27 Jun 2025 17:41:27 +0200 (CEST) Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 436DC4068A for ; Fri, 27 Jun 2025 17:41:23 +0200 (CEST) Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55RD3V1o017955; Fri, 27 Jun 2025 08:41:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=x 9K5/r2Rz8U5GHncTvtFy0YEDsEnGB6fLM9aexgLTVA=; b=FHrUC9Sz3a94lMU1e 0138D/KoNmkLGEU6DBlgd5NH1rOH00AqXU9ih6dVAu3V/zGMAXbaLB2Hn6/xQ1z+ WRVLJkRvCvQq448VXlXc3MzXeSpMyUbT4mDphxZRRWUnz58eblMEmOkz6yY1Fg0H lKYJiUJdmzmgCMhDLaEcwD9xMNxvS2Z2zI9E3RZ3NuyqDnkIlQR7XgRR3B1XegP6 DjqVrYphAQSQfkM04w7RQst9w8Dx3O/cVoVMRU3ugucVlOw5Y5NfljnV0jn7zkSB wUh5NHwDkayWztzaw1Q1g92pORQESrFcIQ2KxwR54238qbeCpZD0jI2rq7rtfFz/ edGCQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 47hfxphykt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Jun 2025 08:41:22 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 27 Jun 2025 08:41:21 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 27 Jun 2025 08:41:21 -0700 Received: from cavium-optiplex-3070-BM15.. (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id 2B7DC3F705C; Fri, 27 Jun 2025 08:41:18 -0700 (PDT) From: Tomasz Duszynski To: CC: , , , , , Subject: [PATCH v7 3/8] lib/pmu: reimplement per-arch ops as callbacks Date: Fri, 27 Jun 2025 17:41:02 +0200 Message-ID: <20250627154107.3405768-4-tduszynski@marvell.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250627154107.3405768-1-tduszynski@marvell.com> References: <20250627105740.3388237-1-tduszynski@marvell.com> <20250627154107.3405768-1-tduszynski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjI3MDEyNyBTYWx0ZWRfX9yZ7U9cX0Tp9 1DCJby8CVt7sebrJtNsRzWHDr6PzGr1CKVI/fMB8BmC9bTKM7vV2HUyhpwfdq/+vZE2Q5BHLFvS 8a0GloieKymjqZUXxE8sVWhjdNIBpJxhuAFse3KNK9X7NCBW8e/vMaJZapgsJdHyjrZWnoo6qEX oCOgvKIaaly6P0Vjjl7rjVFmXshIIqBQpJ7rgJl+shfYXPmEMZXCoNJ9gyyh1+/c8epyUiSQbT2 HjF5ipH/KAy5k6s94N2kKVnMcuemGnedNFhsF2ypweHe4+Nmgn0gH9mka+Tqzp0jsauXZQkdT/y YlkEbITtzpBfXxF/66Rpkrn8nwOwTJCXt6yBF/fbpyAqtGVb4QEFRRP357xw/svXDsGRkdxWEcQ BYdC22g79hGCyl0YPYa7E4/+lwK7djpHTAE5jUMKyujUs3fX32FqZQpsaVqMZPimm92XAvfy X-Proofpoint-GUID: 1UzQg7TUPf4daT6XjJcdFBl6gbYLJ47y X-Proofpoint-ORIG-GUID: 1UzQg7TUPf4daT6XjJcdFBl6gbYLJ47y X-Authority-Analysis: v=2.4 cv=D/BHKuRj c=1 sm=1 tr=0 ts=685ebba2 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=6IFa9wvqVegA:10 a=M5GUcnROAAAA:8 a=C4pt3Q8vb_h7C6Lo94IA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-06-27_04,2025-06-26_05,2025-03-28_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Replace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend. Signed-off-by: Tomasz Duszynski --- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/lib/pmu/pmu.c b/lib/pmu/pmu.c index 46b0b450ac..0709f5e58c 100644 --- a/lib/pmu/pmu.c +++ b/lib/pmu/pmu.c @@ -40,22 +40,7 @@ struct rte_pmu_event { RTE_EXPORT_INTERNAL_SYMBOL(rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED) || defined(RTE_ARCH_X86_64) -int -pmu_arch_init(void) -{ - return 0; -} -void -pmu_arch_fini(void) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops; static int get_term_format(const char *name, int *num, uint64_t *mask) diff --git a/lib/pmu/pmu_arm64.c b/lib/pmu/pmu_arm64.c index a23f1864df..3f4f5fa297 100644 --- a/lib/pmu/pmu_arm64.c +++ b/lib/pmu/pmu_arm64.c @@ -62,8 +62,8 @@ write_attr_int(const char *path, int val) return 0; } -int -pmu_arch_init(void) +static int +pmu_arm64_init(void) { int ret; @@ -78,17 +78,24 @@ pmu_arch_init(void) return write_attr_int(PERF_USER_ACCESS_PATH, 1); } -void -pmu_arch_fini(void) +static void +pmu_arm64_fini(void) { write_attr_int(PERF_USER_ACCESS_PATH, restore_uaccess); } -void -pmu_arch_fixup_config(uint64_t config[3]) +static void +pmu_arm64_fixup_config(uint64_t config[3]) { /* select 64 bit counters */ config[1] |= RTE_BIT64(0); /* enable userspace access */ config[1] |= RTE_BIT64(1); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS(arm64_ops) diff --git a/lib/pmu/pmu_private.h b/lib/pmu/pmu_private.h index 3db1cb242b..d74f7f4092 100644 --- a/lib/pmu/pmu_private.h +++ b/lib/pmu/pmu_private.h @@ -5,20 +5,47 @@ #ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +/** + * Structure describing architecture specific PMU operations. + */ +struct pmu_arch_ops { + int (*init)(void); + void (*fini)(void); + void (*fixup_config)(uint64_t config[3]); +}; + +extern const struct pmu_arch_ops *arch_ops; + +#define PMU_SET_ARCH_OPS(ops) \ + RTE_INIT(libpmu_set_arch_ops) \ + { \ + arch_ops = &(ops); \ + } + /** * Architecture-specific PMU init callback. * * @return * 0 in case of success, negative value otherwise. */ -int -pmu_arch_init(void); +static inline int +pmu_arch_init(void) +{ + if (arch_ops != NULL && arch_ops->init != NULL) + return arch_ops->init(); + + return 0; +} /** * Architecture-specific PMU cleanup callback. */ -void -pmu_arch_fini(void); +static inline void +pmu_arch_fini(void) +{ + if (arch_ops != NULL && arch_ops->fini != NULL) + arch_ops->fini(); +} /** * Apply architecture-specific settings to config before passing it to syscall. @@ -27,7 +54,11 @@ pmu_arch_fini(void); * Architecture-specific event configuration. * Consult kernel sources for available options. */ -void -pmu_arch_fixup_config(uint64_t config[3]); +static inline void +pmu_arch_fixup_config(uint64_t config[3]) +{ + if (arch_ops != NULL && arch_ops->fixup_config != NULL) + arch_ops->fixup_config(config); +} #endif /* PMU_PRIVATE_H */ -- 2.34.1