Message ID | 20231127220902.1315692-35-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3500634vqx; Mon, 27 Nov 2023 14:13:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPfk51ItwnOKRq29PpOEslctFr07MOiCi/7AFTLnnOGCvcbqrtYUCXzxW8d+2Z+kS7+DO0 X-Received: by 2002:a17:903:2652:b0:1cf:6945:7586 with SMTP id je18-20020a170903265200b001cf69457586mr14554970plb.9.1701123230971; Mon, 27 Nov 2023 14:13:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123230; cv=none; d=google.com; s=arc-20160816; b=htRzW7I09omS7RaBsThc6mohN0oI9wCyvm/JSzXYiFrm4sX5As1Z7JP7FOE1PPRcVj xlOES68OdFjrc62j2KHZYbP8fifdJqKLdikVQe1oY+YF4FeNmXHfSHdnJwQShmIu5J6t urGhdpJ3ohYpbA5StySgx851XItvx6rlJvubSbekxetwDTiI/VHoXoaTHgTPAVWLqKNb L75sCy6uVqVa3nYLN2FW8z4bxmy/ikXY64nWQ0zQCGGVVwMBrhLIEXw0l1K6h8W5KcvH f3x2AsZrwvcNd1GiJAmomNJS1ZoPqTjJ1OHWjikbJQT1m42le94jFqSKykfRjIMaBPR4 TLbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=DE11asDQk9rpQtwkVS6wVBngrVh7woxSSqgHs8uGQL0=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=hV7ZmFbuFOFjr6N7DyFzY+Zn6u2IlR3crDL2HROqsHx1L/qplyhkuvpyAqTIjbcDnu SWPuqjbbYye63tbvA8IQc9Q8Tugp7a8rJZ7tX/+lneysgSWIDbKHiN77Ax2zAv6+a850 twZCQke6cUUcjqhDrBoq+TtFs6YXgYP2UFmsBshHfLstNctH2ootFqH1fXQ9pNTy/Otb d8oE5+70yI+0L1gjytbn9wVSNbycdgVjCA3HMdLJYtk3CMsyy91sdNvUjhpdz1ALL7Ds wXrPbbnsVxegESZKEd9ZMp+1CPsRr1IJGymPLf9V88RNMPOGcxceOZJ7v6+CbdL+VPJi Cr0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Szaeqf7V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d12-20020a170903230c00b001cfc68aca49si4144536plh.373.2023.11.27.14.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:13:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Szaeqf7V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A8F7080A5FB3; Mon, 27 Nov 2023 14:13:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233629AbjK0WNf (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 27 Nov 2023 17:13:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233989AbjK0WMm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 27 Nov 2023 17:12:42 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9FDD30D0 for <linux-kernel@vger.kernel.org>; Mon, 27 Nov 2023 14:10:42 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d032ab478fso22191407b3.0 for <linux-kernel@vger.kernel.org>; Mon, 27 Nov 2023 14:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123042; x=1701727842; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=DE11asDQk9rpQtwkVS6wVBngrVh7woxSSqgHs8uGQL0=; b=Szaeqf7V1DZHccV6SqWWH+R5bYAinpW4i6wG8xdUriunnpMJchdnjappz1wzO/gVNw USFAl6eawT7IufaTcAXvdR6/VYFBvd9mG+62df61ZjxtL8TXTsdy8jknviYFc8hm6ucs Wbh/6S9Vyg3GvWmyuVgZkemoHEJdb1KUEv3X7nTBBv2GP9/ZzXt31PnNN9J+oI6L9qaX O/Exx/U7BzxkvUOBxPD5el+mHS5dfJGcnGRYVirFbtYbGEtg/wDqdWwN9+HaX9X+0o9N sF7GI9+PLoEoX4ETJO6TkZ0a2v1gdEVtxEWh0yjgpdiKq6R5/0K34CKi4XyoaI3ofKvw p7lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123042; x=1701727842; h=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=DE11asDQk9rpQtwkVS6wVBngrVh7woxSSqgHs8uGQL0=; b=xVP73KXP/iOxfl93QZs7ZQwxUlk6c1sQM5ioRyov6pYNlPPWkx2mQa+XpTkWPZ135/ BkVp1M3u5B7vjx5P0MMoswFJrEiioFFOqoYP8d4pHMrUkyLvG86Osg+951FgReDhs/4u qWpx+WhWMVaQMuLP4lfuQMmoJz2Hi0dpmDt7sGt4uRkGnb8bTX8vC+A/ZhPrLsZb0UQF rnOpfXd6/gYC7sySCUrOncbQ3tizFVhbnEUtLvOAeNPHNFXfC/h6rKuII9ti351jrC+g ZTcMC0KVpCCbY8lIGBtpvxOZnUFv9kwsFCkOdjRaqoAcxFcFnS4c2FLrtFmfdO3kdzGj cAkQ== X-Gm-Message-State: AOJu0YwurZouJCGZlExR4j6WOhnhNbJQNvYJ0uIZvk9A5nT/81btIKIQ UUiWBXJoMITHI9ZLSFNJ8iclV6fY45no X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:ec5:b0:5ca:321f:a368 with SMTP id cs5-20020a05690c0ec500b005ca321fa368mr517772ywb.7.1701123041929; Mon, 27 Nov 2023 14:10:41 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:46 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-35-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 34/50] perf machine: Move fprintf to for_each loop and a callback From: Ian Rogers <irogers@google.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Nick Terrell <terrelln@fb.com>, Kan Liang <kan.liang@linux.intel.com>, Andi Kleen <ak@linux.intel.com>, Kajol Jain <kjain@linux.ibm.com>, Athira Rajeev <atrajeev@linux.vnet.ibm.com>, Huacai Chen <chenhuacai@kernel.org>, Masami Hiramatsu <mhiramat@kernel.org>, Vincent Whitchurch <vincent.whitchurch@axis.com>, "Steinar H. Gunderson" <sesse@google.com>, Liam Howlett <liam.howlett@oracle.com>, Miguel Ojeda <ojeda@kernel.org>, Colin Ian King <colin.i.king@gmail.com>, Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong <yangjihong1@huawei.com>, Ming Wang <wangming01@loongson.cn>, James Clark <james.clark@arm.com>, K Prateek Nayak <kprateek.nayak@amd.com>, Sean Christopherson <seanjc@google.com>, Leo Yan <leo.yan@linaro.org>, Ravi Bangoria <ravi.bangoria@amd.com>, German Gomez <german.gomez@arm.com>, Changbin Du <changbin.du@huawei.com>, Paolo Bonzini <pbonzini@redhat.com>, Li Dong <lidong@vivo.com>, Sandipan Das <sandipan.das@amd.com>, liuwenyu <liuwenyu7@huawei.com>, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio <amadio@gentoo.org> Content-Type: text/plain; charset="UTF-8" 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:13:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783756993221199818 X-GMAIL-MSGID: 1783756993221199818 |
Series |
Improvements to memory use
|
|
Commit Message
Ian Rogers
Nov. 27, 2023, 10:08 p.m. UTC
Avoid exposing the threads data structure by switching to the callback
machine__for_each_thread approach. machine__fprintf is only used in
tests and verbose >3 output so don't turn to list and sort. Add
machine__threads_nr to be refactored later.
Note, all existing *_fprintf routines ignore fprintf errors.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/machine.c | 43 ++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 6d7a505850c8..7e19303d1aa6 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1114,29 +1114,40 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp) return printed; } -size_t machine__fprintf(struct machine *machine, FILE *fp) +struct machine_fprintf_cb_args { + FILE *fp; + size_t printed; +}; + +static int machine_fprintf_cb(struct thread *thread, void *data) { - struct rb_node *nd; - size_t ret; - int i; + struct machine_fprintf_cb_args *args = data; - for (i = 0; i < THREADS__TABLE_SIZE; i++) { - struct threads *threads = &machine->threads[i]; + /* TODO: handle fprintf errors. */ + args->printed += thread__fprintf(thread, args->fp); + return 0; +} - down_read(&threads->lock); +static size_t machine__threads_nr(const struct machine *machine) +{ + size_t nr = 0; - ret = fprintf(fp, "Threads: %u\n", threads->nr); + for (int i = 0; i < THREADS__TABLE_SIZE; i++) + nr += machine->threads[i].nr; - for (nd = rb_first_cached(&threads->entries); nd; - nd = rb_next(nd)) { - struct thread *pos = rb_entry(nd, struct thread_rb_node, rb_node)->thread; + return nr; +} - ret += thread__fprintf(pos, fp); - } +size_t machine__fprintf(struct machine *machine, FILE *fp) +{ + struct machine_fprintf_cb_args args = { + .fp = fp, + .printed = 0, + }; + size_t ret = fprintf(fp, "Threads: %zu\n", machine__threads_nr(machine)); - up_read(&threads->lock); - } - return ret; + machine__for_each_thread(machine, machine_fprintf_cb, &args); + return ret + args.printed; } static struct dso *machine__get_kernel(struct machine *machine)