diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2025-01-02 22:27:24 +0900 |
|---|---|---|
| committer | John Kehayias <john.kehayias@protonmail.com> | 2025-01-04 19:48:36 -0500 |
| commit | 851f2184e47cf82d8ae5559229e6f675ce4aa1f1 (patch) | |
| tree | 1b21cbb68c27ac3ba111b5cbd64e24abb8afc0a2 | |
| parent | d234d9fa94d0c51c9125472e8c46408fa3dc8e18 (diff) | |
nongnu: linux-firmware: Compress using multiple cores.
* nongnu/packages/patches/linux-firmware-parallel.patch: New patch.
* nongnu/packages/linux.scm (linux-firmware) [source]: Apply it.
[native-inputs]: Add parallel.
Signed-off-by: John Kehayias <john.kehayias@protonmail.com>
| -rw-r--r-- | nongnu/packages/linux.scm | 9 | ||||
| -rw-r--r-- | nongnu/packages/patches/linux-firmware-parallel.patch | 155 |
2 files changed, 161 insertions, 3 deletions
diff --git a/nongnu/packages/linux.scm b/nongnu/packages/linux.scm index 779e46a..fd9dc74 100644 --- a/nongnu/packages/linux.scm +++ b/nongnu/packages/linux.scm | |||
| @@ -26,15 +26,17 @@ | |||
| 26 | ;;; Copyright © 2023 Ada Stevenson <adanskana@gmail.com> | 26 | ;;; Copyright © 2023 Ada Stevenson <adanskana@gmail.com> |
| 27 | ;;; Copyright © 2023 Tomas Volf <~@wolfsden.cz> | 27 | ;;; Copyright © 2023 Tomas Volf <~@wolfsden.cz> |
| 28 | ;;; Copyright © 2023 PRESFIL <presfil@protonmail.com> | 28 | ;;; Copyright © 2023 PRESFIL <presfil@protonmail.com> |
| 29 | ;;; Copyright © 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com> | 29 | ;;; Copyright © 2024, 2025 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
| 30 | 30 | ||
| 31 | (define-module (nongnu packages linux) | 31 | (define-module (nongnu packages linux) |
| 32 | #:use-module (gnu packages) | 32 | #:use-module (gnu packages) |
| 33 | #:use-module (nongnu packages) | ||
| 33 | #:use-module (gnu packages admin) | 34 | #:use-module (gnu packages admin) |
| 34 | #:use-module (gnu packages base) | 35 | #:use-module (gnu packages base) |
| 35 | #:use-module (gnu packages compression) | 36 | #:use-module (gnu packages compression) |
| 36 | #:use-module (gnu packages cpio) | 37 | #:use-module (gnu packages cpio) |
| 37 | #:use-module (gnu packages linux) | 38 | #:use-module (gnu packages linux) |
| 39 | #:use-module (gnu packages parallel) | ||
| 38 | #:use-module (guix licenses) | 40 | #:use-module (guix licenses) |
| 39 | #:use-module (guix packages) | 41 | #:use-module (guix packages) |
| 40 | #:use-module (guix utils) | 42 | #:use-module (guix utils) |
| @@ -320,7 +322,8 @@ stable, responsive and smooth desktop experience."))) | |||
| 320 | "linux-firmware-" version ".tar.xz")) | 322 | "linux-firmware-" version ".tar.xz")) |
| 321 | (sha256 | 323 | (sha256 |
| 322 | (base32 | 324 | (base32 |
| 323 | "1xcsx51z5x0bim10a391n3xk6k8a5v1a35j1gpwpdl3nhmq3bc1b")))) | 325 | "1xcsx51z5x0bim10a391n3xk6k8a5v1a35j1gpwpdl3nhmq3bc1b")) |
| 326 | (patches (nongnu-patches "linux-firmware-parallel.patch")))) | ||
| 324 | (build-system gnu-build-system) | 327 | (build-system gnu-build-system) |
| 325 | (arguments | 328 | (arguments |
| 326 | (list #:tests? #f | 329 | (list #:tests? #f |
| @@ -350,7 +353,7 @@ stable, responsive and smooth desktop experience."))) | |||
| 350 | (setenv "ZSTD_NBTHREADS" num-jobs) | 353 | (setenv "ZSTD_NBTHREADS" num-jobs) |
| 351 | (apply invoke "make" "install-zst" "-j" num-jobs | 354 | (apply invoke "make" "install-zst" "-j" num-jobs |
| 352 | make-flags))))))) | 355 | make-flags))))))) |
| 353 | (native-inputs (list rdfind zstd)) | 356 | (native-inputs (list parallel rdfind zstd)) |
| 354 | (home-page | 357 | (home-page |
| 355 | "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git") | 358 | "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git") |
| 356 | (synopsis "Nonfree firmware blobs for Linux") | 359 | (synopsis "Nonfree firmware blobs for Linux") |
diff --git a/nongnu/packages/patches/linux-firmware-parallel.patch b/nongnu/packages/patches/linux-firmware-parallel.patch new file mode 100644 index 0000000..0e61cc1 --- /dev/null +++ b/nongnu/packages/patches/linux-firmware-parallel.patch | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | Upstream status: https://gitlab.com/kernel-firmware/linux-firmware/-/merge_requests/396 | ||
| 2 | |||
| 3 | From 5d8341be46374c5b4c3e34af0c9fd4837f25ad67 Mon Sep 17 00:00:00 2001 | ||
| 4 | From: Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 5 | Date: Thu, 2 Jan 2025 00:31:43 +0900 | ||
| 6 | Subject: [PATCH 3/4] Add support to install files/symlinks in parallel. | ||
| 7 | |||
| 8 | This reduces the install-zst target time from 100 s to 25 s on my test | ||
| 9 | system, a 400% speed improvement. | ||
| 10 | |||
| 11 | * Makefile (NUM_JOBS): New variable. | ||
| 12 | (install, install-xz, install-zst): Use it. | ||
| 13 | * copy-firmware.sh (num_jobs): New variable. | ||
| 14 | (has_gnu_parallel): New procedure. | ||
| 15 | <-j>: Parse new option, and use it along GNU parallel to parallelize | ||
| 16 | firmware copying and compression/symlink creation. | ||
| 17 | |||
| 18 | Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 19 | --- | ||
| 20 | Makefile | 8 +++++--- | ||
| 21 | copy-firmware.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++---- | ||
| 22 | 2 files changed, 52 insertions(+), 7 deletions(-) | ||
| 23 | |||
| 24 | diff --git a/Makefile b/Makefile | ||
| 25 | index 1f507bfd..0719f874 100644 | ||
| 26 | --- a/Makefile | ||
| 27 | +++ b/Makefile | ||
| 28 | @@ -1,4 +1,6 @@ | ||
| 29 | FIRMWAREDIR = /lib/firmware | ||
| 30 | +NUM_JOBS := $(or $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS))),\ | ||
| 31 | + 1) | ||
| 32 | |||
| 33 | all: | ||
| 34 | |||
| 35 | @@ -33,17 +35,17 @@ install: | ||
| 36 | false; \ | ||
| 37 | fi | ||
| 38 | install -d $(DESTDIR)$(FIRMWAREDIR) | ||
| 39 | - ./copy-firmware.sh $(DESTDIR)$(FIRMWAREDIR) | ||
| 40 | + ./copy-firmware.sh -j$(NUM_JOBS) $(DESTDIR)$(FIRMWAREDIR) | ||
| 41 | @echo "Now run \"make dedup\" to de-duplicate any firmware files" | ||
| 42 | |||
| 43 | install-xz: | ||
| 44 | install -d $(DESTDIR)$(FIRMWAREDIR) | ||
| 45 | - ./copy-firmware.sh --xz $(DESTDIR)$(FIRMWAREDIR) | ||
| 46 | + ./copy-firmware.sh -j$(NUM_JOBS) --xz $(DESTDIR)$(FIRMWAREDIR) | ||
| 47 | @echo "Now run \"make dedup\" to de-duplicate any firmware files" | ||
| 48 | |||
| 49 | install-zst: | ||
| 50 | install -d $(DESTDIR)$(FIRMWAREDIR) | ||
| 51 | - ./copy-firmware.sh --zstd $(DESTDIR)$(FIRMWAREDIR) | ||
| 52 | + ./copy-firmware.sh -j$(NUM_JOBS) --zstd $(DESTDIR)$(FIRMWAREDIR) | ||
| 53 | @echo "Now run \"make dedup\" to de-duplicate any firmware files" | ||
| 54 | |||
| 55 | clean: | ||
| 56 | diff --git a/copy-firmware.sh b/copy-firmware.sh | ||
| 57 | index 1a1094ae..f703443e 100755 | ||
| 58 | --- a/copy-firmware.sh | ||
| 59 | +++ b/copy-firmware.sh | ||
| 60 | @@ -9,6 +9,7 @@ verbose=: | ||
| 61 | compress=cat | ||
| 62 | compext= | ||
| 63 | destdir= | ||
| 64 | +num_jobs=1 | ||
| 65 | |||
| 66 | err() { | ||
| 67 | printf "ERROR: %s\n" "$*" | ||
| 68 | @@ -19,6 +20,15 @@ warn() { | ||
| 69 | printf "WARNING: %s\n" "$*" | ||
| 70 | } | ||
| 71 | |||
| 72 | +has_gnu_parallel() { | ||
| 73 | + if command -v parallel > /dev/null; then | ||
| 74 | + if parallel --version | grep -Fq 'GNU Parallel'; then | ||
| 75 | + return 0 | ||
| 76 | + fi | ||
| 77 | + fi | ||
| 78 | + return 1 | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | while test $# -gt 0; do | ||
| 82 | case $1 in | ||
| 83 | -v | --verbose) | ||
| 84 | @@ -27,6 +37,16 @@ while test $# -gt 0; do | ||
| 85 | shift | ||
| 86 | ;; | ||
| 87 | |||
| 88 | + -j*) | ||
| 89 | + num_jobs=$(echo "$1" | sed 's/-j//') | ||
| 90 | + if [ "$num_jobs" -gt 1 ] && ! has_gnu_parallel; then | ||
| 91 | + err "the GNU parallel command is required to use -j" | ||
| 92 | + fi | ||
| 93 | + parallel_args_file=$(mktemp) | ||
| 94 | + trap 'rm -f $parallel_args_file' EXIT INT QUIT TERM | ||
| 95 | + shift | ||
| 96 | + ;; | ||
| 97 | + | ||
| 98 | --xz) | ||
| 99 | if test "$compext" = ".zst"; then | ||
| 100 | err "cannot mix XZ and ZSTD compression" | ||
| 101 | @@ -76,12 +96,24 @@ grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | ||
| 102 | $verbose "copying/compressing file $f$compext" | ||
| 103 | if test "$compress" != "cat" && test "$k" = "RawFile"; then | ||
| 104 | $verbose "compression will be skipped for file $f" | ||
| 105 | - cat "$f" > "$destdir/$f" | ||
| 106 | + if [ "$num_jobs" -gt 1 ]; then | ||
| 107 | + echo "cat \"$f\" > \"$destdir/$f\"" >> "$parallel_args_file" | ||
| 108 | + else | ||
| 109 | + cat "$f" > "$destdir/$f" | ||
| 110 | + fi | ||
| 111 | else | ||
| 112 | - $compress "$f" > "$destdir/$f$compext" | ||
| 113 | + if [ "$num_jobs" -gt 1 ]; then | ||
| 114 | + echo "$compress \"$f\" > \"$destdir/$f$compext\"" >> "$parallel_args_file" | ||
| 115 | + else | ||
| 116 | + $compress "$f" > "$destdir/$f$compext" | ||
| 117 | + fi | ||
| 118 | fi | ||
| 119 | done | ||
| 120 | +if [ "$num_jobs" -gt 1 ]; then | ||
| 121 | + parallel -j"$num_jobs" -a "$parallel_args_file" | ||
| 122 | +fi | ||
| 123 | |||
| 124 | +echo > "$parallel_args_file" | ||
| 125 | # shellcheck disable=SC2162 # file/folder name can include escaped symbols | ||
| 126 | grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read l t; do | ||
| 127 | directory="$destdir/$(dirname "$l")" | ||
| 128 | @@ -89,12 +121,23 @@ grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read l t; do | ||
| 129 | target="$(cd "$directory" && realpath -m -s "$t")" | ||
| 130 | if test -e "$target"; then | ||
| 131 | $verbose "creating link $l -> $t" | ||
| 132 | - ln -s "$t" "$destdir/$l" | ||
| 133 | + if [ "$num_jobs" -gt 1 ]; then | ||
| 134 | + echo "ln -s \"$t\" \"$destdir/$l\"" >> "$parallel_args_file" | ||
| 135 | + else | ||
| 136 | + ln -s "$t" "$destdir/$l" | ||
| 137 | + fi | ||
| 138 | else | ||
| 139 | $verbose "creating link $l$compext -> $t$compext" | ||
| 140 | - ln -s "$t$compext" "$destdir/$l$compext" | ||
| 141 | + if [ "$num_jobs" -gt 1 ]; then | ||
| 142 | + echo "ln -s \"$t$compext\" \"$destdir/$l$compext\"" >> "$parallel_args_file" | ||
| 143 | + else | ||
| 144 | + ln -s "$t$compext" "$destdir/$l$compext" | ||
| 145 | + fi | ||
| 146 | fi | ||
| 147 | done | ||
| 148 | +if [ "$num_jobs" -gt 1 ]; then | ||
| 149 | + parallel -j"$num_jobs" -a "$parallel_args_file" | ||
| 150 | +fi | ||
| 151 | |||
| 152 | # Verify no broken symlinks | ||
| 153 | if test "$(find "$destdir" -xtype l | wc -l)" -ne 0 ; then | ||
| 154 | -- | ||
| 155 | GitLab | ||
