From 12df75e182e60cda3c7b8ff2f127a5cc0a0480d9 Mon Sep 17 00:00:00 2001 From: Jingyun Hua Date: Thu, 27 Jul 2023 02:11:56 +0000 Subject: [PATCH] Fix build error on loongarch64 --- 0001-add-loongarch-support.patch | 744 +++++++++++++++++++++++++++++++ ucx.spec | 10 +- 2 files changed, 753 insertions(+), 1 deletion(-) create mode 100644 0001-add-loongarch-support.patch diff --git a/0001-add-loongarch-support.patch b/0001-add-loongarch-support.patch new file mode 100644 index 0000000..7576359 --- /dev/null +++ b/0001-add-loongarch-support.patch @@ -0,0 +1,744 @@ +From 3d42367752caab31a439f221dc216e9aa2cebd88 Mon Sep 17 00:00:00 2001 +From: Jingyun Hua +Date: Thu, 27 Jul 2023 01:59:57 +0000 +Subject: [PATCH] add loongarch support + +--- + config.guess | 3 + + src/ucm/Makefile.am | 2 + + src/ucm/Makefile.in | 19 ++++- + src/ucm/bistro/bistro.c | 2 +- + src/ucm/bistro/bistro.h | 2 + + src/ucm/bistro/bistro_loongarch64.c | 81 ++++++++++++++++++++ + src/ucm/bistro/bistro_loongarch64.h | 46 +++++++++++ + src/ucs/Makefile.am | 4 + + src/ucs/Makefile.in | 33 +++++++- + src/ucs/arch/atomic.h | 2 + + src/ucs/arch/bitops.h | 2 + + src/ucs/arch/cpu.h | 2 + + src/ucs/arch/global_opts.h | 2 + + src/ucs/arch/loongarch64/bitops.h | 42 ++++++++++ + src/ucs/arch/loongarch64/cpu.h | 101 +++++++++++++++++++++++++ + src/ucs/arch/loongarch64/global_opts.c | 24 ++++++ + src/ucs/arch/loongarch64/global_opts.h | 24 ++++++ + 17 files changed, 384 insertions(+), 7 deletions(-) + create mode 100644 src/ucm/bistro/bistro_loongarch64.c + create mode 100644 src/ucm/bistro/bistro_loongarch64.h + create mode 100644 src/ucs/arch/loongarch64/bitops.h + create mode 100644 src/ucs/arch/loongarch64/cpu.h + create mode 100644 src/ucs/arch/loongarch64/global_opts.c + create mode 100644 src/ucs/arch/loongarch64/global_opts.h + +diff --git a/config.guess b/config.guess +index b79252d..87fc200 100755 +--- a/config.guess ++++ b/config.guess +@@ -883,6 +883,9 @@ EOF + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; ++ loongarch64:Linux:*:*) ++ echo ${UNAME_MACHINE}-unknown-linux-${LIBC} ++ exit ;; + aarch64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; +diff --git a/src/ucm/Makefile.am b/src/ucm/Makefile.am +index 5140b5a..e2f53b7 100644 +--- a/src/ucm/Makefile.am ++++ b/src/ucm/Makefile.am +@@ -31,6 +31,7 @@ noinst_HEADERS = \ + bistro/bistro.h \ + bistro/bistro_x86_64.h \ + bistro/bistro_aarch64.h \ ++ bistro/bistro_loongarch64.h \ + bistro/bistro_ppc64.h + + libucm_la_SOURCES = \ +@@ -44,6 +45,7 @@ libucm_la_SOURCES = \ + bistro/bistro.c \ + bistro/bistro_x86_64.c \ + bistro/bistro_aarch64.c \ ++ bistro/bistro_loongarch64.c \ + bistro/bistro_ppc64.c + + if HAVE_UCM_PTMALLOC286 +diff --git a/src/ucm/Makefile.in b/src/ucm/Makefile.in +index b83d07b..3202d87 100644 +--- a/src/ucm/Makefile.in ++++ b/src/ucm/Makefile.in +@@ -192,7 +192,7 @@ am__libucm_la_SOURCES_DIST = event/event.c malloc/malloc_hook.c \ + mmap/install.c util/replace.c util/log.c util/reloc.c \ + util/sys.c bistro/bistro.c bistro/bistro_x86_64.c \ + bistro/bistro_aarch64.c bistro/bistro_ppc64.c \ +- ptmalloc286/malloc.c ++ bistro/bistro_loongarch64.c ptmalloc286/malloc.c + am__dirstamp = $(am__leading_dot)dirstamp + @HAVE_UCM_PTMALLOC286_TRUE@am__objects_1 = \ + @HAVE_UCM_PTMALLOC286_TRUE@ ptmalloc286/libucm_la-malloc.lo +@@ -202,6 +202,7 @@ am_libucm_la_OBJECTS = event/libucm_la-event.lo \ + util/libucm_la-reloc.lo util/libucm_la-sys.lo \ + bistro/libucm_la-bistro.lo bistro/libucm_la-bistro_x86_64.lo \ + bistro/libucm_la-bistro_aarch64.lo \ ++ bistro/libucm_la-bistro_loongarch64.lo \ + bistro/libucm_la-bistro_ppc64.lo $(am__objects_1) + libucm_la_OBJECTS = $(am_libucm_la_OBJECTS) + AM_V_lt = $(am__v_lt_@AM_V@) +@@ -265,7 +266,7 @@ am__noinst_HEADERS_DIST = event/event.h malloc/malloc_hook.h \ + util/replace.h util/log.h util/reloc.h util/sys.h \ + bistro/bistro_int.h bistro/bistro.h bistro/bistro_x86_64.h \ + bistro/bistro_aarch64.h bistro/bistro_ppc64.h \ +- ptmalloc286/malloc-2.8.6.h ++ bistro/bistro_loongarch64.h ptmalloc286/malloc-2.8.6.h + HEADERS = $(nobase_dist_libucm_la_HEADERS) $(noinst_HEADERS) + RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +@@ -568,11 +569,11 @@ noinst_HEADERS = event/event.h malloc/malloc_hook.h malloc/allocator.h \ + mmap/mmap.h util/khash_safe.h util/replace.h util/log.h \ + util/reloc.h util/sys.h bistro/bistro_int.h bistro/bistro.h \ + bistro/bistro_x86_64.h bistro/bistro_aarch64.h \ +- bistro/bistro_ppc64.h $(am__append_3) ++ bistro/bistro_ppc64.h bistro/bistro_loongarch64.h $(am__append_3) + libucm_la_SOURCES = event/event.c malloc/malloc_hook.c mmap/install.c \ + util/replace.c util/log.c util/reloc.c util/sys.c \ + bistro/bistro.c bistro/bistro_x86_64.c bistro/bistro_aarch64.c \ +- bistro/bistro_ppc64.c $(am__append_2) ++ bistro/bistro_ppc64.c bistro/bistro_loongarch64.c $(am__append_2) + all: all-recursive + + .SUFFIXES: +@@ -692,6 +693,8 @@ bistro/libucm_la-bistro_x86_64.lo: bistro/$(am__dirstamp) \ + bistro/$(DEPDIR)/$(am__dirstamp) + bistro/libucm_la-bistro_aarch64.lo: bistro/$(am__dirstamp) \ + bistro/$(DEPDIR)/$(am__dirstamp) ++bistro/libucm_la-bistro_loongarch64.lo: bistro/$(am__dirstamp) \ ++ bistro/$(DEPDIR)/$(am__dirstamp) + bistro/libucm_la-bistro_ppc64.lo: bistro/$(am__dirstamp) \ + bistro/$(DEPDIR)/$(am__dirstamp) + ptmalloc286/$(am__dirstamp): +@@ -726,6 +729,7 @@ distclean-compile: + + @AMDEP_TRUE@@am__include@ @am__quote@bistro/$(DEPDIR)/libucm_la-bistro.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@bistro/$(DEPDIR)/libucm_la-bistro_aarch64.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@bistro/$(DEPDIR)/libucm_la-bistro_loongarch64.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@bistro/$(DEPDIR)/libucm_la-bistro_ppc64.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@bistro/$(DEPDIR)/libucm_la-bistro_x86_64.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@event/$(DEPDIR)/libucm_la-event.Plo@am__quote@ +@@ -831,6 +835,13 @@ bistro/libucm_la-bistro_aarch64.lo: bistro/bistro_aarch64.c + @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucm_la_CPPFLAGS) $(CPPFLAGS) $(libucm_la_CFLAGS) $(CFLAGS) -c -o bistro/libucm_la-bistro_aarch64.lo `test -f 'bistro/bistro_aarch64.c' || echo '$(srcdir)/'`bistro/bistro_aarch64.c + ++bistro/libucm_la-bistro_loongarch64.lo: bistro/bistro_loongarch64.c ++@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucm_la_CPPFLAGS) $(CPPFLAGS) $(libucm_la_CFLAGS) $(CFLAGS) -MT bistro/libucm_la-bistro_loongarch64.lo -MD -MP -MF bistro/$(DEPDIR)/libucm_la-bistro_loongarch64.Tpo -c -o bistro/libucm_la-bistro_loongarch64.lo `test -f 'bistro/bistro_loongarch64.c' || echo '$(srcdir)/'`bistro/bistro_loongarch64.c ++@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) bistro/$(DEPDIR)/libucm_la-bistro_loongarch64.Tpo bistro/$(DEPDIR)/libucm_la-bistro_loongarch64.Plo ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bistro/bistro_loongarch64.c' object='bistro/libucm_la-bistro_loongarch64.lo' libtool=yes @AMDEPBACKSLASH@ ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ ++@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucm_la_CPPFLAGS) $(CPPFLAGS) $(libucm_la_CFLAGS) $(CFLAGS) -c -o bistro/libucm_la-bistro_loongarch64.lo `test -f 'bistro/bistro_loongarch64.c' || echo '$(srcdir)/'`bistro/bistro_loongarch64.c ++ + bistro/libucm_la-bistro_ppc64.lo: bistro/bistro_ppc64.c + @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucm_la_CPPFLAGS) $(CPPFLAGS) $(libucm_la_CFLAGS) $(CFLAGS) -MT bistro/libucm_la-bistro_ppc64.lo -MD -MP -MF bistro/$(DEPDIR)/libucm_la-bistro_ppc64.Tpo -c -o bistro/libucm_la-bistro_ppc64.lo `test -f 'bistro/bistro_ppc64.c' || echo '$(srcdir)/'`bistro/bistro_ppc64.c + @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) bistro/$(DEPDIR)/libucm_la-bistro_ppc64.Tpo bistro/$(DEPDIR)/libucm_la-bistro_ppc64.Plo +diff --git a/src/ucm/bistro/bistro.c b/src/ucm/bistro/bistro.c +index c31741a..ca8fb8a 100644 +--- a/src/ucm/bistro/bistro.c ++++ b/src/ucm/bistro/bistro.c +@@ -62,7 +62,7 @@ ucs_status_t ucm_bistro_apply_patch(void *dst, void *patch, size_t len) + return status; + } + +-#if defined(__x86_64__) || defined (__aarch64__) ++#if defined(__x86_64__) || defined (__aarch64__) || defined (__loongarch__) + struct ucm_bistro_restore_point { + void *addr; /* address of function to restore */ + size_t patch_len; /* patch length */ +diff --git a/src/ucm/bistro/bistro.h b/src/ucm/bistro/bistro.h +index 1010004..f4d1662 100644 +--- a/src/ucm/bistro/bistro.h ++++ b/src/ucm/bistro/bistro.h +@@ -20,6 +20,8 @@ typedef struct ucm_bistro_restore_point ucm_bistro_restore_point_t; + # include "bistro_aarch64.h" + #elif defined(__x86_64__) + # include "bistro_x86_64.h" ++#elif defined(__loongarch__) ++# include "bistro_loongarch64.h" + #else + # error "Unsupported architecture" + #endif +diff --git a/src/ucm/bistro/bistro_loongarch64.c b/src/ucm/bistro/bistro_loongarch64.c +new file mode 100644 +index 0000000..0e1fbff +--- /dev/null ++++ b/src/ucm/bistro/bistro_loongarch64.c +@@ -0,0 +1,81 @@ ++/** ++ * Copyright (C) Mellanox Technologies Ltd. 2018. ALL RIGHTS RESERVED. ++ * ++ * See file LICENSE for terms. ++ */ ++ ++#ifdef HAVE_CONFIG_H ++# include "config.h" ++#endif ++ ++/* ******************************************************* ++ * LOONGARCH64 processors family * ++ * ***************************************************** */ ++#if defined(__loongarch__) ++ ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++ ++/* Register number used to store indirect jump address. ++ * r20 is the highest numbered temporary register, assuming this one is safe ++ * to use. */ ++#define R20 20 ++ ++/** ++ * @brief Generate a mov immediate instruction ++ * ++ * @param[in] _rd, _rj register number (0-31) ++ * @param[in] _si20, _si20 signed mmediate value 20, 12 bits ++ * @param[in] _ui12 immediate value ++ */ ++#define LU12I_W(_rd, _si20) \ ++ ((10 << 25) + (((_si20) & 0xfffff) << 5) + (_rd)) ++ ++#define LU32I_D(_rd, _si20) \ ++ (((22 >> 1) << 25) + (((_si20) & 0xfffff) << 5) + (_rd)) ++ ++#define LU52I_D(_rd, _rj, _si12) \ ++ (((48 >> 2) << 22) + (((_si12) & 0xfff) << 10) + ((_rj) << 5) + (_rd)) ++ ++#define ORI(_rd, _rj, _ui12) \ ++ (((56 >> 2) << 22) + (((_ui12) & 0xfff) << 10) + ((_rj) << 5) + (_rd)) ++ ++#define JIRL(_rd, _rj, _offs) \ ++ ((19 << 26) + ((_offs) << 10) + ((_rj) << 5) + (_rd)) ++ ++ucs_status_t ucm_bistro_patch(void *func_ptr, void *hook, const char *symbol, ++ void **orig_func_p, ++ ucm_bistro_restore_point_t **rp) ++{ ++ ucm_bistro_patch_t patch = { ++ .lu12i = LU12I_W(R20, (uintptr_t)hook >> 12), ++ .ori = ORI(R20, R20, (uintptr_t)hook), ++ .lu32i = LU32I_D(R20, (uintptr_t)hook >> 32), ++ .lu52i = LU52I_D(R20, R20, (uintptr_t)hook >> 52), ++ .jirl = JIRL(0, R20, 0) ++ }; ++ ucs_status_t status; ++ ++ if (orig_func_p != NULL) { ++ return UCS_ERR_UNSUPPORTED; ++ } ++ ++ status = ucm_bistro_create_restore_point(func_ptr, sizeof(patch), rp); ++ if (UCS_STATUS_IS_ERR(status)) { ++ return status; ++ } ++ ++ return ucm_bistro_apply_patch(func_ptr, &patch, sizeof(patch)); ++} ++ ++#endif +diff --git a/src/ucm/bistro/bistro_loongarch64.h b/src/ucm/bistro/bistro_loongarch64.h +new file mode 100644 +index 0000000..bbc6c0f +--- /dev/null ++++ b/src/ucm/bistro/bistro_loongarch64.h +@@ -0,0 +1,46 @@ ++/** ++ * Copyright (C) Mellanox Technologies Ltd. 2018. ALL RIGHTS RESERVED. ++ * ++ * See file LICENSE for terms. ++ */ ++ ++ ++#ifndef UCM_BISTRO_BISTRO_LOONGARCH64_H_ ++#define UCM_BISTRO_BISTRO_LOONGARCH64_H_ ++ ++#include ++ ++#include ++#include ++ ++#define UCM_BISTRO_PROLOGUE ++#define UCM_BISTRO_EPILOGUE ++ ++typedef struct ucm_bistro_patch { ++ uint32_t lu12i; /* lu12i.w r20, addr >> 12 */ ++ uint32_t ori; /* ori r20, r20, addr */ ++ uint32_t lu32i; /* lu32i.d r20, r20, addr >> 32 */ ++ uint32_t lu52i; /* lu52i.d r20, r20, addr >> 52*/ ++ uint32_t jirl; /* jirl 0, r20, 0 */ ++} UCS_S_PACKED ucm_bistro_patch_t; ++ ++/** ++ * Set library function call hook using Binary Instrumentation ++ * method (BISTRO): replace function body by user defined call ++ * ++ * @param func_ptr Pointer to function to patch. ++ * @param hook User-defined function-replacer. ++ * @param symbol Function name to replace. ++ * @param orig_func_p Unsupported on this architecture and must be NULL. ++ * If set to a non-NULL value, this function returns ++ * @ref UCS_ERR_UNSUPPORTED. ++ * @param rp Restore point used to restore original function. ++ * Optional, may be NULL. ++ * ++ * @return Error code as defined by @ref ucs_status_t ++ */ ++ucs_status_t ucm_bistro_patch(void *func_ptr, void *hook, const char *symbol, ++ void **orig_func_p, ++ ucm_bistro_restore_point_t **rp); ++ ++#endif +diff --git a/src/ucs/Makefile.am b/src/ucs/Makefile.am +index 7768002..d893f3c 100644 +--- a/src/ucs/Makefile.am ++++ b/src/ucs/Makefile.am +@@ -21,6 +21,7 @@ libucs_la_LIBADD = $(LIBM) $(top_builddir)/src/ucm/libucm.la $(BFD_LIBS) + + nobase_dist_libucs_la_HEADERS = \ + arch/aarch64/bitops.h \ ++ arch/loongarch64/bitops.h \ + arch/ppc64/bitops.h \ + arch/x86_64/bitops.h \ + arch/bitops.h \ +@@ -79,12 +80,14 @@ nobase_dist_libucs_la_HEADERS = \ + arch/x86_64/global_opts.h \ + arch/x86_64/atomic.h \ + arch/aarch64/global_opts.h \ ++ arch/loongarch64/global_opts.h \ + arch/generic/atomic.h \ + arch/ppc64/global_opts.h \ + arch/global_opts.h + + noinst_HEADERS = \ + arch/aarch64/cpu.h \ ++ arch/loongarch64/cpu.h \ + arch/generic/cpu.h \ + arch/ppc64/cpu.h \ + arch/x86_64/cpu.h \ +@@ -134,6 +137,7 @@ libucs_la_SOURCES = \ + algorithm/qsort_r.c \ + arch/aarch64/cpu.c \ + arch/aarch64/global_opts.c \ ++ arch/loongarch64/global_opts.c \ + arch/ppc64/timebase.c \ + arch/ppc64/global_opts.c \ + arch/x86_64/cpu.c \ +diff --git a/src/ucs/Makefile.in b/src/ucs/Makefile.in +index 34fcd02..54855dd 100644 +--- a/src/ucs/Makefile.in ++++ b/src/ucs/Makefile.in +@@ -202,6 +202,7 @@ am__libucs_la_SOURCES_DIST = algorithm/crc.c algorithm/qsort_r.c \ + arch/aarch64/cpu.c arch/aarch64/global_opts.c \ + arch/ppc64/timebase.c arch/ppc64/global_opts.c \ + arch/x86_64/cpu.c arch/x86_64/global_opts.c arch/cpu.c \ ++ arch/loongarch64/global_opts.c \ + async/async.c async/signal.c async/pipe.c async/thread.c \ + config/global_opts.c config/ucm_opts.c config/ini.c \ + config/parser.c datastruct/arbiter.c datastruct/array.c \ +@@ -229,6 +230,7 @@ am__dirstamp = $(am__leading_dot)dirstamp + am_libucs_la_OBJECTS = algorithm/libucs_la-crc.lo \ + algorithm/libucs_la-qsort_r.lo arch/aarch64/libucs_la-cpu.lo \ + arch/aarch64/libucs_la-global_opts.lo \ ++ arch/loongarch64/libucs_la-global_opts.lo \ + arch/ppc64/libucs_la-timebase.lo \ + arch/ppc64/libucs_la-global_opts.lo \ + arch/x86_64/libucs_la-cpu.lo \ +@@ -639,6 +641,7 @@ libucs_ladir = $(includedir)/ucs + libucs_la_LIBADD = $(LIBM) $(top_builddir)/src/ucm/libucm.la $(BFD_LIBS) + nobase_dist_libucs_la_HEADERS = \ + arch/aarch64/bitops.h \ ++ arch/loongarch64/bitops.h \ + arch/ppc64/bitops.h \ + arch/x86_64/bitops.h \ + arch/bitops.h \ +@@ -697,12 +700,14 @@ nobase_dist_libucs_la_HEADERS = \ + arch/x86_64/global_opts.h \ + arch/x86_64/atomic.h \ + arch/aarch64/global_opts.h \ ++ arch/loongarch64/global_opts.h \ + arch/generic/atomic.h \ + arch/ppc64/global_opts.h \ + arch/global_opts.h + + noinst_HEADERS = \ + arch/aarch64/cpu.h \ ++ arch/loongarch64/cpu.h \ + arch/generic/cpu.h \ + arch/ppc64/cpu.h \ + arch/x86_64/cpu.h \ +@@ -751,6 +756,7 @@ libucs_la_SOURCES = algorithm/crc.c algorithm/qsort_r.c \ + arch/aarch64/cpu.c arch/aarch64/global_opts.c \ + arch/ppc64/timebase.c arch/ppc64/global_opts.c \ + arch/x86_64/cpu.c arch/x86_64/global_opts.c arch/cpu.c \ ++ arch/loongarch64/global_opts.c \ + async/async.c async/signal.c async/pipe.c async/thread.c \ + config/global_opts.c config/ucm_opts.c config/ini.c \ + config/parser.c datastruct/arbiter.c datastruct/array.c \ +@@ -868,6 +874,16 @@ arch/aarch64/libucs_la-cpu.lo: arch/aarch64/$(am__dirstamp) \ + arch/aarch64/$(DEPDIR)/$(am__dirstamp) + arch/aarch64/libucs_la-global_opts.lo: arch/aarch64/$(am__dirstamp) \ + arch/aarch64/$(DEPDIR)/$(am__dirstamp) ++arch/loongarch64/$(am__dirstamp): ++ @$(MKDIR_P) arch/loongarch64 ++ @: > arch/loongarch64/$(am__dirstamp) ++arch/loongarch64/$(DEPDIR)/$(am__dirstamp): ++ @$(MKDIR_P) arch/loongarch64/$(DEPDIR) ++ @: > arch/loongarch64/$(DEPDIR)/$(am__dirstamp) ++arch/loongarch64/libucs_la-cpu.lo: arch/loongarch64/$(am__dirstamp) \ ++ arch/loongarch64/$(DEPDIR)/$(am__dirstamp) ++arch/loongarch64/libucs_la-global_opts.lo: arch/loongarch64/$(am__dirstamp) \ ++ arch/loongarch64/$(DEPDIR)/$(am__dirstamp) + arch/ppc64/$(am__dirstamp): + @$(MKDIR_P) arch/ppc64 + @: > arch/ppc64/$(am__dirstamp) +@@ -1152,6 +1168,8 @@ mostlyclean-compile: + -rm -f arch/*.lo + -rm -f arch/aarch64/*.$(OBJEXT) + -rm -f arch/aarch64/*.lo ++ -rm -f arch/loongarch64/*.$(OBJEXT) ++ -rm -f arch/loongarch64/*.lo + -rm -f arch/ppc64/*.$(OBJEXT) + -rm -f arch/ppc64/*.lo + -rm -f arch/x86_64/*.$(OBJEXT) +@@ -1190,6 +1208,7 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@arch/aarch64/$(DEPDIR)/libucs_la-cpu.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@arch/aarch64/$(DEPDIR)/libucs_la-global_opts.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@arch/aarch64/$(DEPDIR)/libucs_la-memcpy_thunderx2.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@arch/loongarch64/$(DEPDIR)/libucs_la-global_opts.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@arch/ppc64/$(DEPDIR)/libucs_la-global_opts.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@arch/ppc64/$(DEPDIR)/libucs_la-timebase.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@arch/x86_64/$(DEPDIR)/libucs_la-cpu.Plo@am__quote@ +@@ -1336,6 +1355,13 @@ arch/aarch64/libucs_la-global_opts.lo: arch/aarch64/global_opts.c + @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucs_la_CPPFLAGS) $(CPPFLAGS) $(libucs_la_CFLAGS) $(CFLAGS) -c -o arch/aarch64/libucs_la-global_opts.lo `test -f 'arch/aarch64/global_opts.c' || echo '$(srcdir)/'`arch/aarch64/global_opts.c + ++arch/loongarch64/libucs_la-global_opts.lo: arch/loongarch64/global_opts.c ++@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucs_la_CPPFLAGS) $(CPPFLAGS) $(libucs_la_CFLAGS) $(CFLAGS) -MT arch/loongarch64/libucs_la-global_opts.lo -MD -MP -MF arch/loongarch64/$(DEPDIR)/libucs_la-global_opts.Tpo -c -o arch/loongarch64/libucs_la-global_opts.lo `test -f 'arch/loongarch64/global_opts.c' || echo '$(srcdir)/'`arch/loongarch64/global_opts.c ++@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) arch/loongarch64/$(DEPDIR)/libucs_la-global_opts.Tpo arch/loongarch64/$(DEPDIR)/libucs_la-global_opts.Plo ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='arch/loongarch64/global_opts.c' object='arch/loongarch64/libucs_la-global_opts.lo' libtool=yes @AMDEPBACKSLASH@ ++@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ ++@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucs_la_CPPFLAGS) $(CPPFLAGS) $(libucs_la_CFLAGS) $(CFLAGS) -c -o arch/loongarch64/libucs_la-global_opts.lo `test -f 'arch/loongarch64/global_opts.c' || echo '$(srcdir)/'`arch/loongarch64/global_opts.c ++ + arch/ppc64/libucs_la-timebase.lo: arch/ppc64/timebase.c + @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libucs_la_CPPFLAGS) $(CPPFLAGS) $(libucs_la_CFLAGS) $(CFLAGS) -MT arch/ppc64/libucs_la-timebase.lo -MD -MP -MF arch/ppc64/$(DEPDIR)/libucs_la-timebase.Tpo -c -o arch/ppc64/libucs_la-timebase.lo `test -f 'arch/ppc64/timebase.c' || echo '$(srcdir)/'`arch/ppc64/timebase.c + @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) arch/ppc64/$(DEPDIR)/libucs_la-timebase.Tpo arch/ppc64/$(DEPDIR)/libucs_la-timebase.Plo +@@ -1792,6 +1818,7 @@ clean-libtool: + -rm -rf algorithm/.libs algorithm/_libs + -rm -rf arch/.libs arch/_libs + -rm -rf arch/aarch64/.libs arch/aarch64/_libs ++ -rm -rf arch/loongarch64/.libs arch/loongarch64/_libs + -rm -rf arch/ppc64/.libs arch/ppc64/_libs + -rm -rf arch/x86_64/.libs arch/x86_64/_libs + -rm -rf async/.libs async/_libs +@@ -2049,6 +2076,8 @@ distclean-generic: + -rm -f arch/$(am__dirstamp) + -rm -f arch/aarch64/$(DEPDIR)/$(am__dirstamp) + -rm -f arch/aarch64/$(am__dirstamp) ++ -rm -f arch/loongarch64/$(DEPDIR)/$(am__dirstamp) ++ -rm -f arch/loongarch64/$(am__dirstamp) + -rm -f arch/ppc64/$(DEPDIR)/$(am__dirstamp) + -rm -f arch/ppc64/$(am__dirstamp) + -rm -f arch/x86_64/$(DEPDIR)/$(am__dirstamp) +@@ -2087,7 +2116,7 @@ clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ + clean-libtool mostlyclean-am + + distclean: distclean-recursive +- -rm -rf algorithm/$(DEPDIR) arch/$(DEPDIR) arch/aarch64/$(DEPDIR) arch/ppc64/$(DEPDIR) arch/x86_64/$(DEPDIR) async/$(DEPDIR) config/$(DEPDIR) datastruct/$(DEPDIR) debug/$(DEPDIR) memory/$(DEPDIR) profile/$(DEPDIR) stats/$(DEPDIR) sys/$(DEPDIR) sys/topo/base/$(DEPDIR) time/$(DEPDIR) type/$(DEPDIR) vfs/base/$(DEPDIR) ++ -rm -rf algorithm/$(DEPDIR) arch/$(DEPDIR) arch/aarch64/$(DEPDIR) arch/loongarch64/$(DEPDIR) arch/ppc64/$(DEPDIR) arch/x86_64/$(DEPDIR) async/$(DEPDIR) config/$(DEPDIR) datastruct/$(DEPDIR) debug/$(DEPDIR) memory/$(DEPDIR) profile/$(DEPDIR) stats/$(DEPDIR) sys/$(DEPDIR) sys/topo/base/$(DEPDIR) time/$(DEPDIR) type/$(DEPDIR) vfs/base/$(DEPDIR) + -rm -f Makefile + distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags +@@ -2134,7 +2163,7 @@ install-ps-am: + installcheck-am: + + maintainer-clean: maintainer-clean-recursive +- -rm -rf algorithm/$(DEPDIR) arch/$(DEPDIR) arch/aarch64/$(DEPDIR) arch/ppc64/$(DEPDIR) arch/x86_64/$(DEPDIR) async/$(DEPDIR) config/$(DEPDIR) datastruct/$(DEPDIR) debug/$(DEPDIR) memory/$(DEPDIR) profile/$(DEPDIR) stats/$(DEPDIR) sys/$(DEPDIR) sys/topo/base/$(DEPDIR) time/$(DEPDIR) type/$(DEPDIR) vfs/base/$(DEPDIR) ++ -rm -rf algorithm/$(DEPDIR) arch/$(DEPDIR) arch/aarch64/$(DEPDIR) arch/loongarch64/$(DEPDIR) arch/ppc64/$(DEPDIR) arch/x86_64/$(DEPDIR) async/$(DEPDIR) config/$(DEPDIR) datastruct/$(DEPDIR) debug/$(DEPDIR) memory/$(DEPDIR) profile/$(DEPDIR) stats/$(DEPDIR) sys/$(DEPDIR) sys/topo/base/$(DEPDIR) time/$(DEPDIR) type/$(DEPDIR) vfs/base/$(DEPDIR) + -rm -f Makefile + maintainer-clean-am: distclean-am maintainer-clean-generic + +diff --git a/src/ucs/arch/atomic.h b/src/ucs/arch/atomic.h +index 6a8551f..2fad8d4 100644 +--- a/src/ucs/arch/atomic.h ++++ b/src/ucs/arch/atomic.h +@@ -15,6 +15,8 @@ + # include "generic/atomic.h" + #elif defined(__aarch64__) + # include "generic/atomic.h" ++#elif defined(__loongarch__) ++# include "generic/atomic.h" + #else + # error "Unsupported architecture" + #endif +diff --git a/src/ucs/arch/bitops.h b/src/ucs/arch/bitops.h +index 77e0057..09e68e6 100644 +--- a/src/ucs/arch/bitops.h ++++ b/src/ucs/arch/bitops.h +@@ -20,6 +20,8 @@ BEGIN_C_DECLS + # include "ppc64/bitops.h" + #elif defined(__aarch64__) + # include "aarch64/bitops.h" ++#elif defined(__loongarch__) ++# include "loongarch64/bitops.h" + #else + # error "Unsupported architecture" + #endif +diff --git a/src/ucs/arch/cpu.h b/src/ucs/arch/cpu.h +index 719913f..cf6e4de 100644 +--- a/src/ucs/arch/cpu.h ++++ b/src/ucs/arch/cpu.h +@@ -98,6 +98,8 @@ typedef struct ucs_cpu_builtin_memcpy { + # include "ppc64/cpu.h" + #elif defined(__aarch64__) + # include "aarch64/cpu.h" ++#elif defined(__loongarch__) ++# include "loongarch64/cpu.h" + #else + # error "Unsupported architecture" + #endif +diff --git a/src/ucs/arch/global_opts.h b/src/ucs/arch/global_opts.h +index 8786f13..28753ef 100644 +--- a/src/ucs/arch/global_opts.h ++++ b/src/ucs/arch/global_opts.h +@@ -15,6 +15,8 @@ + # include "ppc64/global_opts.h" + #elif defined(__aarch64__) + # include "aarch64/global_opts.h" ++#elif defined(__loongarch__) ++# include "loongarch64/global_opts.h" + #else + # error "Unsupported architecture" + #endif +diff --git a/src/ucs/arch/loongarch64/bitops.h b/src/ucs/arch/loongarch64/bitops.h +new file mode 100644 +index 0000000..86ad7f1 +--- /dev/null ++++ b/src/ucs/arch/loongarch64/bitops.h +@@ -0,0 +1,42 @@ ++/** ++* Copyright (C) Mellanox Technologies Ltd. 2001-2015. ALL RIGHTS RESERVED. ++* ++* See file LICENSE for terms. ++*/ ++ ++#ifndef UCS_LOONGARCH64_BITOPS_H_ ++#define UCS_LOONGARCH64_BITOPS_H_ ++ ++#include ++#include ++ ++ ++static UCS_F_ALWAYS_INLINE unsigned __ucs_ilog2_u32(uint32_t n) ++{ ++ int bit; ++ asm ("clz.w %0,%1" : "=r" (bit) : "r" (n)); ++ return 31 - bit; ++} ++ ++static UCS_F_ALWAYS_INLINE unsigned __ucs_ilog2_u64(uint64_t n) ++{ ++ int bit; ++ asm ("clz.d %0,%1" : "=r" (bit) : "r" (n)); ++ return 63 - bit; ++} ++ ++static UCS_F_ALWAYS_INLINE unsigned ucs_ffs32(uint32_t n) ++{ ++ int bit; ++ asm ("ctz.w %0,%1" : "=r" (bit) : "r" (n)); ++ return 31 - bit; ++} ++ ++static UCS_F_ALWAYS_INLINE unsigned ucs_ffs64(uint64_t n) ++{ ++ int bit; ++ asm ("ctz.d %0,%1" : "=r" (bit) : "r" (n)); ++ return 63 - bit; ++} ++ ++#endif +diff --git a/src/ucs/arch/loongarch64/cpu.h b/src/ucs/arch/loongarch64/cpu.h +new file mode 100644 +index 0000000..4f3223e +--- /dev/null ++++ b/src/ucs/arch/loongarch64/cpu.h +@@ -0,0 +1,101 @@ ++/** ++* Copyright (C) Mellanox Technologies Ltd. 2001-2013. ALL RIGHTS RESERVED. ++* Copyright (C) ARM Ltd. 2016-2017. ALL RIGHTS RESERVED. ++* ++* See file LICENSE for terms. ++*/ ++ ++ ++#ifndef UCS_LOONGARCH64_CPU_H_ ++#define UCS_LOONGARCH64_CPU_H_ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++BEGIN_C_DECLS ++ ++/** @file cpu.h */ ++ ++#define UCS_ARCH_CACHE_LINE_SIZE 64 ++ ++/* Assume the worst - weak memory ordering */ ++#define ucs_memory_bus_fence() asm volatile ("dbar 0"::: "memory") ++#define ucs_memory_bus_store_fence() ucs_memory_bus_fence() ++#define ucs_memory_bus_load_fence() ucs_memory_bus_fence() ++#define ucs_memory_bus_cacheline_wc_flush() ++#define ucs_memory_cpu_fence() ucs_memory_bus_fence() ++#define ucs_memory_cpu_store_fence() asm volatile ("dbar 0 \n" \ ++ ::: "memory") ++#define ucs_memory_cpu_load_fence() asm volatile ("dbar 0 \n" \ ++ "dbar 0 \n" \ ++ ::: "memory") ++#define ucs_memory_cpu_wc_fence() ucs_memory_bus_fence() ++ ++ ++static inline uint64_t ucs_arch_read_hres_clock() ++{ ++ uint64_t tb; ++ __drdtime_t tsc; ++ tsc = __rdtime_d(); ++ tb = tsc.dvalue; ++ return tb; ++} ++ ++static inline double ucs_arch_get_clocks_per_sec() { ++ uint64_t freq; ++ freq = 100 * 1000 * 1000; ++ return (double) freq; ++} ++ ++static inline ucs_cpu_model_t ucs_arch_get_cpu_model() ++{ ++ return UCS_CPU_MODEL_UNKNOWN; ++} ++ ++static inline ucs_cpu_vendor_t ucs_arch_get_cpu_vendor() ++{ ++ return UCS_CPU_VENDOR_UNKNOWN; ++} ++ ++static inline int ucs_arch_get_cpu_flag() ++{ ++ return UCS_CPU_FLAG_UNKNOWN; ++} ++ ++static inline void ucs_cpu_init() ++{ ++} ++ ++#define ucs_arch_wait_mem ucs_arch_generic_wait_mem ++ ++#if !HAVE___CLEAR_CACHE ++static inline void ucs_arch_clear_cache(void *start, void *end) ++{ ++ ucs_memory_cpu_fence(); ++} ++#endif ++ ++static inline void *ucs_memcpy_relaxed(void *dst, const void *src, size_t len) ++{ ++ return memcpy(dst, src, len); ++} ++ ++static UCS_F_ALWAYS_INLINE void ++ucs_memcpy_nontemporal(void *dst, const void *src, size_t len) ++{ ++ memcpy(dst, src, len); ++} ++ ++static inline ucs_status_t ucs_arch_get_cache_size(size_t *cache_sizes) ++{ ++ return UCS_ERR_UNSUPPORTED; ++} ++ ++END_C_DECLS ++ ++#endif +diff --git a/src/ucs/arch/loongarch64/global_opts.c b/src/ucs/arch/loongarch64/global_opts.c +new file mode 100644 +index 0000000..17f7a2a +--- /dev/null ++++ b/src/ucs/arch/loongarch64/global_opts.c +@@ -0,0 +1,24 @@ ++/** ++* Copyright (C) Mellanox Technologies Ltd. 2019. ALL RIGHTS RESERVED. ++* ++* See file LICENSE for terms. ++*/ ++ ++#if defined(__loongarch__) ++ ++#ifdef HAVE_CONFIG_H ++# include "config.h" ++#endif ++ ++#include ++#include ++ ++ucs_config_field_t ucs_arch_global_opts_table[] = { ++ {NULL} ++}; ++ ++void ucs_arch_print_memcpy_limits(ucs_arch_global_opts_t *config) ++{ ++} ++ ++#endif +diff --git a/src/ucs/arch/loongarch64/global_opts.h b/src/ucs/arch/loongarch64/global_opts.h +new file mode 100644 +index 0000000..b43786c +--- /dev/null ++++ b/src/ucs/arch/loongarch64/global_opts.h +@@ -0,0 +1,24 @@ ++/** ++* Copyright (C) Mellanox Technologies Ltd. 2019. ALL RIGHTS RESERVED. ++* ++* See file LICENSE for terms. ++*/ ++ ++ ++#ifndef UCS_LOONGARCH64_GLOBAL_OPTS_H_ ++#define UCS_LOONGARCH64_GLOBAL_OPTS_H_ ++ ++#include ++ ++BEGIN_C_DECLS ++ ++#define UCS_ARCH_GLOBAL_OPTS_INITALIZER {} ++ ++/* built-in memcpy config */ ++typedef struct ucs_arch_global_opts { ++ char dummy; ++} ucs_arch_global_opts_t; ++ ++END_C_DECLS ++ ++#endif +-- +2.39.3 + diff --git a/ucx.spec b/ucx.spec index 19846d1..30cbc44 100644 --- a/ucx.spec +++ b/ucx.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.1 +%define anolis_release .0.2 %{!?configure_options: %global configure_options %{nil}} %bcond_without cma %bcond_with cuda @@ -24,6 +24,7 @@ Summary: UCX is a communication library implementing high-performance messaging License: BSD URL: http://www.openucx.org Source: https://github.com/openucx/%{name}/releases/download/v%{version}/ucx-%{version}.tar.gz +Patch0: 0001-add-loongarch-support.patch BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Prefix: %{_prefix} @@ -92,6 +93,7 @@ Provides header files and examples for developing with UCX. %prep %setup -q +%patch0 -p1 %build %define _with_arg() %{expand:%%{?with_%{1}:--with-%{2}}%%{!?with_%{1}:--without-%{2}}} @@ -102,6 +104,9 @@ Provides header files and examples for developing with UCX. --disable-assertions \ --disable-params-check \ --without-java \ +%ifarch loongarch64 + --without-go \ +%endif %_enable_arg cma cma \ %_with_arg cuda cuda \ %_with_arg gdrcopy gdrcopy \ @@ -309,6 +314,9 @@ library internals, protocol objects, transports status, and more. %endif %changelog +* Thu Jul 27 2023 Jingyun Hua - 1.13.1-2.0.2 +- Fix build error on loongarch64 + * Tue Jul 04 2023 Jacob Wang - 1.13.1-2.0.1 - Add support for loongarch64 (gongwen@nfschina.com) -- Gitee