From patchwork Mon Feb 12 20:32:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128170 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3565914ljc; Mon, 12 Feb 2018 12:33:04 -0800 (PST) X-Google-Smtp-Source: AH8x2275p7bSCGdfoOuJTfojB+Jx3g7l7RTRN+W+kOhPjW69rNtkzWAnzEvib2PfElfiPSBxhq2/ X-Received: by 10.98.170.15 with SMTP id e15mr12693384pff.207.1518467584167; Mon, 12 Feb 2018 12:33:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518467584; cv=none; d=google.com; s=arc-20160816; b=CWgXNeYUWdRK870lvt/Gam3TgTQj+w+truCnE19YMuQ6PGkPw+OS92cva8WlHqJG9C r5WRtTWnyVqRccPbutLWjgm5d2GZkIfQLNzBQLmwmBzxdv1kRoOWwsl1sA7YQzTk55f8 fY/9AZIsCuu6JgXV6lgU6q4jNkZdlFYqnIyjUO78tPWNpExWhRfa5YFY6nICetLs4VHI aJFNSjrGOoEtfFV+AoMFxHBmPg/XsKCufFlUJZhTr7pJCLefJWIGbQkI/FyDnBPLzzQy MqUhygB7XFDjkYrgB2htZthevssKSXaIdNvIWjQxXVbzcVP8GwRG453voqvt36unFwOa 33Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YYPAqs8d/WW1nFR7OPHcYzEd+6+zK3sP6g9s1hNcH7Q=; b=wvpz/YuOpIxbG/MzPrSRUxaedS91MsdgAloNdrYeNZ5EImx7+baxybyGBNxICkf0u3 7cno40DFktYkqa4qSueka+hsyQ3X/gOOkZ9+GyJ+hxPAPG6+CPigQZmsM7QHORMy9grr oomBmqV+zQugK7uxK8L6MzV20qTQHoI5TqBl1xdCRVf5WgYnUFmircpT8Qimvj64shFo aRW1Z+7sxSF2qNVKt6UrLc/A79FELX54xuEW2btjNCNMgv+folySgIAVymmq241C12e5 6wHIuVrbIBk5DpPznz8fALJaVirDhfPSBfuHe7UPKPPJa0I479T5p+b6axvp8aT3Q643 O5Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KEYa0zoT; 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 u73si2655949pgc.381.2018.02.12.12.33.03; Mon, 12 Feb 2018 12:33:04 -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=KEYa0zoT; 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 S1754021AbeBLUcr (ORCPT + 26 others); Mon, 12 Feb 2018 15:32:47 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:37790 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753871AbeBLUcn (ORCPT ); Mon, 12 Feb 2018 15:32:43 -0500 Received: by mail-pg0-f68.google.com with SMTP id o1so8258324pgn.4 for ; Mon, 12 Feb 2018 12:32:42 -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:in-reply-to:references; bh=YYPAqs8d/WW1nFR7OPHcYzEd+6+zK3sP6g9s1hNcH7Q=; b=KEYa0zoTw9Toun7jWXIPUsBR8LpI03Mnv1XgrxjUehm6ELz97d3M78cRgplUG9r13X SJh+ALrR9XcbWuQCirwcv1qq6QN/NT55WGR+hOS0p+4pjdYkSflLTIXIvq6XOL+J823K SaZbYjKc4scZz031wzf2tRkBTh5KtSG/3qRTM= 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:in-reply-to :references; bh=YYPAqs8d/WW1nFR7OPHcYzEd+6+zK3sP6g9s1hNcH7Q=; b=PTkvz4QSqIffhic4nwlIGCVmUFm+F1Kg7Ol548lmzWPmulIKS9B4IK4P6XpHzWtm2r W11Ues3dycamaKk7TY+4NMB2yU7CAPc5DnQ+QYHxe91FCvvK2rHDf8YU7Asd9Ii/XxO8 9W9E66QzuZ4Bwgk3mQhz44UXYdvoQaP3WuuGHWcSA7+sJLP7XofzOgAbz8AB+c/1yuGt YiW7AGEAIRFcoxeL5IkDGWj2u8nboUHU/4c9/Fz+d+h6x3sumObyUV0InYoSmaI0NjHb yCFz4c4R82s+4iQJRgQK2VVmAxx/EPiaTpnFaAQSU2MH0MA6a96LYm119yzgShOSOh1X 98iQ== X-Gm-Message-State: APf1xPBj6knKiwcO6PLbof2b+RoOxvQwRLbYln5+PRTNzmjZwq0Ots6l jtMNui3Oapeq26FHavHwuknTLA== X-Received: by 10.101.90.8 with SMTP id y8mr10089443pgs.34.1518467562513; Mon, 12 Feb 2018 12:32:42 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id c8sm12856594pgn.72.2018.02.12.12.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Feb 2018 12:32:41 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, yao.jin@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] perf util: Use target->per_thread and target->system_wide flags Date: Mon, 12 Feb 2018 13:32:36 -0700 Message-Id: <1518467557-18505-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518467557-18505-1-git-send-email-mathieu.poirier@linaro.org> References: <1518467557-18505-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jin Yao Mathieu Poirier reports issue in commit ("73c0ca1eee3d perf thread_map: Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'. Mathieu Poirier's patch ("perf util: Do not reuse target->per_thread flag") can fix this issue by creating a new target->all_threads flag. This patch is based on Mathieu Poirier's patch but it doesn't use a new target->all_threads flag. This patch just uses 'target->per_thread && target->system_wide' as a condition to check for all threads case. Signed-off-by: Jin Yao [Fixed checkpatch warning about line over 80 characters] Signed-off-by: Mathieu Poirier --- tools/perf/util/evlist.c | 21 ++++++++++++++++++++- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index e5fc14e53c05..7b7d535396f7 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1086,11 +1086,30 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages) int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) { + bool all_threads = (target->per_thread && target->system_wide); struct cpu_map *cpus; struct thread_map *threads; + /* + * If specify '-a' and '--per-thread' to perf record, perf record + * will override '--per-thread'. target->per_thread = false and + * target->system_wide = true. + * + * If specify '--per-thread' only to perf record, + * target->per_thread = true and target->system_wide = false. + * + * So target->per_thread && target->system_wide is false. + * For perf record, thread_map__new_str doesn't call + * thread_map__new_all_cpus. That will keep perf record's + * current behavior. + * + * For perf stat, it allows the case that target->per_thread and + * target->system_wide are all true. It means to collect system-wide + * per-thread data. thread_map__new_str will call + * thread_map__new_all_cpus to enumerate all threads. + */ threads = thread_map__new_str(target->pid, target->tid, target->uid, - target->per_thread); + all_threads); if (!threads) return -1; diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 3e1038f6491c..729dad8f412d 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -323,7 +323,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str) } struct thread_map *thread_map__new_str(const char *pid, const char *tid, - uid_t uid, bool per_thread) + uid_t uid, bool all_threads) { if (pid) return thread_map__new_by_pid_str(pid); @@ -331,7 +331,7 @@ struct thread_map *thread_map__new_str(const char *pid, const char *tid, if (!tid && uid != UINT_MAX) return thread_map__new_by_uid(uid); - if (per_thread) + if (all_threads) return thread_map__new_all_cpus(); return thread_map__new_by_tid_str(tid); diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index 0a806b99e73c..5ec91cfd1869 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h @@ -31,7 +31,7 @@ struct thread_map *thread_map__get(struct thread_map *map); void thread_map__put(struct thread_map *map); struct thread_map *thread_map__new_str(const char *pid, - const char *tid, uid_t uid, bool per_thread); + const char *tid, uid_t uid, bool all_threads); struct thread_map *thread_map__new_by_tid_str(const char *tid_str);