Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4882586ybg; Mon, 21 Oct 2019 16:21:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwMmA7lWcx1yZC+OMU0Pcw9zYg+G/IAOD3cQPDmBIXhLp453LeS7XWP7nnNHMm+6DIWqz3 X-Received: by 2002:a17:906:e2cb:: with SMTP id gr11mr10204577ejb.205.1571700077978; Mon, 21 Oct 2019 16:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571700077; cv=none; d=google.com; s=arc-20160816; b=xITLpea217Vhzw1npxGI7yXdQN/g/V1KYmTkAm+yzdCnUif7dkhYAIma7T0Btdllig cTnmQ3OvsnTTjxegQU28L7P8V6XYJ2bRiI9RmCdqUvrfeAJb+idlsAi6fjmYjRNZ8zp+ FD7VsqmeQNYOhavB1decDxrAN2ggq9JR0zHGtkY9RmkJuTNicBsf4o1KwD71qmxZSkKH 8FjZXJayqRYxh16zHeeKt3VAczpOBTB22102Gw2gHcowwAXirZ4TM7KVgtzhVsXxvpMX XvAppCQIEhvOshLUkGcxe4gMGY/eP0nLy/z18IAMSOHPUh35B0Qh2fVephtvUHZluPgY EBYw== 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=hPDFFNWe/m7coFHo18qcsibIkGTnPOmSGFKfD/6WQVY=; b=lWFVN7XHulfm/186m/aYqzKAQQksDFzMaE54NwYvb9TXygVm8dz+Kfebv5H9I0Kjnm X1kSBv1oylhVus2OLJAnQP48OkkTg8ssrXVQph37BcaIOgThUHxkbkdKhDo6plhvMTN5 hGets7bLVbPDl5vx4djgVv1K5ZbYHD677NQ2ttKVW5pyjQVqW+jDgsqYzcx0PLgn9ysn ldQ3v264Mp6C2BRkeYdhY2SijxJ3lcmp9n8LQhNTvFBr6MikzqdKrrjQybeS/ILBS+Zo TdcIr7wvjByqzmIPQ4dkv4iZFLGERai9CBiEiEiaeKPxhtLW61Xv/13u0xPrxTiLAnzI jAfA== 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 t7si3569049eji.439.2019.10.21.16.20.55; Mon, 21 Oct 2019 16:21:17 -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 S1730590AbfJUXUB (ORCPT + 99 others); Mon, 21 Oct 2019 19:20:01 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38303 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730554AbfJUXTB (ORCPT ); Mon, 21 Oct 2019 19:19:01 -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-0003r3-5F; Tue, 22 Oct 2019 01:18:51 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 7DFA31C0489; Tue, 22 Oct 2019 01:18:50 +0200 (CEST) Date: Mon, 21 Oct 2019 23:18:49 -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_cpus 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-8-jolsa@kernel.org> References: <20191017105918.20873-8-jolsa@kernel.org> MIME-Version: 1.0 Message-ID: <157169992990.29376.14004930983969917861.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: 37ac1bbdc31a2007f398b7caf0cbe522f1af9c6c Gitweb: https://git.kernel.org/tip/37ac1bbdc31a2007f398b7caf0cbe522f1af9c6c Author: Jiri Olsa AuthorDate: Thu, 17 Oct 2019 12:59:15 +02:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Sat, 19 Oct 2019 15:35:01 -03:00 libperf: Add tests_mmap_cpus test Add mmaping tests that generates prctl call on every cpu validates it gets all the related events in ring buffer. Committer testing: # 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-8-jolsa@kernel.org [ Added _GNU_SOURCE define for sched.h to get sched_[gs]et_affinity Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/tests/test-evlist.c | 98 +++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+) diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c index 90a1869..741bc1b 100644 --- a/tools/perf/lib/tests/test-evlist.c +++ b/tools/perf/lib/tests/test-evlist.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE // needed for sched.h to get sched_[gs]etaffinity and CPU_(ZERO,SET) +#include #include #include #include @@ -299,6 +301,101 @@ static int test_mmap_thread(void) return 0; } +static int test_mmap_cpus(void) +{ + struct perf_evlist *evlist; + struct perf_evsel *evsel; + struct perf_mmap *map; + struct perf_cpu_map *cpus; + struct perf_event_attr attr = { + .type = PERF_TYPE_TRACEPOINT, + .sample_period = 1, + .wakeup_watermark = 1, + .disabled = 1, + }; + cpu_set_t saved_mask; + char path[PATH_MAX]; + int id, err, cpu, tmp; + union perf_event *event; + 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; + + cpus = perf_cpu_map__new(NULL); + __T("failed to create cpus", cpus); + + 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, NULL); + + 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); + + err = sched_getaffinity(0, sizeof(saved_mask), &saved_mask); + __T("sched_getaffinity failed", err == 0); + + perf_cpu_map__for_each_cpu(cpu, tmp, cpus) { + cpu_set_t mask; + + CPU_ZERO(&mask); + CPU_SET(cpu, &mask); + + err = sched_setaffinity(0, sizeof(mask), &mask); + __T("sched_setaffinity failed", err == 0); + + prctl(0, 0, 0, 0, 0); + } + + err = sched_setaffinity(0, sizeof(saved_mask), &saved_mask); + __T("sched_setaffinity failed", err == 0); + + perf_evlist__disable(evlist); + + 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); + + /* + * The generated prctl events should match the + * number of cpus or be bigger (we are system-wide). + */ + __T("failed count", count >= perf_cpu_map__nr(cpus)); + + perf_cpu_map__put(cpus); + + return 0; +} + int main(int argc, char **argv) { __T_START; @@ -309,6 +406,7 @@ int main(int argc, char **argv) test_stat_thread(); test_stat_thread_enable(); test_mmap_thread(); + test_mmap_cpus(); __T_OK; return 0;