From patchwork Tue Nov 8 07:35:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 16910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2545454wru; Mon, 7 Nov 2022 23:40:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM7GHiqijCzE/7j5EExBTfTWpjaVLyt96d4cf2+usYo95l2ycPU7DdsoMgmYRgPi/HU5bw2D X-Received: by 2002:a63:1521:0:b0:43c:9566:7a6a with SMTP id v33-20020a631521000000b0043c95667a6amr47040859pgl.339.1667893254225; Mon, 07 Nov 2022 23:40:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667893254; cv=none; d=google.com; s=arc-20160816; b=mfD4bP1hHErNhI+lBNtR7x4TeHOKq5ow/KN0nQ8NChy1feJODBj1FRWBQAX/8L+ZmH TT1vv+jTu1DxZzHvxHWDU7uQXGh/Lk9AR8C9DnoWbemL2HywTtyZzq1yZxlo20HAvBt/ TS7JeWkHVLwuyRNXBEsQqKOfX/j3WXAURf1lZN85jiQsbZo83qMQdTIbXWZo2eWi/utw 8t28k1O3M1qKwytr+E9ffcLFf6RD/TRisDk4HJvZYwguI/y36iBctRQ8e6YxCV7d6UKX kBJ2uStuEX3yN5dng3K2/dw1Z+w84zW8bA4XwrdRAaKSdk/zExSXE2pv+RJv0vmf6wr0 esXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=mcIKP47y+JSPnlG86ZitTgFKXbNZnIlDlaeWOyIniEY=; b=kAvkvCiBIIQHyyDWp/Qy6KmO9l6STX9Ak/bWm2syAbQ/7fbaIezrMRg83A8gH7n1dR wjJwtvG1af8rwBYUtDijFXcr9yzmGxcf7hbUaWGCAj19SvscYmDbySNTMf00SsDzJLL9 xvq+9GYnUwEdxt2FWrmk1TA/0wk+jWpeo9H7JPevkIFUU8CmHn0wdge3m0gq5UtDC23c s+jX7V+a68rAmuOrbfPcSGfW8z0k97KJ9ES/qYjSATNTvqCq/0n+8Qor3E5Fu4HBPAcU Jbp0ikEDNDOdDTAC2EKCM8y5P7MgTebMeISTHQRD87rOE7nEWhifj5Ai7fEvQ3pa+A50 B11g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BMEqfqsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w184-20020a6382c1000000b0046ebb8fc292si13401700pgd.7.2022.11.07.23.40.41; Mon, 07 Nov 2022 23:40:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BMEqfqsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233656AbiKHHhm (ORCPT + 99 others); Tue, 8 Nov 2022 02:37:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233647AbiKHHhK (ORCPT ); Tue, 8 Nov 2022 02:37:10 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA07A32057 for ; Mon, 7 Nov 2022 23:37:08 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id h67-20020a252146000000b006ccc4702068so13436919ybh.12 for ; Mon, 07 Nov 2022 23:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mcIKP47y+JSPnlG86ZitTgFKXbNZnIlDlaeWOyIniEY=; b=BMEqfqsjTeaurfuCtzDjeW0q1DlJjsXAbVlSiJWF6mS4cGaDikyIVmW7hXbUkRIkPW UvWAdu2eu24JqRTfL0s+jvV5dTXwHqNOq9TIUN9qMWufZJfLai2rq51rnM92BzwNufQ9 Aw3eqRg7nFANy08wGWjKnI3o/1l48dQ36o+G7IpZ9i0EWrwoB84wfu05aAFalfhT8Yma HMUnB9GWxsHH9jUcZKCKj5gGbAwrrNiudjy72wClI37rzGIw6Zjd27IA4VUF9cVbRUOe NunT5LBVtrED8jJM8ywv+7FzBrvbug7O2c8iZDwIfmozF2NCetrmb1eR0bcZOk/4Q0G4 ilSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mcIKP47y+JSPnlG86ZitTgFKXbNZnIlDlaeWOyIniEY=; b=6dlbKKHvY/TQkooqefLF8zSwyoVdgo55x9oJ1g9/Ick8CQgeI0vxNjkmW/UcWvrvPy YW/25zOfg16hdJCETH4hFZluwmitMml5w27TSwPqzMrHLdaLzaOeW/Yrt6CoDVbna+9b OMp/hI96BV80/EeuGQGgyt5OYI4feUaE8jFBSroa0Cmgm33sd6eydmzLvPhrkLsJMvqY OBDFNz90XrY98F6iOtHOX+25F5c4CjrwTNwwxtap3t84IuJwlRwyc/hVWx1es08c0mfG TN4PHfPHf5XC2Fv6W9nPutzn5/964dPV6jN2bZlq/hTK0dgxBrpIrXwB2g5pjOn5Zgby 55bQ== X-Gm-Message-State: ACrzQf1pgVirYi4iR4u/Y0IJL5qB0rvbffSneoKmCsThUGjs7lA47Uuf N8ZN4Ccyf+NPwKRulZs9s54T/GohoP8U X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:a697:9013:186f:ed07]) (user=irogers job=sendgmr) by 2002:a0d:c481:0:b0:370:7a9a:564 with SMTP id g123-20020a0dc481000000b003707a9a0564mr863517ywd.278.1667893028204; Mon, 07 Nov 2022 23:37:08 -0800 (PST) Date: Mon, 7 Nov 2022 23:35:16 -0800 In-Reply-To: <20221108073518.1154450-1-irogers@google.com> Message-Id: <20221108073518.1154450-13-irogers@google.com> Mime-Version: 1.0 References: <20221108073518.1154450-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Subject: [PATCH v1 12/14] perf thread_map: Reduce exposure of libperf internal API From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Masahiro Yamada , Nicolas Schier , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, Nick Desaulniers , Andrii Nakryiko Cc: Stephane Eranian , Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748912837236962492?= X-GMAIL-MSGID: =?utf-8?q?1748912837236962492?= Remove unnecessary include of internal threadmap.h and refcount.h in thread_map.h. Switch to using public APIs when possible or including the internal header file in the C file. Fix a transitive dependency in openat-syscall.c broken by the clean up. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 1 + tools/perf/builtin-trace.c | 4 ++-- tools/perf/tests/openat-syscall.c | 1 + tools/perf/tests/thread-map.c | 1 + tools/perf/util/bpf_counter.c | 2 +- tools/perf/util/evsel.c | 1 + tools/perf/util/python.c | 6 +++--- tools/perf/util/scripting-engines/trace-event-python.c | 2 +- tools/perf/util/thread_map.c | 1 + tools/perf/util/thread_map.h | 2 -- 10 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d5e1670bca20..fb2d13650e42 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -93,6 +93,7 @@ #include #include +#include #define DEFAULT_SEPARATOR " " #define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi" diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 72991528687e..b403f3fab2a4 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -4092,8 +4092,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv) } trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 || - evlist->core.threads->nr > 1 || - evlist__first(evlist)->core.attr.inherit; + perf_thread_map__nr(evlist->core.threads) > 1 || + evlist__first(evlist)->core.attr.inherit; /* * Now that we already used evsel->core.attr to ask the kernel to setup the diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c index 7e05b8b5cc95..131b62271bfa 100644 --- a/tools/perf/tests/openat-syscall.c +++ b/tools/perf/tests/openat-syscall.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "thread_map.h" #include "evsel.h" #include "debug.h" diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c index e413c1387fcb..74308c1368fe 100644 --- a/tools/perf/tests/thread-map.c +++ b/tools/perf/tests/thread-map.c @@ -11,6 +11,7 @@ #include "util/synthetic-events.h" #include #include +#include struct perf_sample; struct perf_tool; diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index ef1c15e4aeba..eeee899fcf34 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -561,7 +561,7 @@ static int bperf__load(struct evsel *evsel, struct target *target) if (filter_type == BPERF_FILTER_PID || filter_type == BPERF_FILTER_TGID) - key = evsel->core.threads->map[i].pid; + key = perf_thread_map__pid(evsel->core.threads, i); else if (filter_type == BPERF_FILTER_CPU) key = evsel->core.cpus->map[i].cpu; else diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2139e8b0e401..2e212ae73b9f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -53,6 +53,7 @@ #include "util/parse-branch-options.h" #include #include +#include #include diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 5be5fa2391de..b5941c74a0d6 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -718,17 +718,17 @@ static Py_ssize_t pyrf_thread_map__length(PyObject *obj) { struct pyrf_thread_map *pthreads = (void *)obj; - return pthreads->threads->nr; + return perf_thread_map__nr(pthreads->threads); } static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i) { struct pyrf_thread_map *pthreads = (void *)obj; - if (i >= pthreads->threads->nr) + if (i >= perf_thread_map__nr(pthreads->threads)) return NULL; - return Py_BuildValue("i", pthreads->threads->map[i]); + return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i)); } static PySequenceMethods pyrf_thread_map__sequence_methods = { diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 1985d1a42a22..1cf65db8f861 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1654,7 +1654,7 @@ static void python_process_stat(struct perf_stat_config *config, struct perf_cpu_map *cpus = counter->core.cpus; int cpu, thread; - for (thread = 0; thread < threads->nr; thread++) { + for (thread = 0; thread < perf_thread_map__nr(threads); thread++) { for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { process_stat(counter, perf_cpu_map__cpu(cpus, cpu), perf_thread_map__pid(threads, thread), tstamp, diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index c9bfe4696943..e848579e61a8 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -18,6 +18,7 @@ #include "thread_map.h" #include "debug.h" #include "event.h" +#include /* Skip "." and ".." directories */ static int filter(const struct dirent *dir) diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index 3bb860a32b8e..00ec05fc1656 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h @@ -4,8 +4,6 @@ #include #include -#include -#include #include struct perf_record_thread_map;