rpm/rpm-5.4.10-Multithreaded-XZ.patch
2018-12-25 01:30:09 +03:00

108 lines
3 KiB
Diff

From 885436e995aa39249a7089bf1f850431ed318b7f Mon Sep 17 00:00:00 2001
From: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
Date: Tue, 25 Dec 2018 01:04:37 +0300
Subject: [PATCH] Multithreaded XZ
Ported commits 7740d1098642cd42f725fb9a2a3819ceaf51a80b and bec7592a36a2243aa4656afecf3247598baac5ff
from RPM4 rpm-4.14.0-rc1 to RPM5 5.4.10 (ROSA)
https://github.com/rpm-software-management/rpm/commit/7740d1098642cd42f725fb9a2a3819ceaf51a80b
https://github.com/rpm-software-management/rpm/commit/bec7592a36a2243aa4656afecf3247598baac5ff
---
rpmio/xzdio.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 3 deletions(-)
diff --git a/rpmio/xzdio.c b/rpmio/xzdio.c
index f7a078f..e33f3a4 100644
--- a/rpmio/xzdio.c
+++ b/rpmio/xzdio.c
@@ -7,6 +7,7 @@
#include "rpmio_internal.h"
#include <rpmmacro.h>
#include <rpmcb.h>
+#include <ctype.h>
#if defined(WITH_XZ)
@@ -33,6 +34,10 @@
#endif
#include "lzma.h"
+/* Multithreading support in stable API since xz 5.2.0 */
+#if LZMA_VERSION >= 50020002
+#define HAVE_LZMA_MT
+#endif
#ifndef LZMA_PRESET_DEFAULT
#define LZMA_PRESET_DEFAULT UINT32_C(6)
@@ -68,7 +73,9 @@ static XZFILE *xzopen_internal(const char *path, const char *mode, int fdno, int
XZFILE *xzfile;
lzma_stream tmp;
lzma_ret ret;
-
+#ifdef HAVE_LZMA_MT
+ int threads = 0;
+#endif
for (; *mode != '\0'; mode++) {
if (*mode == 'w')
encoding = 1;
@@ -76,6 +83,21 @@ static XZFILE *xzopen_internal(const char *path, const char *mode, int fdno, int
encoding = 0;
else if (*mode >= '0' && *mode <= '9')
level = (int)(*mode - '0');
+ else if (*mode == 'T') {
+ if (isdigit(*(mode+1))) {
+#ifdef HAVE_LZMA_MT
+ threads = atoi(++mode);
+#endif
+ /* skip past rest of digits in string that atoi()
+ * should've processed
+ * */
+ while(isdigit(*++mode));
+ }
+#ifdef HAVE_LZMA_MT
+ else
+ threads = -1;
+#endif
+ }
}
if (fdno != -1)
fp = fdopen(fdno, encoding ? "w" : "r");
@@ -95,7 +117,26 @@ static XZFILE *xzopen_internal(const char *path, const char *mode, int fdno, int
xzfile->strm = tmp;
if (encoding) {
if (xz) {
- ret = lzma_easy_encoder(&xzfile->strm, level, LZMA_CHECK_CRC32);
+#ifdef HAVE_LZMA_MT
+ if (!threads) {
+#endif
+ ret = lzma_easy_encoder(&xzfile->strm, level, LZMA_CHECK_CRC32);
+#ifdef HAVE_LZMA_MT
+ } 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(&xzfile->strm, &mt_options);
+ }
+#endif
} else {
lzma_options_lzma options;
(void) lzma_lzma_preset(&options, level);
@@ -167,7 +208,6 @@ static int xzclose(/*@only@*/ XZFILE *xzfile)
lzma_ret ret;
size_t n;
int rc;
-
if (!xzfile)
return -1;
if (xzfile->encoding) {
--
2.17.1