Merge tag 'rpmsg-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc...
[platform/kernel/linux-starfive.git] / tools / rcu / extract-stall.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0+
3 #
4 # Extract any RCU CPU stall warnings present in specified file.
5 # Filter out clocksource lines.  Note that preceding-lines excludes the
6 # initial line of the stall warning but trailing-lines includes it.
7 #
8 # Usage: extract-stall.sh dmesg-file [ preceding-lines [ trailing-lines ] ]
9
10 echo $1
11 preceding_lines="${2-3}"
12 trailing_lines="${3-10}"
13
14 awk -v preceding_lines="$preceding_lines" -v trailing_lines="$trailing_lines" '
15 suffix <= 0 {
16         for (i = preceding_lines; i > 0; i--)
17                 last[i] = last[i - 1];
18         last[0] = $0;
19 }
20
21 suffix > 0 {
22         print $0;
23         suffix--;
24         if (suffix <= 0)
25                 print "";
26 }
27
28 suffix <= 0 && /detected stall/ {
29         for (i = preceding_lines; i >= 0; i--)
30                 if (last[i] != "")
31                         print last[i];
32         suffix = trailing_lines;
33 }' < "$1" | tr -d '\015' | grep -v clocksource
34