Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4920916ybg; Mon, 21 Oct 2019 17:06:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhr4Nsn940apDRezhsz0ikYEeMPsEe7x6soXjLHpTqORtp8dGvfwzetJ3va5PmX4Yz/Irs X-Received: by 2002:a17:906:2989:: with SMTP id x9mr2653995eje.318.1571702804224; Mon, 21 Oct 2019 17:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571702804; cv=none; d=google.com; s=arc-20160816; b=JRYZdAhB/zTOISHWs3WqX7uNEOoQ9ol7bagx97TsG3oyrZUtL4Y7B5IxG4o1T/BIdi zZhVSLwETK+ZFAExZkabVPcHP/4A+M0xAH33JZl5907VnSnLEjrox8xYmyCdvTVlwKMp Fsp0uznf9sG8hVp/G47NEufbLehblyJB7U6ypnsxGGNtOZK+LUnpG5+U50N7HyXHy4QF bNXdPaeoJk52IeHuuLD7/o7RvIVzhwNw4Y8cLPZy5lbNFSbOzLS32irJE1FrkvZ9upzz NK5WruumGv99vz3SVJoZkGV2Wm4q00ss6w41IOFvDKgiv9mRl4Hrw+xqUUvEKx42xWN/ aGkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=i/l61hfy3MjBVp1uzIvlOWSZ9XvwAcra4Q7jAsZCoKQ=; b=qIeLpCs2s6M7dddDuMzGRyv8cOpbXDTkrjDhkweIeaR7PofyEUIlDUUrc5jnvF1sR2 WNojX7oiHKSeJ3lNfD9T4eJsWE+5pqSg6IVQca4I5oS4XEf/WfyOPw5TfXvIOVJctPwG 2iWMn7KnBiH/3HBE0M3PKmXQknmN8PHaidC/vi4YBSmNV5Td71A0sWF4ngdfSJpZMmP5 pEWmO0R8AHl5WLUYvK1v6DnetmFz6qFJ802+FXHZcJKvD8tVHcg6eLz3r7G0hL3GKAQB ppUp7DiA2Qqg2P1qLkC0xviJxoKLMqRrgsT1k2Dmjc5X0epUMx+YCWAqz5VhUIobBcJ3 Mbrg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si3843113ejy.427.2019.10.21.17.06.21; Mon, 21 Oct 2019 17:06:44 -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 S2387686AbfJVAF3 (ORCPT + 99 others); Mon, 21 Oct 2019 20:05:29 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38895 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387667AbfJVAF1 (ORCPT ); Mon, 21 Oct 2019 20:05:27 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iMgwt-0003s6-Tt; Tue, 22 Oct 2019 01:18:52 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 4C5801C0086; Tue, 22 Oct 2019 01:18:51 +0200 (CEST) Date: Mon, 21 Oct 2019 23:18:50 -0000 From: "tip-bot2 for Jiri Olsa" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] libperf: Add tests_mmap_thread test Cc: Jiri Olsa , Arnaldo Carvalho de Melo , Alexander Shishkin , Alexey Budankov , Andi Kleen , Jin Yao , Michael Petlan , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191017105918.20873-7-jolsa@kernel.org> References: <20191017105918.20873-7-jolsa@kernel.org> MIME-Version: 1.0 Message-ID: <157169993065.29376.8961532926431133463.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: bd6b7736c1ed109f4d86f725e96a48fb81ce71f6 Gitweb: https://git.kernel.org/tip/bd6b7736c1ed109f4d86f725e96a48fb81ce71f6 Author: Jiri Olsa AuthorDate: Thu, 17 Oct 2019 12:59:14 +02:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Sat, 19 Oct 2019 15:35:01 -03:00 libperf: Add tests_mmap_thread test Add mmaping tests that generates 100 prctl calls in monitored child process and validates it gets 100 events in ring buffer. Committer tests: # make -C tools/perf/lib tests make: Entering directory '/home/acme/git/perf/tools/perf/lib' LINK test-cpumap-a LINK test-threadmap-a LINK test-evlist-a LINK test-evsel-a LINK test-cpumap-so LINK test-threadmap-so LINK test-evlist-so LINK test-evsel-so running static: - running test-cpumap.c...OK - running test-threadmap.c...OK - running test-evlist.c...OK - running test-evsel.c...OK running dynamic: - running test-cpumap.c...OK - running test-threadmap.c...OK - running test-evlist.c...OK - running test-evsel.c...OK make: Leaving directory '/home/acme/git/perf/tools/perf/lib' # Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Jin Yao Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20191017105918.20873-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/tests/test-evlist.c | 119 ++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+) diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c index e6b2ab2..90a1869 100644 --- a/tools/perf/lib/tests/test-evlist.c +++ b/tools/perf/lib/tests/test-evlist.c @@ -1,12 +1,21 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include +#include #include +#include +#include +#include +#include #include #include #include #include +#include +#include #include +#include static int libperf_print(enum libperf_print_level level, const char *fmt, va_list ap) @@ -181,6 +190,115 @@ static int test_stat_thread_enable(void) return 0; } +static int test_mmap_thread(void) +{ + struct perf_evlist *evlist; + struct perf_evsel *evsel; + struct perf_mmap *map; + struct perf_cpu_map *cpus; + struct perf_thread_map *threads; + struct perf_event_attr attr = { + .type = PERF_TYPE_TRACEPOINT, + .sample_period = 1, + .wakeup_watermark = 1, + .disabled = 1, + }; + char path[PATH_MAX]; + int id, err, pid, go_pipe[2]; + union perf_event *event; + char bf; + int count = 0; + + snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id", + sysfs__mountpoint()); + + if (filename__read_int(path, &id)) { + fprintf(stderr, "error: failed to get tracepoint id: %s\n", path); + return -1; + } + + attr.config = id; + + err = pipe(go_pipe); + __T("failed to create pipe", err == 0); + + fflush(NULL); + + pid = fork(); + if (!pid) { + int i; + + read(go_pipe[0], &bf, 1); + + /* Generate 100 prctl calls. */ + for (i = 0; i < 100; i++) + prctl(0, 0, 0, 0, 0); + + exit(0); + } + + threads = perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + cpus = perf_cpu_map__dummy_new(); + __T("failed to create cpus", cpus); + + perf_thread_map__set_pid(threads, 0, pid); + + evlist = perf_evlist__new(); + __T("failed to create evlist", evlist); + + evsel = perf_evsel__new(&attr); + __T("failed to create evsel1", evsel); + + perf_evlist__add(evlist, evsel); + + perf_evlist__set_maps(evlist, cpus, threads); + + err = perf_evlist__open(evlist); + __T("failed to open evlist", err == 0); + + err = perf_evlist__mmap(evlist, 4); + __T("failed to mmap evlist", err == 0); + + perf_evlist__enable(evlist); + + /* kick the child and wait for it to finish */ + write(go_pipe[1], &bf, 1); + waitpid(pid, NULL, 0); + + /* + * There's no need to call perf_evlist__disable, + * monitored process is dead now. + */ + + perf_evlist__for_each_mmap(evlist, map, false) { + if (perf_mmap__read_init(map) < 0) + continue; + + while ((event = perf_mmap__read_event(map)) != NULL) { + count++; + perf_mmap__consume(map); + } + + perf_mmap__read_done(map); + } + + /* calls perf_evlist__munmap/perf_evlist__close */ + perf_evlist__delete(evlist); + + perf_thread_map__put(threads); + perf_cpu_map__put(cpus); + + /* + * The generated prctl calls should match the + * number of events in the buffer. + */ + __T("failed count", count == 100); + + return 0; +} + int main(int argc, char **argv) { __T_START; @@ -190,6 +308,7 @@ int main(int argc, char **argv) test_stat_cpu(); test_stat_thread(); test_stat_thread_enable(); + test_mmap_thread(); __T_OK; return 0;