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 AD16FA0543; Sat, 28 May 2022 11:33:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1BF6442B75; Sat, 28 May 2022 11:33:27 +0200 (CEST) Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by mails.dpdk.org (Postfix) with ESMTP id D4CBF4114A for ; Sat, 28 May 2022 11:33:19 +0200 (CEST) Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Ax_+ZX7JFiWWUFAA--.26269S7; Sat, 28 May 2022 17:33:18 +0800 (CST) From: Min Zhou To: thomas@monjalon.net, david.marchand@redhat.com, bruce.richardson@intel.com, anatoly.burakov@intel.com, qiming.yang@intel.com, Yuying.Zhang@intel.com, jgrajcia@cisco.com, konstantin.v.ananyev@yandex.ru Cc: dev@dpdk.org, maobibo@loongson.cn Subject: [v1 05/24] eal/loongarch: add spinlock operations for LoongArch Date: Sat, 28 May 2022 17:32:52 +0800 Message-Id: <20220528093311.123946-6-zhoumin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220528093311.123946-1-zhoumin@loongson.cn> References: <20220528093311.123946-1-zhoumin@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9Ax_+ZX7JFiWWUFAA--.26269S7 X-Coremail-Antispam: 1UD129KBjvJXoWxArWDAr45trWxGrW8WFWkXrb_yoW5Gw4Upr W3CrnxJa1xWF1I9FWfAF1qqr15Jws29r17JrZxWw18trZrW3sxK3ykJr90v3WFqa47tFyD XFs0vr45GrW7G3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: 52kr3ztlq6z05rqj20fqof0/ 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 This patch adds spinlock operations for LoongArch architecture. These implementations refer to GLIBC pthread_spin_xxlock(). The underlying implementation is based on LoongArch atomic instructions (ie, AMSWAP_DB.W). Signed-off-by: Min Zhou --- lib/eal/loongarch/include/rte_spinlock.h | 93 ++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/eal/loongarch/include/rte_spinlock.h diff --git a/lib/eal/loongarch/include/rte_spinlock.h b/lib/eal/loongarch/include/rte_spinlock.h new file mode 100644 index 0000000000..6b565dc4d9 --- /dev/null +++ b/lib/eal/loongarch/include/rte_spinlock.h @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Loongson Technology Corporation Limited + */ + +#ifndef _RTE_SPINLOCK_LOONGARCH_H_ +#define _RTE_SPINLOCK_LOONGARCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "generic/rte_spinlock.h" + +#ifndef RTE_FORCE_INTRINSICS +/* + * These implementations refer to GLIBC pthread_spin_xxlock(). + */ +static inline void +rte_spinlock_lock(rte_spinlock_t *sl) +{ + int val = 0; + + if (rte_atomic32_exchange((volatile uint32_t *)&sl->locked, 1) == 0) + return; + + do { + do { + val = sl->locked; + } while (val != 0); + + } while (rte_atomic32_exchange((volatile uint32_t *)&sl->locked, 1) == 1); +} + +static inline void +rte_spinlock_unlock(rte_spinlock_t *sl) +{ + sl->locked = 0; +} + +static inline int +rte_spinlock_trylock(rte_spinlock_t *sl) +{ + return rte_atomic32_exchange((volatile uint32_t *)&sl->locked, 1) == 0; +} +#endif + +static inline int rte_tm_supported(void) +{ + return 0; +} + +static inline void +rte_spinlock_lock_tm(rte_spinlock_t *sl) +{ + rte_spinlock_lock(sl); /* fall-back */ +} + +static inline int +rte_spinlock_trylock_tm(rte_spinlock_t *sl) +{ + return rte_spinlock_trylock(sl); +} + +static inline void +rte_spinlock_unlock_tm(rte_spinlock_t *sl) +{ + rte_spinlock_unlock(sl); +} + +static inline void +rte_spinlock_recursive_lock_tm(rte_spinlock_recursive_t *slr) +{ + rte_spinlock_recursive_lock(slr); /* fall-back */ +} + +static inline void +rte_spinlock_recursive_unlock_tm(rte_spinlock_recursive_t *slr) +{ + rte_spinlock_recursive_unlock(slr); +} + +static inline int +rte_spinlock_recursive_trylock_tm(rte_spinlock_recursive_t *slr) +{ + return rte_spinlock_recursive_trylock(slr); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_SPINLOCK_LOONGARCH_H_ */ -- 2.31.1