torture: Select line in sed and replace grep
Subsystems (3)
PATCH 1/2 torture: Select line in sed and replace grep
sed’s switch -n (--silent) suppresses the automatic printing of the pattern space, therefore, allowing to replace grep by only printing the current pattern space using the command p.
--- tools/testing/selftests/rcutorture/bin/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/functions.sh +1 -1
@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`" + nt="`lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esac
Signature · 1 line
2.35.1
PATCH 2/2 torture: Make thread detection more robust by using lspcu
For consecutive numbers *lscpu* collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8
$ lscpu | grep '^NUMA node'
NUMA node(s): 2
NUMA node0 CPU(s): 0-79
NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p'
$(Before the last patch, the whole line was returned.)
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/'
NUMA node0 CPU(s): 0-79*lscpu* shows the number of threads per core, so use that value directly.
$ sudo ppc64_cpu --smt=8
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 8
$ sudo ppc64_cpu --smt=off
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 1Note, the replaced heuristic is also incorrect for that case, where the threads per core are disabled.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p'
8--- tools/testing/selftests/rcutorture/bin/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/functions.sh +1 -1
@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p'`" + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esac
Signature · 1 line
2.35.1
Paul E. McKenney
maintainerRe: [PATCH 2/2] torture: Make thread detection more robust by using lspcu
Quoted 30 lines · Paul Menzel
For consecutive numbers *lscpu* collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep '^NUMA node' NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' $(Before the last patch, the whole line was returned.)
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' NUMA node0 CPU(s): 0-79*lscpu* shows the number of threads per core, so use that value directly.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 8 $ sudo ppc64_cpu --smt=off $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 1
Quoted 7 lines
Note, the replaced heuristic is also incorrect for that case, where the threads per core are disabled.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' 8Signed-off-by Paul Menzel <[email protected]>
Makes sense, and thank you for chasing this down and for the fix!
But should this patch and 1/2 be merged? Or am I confused and they are somehow affecting two different lines of scripting?
Thanx, Paul
Quoted 20 lines
--- tools/testing/selftests/rcutorture/bin/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/rcutorture/bin/functions.sh +1
-1@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p'`" + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esacSignature · 1 line
2.35.1
Re: [PATCH 2/2] torture: Make thread detection more robust by using lspcu
Dear Paul,
Am 22.02.22 um 18:43 schrieb Paul E. McKenney:
Quoted 37 lines · Paul Menzel
Quoted 36 lines
For consecutive numbers *lscpu* collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep '^NUMA node' NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' $(Before the last patch, the whole line was returned.)
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' NUMA node0 CPU(s): 0-79*lscpu* shows the number of threads per core, so use that value directly.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 8 $ sudo ppc64_cpu --smt=off $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 1Note, the replaced heuristic is also incorrect for that case, where the threads per core are disabled.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' 8
Quoted 6 lines
Quoted 1 line
Signed-off-by Paul Menzel <[email protected]>Makes sense, and thank you for chasing this down and for the fix!
But should this patch and 1/2 be merged? Or am I confused and they are somehow affecting two different lines of scripting?
You are right. I guess with 1/2 I just wanted to document clearly, what I learned in #[email protected], that means, how to avoid using grep, when sed is used.
Kind regards,
Paul
Quoted 20 lines
Quoted 20 lines
--- tools/testing/selftests/rcutorture/bin/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/rcutorture/bin/functions.sh +1
-1@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p'`" + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esacSignature · 1 line
2.35.1
Paul E. McKenney
maintainerRe: [PATCH 2/2] torture: Make thread detection more robust by using lspcu
Quoted 43 lines · Paul Menzel
Dear Paul,
Am 22.02.22 um 18:43 schrieb Paul E. McKenney:
Quoted 39 lines · Paul Menzel
Quoted 37 lines
For consecutive numbers *lscpu* collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep '^NUMA node' NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' $(Before the last patch, the whole line was returned.)
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' NUMA node0 CPU(s): 0-79*lscpu* shows the number of threads per core, so use that value directly.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 8 $ sudo ppc64_cpu --smt=off $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 1Note, the replaced heuristic is also incorrect for that case, where the threads per core are disabled.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' 8Signed-off-by Paul Menzel <[email protected]>
Quoted 8 lines
Quoted 4 lines
Makes sense, and thank you for chasing this down and for the fix!
But should this patch and 1/2 be merged? Or am I confused and they are somehow affecting two different lines of scripting?
You are right. I guess with 1/2 I just wanted to document clearly, what I learned in #[email protected], that means, how to avoid using grep, when sed is used.
Nothing wrong with that!
I have merged the two patches as shown below. Does this work for you?
Thanx, Paul
------------------------------------------------------------------------
commit 9f0daba62e958c31326c7a9eae33651e3a3cc6b4
Author: Paul Menzel <[email protected]> Date: Tue Feb 22 13:07:16 2022 +0100
torture: Make thread detection more robust by using lspcu
For consecutive numbers the lscpu command collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8
$ lscpu | grep '^NUMA node'
NUMA node(s): 2
NUMA node0 CPU(s): 0-79
NUMA node8 CPU(s): 80-159
This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/'
NUMA node0 CPU(s): 0-79
But the lscpu command shows the number of threads per core:
$ sudo ppc64_cpu --smt=8
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 8
$ sudo ppc64_cpu --smt=off
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 1
This commit therefore directly uses that value.
tools/testing/selftests/rcutorture/bin/functions.sh +1 -1
@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`" + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esac
Re: [PATCH 2/2] torture: Make thread detection more robust by using lspcu
Dear Paul,
Am 24.02.22 um 21:56 schrieb Paul E. McKenney:
Quoted 84 lines · Paul Menzel
Quoted 41 lines
Am 22.02.22 um 18:43 schrieb Paul E. McKenney:
Quoted 39 lines · Paul Menzel
Quoted 37 lines
For consecutive numbers *lscpu* collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep '^NUMA node' NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' $(Before the last patch, the whole line was returned.)
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' NUMA node0 CPU(s): 0-79*lscpu* shows the number of threads per core, so use that value directly.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 8 $ sudo ppc64_cpu --smt=off $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 1Note, the replaced heuristic is also incorrect for that case, where the threads per core are disabled.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' 8Signed-off-by Paul Menzel <[email protected]>Quoted 8 lines
Quoted 4 lines
Makes sense, and thank you for chasing this down and for the fix!
But should this patch and 1/2 be merged? Or am I confused and they are somehow affecting two different lines of scripting?
You are right. I guess with 1/2 I just wanted to document clearly, what I learned in #[email protected], that means, how to avoid using grep, when sed is used.
Nothing wrong with that!
I have merged the two patches as shown below. Does this work for you?
Thanx, Paul
------------------------------------------------------------------------
commit
9f0daba62e958c31326c7a9eae33651e3a3cc6b4Author: Paul Menzel <[email protected]> Date: Tue Feb 22 13:07:16 2022 +0100torture: Make thread detection more robust by using lspcu
For consecutive numbers the lscpu command collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo
ppc64_cpu--smt=8
$ lscpu | grep '^NUMA node'
NUMA node(s): 2
NUMA node0 CPU(s): 0-79
NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/'
NUMA node0 CPU(s): 0-79But the lscpu command shows the number of threads per core:
Quoted 8 lines
$ sudo
ppc64_cpu--smt=8
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 8
$ sudoppc64_cpu--smt=off
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 1This commit therefore directly uses that value.
Maybe extend: …, and replaces grep by using using sed’s switch -n and the command p.
Quoted 9 lines
Signed-off-by Paul Menzel <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>tools/testing/selftests/rcutorture/bin/functions.sh +0
-0
tools/testing/selftests/rcutorture/bin/functions.sh specify_qemu_cpus () { · line 307
Quoted 8 lines
tools/testing/selftests/rcutorture/bin/functions.sh +1
-1@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`" + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esac
Thank you for doing that, and sorry for the extra work.
Kind regards,
Paul
Paul E. McKenney
maintainerRe: [PATCH 2/2] torture: Make thread detection more robust by using lspcu
Quoted 90 lines · Paul Menzel
Dear Paul,
Am 24.02.22 um 21:56 schrieb Paul E. McKenney:
Quoted 77 lines · Paul Menzel
Quoted 41 lines
Am 22.02.22 um 18:43 schrieb Paul E. McKenney:
Quoted 39 lines · Paul Menzel
Quoted 37 lines
For consecutive numbers *lscpu* collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep '^NUMA node' NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node8 CPU(s): 80-159This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' $(Before the last patch, the whole line was returned.)
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' NUMA node0 CPU(s): 0-79*lscpu* shows the number of threads per core, so use that value directly.
$ sudo ppc64_cpu --smt=8 $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 8 $ sudo ppc64_cpu --smt=off $ lscpu | grep 'Thread(s) per core' Thread(s) per core: 1Note, the replaced heuristic is also incorrect for that case, where the threads per core are disabled.
$ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' 8Signed-off-by Paul Menzel <[email protected]>Quoted 8 lines
Quoted 4 lines
Makes sense, and thank you for chasing this down and for the fix!
But should this patch and 1/2 be merged? Or am I confused and they are somehow affecting two different lines of scripting?
You are right. I guess with 1/2 I just wanted to document clearly, what I learned in #[email protected], that means, how to avoid using grep, when sed is used.
Nothing wrong with that!
I have merged the two patches as shown below. Does this work for you?
Thanx, Paul
------------------------------------------------------------------------
commit
9f0daba62e958c31326c7a9eae33651e3a3cc6b4Author: Paul Menzel <[email protected]> Date: Tue Feb 22 13:07:16 2022 +0100torture: Make thread detection more robust by using lspcu
For consecutive numbers the lscpu command collapses the output and just shows the range with start and end. The processors are numbered that way on POWER8.
$ sudoppc64_cpu--smt=8
$ lscpu | grep '^NUMA node'
NUMA node(s): 2
NUMA node0 CPU(s): 0-79
NUMA node8 CPU(s): 80-159
This causes the heuristic to detect the number threads per core, looking for the number after the first comma, to fail, and QEMU aborts because of invalid arguments.
$ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/'
NUMA node0 CPU(s): 0-79Quoted 8 lines
But the lscpu command shows the number of threads per core:
$ sudoppc64_cpu--smt=8
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 8
$ sudoppc64_cpu--smt=off
$ lscpu | grep 'Thread(s) per core'
Thread(s) per core: 1
This commit therefore directly uses that value.
Quoted 2 lines
Maybe extend: …, and replaces
grepby using using sed’s switch-nand the command p.
Ah, good point -- I will update this on the next rebase.
Quoted 18 lines
Quoted 8 lines
Signed-off-by Paul Menzel <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>tools/testing/selftests/rcutorture/bin/functions.sh +0
-0tools/testing/selftests/rcutorture/bin/functions.sh specify_qemu_cpus () { · line 307
Quoted 8 lines
tools/testing/selftests/rcutorture/bin/functions.sh +1
-1@@ -301,7 +301,7 @@ specify_qemu_cpus () { echo $2 -smp $3 ;; qemu-system-ppc64) - nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`" + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt ;; esacThank you for doing that, and sorry for the extra work.
No complaints! You are after all testing on powerpc, and getting that working better is a good thing.
Thanx, Paul