From patchwork Fri Jul 1 02:23:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 71285 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp65641qgy; Thu, 30 Jun 2016 19:29:16 -0700 (PDT) X-Received: by 10.66.245.1 with SMTP id xk1mr27688475pac.58.1467340156143; Thu, 30 Jun 2016 19:29:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si1552941pfj.61.2016.06.30.19.29.15; Thu, 30 Jun 2016 19:29:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752756AbcGAC26 (ORCPT + 30 others); Thu, 30 Jun 2016 22:28:58 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:10190 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751948AbcGAC1S (ORCPT ); Thu, 30 Jun 2016 22:27:18 -0400 Received: from 172.24.1.136 (EHLO szxeml432-hub.china.huawei.com) ([172.24.1.136]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CEE20769; Fri, 01 Jul 2016 10:24:06 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.235.1; Fri, 1 Jul 2016 10:23:56 +0800 From: Wang Nan To: , CC: , , , Wang Nan , Arnaldo Carvalho de Melo , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Nilay Vaish , "He Kuang" Subject: [PATCH v12 3/8] perf tests: Add testcase for auxiliary evlist Date: Fri, 1 Jul 2016 02:23:46 +0000 Message-ID: <1467339831-171169-4-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1467339831-171169-1-git-send-email-wangnan0@huawei.com> References: <1467339831-171169-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.5775D447.00F5, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 92531e9d35e947fc0280918f689b0127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Improve test backward-ring-buffer, trace both enter and exit event of prctl() syscall, utilize auxiliary evlist to mmap enter and exit event into separated mmaps. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: Nilay Vaish Cc: He Kuang --- tools/perf/tests/backward-ring-buffer.c | 90 ++++++++++++++++++++++++++------- tools/perf/util/evlist.h | 8 +++ 2 files changed, 80 insertions(+), 18 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c index 0731b0b..0b100b8 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -26,12 +26,21 @@ static void testcase(void) static int count_samples(struct perf_evlist *evlist, int *sample_count, int *comm_count) { - int i; + int i, dummy; + + if (!comm_count) + comm_count = &dummy; + if (!sample_count) + sample_count = &dummy; for (i = 0; i < evlist->nr_mmaps; i++) { union perf_event *event; - perf_evlist__mmap_read_catchup(evlist, i); + /* + * Before calling count_samples(), ring buffers in backward + * evlist should have catched up with newest record + * using perf_evlist__mmap_read_catchup_all(). + */ while ((event = perf_evlist__mmap_read_backward(evlist, i)) != NULL) { const u32 type = event->header.type; @@ -51,34 +60,54 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count, return TEST_OK; } -static int do_test(struct perf_evlist *evlist, int mmap_pages, - int *sample_count, int *comm_count) +static int do_test(struct perf_evlist *evlist, + struct perf_evlist *aux_evlist, + int mmap_pages, + int *enter_sample_count, + int *exit_sample_count, + int *comm_count) { int err; char sbuf[STRERR_BUFSIZE]; - err = perf_evlist__mmap(evlist, mmap_pages, true); + err = perf_evlist__mmap(evlist, mmap_pages, false); if (err < 0) { pr_debug("perf_evlist__mmap: %s\n", strerror_r(errno, sbuf, sizeof(sbuf))); return TEST_FAIL; } + err = perf_evlist__mmap(aux_evlist, mmap_pages, true); + if (err < 0) { + pr_debug("perf_evlist__mmap for aux_evlist: %s\n", + strerror_r(errno, sbuf, sizeof(sbuf))); + return TEST_FAIL; + } + perf_evlist__enable(evlist); testcase(); perf_evlist__disable(evlist); - err = count_samples(evlist, sample_count, comm_count); + perf_evlist__mmap_read_catchup_all(aux_evlist); + err = count_samples(aux_evlist, exit_sample_count, comm_count); + if (err) + goto errout; + err = count_samples(evlist, enter_sample_count, NULL); + if (err) + goto errout; +errout: perf_evlist__munmap(evlist); + perf_evlist__munmap(aux_evlist); return err; } int test__backward_ring_buffer(int subtest __maybe_unused) { - int ret = TEST_SKIP, err, sample_count = 0, comm_count = 0; + int ret = TEST_SKIP, err; + int enter_sample_count = 0, exit_sample_count = 0, comm_count = 0; char pid[16], sbuf[STRERR_BUFSIZE]; - struct perf_evlist *evlist; + struct perf_evlist *evlist, *aux_evlist = NULL; struct perf_evsel *evsel __maybe_unused; struct parse_events_error parse_error; struct record_opts opts = { @@ -115,13 +144,22 @@ int test__backward_ring_buffer(int subtest __maybe_unused) goto out_delete_evlist; } - perf_evlist__config(evlist, &opts, NULL); + /* + * Set backward bit, ring buffer should be writing from end. Record + * it in aux evlist + */ + perf_evlist__last(evlist)->overwrite = true; + perf_evlist__last(evlist)->attr.write_backward = 1; - /* Set backward bit, ring buffer should be writing from end */ - evlist__for_each_entry(evlist, evsel) { - evsel->overwrite = true; - evsel->attr.write_backward = 1; + err = parse_events(evlist, "syscalls:sys_exit_prctl", &parse_error); + if (err) { + pr_debug("Failed to parse tracepoint event, try use root\n"); + ret = TEST_SKIP; + goto out_delete_evlist; } + /* Don't set backward bit for exit event. Record it in main evlist */ + + perf_evlist__config(evlist, &opts, NULL); err = perf_evlist__open(evlist); if (err < 0) { @@ -130,24 +168,40 @@ int test__backward_ring_buffer(int subtest __maybe_unused) goto out_delete_evlist; } + aux_evlist = perf_evlist__new_aux(evlist); + if (!aux_evlist) { + pr_debug("perf_evlist__new_aux failed\n"); + goto out_delete_evlist; + } + aux_evlist->backward = true; + ret = TEST_FAIL; - err = do_test(evlist, opts.mmap_pages, &sample_count, + err = do_test(evlist, aux_evlist, opts.mmap_pages, + &enter_sample_count, &exit_sample_count, &comm_count); if (err != TEST_OK) goto out_delete_evlist; - if ((sample_count != NR_ITERS) || (comm_count != NR_ITERS)) { - pr_err("Unexpected counter: sample_count=%d, comm_count=%d\n", - sample_count, comm_count); + if (enter_sample_count != exit_sample_count) { + pr_err("Unexpected counter: enter_sample_count=%d, exit_sample_count=%d\n", + enter_sample_count, exit_sample_count); + goto out_delete_evlist; + } + + if ((exit_sample_count != NR_ITERS) || (comm_count != NR_ITERS)) { + pr_err("Unexpected counter: exit_sample_count=%d, comm_count=%d\n", + exit_sample_count, comm_count); goto out_delete_evlist; } - err = do_test(evlist, 1, &sample_count, &comm_count); + err = do_test(evlist, aux_evlist, 1, NULL, NULL, NULL); if (err != TEST_OK) goto out_delete_evlist; ret = TEST_OK; out_delete_evlist: + if (aux_evlist) + perf_evlist__delete(aux_evlist); perf_evlist__delete(evlist); return ret; } diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 99bcc02..d736cd3 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -149,6 +149,14 @@ union perf_event *perf_evlist__mmap_read_backward(struct perf_evlist *evlist, int idx); void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx); +static inline void perf_evlist__mmap_read_catchup_all(struct perf_evlist *evlist) +{ + int i; + + for (i = 0; i < evlist->nr_mmaps; i++) + perf_evlist__mmap_read_catchup(evlist, i); +} + void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx); int perf_evlist__pause(struct perf_evlist *evlist);