[PATCH v7 2/5] erofs-utils: add a helper to get available processors

Huang Jianan jnhuang95 at gmail.com
Thu Mar 21 05:15:14 AEDT 2024


On 2024/3/15 9:10, Gao Xiang wrote:

> In order to prepare for multi-threaded decompression.

multi-threaded compression.

Thanks,
Jianan

> Signed-off-by: Yifan Zhao<zhaoyifan at sjtu.edu.cn>
> 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 3ccd6bb..2e69260 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
> +}


More information about the Linux-erofs mailing list