Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1361953rdb; Wed, 6 Dec 2023 17:18:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRnLIVDgvumV8KaGF6AioRWhOzdJ719MG/nW+6vgMZM6W0wdgPdpk5kZYDvIrdT7mF6rOJ X-Received: by 2002:a17:902:f68c:b0:1d0:a7b7:74c2 with SMTP id l12-20020a170902f68c00b001d0a7b774c2mr1751660plg.43.1701911903765; Wed, 06 Dec 2023 17:18:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911903; cv=none; d=google.com; s=arc-20160816; b=M2WmmDHgSqhQJU5AwMeahqdbaYRa0CfBacoCnqpedoIjJ/Lu1+IX0CVX44k5g+cF9c N3zzw3DEDWo5voR/yg0bvuxMOKtWfj2TPTuHq5vg6+H3/eA3PVgyZMvojERWeitlG+eu zmqJ3+hSWpg513QNw9MY19iWdA79j2ZksS5HJNe5c2IaMiuUUzv4uScVRa47BVJnfA0o JN08Tu0qETgE9ITqIpSzYjIpfxgpPnxbda4oXHuzI5NVI22RvQNOhgRWt7Dmw2aGCcGN wcFrnQjQny1tLTxSi1qn30+FAPdAiKPuAKn5cyc6GLZW7GZrDg9+wCxvTcQXLZMuz2f4 4fbw== 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=SY+VZ2g7Sz9SUrig6hGASQIeGQdVI2UxDJkUdRi/lk4=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=m6l6LVwy/w15Gkj/JL3JBgAa29likHPSQoEntlplWvYxlhj1sNDrugcVXHmdt1FI9o zojckVz8Y8BmN9NTZCyg0foWZfvGNhgz+XaEtDOwtKxe9N23LEEr+xIrYfgLXbKpW/cV 2tlx/Y82EegBHDu0wcrJrEkxywCXT6dDSD6uNV+vW6/r6IbrLjc9QNOLsrXBfeExa63s AR9tYD0Gd6zzqkSqP9o/8U6G/KBSv5DDditKDSdYMDJH4kqgoekPZB5ZA3/y5CF6UnnW 3u0WZ7hznP7IIfMOHdbyPdqkpwy5jizjZpTaJj4sIzZUh2C/TATZcSpc/dXUICuA5OIM cNgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=f0LC3uUW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 4-20020a170902c24400b001cfb3d25f2asi134455plg.652.2023.12.06.17.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:18:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=f0LC3uUW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id AB89C80D773E; Wed, 6 Dec 2023 17:18:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442044AbjLGBRg (ORCPT + 99 others); Wed, 6 Dec 2023 20:17:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442019AbjLGBRc (ORCPT ); Wed, 6 Dec 2023 20:17:32 -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 7C69ED72 for ; Wed, 6 Dec 2023 17:17:37 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d98fde753eso1778947b3.2 for ; Wed, 06 Dec 2023 17:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911856; x=1702516656; 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=SY+VZ2g7Sz9SUrig6hGASQIeGQdVI2UxDJkUdRi/lk4=; b=f0LC3uUW/cEQraZC/IobZ9ZkfT2/zJsoAuA/0MNe2oMW01UFK78qQwd4PSU7p0eJRo DLx3AAIgMYFN4Yne9xVwhS32HXCV7TedGCVR7O2/2n3XafEL7A6Te0r8Dpct63E5pS3o 4TWlSzI64OP+0iCt3zQjDrqDVLcCGXtYRztkxKEU6BNtUEa1FyVhmt+95/Tr9A28qIvi wTWhQlEd/x+i4Q4znhc4uPbkhBt70B5sgfObCTFoWUID36Ygrd4EbCsIvVdwl6zB6muu iKcqm5smsc1UmCVMZA1SyznCIc3UWpoCpl/OWj9HX1LlDuKU5yyhy3vI4Zrc8LWymoqe JXgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911856; x=1702516656; 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=SY+VZ2g7Sz9SUrig6hGASQIeGQdVI2UxDJkUdRi/lk4=; b=dca6/p8UwpWxllc5i1wNE1QcvA6KNik5CW38C1VAUq3B6+CdFFGa+zp/URW7fuBuhu sH4of46hO2MytQwXpRqntNMBrvwXKv4KQOGvmCmUy8qOuCqDEK+UbkKFVaam3sRAF1cC oKRnqO5hAATVmyvdnuGaj3xzXMcIytPBZI4OPkjIUzwl6T6sIUS0BUC3N061vovWqKoa Woia0CsvWGGT9xnNNngO/0RvW4C8O/sviJsKzqitQ8UNg3IlFuzQmxYDhnkWjZ4t/Dwa fTgcGnPR+SLUV3QdbguVBISm/aP7jBri0/+untFGjmE2etjMfipdDdnm8iRwbGoyNs39 deeA== X-Gm-Message-State: AOJu0YxAbygKaTMWSrMqKxYRVSsSIFIu/Dl1iT1GVYAR0XMwk3S6t6dN u2+Kx0nDwn9MD0VSppm4BqjuEbKJzxB5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a05:690c:2847:b0:5d9:4242:8d21 with SMTP id ed7-20020a05690c284700b005d942428d21mr23555ywb.9.1701911856720; Wed, 06 Dec 2023 17:17:36 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:38 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-5-irogers@google.com> Mime-Version: 1.0 References: <20231207011722.1220634-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v6 04/47] perf report: Use function to add missing maps lock From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, 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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:18:15 -0800 (PST) Switch maps__fprintf_task from loop macro maps__for_each_entry to maps__for_each_map function that takes a callback. The function holds the maps lock, which should be held during iteration. Signed-off-by: Ian Rogers --- tools/perf/builtin-report.c | 54 +++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 121a2781323c..a5d7bc5b843f 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -859,27 +859,47 @@ static struct task *tasks_list(struct task *task, struct machine *machine) return tasks_list(parent_task, machine); } -static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp) +struct maps__fprintf_task_args { + int indent; + FILE *fp; + size_t printed; +}; + +static int maps__fprintf_task_cb(struct map *map, void *data) { - size_t printed = 0; - struct map_rb_node *rb_node; + struct maps__fprintf_task_args *args = data; + const struct dso *dso = map__dso(map); + u32 prot = map__prot(map); + int ret; - maps__for_each_entry(maps, rb_node) { - struct map *map = rb_node->map; - const struct dso *dso = map__dso(map); - u32 prot = map__prot(map); + ret = fprintf(args->fp, + "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n", + args->indent, "", map__start(map), map__end(map), + prot & PROT_READ ? 'r' : '-', + prot & PROT_WRITE ? 'w' : '-', + prot & PROT_EXEC ? 'x' : '-', + map__flags(map) ? 's' : 'p', + map__pgoff(map), + dso->id.ino, dso->name); - printed += fprintf(fp, "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n", - indent, "", map__start(map), map__end(map), - prot & PROT_READ ? 'r' : '-', - prot & PROT_WRITE ? 'w' : '-', - prot & PROT_EXEC ? 'x' : '-', - map__flags(map) ? 's' : 'p', - map__pgoff(map), - dso->id.ino, dso->name); - } + if (ret < 0) + return ret; + + args->printed += ret; + return 0; +} + +static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp) +{ + struct maps__fprintf_task_args args = { + .indent = indent, + .fp = fp, + .printed = 0, + }; + + maps__for_each_map(maps, maps__fprintf_task_cb, &args); - return printed; + return args.printed; } static void task__print_level(struct task *task, FILE *fp, int level) -- 2.43.0.rc2.451.g8631bc7472-goog