From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (xvm-189-124.dc0.ghst.net [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EAB0DA0524; Fri, 8 Jan 2021 18:42:42 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2B218140F02; Fri, 8 Jan 2021 18:42:28 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id C302F140E92 for ; Fri, 8 Jan 2021 18:42:26 +0100 (CET) IronPort-SDR: uPClQ6pIKlxoGRIz+SqGyGMD864LDCB3+PQRQBApjk3F/3gKULFb1h2Tm1rO7M9QrHfjTL23dg /h4OnRpThVqA== X-IronPort-AV: E=McAfee;i="6000,8403,9858"; a="175049945" X-IronPort-AV: E=Sophos;i="5.79,332,1602572400"; d="scan'208";a="175049945" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2021 09:42:26 -0800 IronPort-SDR: jlrJIyysWcGMOtExCZx1/FIe6v1StCkjTsK/Z9vi0h2LsCxltsHWf7XlCiJlWs+0Y2pvNSW+Jr 2CS+Y2n0gAhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,332,1602572400"; d="scan'208";a="396368011" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.222.179]) by fmsmga004.fm.intel.com with ESMTP; 08 Jan 2021 09:42:23 -0800 From: Anatoly Burakov To: dev@dpdk.org Cc: Timothy McDaniel , Jan Viktorin , Ruifeng Wang , Jerin Jacob , David Christensen , Bruce Richardson , Konstantin Ananyev , thomas@monjalon.net, gage.eads@intel.com, david.hunt@intel.com, chris.macnamara@intel.com Date: Fri, 8 Jan 2021 17:42:06 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v13 03/11] eal: change API of power intrinsics 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 Sender: "dev" Instead of passing around pointers and integers, collect everything into struct. This makes API design around these intrinsics much easier. Signed-off-by: Anatoly Burakov --- drivers/event/dlb/dlb.c | 10 ++-- drivers/event/dlb2/dlb2.c | 10 ++-- .../arm/include/rte_power_intrinsics.h | 20 +++----- .../include/generic/rte_power_intrinsics.h | 49 ++++++++----------- .../ppc/include/rte_power_intrinsics.h | 20 +++----- lib/librte_eal/x86/rte_power_intrinsics.c | 32 ++++++------ 6 files changed, 62 insertions(+), 79 deletions(-) diff --git a/drivers/event/dlb/dlb.c b/drivers/event/dlb/dlb.c index 0c95c4793d..d2f2026291 100644 --- a/drivers/event/dlb/dlb.c +++ b/drivers/event/dlb/dlb.c @@ -3161,6 +3161,7 @@ dlb_dequeue_wait(struct dlb_eventdev *dlb, /* Interrupts not supported by PF PMD */ return 1; } else if (dlb->umwait_allowed) { + struct rte_power_monitor_cond pmc; volatile struct dlb_dequeue_qe *cq_base; union { uint64_t raw_qe[2]; @@ -3181,9 +3182,12 @@ dlb_dequeue_wait(struct dlb_eventdev *dlb, else expected_value = 0; - rte_power_monitor(monitor_addr, expected_value, - qe_mask.raw_qe[1], timeout + start_ticks, - sizeof(uint64_t)); + pmc.addr = monitor_addr; + pmc.val = expected_value; + pmc.mask = qe_mask.raw_qe[1]; + pmc.data_sz = sizeof(uint64_t); + + rte_power_monitor(&pmc, timeout + start_ticks); DLB_INC_STAT(ev_port->stats.traffic.rx_umonitor_umwait, 1); } else { diff --git a/drivers/event/dlb2/dlb2.c b/drivers/event/dlb2/dlb2.c index 86724863f2..c9a8a02278 100644 --- a/drivers/event/dlb2/dlb2.c +++ b/drivers/event/dlb2/dlb2.c @@ -2870,6 +2870,7 @@ dlb2_dequeue_wait(struct dlb2_eventdev *dlb2, if (elapsed_ticks >= timeout) { return 1; } else if (dlb2->umwait_allowed) { + struct rte_power_monitor_cond pmc; volatile struct dlb2_dequeue_qe *cq_base; union { uint64_t raw_qe[2]; @@ -2890,9 +2891,12 @@ dlb2_dequeue_wait(struct dlb2_eventdev *dlb2, else expected_value = 0; - rte_power_monitor(monitor_addr, expected_value, - qe_mask.raw_qe[1], timeout + start_ticks, - sizeof(uint64_t)); + pmc.addr = monitor_addr; + pmc.val = expected_value; + pmc.mask = qe_mask.raw_qe[1]; + pmc.data_sz = sizeof(uint64_t); + + rte_power_monitor(&pmc, timeout + start_ticks); DLB2_INC_STAT(ev_port->stats.traffic.rx_umonitor_umwait, 1); } else { diff --git a/lib/librte_eal/arm/include/rte_power_intrinsics.h b/lib/librte_eal/arm/include/rte_power_intrinsics.h index 5e384d380e..76a5fa5234 100644 --- a/lib/librte_eal/arm/include/rte_power_intrinsics.h +++ b/lib/librte_eal/arm/include/rte_power_intrinsics.h @@ -17,31 +17,23 @@ extern "C" { * This function is not supported on ARM. */ void -rte_power_monitor(const volatile void *p, const uint64_t expected_value, - const uint64_t value_mask, const uint64_t tsc_timestamp, - const uint8_t data_sz) +rte_power_monitor(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp) { - RTE_SET_USED(p); - RTE_SET_USED(expected_value); - RTE_SET_USED(value_mask); + RTE_SET_USED(pmc); RTE_SET_USED(tsc_timestamp); - RTE_SET_USED(data_sz); } /** * This function is not supported on ARM. */ void -rte_power_monitor_sync(const volatile void *p, const uint64_t expected_value, - const uint64_t value_mask, const uint64_t tsc_timestamp, - const uint8_t data_sz, rte_spinlock_t *lck) +rte_power_monitor_sync(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp, rte_spinlock_t *lck) { - RTE_SET_USED(p); - RTE_SET_USED(expected_value); - RTE_SET_USED(value_mask); + RTE_SET_USED(pmc); RTE_SET_USED(tsc_timestamp); RTE_SET_USED(lck); - RTE_SET_USED(data_sz); } /** diff --git a/lib/librte_eal/include/generic/rte_power_intrinsics.h b/lib/librte_eal/include/generic/rte_power_intrinsics.h index ffa72f7578..00c670cb50 100644 --- a/lib/librte_eal/include/generic/rte_power_intrinsics.h +++ b/lib/librte_eal/include/generic/rte_power_intrinsics.h @@ -18,6 +18,18 @@ * which are architecture-dependent. */ +struct rte_power_monitor_cond { + volatile void *addr; /**< Address to monitor for changes */ + uint64_t val; /**< Before attempting the monitoring, the address + * may be read and compared against this value. + **/ + uint64_t mask; /**< 64-bit mask to extract current value from addr */ + uint8_t data_sz; /**< Data size (in bytes) that will be used to compare + * expected value with the memory address. Can be 1, + * 2, 4, or 8. Supplying any other value will lead to + * undefined result. */ +}; + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice @@ -35,25 +47,15 @@ * @warning It is responsibility of the user to check if this function is * supported at runtime using `rte_cpu_get_intrinsics_support()` API call. * - * @param p - * Address to monitor for changes. - * @param expected_value - * Before attempting the monitoring, the `p` address may be read and compared - * against this value. If `value_mask` is zero, this step will be skipped. - * @param value_mask - * The 64-bit mask to use to extract current value from `p`. + * @param pmc + * The monitoring condition structure. * @param tsc_timestamp * Maximum TSC timestamp to wait for. Note that the wait behavior is * architecture-dependent. - * @param data_sz - * Data size (in bytes) that will be used to compare expected value with the - * memory address. Can be 1, 2, 4 or 8. Supplying any other value will lead - * to undefined result. */ __rte_experimental -void rte_power_monitor(const volatile void *p, - const uint64_t expected_value, const uint64_t value_mask, - const uint64_t tsc_timestamp, const uint8_t data_sz); +void rte_power_monitor(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp); /** * @warning @@ -75,30 +77,19 @@ void rte_power_monitor(const volatile void *p, * @warning It is responsibility of the user to check if this function is * supported at runtime using `rte_cpu_get_intrinsics_support()` API call. * - * @param p - * Address to monitor for changes. - * @param expected_value - * Before attempting the monitoring, the `p` address may be read and compared - * against this value. If `value_mask` is zero, this step will be skipped. - * @param value_mask - * The 64-bit mask to use to extract current value from `p`. + * @param pmc + * The monitoring condition structure. * @param tsc_timestamp * Maximum TSC timestamp to wait for. Note that the wait behavior is * architecture-dependent. - * @param data_sz - * Data size (in bytes) that will be used to compare expected value with the - * memory address. Can be 1, 2, 4 or 8. Supplying any other value will lead - * to undefined result. * @param lck * A spinlock that must be locked before entering the function, will be * unlocked while the CPU is sleeping, and will be locked again once the CPU * wakes up. */ __rte_experimental -void rte_power_monitor_sync(const volatile void *p, - const uint64_t expected_value, const uint64_t value_mask, - const uint64_t tsc_timestamp, const uint8_t data_sz, - rte_spinlock_t *lck); +void rte_power_monitor_sync(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp, rte_spinlock_t *lck); /** * @warning diff --git a/lib/librte_eal/ppc/include/rte_power_intrinsics.h b/lib/librte_eal/ppc/include/rte_power_intrinsics.h index 4cb5560c02..cff0996770 100644 --- a/lib/librte_eal/ppc/include/rte_power_intrinsics.h +++ b/lib/librte_eal/ppc/include/rte_power_intrinsics.h @@ -17,31 +17,23 @@ extern "C" { * This function is not supported on PPC64. */ void -rte_power_monitor(const volatile void *p, const uint64_t expected_value, - const uint64_t value_mask, const uint64_t tsc_timestamp, - const uint8_t data_sz) +rte_power_monitor(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp) { - RTE_SET_USED(p); - RTE_SET_USED(expected_value); - RTE_SET_USED(value_mask); + RTE_SET_USED(pmc); RTE_SET_USED(tsc_timestamp); - RTE_SET_USED(data_sz); } /** * This function is not supported on PPC64. */ void -rte_power_monitor_sync(const volatile void *p, const uint64_t expected_value, - const uint64_t value_mask, const uint64_t tsc_timestamp, - const uint8_t data_sz, rte_spinlock_t *lck) +rte_power_monitor_sync(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp, rte_spinlock_t *lck) { - RTE_SET_USED(p); - RTE_SET_USED(expected_value); - RTE_SET_USED(value_mask); + RTE_SET_USED(pmc); RTE_SET_USED(tsc_timestamp); RTE_SET_USED(lck); - RTE_SET_USED(data_sz); } /** diff --git a/lib/librte_eal/x86/rte_power_intrinsics.c b/lib/librte_eal/x86/rte_power_intrinsics.c index b48a54ec7f..3e224f5ac7 100644 --- a/lib/librte_eal/x86/rte_power_intrinsics.c +++ b/lib/librte_eal/x86/rte_power_intrinsics.c @@ -31,9 +31,8 @@ __get_umwait_val(const volatile void *p, const uint8_t sz) * Intel(R) 64 and IA-32 Architectures Software Developer's Manual. */ void -rte_power_monitor(const volatile void *p, const uint64_t expected_value, - const uint64_t value_mask, const uint64_t tsc_timestamp, - const uint8_t data_sz) +rte_power_monitor(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp) { const uint32_t tsc_l = (uint32_t)tsc_timestamp; const uint32_t tsc_h = (uint32_t)(tsc_timestamp >> 32); @@ -50,14 +49,15 @@ rte_power_monitor(const volatile void *p, const uint64_t expected_value, /* set address for UMONITOR */ asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;" : - : "D"(p)); + : "D"(pmc->addr)); - if (value_mask) { - const uint64_t cur_value = __get_umwait_val(p, data_sz); - const uint64_t masked = cur_value & value_mask; + if (pmc->mask) { + const uint64_t cur_value = __get_umwait_val( + pmc->addr, pmc->data_sz); + const uint64_t masked = cur_value & pmc->mask; /* if the masked value is already matching, abort */ - if (masked == expected_value) + if (masked == pmc->val) return; } /* execute UMWAIT */ @@ -73,9 +73,8 @@ rte_power_monitor(const volatile void *p, const uint64_t expected_value, * Intel(R) 64 and IA-32 Architectures Software Developer's Manual. */ void -rte_power_monitor_sync(const volatile void *p, const uint64_t expected_value, - const uint64_t value_mask, const uint64_t tsc_timestamp, - const uint8_t data_sz, rte_spinlock_t *lck) +rte_power_monitor_sync(const struct rte_power_monitor_cond *pmc, + const uint64_t tsc_timestamp, rte_spinlock_t *lck) { const uint32_t tsc_l = (uint32_t)tsc_timestamp; const uint32_t tsc_h = (uint32_t)(tsc_timestamp >> 32); @@ -92,14 +91,15 @@ rte_power_monitor_sync(const volatile void *p, const uint64_t expected_value, /* set address for UMONITOR */ asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;" : - : "D"(p)); + : "D"(pmc->addr)); - if (value_mask) { - const uint64_t cur_value = __get_umwait_val(p, data_sz); - const uint64_t masked = cur_value & value_mask; + if (pmc->mask) { + const uint64_t cur_value = __get_umwait_val( + pmc->addr, pmc->data_sz); + const uint64_t masked = cur_value & pmc->mask; /* if the masked value is already matching, abort */ - if (masked == expected_value) + if (masked == pmc->val) return; } rte_spinlock_unlock(lck); -- 2.25.1