linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH 3/3] libperf tests: Add test_stat_multiplexing test
Date: Fri, 20 Aug 2021 18:39:08 +0900	[thread overview]
Message-ID: <20210820093908.734503-4-nakamura.shun@fujitsu.com> (raw)
In-Reply-To: <20210820093908.734503-1-nakamura.shun@fujitsu.com>

Adds a test for a counter obtained using read() system call during multiplexing

Committer testing:

  $ sudo make tests V=1 -C tools/lib/perf/
  make: Entering directory '/home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/lib/perf'
  make -f /home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/build/Makefile.build dir=. obj=libperf
  make -C /home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/lib/api/ O= libapi.a
  make -f /home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/build/Makefile.build dir=./fd obj=libapi
  make -f /home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/build/Makefile.build dir=./fs obj=libapi
  make -f /home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/build/Makefile.build dir=. obj=tests
  make -f /home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/build/Makefile.build dir=./tests obj=tests
  running static:
  - running tests/test-cpumap.c...OK
  - running tests/test-threadmap.c...OK
  - running tests/test-evlist.c...
  	count = 503074578, run = 261416566, enable = 435415718
  	count = 503295562, run = 261411675, enable = 435412316
  	count = 501603369, run = 261421312, enable = 435408854
  	count = 501245546, run = 261419457, enable = 435405029
  	count = 501849603, run = 261415041, enable = 435400600
  	count = 500801298, run = 261410125, enable = 435395597
  	count = 502116997, run = 261401960, enable = 435389539
  	count = 501797294, run = 261397791, enable = 435382777
  	count = 501249740, run = 261377402, enable = 435374884
  	count = 501754502, run = 260985031, enable = 435366109
  	count = 501659788, run = 260985466, enable = 435354970
  	count = 503670502, run = 260985172, enable = 435345076
  	count = 503209138, run = 260987272, enable = 435335863
  	count = 502772845, run = 260985720, enable = 435314163
  	count = 504045922, run = 260985324, enable = 435303814
     Expected: 502005425
     High: 504045922   Low:  500801298   Average:  502276445
     Average Error = 0.05%
  OK
  - running tests/test-evsel.c...
  	loop = 65536, count = 333260
  	loop = 131072, count = 655861
  	loop = 262144, count = 1315513
  	loop = 524288, count = 2633730
  	loop = 1048576, count = 5270513
  	loop = 65536, count = 407118
  	loop = 131072, count = 786947
  	loop = 262144, count = 1859532
  	loop = 524288, count = 3849286
  	loop = 1048576, count = 7310477
  OK
  running dynamic:
  - running tests/test-cpumap.c...OK
  - running tests/test-threadmap.c...OK
  - running tests/test-evlist.c...
  	count = 502071859, run = 275961923, enable = 461897932
  	count = 501339557, run = 275959274, enable = 461895615
  	count = 501706307, run = 275912910, enable = 461892367
  	count = 501877502, run = 275906600, enable = 461888804
  	count = 501773043, run = 275905934, enable = 461884843
  	count = 502724983, run = 275884848, enable = 461880027
  	count = 502436857, run = 276864452, enable = 461874272
  	count = 502598147, run = 277873765, enable = 461867901
  	count = 502601952, run = 278872100, enable = 461860271
  	count = 502356640, run = 278933007, enable = 461851421
  	count = 503474674, run = 278930678, enable = 461840342
  	count = 503365623, run = 278976959, enable = 461830886
  	count = 503307062, run = 278004451, enable = 461821700
  	count = 502845553, run = 276988055, enable = 461812741
  	count = 501627390, run = 275995291, enable = 461803691
     Expected: 501940978
     High: 503474674   Low:  501339557   Average:  502407143
     Average Error = 0.09%
  OK
  - running tests/test-evsel.c...
  	loop = 65536, count = 328182
  	loop = 131072, count = 661219
  	loop = 262144, count = 1316712
  	loop = 524288, count = 2641030
  	loop = 1048576, count = 5267395
  	loop = 65536, count = 393675
  	loop = 131072, count = 842152
  	loop = 262144, count = 1664160
  	loop = 524288, count = 3421570
  	loop = 1048576, count = 6856783
  OK
  make: Leaving directory '/home/nakamura/build_work/build_kernel/linux_kernel/linux/tools/lib/perf'

Signed-off-by: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
---
 tools/lib/perf/tests/test-evlist.c | 138 +++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)

diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test-evlist.c
index c67c83399170..c7184d8b6ce9 100644
--- a/tools/lib/perf/tests/test-evlist.c
+++ b/tools/lib/perf/tests/test-evlist.c
@@ -21,6 +21,9 @@
 #include "tests.h"
 #include <internal/evsel.h>
 
+#define EVENT_NUM 15
+#define WAIT_COUNT 100000000UL
+
 static int libperf_print(enum libperf_print_level level,
 			 const char *fmt, va_list ap)
 {
@@ -413,6 +416,140 @@ static int test_mmap_cpus(void)
 	return 0;
 }
 
+static double display_error(long long average,
+		     long long high,
+		     long long low,
+		     long long expected) {
+
+	double error;
+
+	error = (((double)average - expected) / expected) * 100.0;
+
+	__T_VERBOSE("   Expected: %lld\n", expected);
+	__T_VERBOSE("   High: %lld   Low:  %lld   Average:  %lld\n",
+			high, low, average);
+
+	__T_VERBOSE("   Average Error = %.2f%%\n",error);
+
+	return error;
+
+}
+
+static int test_stat_multiplexing(void)
+{
+	struct perf_counts_values expected_counts = { .val = 0 };
+	struct perf_counts_values multi_counts[EVENT_NUM] = {{ .val = 0 },};
+	struct perf_thread_map *threads;
+	struct perf_evlist *evlist;
+	struct perf_evsel *evsel;
+	struct perf_event_attr attr = {
+		.type	     = PERF_TYPE_HARDWARE,
+		.config	     = PERF_COUNT_HW_INSTRUCTIONS,
+		.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
+			       PERF_FORMAT_TOTAL_TIME_RUNNING,
+		.disabled    = 1,
+	};
+	int err, i, nonzero=0;
+	unsigned long count;
+	long long max = 0, min = 0, avg = 0;
+	double error = 0.0;
+
+	/* read for non-multiplexing event count */
+	threads = perf_thread_map__new_dummy();
+	__T("failed to create threads", threads);
+
+	perf_thread_map__set_pid(threads, 0, 0);
+
+	evsel = perf_evsel__new(&attr);
+	__T("failed to create evsel", evsel);
+
+	err = perf_evsel__open(evsel, NULL, threads);
+	__T("failed to open evsel", err == 0);
+
+	err = perf_evsel__enable(evsel);
+	__T("failed to enable evsel", err == 0);
+
+	count = WAIT_COUNT;
+	while(count--);
+
+	perf_evsel__read(evsel, 0, 0, &expected_counts);
+	__T("failed to read value for evsel", expected_counts.val != 0);
+	__T("failed to read non-multiplexing event count",
+	    expected_counts.ena == expected_counts.run);
+
+	err = perf_evsel__disable(evsel);
+	__T("failed to enable evsel", err == 0);
+
+	perf_evsel__close(evsel);
+	perf_evsel__delete(evsel);
+
+	perf_thread_map__put(threads);
+
+
+	/* read for multiplexing event count */
+	threads = perf_thread_map__new_dummy();
+	__T("failed to create threads", threads);
+
+	perf_thread_map__set_pid(threads, 0, 0);
+
+	evlist = perf_evlist__new();
+	__T("failed to create evlist", evlist);
+
+	for (i = 0; i < EVENT_NUM; i++) {
+		evsel = perf_evsel__new(&attr);
+		__T("failed to create evsel1", evsel);
+
+		perf_evlist__add(evlist, evsel);
+	}
+	perf_evlist__set_maps(evlist, NULL, threads);
+
+	err = perf_evlist__open(evlist);
+	__T("failed to open evsel", err == 0);
+
+	perf_evlist__enable(evlist);
+
+	count = WAIT_COUNT;
+	while (count--);
+
+	i = 0;
+	perf_evlist__for_each_evsel(evlist, evsel) {
+		perf_evsel__read(evsel, 0, 0, &multi_counts[i]);
+		__T("failed to read value for evsel", multi_counts[i].val != 0);
+		i++;
+	}
+
+	perf_evlist__disable(evlist);
+
+
+	min = multi_counts[0].val;
+	for (i = 0; i < EVENT_NUM; i++) {
+		__T_VERBOSE("\tcount = %lu, run = %lu, enable = %lu\n",
+			    multi_counts[i].val, multi_counts[i].run, multi_counts[i].ena);
+
+		if (multi_counts[i].val > max)
+			max = multi_counts[i].val;
+
+		if (multi_counts[i].val < min)
+			min = multi_counts[i].val;
+
+		avg += multi_counts[i].val;
+
+		if (multi_counts[i].val != 0)
+			nonzero++;
+	}
+	avg = avg / nonzero;
+
+	error = display_error(avg, max, min, expected_counts.val);
+
+	__T("Error out of range!", ((error <= 1.0) && (error >= -1.0)));
+
+	perf_evlist__close(evlist);
+	perf_evlist__delete(evlist);
+
+	perf_thread_map__put(threads);
+	return 0;
+}
+
 int test_evlist(int argc, char **argv)
 {
 	__T_START;
@@ -424,6 +561,7 @@ int test_evlist(int argc, char **argv)
 	test_stat_thread_enable();
 	test_mmap_thread();
 	test_mmap_cpus();
+	test_stat_multiplexing();
 
 	__T_END;
 	return tests_failed == 0 ? 0 : -1;
-- 
2.25.1


      parent reply	other threads:[~2021-08-20  9:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  9:39 [PATCH 0/3] libperf: Add support for scaling counters obtained from the read() system call during multiplexing Shunsuke Nakamura
2021-08-20  9:39 ` [PATCH 1/3] libperf: Add processing to scale the counters obtained during the read() system call when multiplexing Shunsuke Nakamura
2021-08-23 20:12   ` Rob Herring
2021-08-24 10:11     ` nakamura.shun
2021-08-31  8:58       ` nakamura.shun
2021-08-31 12:26       ` Rob Herring
2021-09-07 23:59         ` Ian Rogers
2021-09-17  8:04           ` nakamura.shun
2021-08-20  9:39 ` [PATCH 2/3] libperf tests: Fix verbose printing Shunsuke Nakamura
2021-08-23 20:26   ` Rob Herring
2021-08-24 18:06     ` Arnaldo Carvalho de Melo
2021-08-20  9:39 ` Shunsuke Nakamura [this message]

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=20210820093908.734503-4-nakamura.shun@fujitsu.com \
    --to=nakamura.shun@fujitsu.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).