!12 升级软件包,清理多余补丁,解决issueI8Z5F4

From: @yang_yanchao 
Reviewed-by: @wangbin224 
Signed-off-by: @wangbin224
This commit is contained in:
openeuler-ci-bot 2024-02-02 01:25:49 +00:00 committed by Gitee
commit b1819a9034
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 25 additions and 596 deletions

View File

@ -1,67 +0,0 @@
From 512d8df361f3afa3831fff90cdf3c3f43bbc9142 Mon Sep 17 00:00:00 2001
From: Yang Yanchao <yangyanchao6@huawei.com>
Date: Tue, 12 Sep 2023 10:54:05 +0800
Subject: [PATCH] Structures and macros use the default definition of the
kernel
Signed-off-by: Yang Yanchao <yangyanchao6@huawei.com>
---
include/libgmem.h | 29 -----------------------------
src/libgmem.c | 1 +
2 files changed, 1 insertion(+), 29 deletions(-)
diff --git a/include/libgmem.h b/include/libgmem.h
index ece13a3..35cf463 100644
--- a/include/libgmem.h
+++ b/include/libgmem.h
@@ -17,35 +17,6 @@
#include <syscall.h>
__BEGIN_DECLS
-/*
- * TODO: Remove these "ifndef" after kernel upgrade
- */
-#include <sys/ioctl.h>
-struct hmadvise_arg {
- int hnid;
- unsigned long start;
- size_t len_in;
- int behavior;
-};
-struct gmem_hnid_arg {
- int *hnuma_id;
-};
-#ifndef GMEM_GET_HNUMA_ID
- #define GMEM_GET_HNUMA_ID _IOW(0x55, 1, struct gmem_hnid_arg)
-#endif
-
-#ifndef GMEM_MADVISE
- #define GMEM_MADVISE _IOW(0x55, 2, struct hmadvise_arg)
-#endif
-
-#ifndef MADV_PREFETCH
-# define MADV_PREFETCH 32
-#endif
-
-#ifndef MADV_DONTNEED
-# define MADV_DONTNEED 4
-#endif
-
/*
* gmemFreeEager - unmap memory data
* @args
diff --git a/src/libgmem.c b/src/libgmem.c
index 59682af..870da87 100644
--- a/src/libgmem.c
+++ b/src/libgmem.c
@@ -14,6 +14,7 @@
#include <linux/mman.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/ioctl.h>
#include <libgmem.h>
#include <gmem_common.h>
--
2.41.0.windows.3

View File

@ -1,67 +0,0 @@
From 7ec0cd6ce9c75de770426bde8747d329397ad4c8 Mon Sep 17 00:00:00 2001
From: Lemmy Huang <huangliming5@huawei.com>
Date: Wed, 20 Sep 2023 14:15:48 +0800
Subject: [PATCH] add install_npu_driver.sh
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
---
scripts/install_npu_driver.sh | 47 +++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 scripts/install_npu_driver.sh
diff --git a/scripts/install_npu_driver.sh b/scripts/install_npu_driver.sh
new file mode 100644
index 0000000..37b35ea
--- /dev/null
+++ b/scripts/install_npu_driver.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# install npu-driver to kernel-6.4
+
+RPM_NAME=$1
+RUN_DIR="/usr/local/Ascend"
+RUN_NAME="$RUN_DIR/Ascend-hdk-910-npu-driver_6.0.0.1_linux-aarch64.run"
+
+function sed_run()
+{
+ echo "sed $RUN_NAME ..."
+
+ sed -n '1,/^eval $finish; exit $res/!p' $RUN_NAME > tmp.tar.gz
+ sed -n '1,/^eval $finish; exit $res/p' $RUN_NAME > install.sh
+ sed -i 's/MS_Check "$0".*/echo "skip MS_Check"/g' install.sh
+
+ mkdir sz_tmp
+ mv tmp.tar.gz sz_tmp/
+ cd sz_tmp
+
+ tar -axf tmp.tar.gz
+ rm -rf tmp.tar.gz
+
+ sed -i "s/^check_euleros$/#check_euleros/g" driver/script/run_driver_map_kernel.sh
+ sed -i "s/^check_and_match$/#check_and_match/g" driver/script/run_driver_map_kernel.sh
+ sed -i "s/^drv_dkms_env_check$/#/g" driver/script/run_driver_install.sh
+ sed -i "s/^.*driver_ko_install_manually$/echo \"skip\"/g" driver/script/run_driver_install.sh
+
+ tar -acf tmp.tar.gz *
+ mv tmp.tar.gz ../tmp.tar.gz
+ cd ..
+
+ cat install.sh tmp.tar.gz > $RUN_NAME
+ rm -rf sz_tmp
+ rm -f install.sh tmp.tar.gz
+}
+
+
+rpm -ivh $RPM_NAME --noscripts
+
+cd $RUN_DIR
+sed_run
+groupadd HwHiAiUser
+useradd -g HwHiAiUser -d /home/HwHiAiUser -m HwHiAiUser -s /bin/bash
+$RUN_NAME --full --force
+cd -
+
--
2.33.0

View File

@ -1,96 +0,0 @@
From 25335f5ab5c0f3dd448613bc0cf75ec6e58f6a5a Mon Sep 17 00:00:00 2001
From: Yang Yanchao <yangyanchao6@huawei.com>
Date: Wed, 6 Sep 2023 16:01:53 +0800
Subject: [PATCH] fix three issue
Check the return ptr of the malloc[#I7YV2X]
add hnid in gmemPrefetch [#I7XQMW]
free userData in stream to avoid async operations accessing illeagal address[#I7Z2RF]
Signed-off-by: Yang Yanchao <yangyanchao6@huawei.com>
---
include/libgmem.h | 10 ++++++----
src/libgmem.c | 15 +++++++++++----
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/include/libgmem.h b/include/libgmem.h
index 4cd918b..ece13a3 100644
--- a/include/libgmem.h
+++ b/include/libgmem.h
@@ -62,17 +62,19 @@ int gmemFreeEager(unsigned long addr, size_t size, void *stream);
* @args
* addr: start address of the memory to be migrated
* length: length of the memory to be migrated
+ * hnid: the numa id of the target device
* stream: the stream where work queue used by operation
*
* The physical data mapped by [addr, addr + length) will migrate to
- * the device corresponding to streamid. The hnuma node of the device
- * in the current context needs to be automatically obtained
- * and the prefetch instruction of hmadvise is invoked.
+ * the target device corresponding to streamid.
+ *
+ * If stream is NULL, perform synchronous operation; otherwise,
+ * perform asynchronous operation.
*
* The asynchronous operation is non-blocking, but is executed in
* sequence with the tasks in the stream.
*/
-int gmemPrefetch(unsigned long addr, size_t length, void *stream);
+int gmemPrefetch(unsigned long addr, size_t length, int hnid, void *stream);
/*
* gmemGetNumaId - get the numaid of the current device
diff --git a/src/libgmem.c b/src/libgmem.c
index 9a34de0..59682af 100644
--- a/src/libgmem.c
+++ b/src/libgmem.c
@@ -37,6 +37,7 @@ int gmemAdvise(void *userData)
if(ret) {
printf("hmadvise failed: addr:%lx, size:%lx, behavior:%d, hnid:%d\n", msg.start, msg.len_in, msg.behavior, msg.hnid);
}
+ free(userData);
return ret;
}
@@ -44,27 +45,33 @@ int gmemFreeEager(unsigned long addr, size_t length, void *stream)
{
int ret = -1;
gm_msg_t userData = (gm_msg_t)malloc(sizeof(gm_msg));
+ if (userData == NULL) {
+ fprintf(stderr, "Failed to allocate memory for userData\n");
+ return -ENOMEM;
+ }
mix_userData(userData, addr, length, -1, MADV_DONTNEED);
if (!stream) {
ret = gmemAdvise(userData);
} else if(gmemSemantics.FreeEager != NULL) {
ret = gmemSemantics.FreeEager(userData, stream);
}
- free(userData);
return ret;
}
-int gmemPrefetch(unsigned long addr, size_t length, void *stream)
+int gmemPrefetch(unsigned long addr, size_t length, int hnid, void *stream)
{
int ret = -1;
gm_msg_t userData = (gm_msg_t)malloc(sizeof(gm_msg));
- mix_userData(userData, addr, length, gmemGetNumaId(), MADV_PREFETCH);
+ if (userData == NULL) {
+ fprintf(stderr, "Failed to allocate memory for userData\n");
+ return -ENOMEM;
+ }
+ mix_userData(userData, addr, length, hnid, MADV_PREFETCH);
if (!stream) {
ret = gmemAdvise(userData);
} else if(gmemSemantics.Prefetch != NULL) {
ret = gmemSemantics.Prefetch(userData, stream);
}
- free(userData);
return ret;
}
--
2.41.0.windows.3

Binary file not shown.

View File

@ -1,18 +1,14 @@
%define gmem_path /usr/local/gmem
%define with_gmem 0
Name: libgmem
Version: 0.1
Release: 5
Release: 6
Summary: Library of Generalized Memory Management
License: MulanPSL-2.0
URL: https://gitee.com/openeuler/libgmem
Source0: https://gitee.com/openeuler/libgmem/repository/archive/%{name}-v%{version}.tar.gz
PATCH0001: use-ioctl-instead-of-syscall.patch
PATCH0002: fix-three-issue-I7YV2X-I7XQMW-I7Z2RF.patch
Patch0003: Structures-and-macros-use-the-default-definition-of-.patch
Patch0004: optimize-headers-file.patch
Patch0005: add-install_npu_driver.sh.patch
BuildRequires: autoconf automake libtool
BuildRequires: gcc glibc-devel make kernel-headers
@ -28,6 +24,7 @@ Requires: %{name} = %{version}-%{release}
%description devel
The libgmem-devel package provides header files used for GMEM.
%if %{with_gmem}
%prep
%autosetup -p1 -n %{name}-v%{version}
@ -53,8 +50,30 @@ install -Dp %{_builddir}/%{name}-v%{version}/scripts/install_npu_driver.sh %{bu
%{_includedir}/libgmem.h
%dir %{gmem_path}
%{gmem_path}/install_npu_driver.sh
%else
%prep
%autosetup -p1 -n %{name}-v%{version}
%install
install -dp %{buildroot}/%{gmem_path}
install -dp %{buildroot}/%{_includedir}
install -Dp %{_builddir}/%{name}-v%{version}/License %{buildroot}/%{gmem_path}/
install -Dp %{_builddir}/%{name}-v%{version}/include/libgmem.h %{buildroot}/%{_includedir}
%files
%{gmem_path}/License
%files devel
%{_includedir}/libgmem.h
%endif
%changelog
* Fri Feb 2 2024 Yang Yanchao <yangyanchap6@huawei.com> - 0.1-6
-update libgmem-v0.1.tar.gz to 4dc188c
Skip building when the kernel does not support GMEM[I8Z5F4]
* Wed Sep 20 2023 Lemmy Huang <huangliming5@huawei.com> - 0.1-5
- add install_npu_driver.sh

View File

@ -1,42 +0,0 @@
From 074fe4486f48838690e674a7e0f394705777cc93 Mon Sep 17 00:00:00 2001
From: Yang Yanchao <yangyanchao6@huawei.com>
Date: Tue, 12 Sep 2023 12:02:03 +0800
Subject: [PATCH] optimize headers file
add linux/gmem_dev.h in gmem_common.h
change syscall.h position
Signed-off-by: Yang Yanchao <yangyanchao6@huawei.com>
---
include/gmem_common.h | 2 ++
include/libgmem.h | 1 -
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/gmem_common.h b/include/gmem_common.h
index a400b37..dfaeb56 100644
--- a/include/gmem_common.h
+++ b/include/gmem_common.h
@@ -15,6 +15,8 @@
#include <libgmem.h>
#include <stdlib.h>
+#include <syscall.h>
+#include <linux/gmem_dev.h>
typedef struct {
int (*FreeEager)(void *userData, void *stream);
diff --git a/include/libgmem.h b/include/libgmem.h
index 35cf463..d68aed7 100644
--- a/include/libgmem.h
+++ b/include/libgmem.h
@@ -14,7 +14,6 @@
#define _LIBGMEM_H
#include <unistd.h>
-#include <syscall.h>
__BEGIN_DECLS
/*
--
2.41.0.windows.3

View File

@ -1,318 +0,0 @@
From 762c6c0c4c8618fc95aa25696345e369681d0465 Mon Sep 17 00:00:00 2001
From: Yang Yanchao <yangyanchao6@huawei.com>
Date: Fri, 25 Aug 2023 18:39:54 +0800
Subject: [PATCH] use ioctl instead of syscall
---
Makefile.am | 3 ++-
include/gmem_common.h | 16 ++++++------
include/libgmem.h | 24 +++++++++++------
src/ascend/gmem_ascend.c | 22 ++++------------
src/ascend/gmem_ascend.h | 35 -------------------------
src/init.c | 56 ++++++++++++++++++++++++++++++++++++++++
src/libgmem.c | 18 +++++++------
7 files changed, 97 insertions(+), 77 deletions(-)
delete mode 100644 src/ascend/gmem_ascend.h
create mode 100644 src/init.c
diff --git a/Makefile.am b/Makefile.am
index e18c2fc..06b1435 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,7 +23,8 @@ include_HEADERS = include/libgmem.h
lib_LTLIBRARIES = libgmem.la
libgmem_la_SOURCES = \
- src/libgmem.c
+ src/libgmem.c \
+ src/init.c
libgmem_la_CFLAGS = $(AM_CFLAGS) \
-I$(top_srcdir)/include
diff --git a/include/gmem_common.h b/include/gmem_common.h
index 994f953..a400b37 100644
--- a/include/gmem_common.h
+++ b/include/gmem_common.h
@@ -13,22 +13,22 @@
#ifndef _GMEM_WAPPER_H_
#define _GMEM_WAPPER_H_
+#include <libgmem.h>
#include <stdlib.h>
-struct gm_msg {
- int behavior;
- unsigned long addr;
- size_t size;
- int hnid;
-};
-typedef struct gm_msg *gm_msg_t;
-
typedef struct {
int (*FreeEager)(void *userData, void *stream);
int (*Prefetch)(void *userData, void *stream);
int (*GetNumaId)(void);
} gmem_semantics;
extern gmem_semantics gmemSemantics;
+extern int gmem_fd;
+
+typedef struct hmadvise_arg gm_msg;
+typedef gm_msg *gm_msg_t;
+
+void init_device(void);
+void destory_device(void);
int gmemAdvise(void *userData);
#endif
diff --git a/include/libgmem.h b/include/libgmem.h
index ea313a3..4cd918b 100644
--- a/include/libgmem.h
+++ b/include/libgmem.h
@@ -20,14 +20,22 @@ __BEGIN_DECLS
/*
* TODO: Remove these "ifndef" after kernel upgrade
*/
-/*
- * __NR_madvise 441
- */
-#ifndef SYS_hmdvise
-# ifndef __NR_hmadvise
-# define __NR_hmadvise 441
-# endif
-# define SYS_hmadvise __NR_hmadvise
+#include <sys/ioctl.h>
+struct hmadvise_arg {
+ int hnid;
+ unsigned long start;
+ size_t len_in;
+ int behavior;
+};
+struct gmem_hnid_arg {
+ int *hnuma_id;
+};
+#ifndef GMEM_GET_HNUMA_ID
+ #define GMEM_GET_HNUMA_ID _IOW(0x55, 1, struct gmem_hnid_arg)
+#endif
+
+#ifndef GMEM_MADVISE
+ #define GMEM_MADVISE _IOW(0x55, 2, struct hmadvise_arg)
#endif
#ifndef MADV_PREFETCH
diff --git a/src/ascend/gmem_ascend.c b/src/ascend/gmem_ascend.c
index be54813..6181c07 100644
--- a/src/ascend/gmem_ascend.c
+++ b/src/ascend/gmem_ascend.c
@@ -19,13 +19,8 @@
#include <gmem_common.h>
-#include "gmem_ascend.h"
-
#define LIB_ASCENDCL_PATH "/usr/local/Ascend/ascend-toolkit/latest/aarch64-linux/lib64/libascendcl.so"
-void init_gmemSemantics(void) __attribute__ ((constructor));
-void exit_gmemSemantics(void) __attribute__ ((destructor));
-
typedef void (*Callback_fn)(void *userData);
typedef int (*ACLRT_LAUNCH_CB_FUNC)(Callback_fn fn, void *userData, int vlockType, void *stream);
ACLRT_LAUNCH_CB_FUNC aclrtLaunchCallback_fn;
@@ -43,26 +38,19 @@ int ascend_prefech(void *userData, void *stream)
int ascend_numaid(void)
{
- int ret, id, fd;
- struct rpg_hnid_arg arg;
-
- fd = open("/dev/remote_pager", O_RDWR);
- if (fd == -1) {
- perror("Get davinci_manager fd failed");
- return -ENXIO;
- }
+ int ret, id;
+ struct gmem_hnid_arg arg;
arg.hnuma_id = &id;
- ret = ioctl(fd, RPG_GET_HNUMA_ID, &arg);
+ ret = ioctl(gmem_fd, GMEM_GET_HNUMA_ID, &arg);
if (ret < 0) {
perror("Get hnuma id ioctl failed.");
return ret;
}
- close(fd);
return id;
}
-void init_gmemSemantics()
+void init_device()
{
handle = dlopen(LIB_ASCENDCL_PATH, RTLD_LAZY);
if (!handle) {
@@ -76,7 +64,7 @@ void init_gmemSemantics()
gmemSemantics.GetNumaId = ascend_numaid;
}
-void exit_gmemSemantics()
+void destory_device()
{
dlclose(handle);
}
diff --git a/src/ascend/gmem_ascend.h b/src/ascend/gmem_ascend.h
deleted file mode 100644
index 5348c2e..0000000
--- a/src/ascend/gmem_ascend.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2023 yangyanchao6@huawei.com 
- * libgmem is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
- * You may obtain a copy of Mulan PSL v2 at:
- *          http://license.coscl.org.cn/MulanPSL2
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- * See the Mulan PSL v2 for more details.
- */
-
-#ifndef _GMEM_ASCEND_H_
-#define _GMEM_ASCEND_H_
-
-/*
- * These definitions should be placed in the kernel,
- * which is a temporary implementation here.
- */
-
-#define RPG_MAGIC 0x55
-
-enum _RPG_IOCTL_CMD {
- _RPG_GET_HNUMA_ID = 1,
- _RPG_IOC_MAX_NR
-};
-
-struct rpg_hnid_arg {
- int *hnuma_id;
-};
-
-#define RPG_GET_HNUMA_ID \
- _IOW(RPG_MAGIC, _RPG_GET_HNUMA_ID, struct rpg_hnid_arg)
-
-#endif
diff --git a/src/init.c b/src/init.c
new file mode 100644
index 0000000..08b2800
--- /dev/null
+++ b/src/init.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2023 yangyanchao6@huawei.com 
+ * libgmem is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *          http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+#include <errno.h>
+#include <linux/mman.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+#include <libgmem.h>
+#include <gmem_common.h>
+
+int gmem_fd;
+
+int init_libgmem(void) __attribute__ ((constructor));
+void exit_libgmem(void) __attribute__ ((destructor));
+
+int get_gmem_fd()
+{
+ gmem_fd = open("/dev/gmem", O_RDWR);
+ if (gmem_fd == -1) {
+ perror("Get gmem fd failed");
+ return -ENXIO;
+ }
+ return 0;
+}
+
+void release_gmem_fd()
+{
+ close(gmem_fd);
+}
+
+int init_libgmem(void)
+{
+ if (get_gmem_fd()) {
+ return -ENXIO;
+ }
+ init_device();
+ return 0;
+}
+
+void exit_libgmem(void)
+{
+ release_gmem_fd();
+ destory_device();
+}
+
diff --git a/src/libgmem.c b/src/libgmem.c
index a1a1640..9a34de0 100644
--- a/src/libgmem.c
+++ b/src/libgmem.c
@@ -23,17 +23,19 @@ gmem_semantics gmemSemantics;
static void mix_userData(gm_msg_t userData, unsigned long addr, size_t length, int hnid, int behavior)
{
userData->behavior = behavior;
- userData->addr = addr;
- userData->size = length;
+ userData->start = addr;
+ userData->len_in = length;
userData->hnid = hnid;
}
int gmemAdvise(void *userData)
{
- gm_msg_t msg = (gm_msg_t)userData;
- int ret = syscall(SYS_hmadvise, msg->hnid, msg->addr, msg->size, msg->behavior);
+ int ret;
+ gm_msg msg = *(gm_msg_t)userData;
+
+ ret = ioctl(gmem_fd, GMEM_MADVISE, msg);
if(ret) {
- printf("hmadvise failed: addr:%lx, size:%lx, behavior:%d, hnid:%d\n", msg->addr, msg->size, msg->behavior, msg->hnid);
+ printf("hmadvise failed: addr:%lx, size:%lx, behavior:%d, hnid:%d\n", msg.start, msg.len_in, msg.behavior, msg.hnid);
}
return ret;
}
@@ -41,7 +43,7 @@ int gmemAdvise(void *userData)
int gmemFreeEager(unsigned long addr, size_t length, void *stream)
{
int ret = -1;
- gm_msg_t userData = (gm_msg_t)malloc(sizeof(struct gm_msg));
+ gm_msg_t userData = (gm_msg_t)malloc(sizeof(gm_msg));
mix_userData(userData, addr, length, -1, MADV_DONTNEED);
if (!stream) {
ret = gmemAdvise(userData);
@@ -55,12 +57,12 @@ int gmemFreeEager(unsigned long addr, size_t length, void *stream)
int gmemPrefetch(unsigned long addr, size_t length, void *stream)
{
int ret = -1;
- gm_msg_t userData = (gm_msg_t)malloc(sizeof(struct gm_msg));
+ gm_msg_t userData = (gm_msg_t)malloc(sizeof(gm_msg));
mix_userData(userData, addr, length, gmemGetNumaId(), MADV_PREFETCH);
if (!stream) {
ret = gmemAdvise(userData);
} else if(gmemSemantics.Prefetch != NULL) {
- ret = gmemSemantics.FreeEager(userData,stream);
+ ret = gmemSemantics.Prefetch(userData, stream);
}
free(userData);
return ret;
--
2.41.0.windows.3