From patchwork Fri Jan 12 16:44:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 124370 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2267162qgn; Fri, 12 Jan 2018 08:45:00 -0800 (PST) X-Google-Smtp-Source: ACJfBosL1FdE6wZ5CAKG+ZJzLpPU0xwrezpFCXaYQtdgUTC9MzzWMlSJUoP+nwM3EDoOzzEgZRUp X-Received: by 10.101.77.195 with SMTP id q3mr21071627pgt.436.1515775500632; Fri, 12 Jan 2018 08:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515775500; cv=none; d=google.com; s=arc-20160816; b=0lW8qCByikmwbnyEvJUULyhixfFdEEoUk0ITI1W1RBthxe2qTHaQqVOfPj6SCcmBJM aEDenOM8aGq611KgIPvpOi3+HPZT18Z+RrAQ6SEfnDL2NMtJlTbADqebZy7xK6/Bk7MX h8WT/sebb25ODeDKvYQasu02T2eIRnmPXuZwkGjNqyBZsX6XY2RJhpPZRf0FUledM/Od t+vIOAcvLPvzZ+qwS3J79+8uR+6hwoHreSJeEj01fOI2WyGjVKF2gfWomsNIDywK/d/C lpU0NYcHkxjFRbQywQC95ajdDnGYI8tA4xv3zgzD5UgpnG3D7b3Uvh8ag+wMj/rQVckW cu1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=oUn4khkTlNBt+6pzGphPl/Ftn2nveQokUoo+Vv+keU0=; b=gytIoOJ/Wj13JvH2c3jStmyz2aLdKLMl1BWPRjryJvlSy3LJpVYg4QaPRVEL6VKPZo NXXQ00ghd8Jp73wE0DTu3FtikCMtPjs8heAPwUzhYuVfd9fw8+g/oCmACTLJ9X0SK4sQ Q4A7d49+BfAhiCJx6WqqcOi9+GBS+mEoF/LzOhFBnwJVt3Owyf0cvLw2moDIuan/9qDY XOkZvMrVxUrwsuFQSniCuuZCk42+vX7iQbbJl2se68y1gUHu0bA9ZpV+bnmNr/IvxZBK 2liTaU2y9vN/xRjJ1XJMw1xX+nc3J0YVLz1xkw1F28x0DPyb6pUgdBd8AZmmTks8XNXQ Ir1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RcPDd6zs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q22si2459841pff.200.2018.01.12.08.45.00; Fri, 12 Jan 2018 08:45:00 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=RcPDd6zs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934199AbeALQo6 (ORCPT + 28 others); Fri, 12 Jan 2018 11:44:58 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:35028 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934027AbeALQo4 (ORCPT ); Fri, 12 Jan 2018 11:44:56 -0500 Received: by mail-io0-f193.google.com with SMTP id 14so6501337iou.2 for ; Fri, 12 Jan 2018 08:44:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=oUn4khkTlNBt+6pzGphPl/Ftn2nveQokUoo+Vv+keU0=; b=RcPDd6zsLwvVQlHiaMea/qv8jRF9yjUZbGZMulrcKQa3dQHzp6wm5S+uIJr+GoHYQ+ mzHTcCCRmpC/2bIg+UtDwDl8gj01QL+AnwL/vQjPSzFbRRHk/OvMnhoh+BZLIDPiBHv0 YNRPHI+dbVOZ6rYOs2VBAMGf+j7ZpUI42Oi8o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oUn4khkTlNBt+6pzGphPl/Ftn2nveQokUoo+Vv+keU0=; b=p0UJVjE9txQMeAkDpQZNrho5O0S6RhHnV9SVujkK+NJNficKg3IZPGIJb+XhAXX3o4 Jn9h2R5/+K6l5DEr3NO4oIbpzRaRk1/XPJtryBFZBFtNj9FDU9qCqOjTWor22zbD72wo DKFalorBum9k4S+azQ3s7RCFGEdSAfdsDBhkF76sHOqRztmegbR6hKB5J6Q5bFKbxjJr LmQPbGALEApomOuF6Wuy/i6Mq3xc18c0kymV9a9gwyrFcdkrSNJTKFlqxMSyu26MRj6Z tR7F2hpRAEGgPU2XgyRCcf7ViQFcBNOd0PMmlLEPG74zdiapG+6Fp9ujiYv1r7XpYEf5 ofkQ== X-Gm-Message-State: AKGB3mILIxfoGkUJovoH/hAjhWAIP3WRnKFhpJYERFSigCSvpW7RzK3p JHQCSMAIKMWvwff7QfyghCVmFWahKFg= X-Received: by 10.107.97.13 with SMTP id v13mr26076639iob.252.1515775496212; Fri, 12 Jan 2018 08:44:56 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p132sm13034857ioe.18.2018.01.12.08.44.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 08:44:55 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, yao.jin@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH] perf util: Fix evlist->threads when working with 'perf stat --per-thread' Date: Fri, 12 Jan 2018 09:44:53 -0700 Message-Id: <1515775493-14254-1-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit ("73c0ca1eee3d perf thread_map: Enumerate all threads from /proc") any condition where target->per_thread is set will see all the threads in a system added to evlist->threads. Since the 'record' utility also uses function thread_map__new_str(), any attempt to use the --perf-thread option will also end up accounting for all threads in a system, resulting in new kernel events being created for all threads rather than just the thread of interest. This patch keeps the newly introduced functionality but make sure it doesn't affect other utilities outside of 'stat'. Signed-off-by: Mathieu Poirier --- tools/perf/builtin-stat.c | 2 +- tools/perf/util/evlist.c | 29 ++++++++++++++++++++++++----- tools/perf/util/evlist.h | 2 ++ 3 files changed, 27 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 98bf9d32f222..82d16426b984 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2833,7 +2833,7 @@ int cmd_stat(int argc, const char **argv) if ((stat_config.aggr_mode == AGGR_THREAD) && (target.system_wide)) target.per_thread = true; - if (perf_evlist__create_maps(evsel_list, &target) < 0) { + if (perf_evlist__create_stat_maps(evsel_list, &target) < 0) { if (target__has_task(&target)) { pr_err("Problems finding threads of monitor\n"); parse_options_usage(stat_usage, stat_options, "p", 1); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index f0a5e09c4071..a4ae684f28de 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1100,13 +1100,11 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages) return perf_evlist__mmap_ex(evlist, pages, 0, false); } -int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) +static int _perf_evlist__create_maps(struct perf_evlist *evlist, + struct target *target, + struct thread_map *threads) { struct cpu_map *cpus; - struct thread_map *threads; - - threads = thread_map__new_str(target->pid, target->tid, target->uid, - target->per_thread); if (!threads) return -1; @@ -1130,6 +1128,27 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) return -1; } +int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) +{ + struct thread_map *threads; + + threads = thread_map__new_str(target->pid, target->tid, target->uid, + false); + + return _perf_evlist__create_maps(evlist, target, threads); +} + +int perf_evlist__create_stat_maps(struct perf_evlist *evlist, + struct target *target) +{ + struct thread_map *threads; + + threads = thread_map__new_str(target->pid, target->tid, target->uid, + target->per_thread); + + return _perf_evlist__create_maps(evlist, target, threads); +} + void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus, struct thread_map *threads) { diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 75160666d305..80c654990e19 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -188,6 +188,8 @@ void perf_evlist__set_selected(struct perf_evlist *evlist, void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus, struct thread_map *threads); int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target); +int perf_evlist__create_stat_maps(struct perf_evlist *evlist, + struct target *target); int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel); void __perf_evlist__set_leader(struct list_head *list);