From 61702223c11c73ed47fb81c0c26d04322daf62bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Wed, 12 Aug 2015 03:15:42 +0200 Subject: Add support for multithreaded xz compression Change-Id: I77af75943420c65868672f05cbde73563370c351 --- rpmio/rpmio.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 0c1a674dc..7add8536b 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -5,6 +5,7 @@ #include "system.h" #include #include +#include #include #include @@ -898,6 +899,7 @@ static LZFILE *lzopen_internal(const char *path, const char *mode, int fd, int x lzma_ret ret; lzma_stream init_strm = LZMA_STREAM_INIT; uint64_t mem_limit = rpmExpandNumeric("%{_xz_memlimit}"); + int threads = 0; for (; *mode; mode++) { if (*mode == 'w') @@ -906,6 +908,17 @@ static LZFILE *lzopen_internal(const char *path, const char *mode, int fd, int x encoding = 0; else if (*mode >= '0' && *mode <= '9') level = *mode - '0'; + else if (*mode == 'T') { + if (isdigit(*(mode+1))) { + threads = atoi(++mode); + /* skip past rest of digits in string that atoi() + * should've processed + * */ + while(isdigit(*++mode)); + } + else + threads = -1; + } } if (fd != -1) fp = fdopen(fd, encoding ? "w" : "r"); @@ -925,7 +938,22 @@ static LZFILE *lzopen_internal(const char *path, const char *mode, int fd, int x lzfile->strm = init_strm; if (encoding) { if (xz) { - ret = lzma_easy_encoder(&lzfile->strm, level, LZMA_CHECK_SHA256); + if (!threads) { + ret = lzma_easy_encoder(&lzfile->strm, level, LZMA_CHECK_SHA256); + } else { + if (threads == -1) + threads = sysconf(_SC_NPROCESSORS_ONLN); + lzma_mt mt_options = { + .flags = 0, + .threads = threads, + .block_size = 0, + .timeout = 0, + .preset = level, + .filters = NULL, + .check = LZMA_CHECK_SHA256 }; + + ret = lzma_stream_encoder_mt(&lzfile->strm, &mt_options); + } } else { lzma_options_lzma options; lzma_lzma_preset(&options, level); -- cgit v1.2.3