summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <proyvind@moondrake.org>2015-08-12 03:15:42 +0200
committerpark <sk7.park@samsung.com>2017-01-02 02:38:14 -0800
commit61702223c11c73ed47fb81c0c26d04322daf62bb (patch)
tree1ef24c395fca8deb01985212e0952aaf41821417
parent2b208642be85a9b03250c6ac403d1bbd1b293336 (diff)
downloadrpm-61702223c11c73ed47fb81c0c26d04322daf62bb.tar.gz
rpm-61702223c11c73ed47fb81c0c26d04322daf62bb.tar.bz2
rpm-61702223c11c73ed47fb81c0c26d04322daf62bb.zip
Add support for multithreaded xz compression
Change-Id: I77af75943420c65868672f05cbde73563370c351
-rw-r--r--rpmio/rpmio.c30
1 files changed, 29 insertions, 1 deletions
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 <stdarg.h>
#include <errno.h>
+#include <ctype.h>
#include <rpm/rpmlog.h>
#include <rpm/rpmmacro.h>
@@ -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);