From cd6eedad11601cc6cdc472ed73a47f76fb4bfa09 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Tue, 23 May 2023 15:02:19 +0200 Subject: [PATCH] find-provides.ksyms, find-requires.ksyms: avoid calling nm twice Instead of running the nm output through grep and then running it through awk again, run it directly through awk, and bail of immediately if a non-absolute symbol is found. Also, while we're here, avoid executing the indirect parsing code if no __crc_* symbols are present at all, which shaves around 8-18% off of the run time: % for i in ./lib/modules/*; do \ echo "====== $i ====="; \ diff -u <(find $i | ./find-provides.ksyms.old) <(find $i | ./find-provides.ksyms.new); \ echo old:; find $i | time ./find-provides.ksyms.old > /dev/null; \ echo new:; find $i | time ./find-provides.ksyms.new > /dev/null; \ done ====== ./lib/modules/4.18.0-372.57.1.el8_6.s390x ===== old: ../find-provides.ksyms.old > /dev/null 5.10s user 4.52s system 150% cpu 6.412 total new: ../find-provides.ksyms.new > /dev/null 4.41s user 3.48s system 136% cpu 5.764 total ====== ./lib/modules/4.18.0-372.57.1.el8_6.x86_64 ===== old: ../find-provides.ksyms.old > /dev/null 7.80s user 6.19s system 143% cpu 9.740 total new: ../find-provides.ksyms.new > /dev/null 6.07s user 3.97s system 124% cpu 8.066 total ====== ./lib/modules/5.14.0-284.15.1.el9_2.s390x ===== old: ../find-provides.ksyms.old > /dev/null 5.87s user 4.35s system 143% cpu 7.113 total new: ../find-provides.ksyms.new > /dev/null 5.12s user 3.56s system 132% cpu 6.533 total ====== ./lib/modules/5.14.0-284.15.1.el9_2.x86_64 ===== old: ../find-provides.ksyms.old > /dev/null 8.44s user 6.78s system 144% cpu 10.535 total new: ../find-provides.ksyms.new > /dev/null 6.55s user 4.17s system 123% cpu 8.666 total ====== ./lib/modules/6.4.0-0.rc1.20230511git80e62bc8487b.19.eln126.s390x ===== old: ../find-provides.ksyms.old > /dev/null 5.04s user 3.95s system 145% cpu 6.166 total new: ../find-provides.ksyms.new > /dev/null 4.64s user 3.17s system 136% cpu 5.719 total ====== ./lib/modules/6.4.0-0.rc1.20230511git80e62bc8487b.19.eln126.x86_64 ===== old: ../find-provides.ksyms.old > /dev/null 8.49s user 5.54s system 139% cpu 10.043 total new: ../find-provides.ksyms.new > /dev/null 7.41s user 4.31s system 129% cpu 9.046 total * find-provides.ksyms: Rewrite the "if nm | grep -q; then nm | awk" with straight "nm | awk", update the awk script to return the exit code accordingly, execute indirect symbol parsing only if inderect __crc_* symbols are present. * find-requires.ksyms (all_provides): Likewise. Resolves: #2178935 Signed-off-by: Eugene Syromiatnikov --- find-provides.ksyms | 31 +++++++++++++++++++++++-------- find-requires.ksyms | 31 +++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/find-provides.ksyms b/find-provides.ksyms index db85657..1259dcb 100755 --- a/find-provides.ksyms +++ b/find-provides.ksyms @@ -38,13 +38,28 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do module="$tmpfile" fi - 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])) }' - else + # awk script return code: + # 0 - absolute __crc_* symbols have been found, output has been + # generated; + # 23 - a non-absolute __crc_* symbold has been found; + # 42 - no __crc_* symbols have been found. + nm "$module" \ + | awk \ + -v 'dep_pfx='"$dep_pfx" \ + --non-decimal-data \ + 'BEGIN { exit_code = 42 } + match($0, /^([0-9a-f]+) (.) __crc_(.+)/, a) { + if (a[2] == "A") { + printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1])); + exit_code = 0; + } else { + exit_code = 23; + exit; + } + } + END { exit exit_code }' + + [ 23 = "$?" ] && { objdump -t "$module" \ | sed -n 's/^[0-9a-f][0-9a-f]* [gl]...... \(.*\) [0-9a-f][0-9a-f]* __crc_.*$/\1/p' \ | sort -u \ @@ -72,7 +87,7 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do } match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) && a[2] == sectname { printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata, (strtonum("0x" a[1]) * 2) + 1, 8)) }' done - fi + } [ -z "$tmpfile" ] || rm -f -- "$tmpfile" done \ diff --git a/find-requires.ksyms b/find-requires.ksyms index ac3388c..d236cff 100644 --- a/find-requires.ksyms +++ b/find-requires.ksyms @@ -40,13 +40,28 @@ all_provides() { module="$tmpfile" fi - 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])) }' - else + # awk script return code: + # 0 - absolute __crc_* symbols have been found, output has been + # generated; + # 23 - a non-absolute __crc_* symbold has been found; + # 42 - no __crc_* symbols have been found. + nm "$module" \ + | awk \ + -v 'dep_pfx='"$dep_pfx" \ + --non-decimal-data \ + 'BEGIN { exit_code = 42 } + match($0, /^([0-9a-f]+) (.) __crc_(.+)/, a) { + if (a[2] == "A") { + printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1])); + exit_code = 0; + } else { + exit_code = 23; + exit; + } + } + END { exit exit_code }' + + [ 23 = "$?" ] && { objdump -t "$module" \ | sed -n 's/^[0-9a-f][0-9a-f]* [gl]...... \(.*\) [0-9a-f][0-9a-f]* __crc_.*$/\1/p' \ | sort -u \ @@ -74,7 +89,7 @@ all_provides() { } match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) && a[2] == sectname { printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata, (strtonum("0x" a[1]) * 2) + 1, 8)) }' done - fi + } [ -z "$tmpfile" ] || rm -f -- "$tmpfile" done \