From 4eeb0630777a3eada6f7a6c72254388a0c43585b Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Sun, 5 Feb 2023 01:12:50 +0100 Subject: [PATCH] find-provides.ksyms, find-requires.ksyms: rewrite absolute CRC parsing Avoid running sed on the whole "nm" output and also avoid "sed | awk" pipe in favor of a single awk call. Overall, this gives around 20% speedup on some quick synthetic tests: $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" | find-provides.ksyms.old > /dev/null 2> /dev/null' sh -c 14.20s user 8.93s system 144% cpu 16.014 total $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" | find-provides.ksyms.new > /dev/null 2> /dev/null' sh -c 12.01s user 7.46s system 143% cpu 13.567 total $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.old" \; > /dev/null 2> /dev/null' sh -c 16.31s user 10.77s system 134% cpu 20.092 total $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.new" \; > /dev/null 2> /dev/null' sh -c 13.95s user 8.92s system 135% cpu 16.836 total * find-provides.ksyms: Check presence of absolute __crc_* symbols with "grep -q" exit code and not presence of sed output; rewrite awk script to match the __crc_* symbols instead of preprocessing the nm output with sed. * find-requires.ksyms: Likewise. Signed-off-by: Eugene Syromiatnikov Resolves: #2135047 --- find-provides.ksyms | 10 ++++++---- find-requires.ksyms | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/find-provides.ksyms b/find-provides.ksyms index 60ea837..22eb39b 100755 --- a/find-provides.ksyms +++ b/find-provides.ksyms @@ -34,10 +34,12 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do module="$tmpfile" fi - if [[ -n $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then - nm $module \ - | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \ - | awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08x\n", $2, $1)}' \ + if nm "$module" | grep -qE '^([0-9a-f]+) A __crc_(.+)' 2> /dev/null; then + nm "$module" \ + | awk \ + -v 'dep_pfx='"$dep_pfx" \ + --non-decimal-data \ + 'match($0, /^([0-9a-f]+) A __crc_(.+)/, a) { printf("%s(%s) = 0x%08x\n", dep_pfx, a[2], strtonum("0x" a[1])) }' \ | sort -u else ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}') diff --git a/find-requires.ksyms b/find-requires.ksyms index 105a458..c93d1d2 100755 --- a/find-requires.ksyms +++ b/find-requires.ksyms @@ -35,10 +35,12 @@ all_provides() { module="$tmpfile" fi - if [[ -n $(nm "$module" | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then + if nm "$module" | grep -qE '^([0-9a-f]+) A __crc_(.+)' 2> /dev/null; then nm "$module" \ - | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \ - | awk --non-decimal-data '{printf("%s:0x%08x\n", $2, $1)}' + | awk \ + -v 'dep_pfx='"$dep_pfx" \ + --non-decimal-data \ + 'match($0, /^([0-9a-f]+) A __crc_(.+)/, a) { printf("%s(%s) = 0x%08x\n", dep_pfx, a[2], strtonum("0x" a[1])) }' else ELFRODATA=$(readelf -R .rodata "$module" | awk '/0x/{printf $2$3$4$5}') if [[ -n $(readelf -h "$module" | grep "little endian") ]]; then