[PATCH v3 2/4] erofs-utils: add a helper to get available processors
Yifan Zhao
zhaoyifan at sjtu.edu.cn
Mon Feb 26 01:27:57 AEDT 2024
From: Gao Xiang <hsiangkao at linux.alibaba.com>
In order to prepare for multi-threaded decompression.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
configure.ac | 1 +
include/erofs/config.h | 1 +
lib/config.c | 12 ++++++++++++
3 files changed, 14 insertions(+)
diff --git a/configure.ac b/configure.ac
index 1c7f53b..08eee08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -256,6 +256,7 @@ AC_CHECK_FUNCS(m4_flatten([
strerror
strrchr
strtoull
+ sysconf
tmpfile64
utimensat]))
diff --git a/include/erofs/config.h b/include/erofs/config.h
index eecf575..73e3ac2 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -109,6 +109,7 @@ static inline int erofs_selabel_open(const char *file_contexts)
void erofs_update_progressinfo(const char *fmt, ...);
char *erofs_trim_for_progressinfo(const char *str, int placeholder);
+unsigned int erofs_get_available_processors(void);
#ifdef __cplusplus
}
diff --git a/lib/config.c b/lib/config.c
index 1096cd1..947a183 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -14,6 +14,9 @@
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
struct erofs_configure cfg;
struct erofs_sb_info sbi;
@@ -177,3 +180,12 @@ void erofs_update_progressinfo(const char *fmt, ...)
fputs(msg, stdout);
fputc('\n', stdout);
}
+
+unsigned int erofs_get_available_processors(void)
+{
+#if defined(HAVE_UNISTD_H) && defined(HAVE_SYSCONF)
+ return sysconf(_SC_NPROCESSORS_ONLN);
+#else
+ return 0;
+#endif
+}
--
2.44.0
More information about the Linux-erofs
mailing list