From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>,
Stephane Eranian <eranian@google.com>,
Ian Rogers <irogers@google.com>
Subject: Re: [PATCH v2 2/2] perf test: Add shadow stat test
Date: Mon, 30 Nov 2020 08:59:25 -0300 [thread overview]
Message-ID: <20201130115925.GA20959@kernel.org> (raw)
In-Reply-To: <20201127041404.390276-2-namhyung@kernel.org>
Em Fri, Nov 27, 2020 at 01:14:04PM +0900, Namhyung Kim escreveu:
> It calculates IPC from the cycles and instruction counts and compares
> it with the shadow stat for both global aggregation (default) and no
> aggregation mode.
>
> $ perf stat -a -A -e cycles,instructions sleep 1
>
> Performance counter stats for 'system wide':
>
> CPU0 39,580,880 cycles
> CPU1 45,426,945 cycles
> CPU2 31,151,685 cycles
> CPU3 55,167,421 cycles
> CPU0 17,073,564 instructions # 0.43 insn per cycle
> CPU1 34,955,764 instructions # 0.77 insn per cycle
> CPU2 15,688,459 instructions # 0.50 insn per cycle
> CPU3 34,699,217 instructions # 0.63 insn per cycle
>
> 1.003275495 seconds time elapsed
>
> In this example, the 'insn per cycle' should be matched to the number
> for each cpu. For CPU2, 0.50 = 15,688,459 / 31,151,685 .
Merged torvalds/master into perf/core and applied this patch,
Thanks,
- Arnaldo
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/tests/shell/stat+shadow_stat.sh | 80 ++++++++++++++++++++++
> 1 file changed, 80 insertions(+)
> create mode 100755 tools/perf/tests/shell/stat+shadow_stat.sh
>
> diff --git a/tools/perf/tests/shell/stat+shadow_stat.sh b/tools/perf/tests/shell/stat+shadow_stat.sh
> new file mode 100755
> index 000000000000..249dfe48cf6a
> --- /dev/null
> +++ b/tools/perf/tests/shell/stat+shadow_stat.sh
> @@ -0,0 +1,80 @@
> +#!/bin/sh
> +# perf stat metrics (shadow stat) test
> +# SPDX-License-Identifier: GPL-2.0
> +
> +set -e
> +
> +# skip if system-wide mode is forbidden
> +perf stat -a true > /dev/null 2>&1 || exit 2
> +
> +test_global_aggr()
> +{
> + local cyc
> +
> + perf stat -a --no-big-num -e cycles,instructions sleep 1 2>&1 | \
> + grep -e cycles -e instructions | \
> + while read num evt hash ipc rest
> + do
> + # skip not counted events
> + if [[ $num == "<not" ]]; then
> + continue
> + fi
> +
> + # save cycles count
> + if [[ $evt == "cycles" ]]; then
> + cyc=$num
> + continue
> + fi
> +
> + # skip if no cycles
> + if [[ -z $cyc ]]; then
> + continue
> + fi
> +
> + # use printf for rounding and a leading zero
> + local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
> + if [[ $ipc != $res ]]; then
> + echo "IPC is different: $res != $ipc ($num / $cyc)"
> + exit 1
> + fi
> + done
> +}
> +
> +test_no_aggr()
> +{
> + declare -A results
> +
> + perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \
> + grep ^CPU | \
> + while read cpu num evt hash ipc rest
> + do
> + # skip not counted events
> + if [[ $num == "<not" ]]; then
> + continue
> + fi
> +
> + # save cycles count
> + if [[ $evt == "cycles" ]]; then
> + results[$cpu]=$num
> + continue
> + fi
> +
> + # skip if no cycles
> + local cyc=${results[$cpu]}
> + if [[ -z $cyc ]]; then
> + continue
> + fi
> +
> + # use printf for rounding and a leading zero
> + local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
> + if [[ $ipc != $res ]]; then
> + echo "IPC is different for $cpu: $res != $ipc ($num / $cyc)"
> + exit 1
> + fi
> + done
> +}
> +
> +test_global_aggr
> +test_no_aggr
> +
> +exit 0
> --
> 2.29.2.454.gaff20da3a2-goog
>
--
- Arnaldo
next prev parent reply other threads:[~2020-11-30 12:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-27 4:14 [PATCH v2 1/2] perf stat: Use proper cpu for shadow stats Namhyung Kim
2020-11-27 4:14 ` [PATCH v2 2/2] perf test: Add shadow stat test Namhyung Kim
2020-11-30 11:59 ` Arnaldo Carvalho de Melo [this message]
2020-11-27 17:32 ` [PATCH v2 1/2] perf stat: Use proper cpu for shadow stats Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201130115925.GA20959@kernel.org \
--to=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.