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 <esyr@redhat.com>
Resolves: #2135047
This commit is contained in:
Eugene Syromiatnikov 2023-02-05 01:12:50 +01:00
parent 1745d287de
commit 594e5a5a30
2 changed files with 11 additions and 7 deletions

View File

@ -34,10 +34,12 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
module="$tmpfile" module="$tmpfile"
fi 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 \ nm "$module" \
| sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \ | awk \
| awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08x\n", $2, $1)}' \ -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 | sort -u
else else
ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}') ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}')

View File

@ -35,10 +35,12 @@ all_provides() {
module="$tmpfile" module="$tmpfile"
fi 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" \ nm "$module" \
| sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \ | awk \
| awk --non-decimal-data '{printf("%s:0x%08x\n", $2, $1)}' -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 else
ELFRODATA=$(readelf -R .rodata "$module" | awk '/0x/{printf $2$3$4$5}') ELFRODATA=$(readelf -R .rodata "$module" | awk '/0x/{printf $2$3$4$5}')
if [[ -n $(readelf -h "$module" | grep "little endian") ]]; then if [[ -n $(readelf -h "$module" | grep "little endian") ]]; then