From patchwork Tue Jun 20 20:18:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 110682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3917830vqr; Tue, 20 Jun 2023 13:21:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mM7o/QdvWkd9byRfCbfayp25gubG7KcrKYftZ+P5LZhtt0I5uE0nQkMStkHC01uLxWUiK X-Received: by 2002:a17:90a:bb85:b0:25e:7ead:3c9 with SMTP id v5-20020a17090abb8500b0025e7ead03c9mr13305838pjr.19.1687292497104; Tue, 20 Jun 2023 13:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687292497; cv=none; d=google.com; s=arc-20160816; b=KkhIhHD4yESPlWw9CJyOtqeN2tSAveUDmBS4FjWeQN4xqqJvDEt4ks4z2JxUto30yI Vsvu58+c793BoSWXo2ANXJ4XMOQGfvKn9r4IKa8GaHJcGRZ4eZeWogqwW9pX3rlvDkcf aEwzQjpPyVmFJJX5HviYDtVEujbPS14WQNYLdSF3eEMc9t3HC0GGygD+LNKN3wS/5de9 RKFbgRlVM8J314Q60MeCY8l1XCiucIRsgnTrBE0jn/BZzNBOauzvgUX7bWGAHVN+ura/ LZQdYcgAGuxmMtQTDbxrMlzXjptZSnM5dwfnpSETQxq2BwR/7+ZnCaDXsd11Eiya8fZv xVTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=pqVZ+yJ0tuR0/Xa4/mt71IlpN1AZgNtJ4C3nrUuBuoc=; b=yp1/Zxk4HPK0YKsouNBkRlroGwYyYYa8FspmjP25NAs1+u6rr+WFOGCn4uNQlBA42m PE1V6ZyPYNnPwWqEntPOA1D44v0S425hcXIbOl0fd7qU7WtHttmoErb+q4ocxlxevjwt 70prodtTP6LHTF8V/16x6UWmL8XFCI0lnUqVCQaCR1sTxNcQxEGAkhYca1EzTjq7i4Ur BW68KPlEq9M10g4qlVczBXZ1dAIjI52RfRIQZrmm22vcm9MPLj1OwYtq8LDHMgYO/NNd 4lZokKqgecPBE87OxLXP7I5WPN2u1k43Mg9dUhGzgDLCpuQNfwyPU3OngQBjZwlGTBAj O8ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QwlgXK20; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l21-20020a637015000000b00553859c59c1si2464200pgc.695.2023.06.20.13.21.22; Tue, 20 Jun 2023 13:21:37 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=QwlgXK20; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjFTUTI (ORCPT + 99 others); Tue, 20 Jun 2023 16:19:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230270AbjFTUSo (ORCPT ); Tue, 20 Jun 2023 16:18:44 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 139351BD1; Tue, 20 Jun 2023 13:18:22 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-25edb50c3acso2853412a91.1; Tue, 20 Jun 2023 13:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687292301; x=1689884301; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=pqVZ+yJ0tuR0/Xa4/mt71IlpN1AZgNtJ4C3nrUuBuoc=; b=QwlgXK20+sNDmTiVystCzoccyU/n8dUHDNtuFGDLv2rdPzZFL0Go6eVyLb7pV9BBKp vzJ9BAgsyXlXd6SX5FL288SJoXin2fzISWH1j3xXt8Ul89zhxzoPzHtcfwzCRox5DXwF 6n6Q/orn88LCpdezK2vckhKAYTQwjZo+Oktfxzoh65WlCRIueLMsib0UvwSGGUAXgLQp /wGWvFQUHlOUrZF0/zpY/tjnvqfnQ2GzNhQm4y266w25SmWTPdrRFqQ2MCfpI8PZZhtI 6KVOjo+lQDY9ue59Wht0u9Zo0v9kD+VvAQFOHdO9QcXnDbaalld5f3CrhfJONkBxJvX3 WcIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687292301; x=1689884301; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pqVZ+yJ0tuR0/Xa4/mt71IlpN1AZgNtJ4C3nrUuBuoc=; b=DI+MhgPVBvtN4MwY9EeQCMEkdndN50HsIK6vnFlxArtvR96KwRurLXyII0ZUuMraZA hOlWRNsa+xNF+79Y4RQX875utf16DgwGxiI06nk2KsQP3yjwR6XOZIkcQn6bdk2rXQRw 68pX5pHG/8Nr33XzkzJ3BgUTp0S7Z0fHjxtU7RbkQvYGNwf2BBZE4icLofEgjdQebzUe ghiA7vWaQ/c8imRniFUoOUBcK/AL5/dmTnCM5z8r0vQZizRsEjI1idIvmbnN1TqSykhT Ey8GqCykTpvnEXXX5JrPNltZppoprGg7a8wPw/VKxyE4cEul9X6c5XjusQZLj3rTx7RO uNbw== X-Gm-Message-State: AC+VfDzAGGPCDQT6hmxwgPmewrLrXG+WLVcHUc4I19kSSCkaevN1zsYt k7UPOSodv3USEfPHdGRMYS8= X-Received: by 2002:a17:90b:a46:b0:25c:2a5d:e06b with SMTP id gw6-20020a17090b0a4600b0025c2a5de06bmr13736156pjb.2.1687292301105; Tue, 20 Jun 2023 13:18:21 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6700:7f00:2824:dc1c:af73:dbd8]) by smtp.gmail.com with ESMTPSA id 27-20020a17090a01db00b0025c23bb7fdasm8191774pjd.16.2023.06.20.13.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 13:18:20 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/3] perf machine: Add machine->has_data_mmap field Date: Tue, 20 Jun 2023 13:18:16 -0700 Message-ID: <20230620201818.1670753-1-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.185.g7c58973941-goog MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1769254417520323580?= X-GMAIL-MSGID: =?utf-8?q?1769254417520323580?= So that it can indicate the it needs to collect data mappings. This is needed especially for kernel maps. At first, I just wanted to add it to struct machines only and to use the machine->machines to check the value. But it turned out that some of machine didn't belong to any machines (eg. some test codes), so I just copied the value to individual struct machine. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 4 ++-- tools/perf/util/machine.c | 12 +++++++----- tools/perf/util/machine.h | 10 ++++++++-- tools/perf/util/session.c | 4 ++-- tools/perf/util/session.h | 4 ++-- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index c8cf2fdd9cff..481adaa97a68 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2325,7 +2325,7 @@ int cmd_inject(int argc, const char **argv) } inject.session = __perf_session__new(&data, repipe, - output_fd(&inject), + output_fd(&inject), false, &inject.tool); if (IS_ERR(inject.session)) { ret = PTR_ERR(inject.session); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index aec18db7ff23..b4d0154dcb18 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2373,7 +2373,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) signal(SIGUSR2, SIG_IGN); } - session = perf_session__new(data, tool); + session = __perf_session__new(data, false, -1, rec->opts.sample_address, tool); if (IS_ERR(session)) { pr_err("Perf session creation failed.\n"); return PTR_ERR(session); diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c index 1078a93b01aa..1f1ba3ae88aa 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -131,8 +131,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused * Init the machines that will hold kernel, modules obtained from * both vmlinux + .ko files and from /proc/kallsyms split by modules. */ - machine__init(&kallsyms, "", HOST_KERNEL_ID); - machine__init(&vmlinux, "", HOST_KERNEL_ID); + machine__init(&kallsyms, "", HOST_KERNEL_ID, false); + machine__init(&vmlinux, "", HOST_KERNEL_ID, false); maps = machine__kernel_maps(&vmlinux); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 4e62843d51b7..ddc0a2130caf 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -110,7 +110,7 @@ static void thread__set_guest_comm(struct thread *thread, pid_t pid) thread__set_comm(thread, comm, 0); } -int machine__init(struct machine *machine, const char *root_dir, pid_t pid) +int machine__init(struct machine *machine, const char *root_dir, pid_t pid, bool has_data_mmap) { int err = -ENOMEM; @@ -128,6 +128,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) machine->env = NULL; machine->pid = pid; + machine->has_data_mmap = has_data_mmap; machine->id_hdr_size = 0; machine->kptr_restrict_warned = false; @@ -170,7 +171,7 @@ struct machine *machine__new_host(void) struct machine *machine = malloc(sizeof(*machine)); if (machine != NULL) { - machine__init(machine, "", HOST_KERNEL_ID); + machine__init(machine, "", HOST_KERNEL_ID, false); if (machine__create_kernel_maps(machine) < 0) goto out_delete; @@ -272,10 +273,11 @@ void machine__delete(struct machine *machine) } } -void machines__init(struct machines *machines) +void __machines__init(struct machines *machines, bool have_data_mmap) { - machine__init(&machines->host, "", HOST_KERNEL_ID); + machine__init(&machines->host, "", HOST_KERNEL_ID, have_data_mmap); machines->guests = RB_ROOT_CACHED; + machines->have_data_mmaps = have_data_mmap; } void machines__exit(struct machines *machines) @@ -295,7 +297,7 @@ struct machine *machines__add(struct machines *machines, pid_t pid, if (machine == NULL) return NULL; - if (machine__init(machine, root_dir, pid) != 0) { + if (machine__init(machine, root_dir, pid, machines->have_data_mmaps) != 0) { free(machine); return NULL; } diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index d034ecaf89c1..f54e5c888a99 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -46,6 +46,7 @@ struct machine { bool comm_exec; bool kptr_restrict_warned; bool single_address_space; + bool has_data_mmap; char *root_dir; char *mmap_name; char *kallsyms_filename; @@ -160,9 +161,14 @@ typedef void (*machine__process_t)(struct machine *machine, void *data); struct machines { struct machine host; struct rb_root_cached guests; + bool have_data_mmaps; }; -void machines__init(struct machines *machines); +void __machines__init(struct machines *machines, bool data_mmap); +static inline void machines__init(struct machines *machines) +{ + __machines__init(machines, false); +} void machines__exit(struct machines *machines); void machines__process_guests(struct machines *machines, @@ -181,7 +187,7 @@ void machines__set_comm_exec(struct machines *machines, bool comm_exec); struct machine *machine__new_host(void); struct machine *machine__new_kallsyms(void); -int machine__init(struct machine *machine, const char *root_dir, pid_t pid); +int machine__init(struct machine *machine, const char *root_dir, pid_t pid, bool has_data_mmap); void machine__exit(struct machine *machine); void machine__delete_threads(struct machine *machine); void machine__delete(struct machine *machine); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 00d18c74c090..e09a02ec8f28 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -191,7 +191,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe, } struct perf_session *__perf_session__new(struct perf_data *data, - bool repipe, int repipe_fd, + bool repipe, int repipe_fd, bool data_mmap, struct perf_tool *tool) { int ret = -ENOMEM; @@ -205,7 +205,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, session->decomp_data.zstd_decomp = &session->zstd_data; session->active_decomp = &session->decomp_data; INIT_LIST_HEAD(&session->auxtrace_index); - machines__init(&session->machines); + __machines__init(&session->machines, data_mmap); ordered_events__init(&session->ordered_events, ordered_events__deliver_event, NULL); diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index ee3715e8563b..465610e81e95 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -64,13 +64,13 @@ struct decomp { struct perf_tool; struct perf_session *__perf_session__new(struct perf_data *data, - bool repipe, int repipe_fd, + bool repipe, int repipe_fd, bool data_mmap, struct perf_tool *tool); static inline struct perf_session *perf_session__new(struct perf_data *data, struct perf_tool *tool) { - return __perf_session__new(data, false, -1, tool); + return __perf_session__new(data, false, -1, false, tool); } void perf_session__delete(struct perf_session *session); From patchwork Tue Jun 20 20:18:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 110690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3923053vqr; Tue, 20 Jun 2023 13:33:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7IdvDaKpubfkv/uY4L+pU4C3iFjf5opynrsTFLoxHAN3Ce7XOwXW2W8Na5Ntv+RbFNBsT1 X-Received: by 2002:a17:902:c254:b0:1b5:219a:cbbd with SMTP id 20-20020a170902c25400b001b5219acbbdmr12965778plg.3.1687293185340; Tue, 20 Jun 2023 13:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687293185; cv=none; d=google.com; s=arc-20160816; b=t5/bGzmWV6apgGymVTa53NlnZoOLnOm2JiBu2YshZt38wZ/ZaCrLVfgkBXk7f4SLgk +tbQeGdtJye1OSlYakNUwIsR+1JdUGD+pF4m4xF1nUPX2O8L1bBCvbzH/Uo1a4+mTKgx OgcuXLLfdk2xhSbt5Qj7RG07Hp56gCAuXVUn/0GK0c0uFpp+udBXw/2fEWTuMEafHyNP rCVL88oDQSAGIqCBrwsnqUac7cLz/HK9BOFO7Jeo3CWoI6RYptFlvVCy4hU4EJNSDEaF QfsIBgNHQska5VKzkx2/nbPsRSZp0kBtKrSIilZR0CMykd3kZzoAsR5/1l4ovNANvLlr VoTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=0d5/yApfhsMQixM8RWfKiFMt1LEPDQuyjPU1y1ZmVQw=; b=sRtw6dVFpkJ7FCawtdePgcOBvP284RCCLyTZVU9QtlzM6J/5T5qkTfrhG7TnEmpmJc 0SthajbnXdlIB1TfDs3a7ysT46/MD5Ams6OBGLGbgKUWzR0IU96gdG3eLFPBAcym8NkL 0dsUHJEItn0erTAMm7jtKbOTnxdAZPu2Ka4VDrqF08kLgw/dtXzd2tt2hj1V9htQBMMC g3/avPsTKy+SnQFe4Q0+9a9po5ldaojYUNy1ZkC9b0rqHi0wGfrXP818iJwlR1L94p+7 TijoIf7ue3fEAvf6/Qh/Y4ZUHG7Xzejux7GxhhftBr4eLKJUuG+/M273LTJ/u11n7c6f 24VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=J0izd5y9; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id im16-20020a170902bb1000b001ae5b59462asi2868261plb.309.2023.06.20.13.32.50; Tue, 20 Jun 2023 13:33:05 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=J0izd5y9; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjFTUTK (ORCPT + 99 others); Tue, 20 Jun 2023 16:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbjFTUSo (ORCPT ); Tue, 20 Jun 2023 16:18:44 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD6E1BDA; Tue, 20 Jun 2023 13:18:22 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b52bf6e669so41270815ad.2; Tue, 20 Jun 2023 13:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687292302; x=1689884302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=0d5/yApfhsMQixM8RWfKiFMt1LEPDQuyjPU1y1ZmVQw=; b=J0izd5y9xfFGM+eE/ia0pKix6/OZlMR3fuhavOMI2YEVGxpjkbUTkmGSmo271MaVca HRW/lwoq+IyuD33urtnvtYaDcCe2bYxlkDDotb6ystrdC++mzTEwnqvazYGZUtQ3ZdUn W+fPxuuSgQXMtx/5gr1Nuoc6MUdxbCGpdPbf0XUhNPL4/gfmwkvfjlmeqaNF8fKV/Zwr EHPEiB8f6z1jmvxeX0ECy5cGOmyORzUb+MApJxpju2TRUt6eAs86Tfv5ZQV+TbQnKnLg VUDtm+F0v56ClSpXcLPrJJlrcMG61uTVJCpHLl0CvZk9ZCQKkcVTNgrSVR0FQRbx4rdT 6ooQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687292302; x=1689884302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0d5/yApfhsMQixM8RWfKiFMt1LEPDQuyjPU1y1ZmVQw=; b=Va+Wrv5/vxzNTu731uq9CFDwQz8DiA9a7eiEOJ+3eGH4AP57k8RGET70maLYTNZEsd WXKeO9THirhQ9JqbVKqdfwEyPZFRjW87t5FR0yxMcG+s6uH+oupo1wtIcEQd2+jtiGrC v9R8t4jQPCmfuc4Wleo9a944K1tjMLVkCP8O+rs4cjaQnT10dzTK7grKlAItPuFSCrAZ UsHuGSmibK5MrVPPFIfFRx8+Jham5ypsxjSj4omQ2eOmWZ8KEnxzZIp6sqsZMtaSR+LF OwoW2OscCXDoE/pV+lbktSp0ygZmJf7jAwVaFZwFzFuuDJNFTrexvSzqbd2BYy9SWztE Ufvw== X-Gm-Message-State: AC+VfDxCaPCklO/CorVCP+ok+3demssDn1TP2AZMQRx6UQ9EjfQJ6YYX rc4R5gcGeW+/kNS/3LJ1Z/O2Oz3AfAI= X-Received: by 2002:a17:90b:3590:b0:25c:2dc:361f with SMTP id mm16-20020a17090b359000b0025c02dc361fmr13109933pjb.31.1687292302283; Tue, 20 Jun 2023 13:18:22 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6700:7f00:2824:dc1c:af73:dbd8]) by smtp.gmail.com with ESMTPSA id 27-20020a17090a01db00b0025c23bb7fdasm8191774pjd.16.2023.06.20.13.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 13:18:22 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/3] perf tools: Add kallsyms__get_symbol_start() Date: Tue, 20 Jun 2023 13:18:17 -0700 Message-ID: <20230620201818.1670753-2-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.185.g7c58973941-goog In-Reply-To: <20230620201818.1670753-1-namhyung@kernel.org> References: <20230620201818.1670753-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1769255138856555060?= X-GMAIL-MSGID: =?utf-8?q?1769255138856555060?= The kallsyms__get_symbol_start() to get any symbol address from kallsyms. The existing kallsyms__get_function_start() only allows text symbols so create this to allow data symbols too. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/event.c | 30 +++++++++++++++++++++++++++--- tools/perf/util/event.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 3860b0c74829..6fdda0eb3854 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -93,8 +93,8 @@ struct process_symbol_args { u64 start; }; -static int find_symbol_cb(void *arg, const char *name, char type, - u64 start) +static int find_func_symbol_cb(void *arg, const char *name, char type, + u64 start) { struct process_symbol_args *args = arg; @@ -110,12 +110,36 @@ static int find_symbol_cb(void *arg, const char *name, char type, return 1; } +static int find_any_symbol_cb(void *arg, const char *name, + char type __maybe_unused, u64 start) +{ + struct process_symbol_args *args = arg; + + if (strcmp(name, args->name)) + return 0; + + args->start = start; + return 1; +} + int kallsyms__get_function_start(const char *kallsyms_filename, const char *symbol_name, u64 *addr) { struct process_symbol_args args = { .name = symbol_name, }; - if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0) + if (kallsyms__parse(kallsyms_filename, &args, find_func_symbol_cb) <= 0) + return -1; + + *addr = args.start; + return 0; +} + +int kallsyms__get_symbol_start(const char *kallsyms_filename, + const char *symbol_name, u64 *addr) +{ + struct process_symbol_args args = { .name = symbol_name, }; + + if (kallsyms__parse(kallsyms_filename, &args, find_any_symbol_cb) <= 0) return -1; *addr = args.start; diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index de20e01c9d72..d8bcee2e9b93 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FIL int kallsyms__get_function_start(const char *kallsyms_filename, const char *symbol_name, u64 *addr); +int kallsyms__get_symbol_start(const char *kallsyms_filename, + const char *symbol_name, u64 *addr); void event_attr_init(struct perf_event_attr *attr); From patchwork Tue Jun 20 20:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 110695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3936212vqr; Tue, 20 Jun 2023 14:02:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4LDoar7NJRainXW6ZWhu05+0EL8tRBwwRZoLUmOrs6A4s3SOtYcupomHM0il5sACwo7Drn X-Received: by 2002:a05:6808:138f:b0:3a0:330e:ea98 with SMTP id c15-20020a056808138f00b003a0330eea98mr5193099oiw.23.1687294928465; Tue, 20 Jun 2023 14:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687294928; cv=none; d=google.com; s=arc-20160816; b=ZKcRph+L/yjUKfAUFk3kNDMDQ9y8nCqNfeBHt7En7EHumDCow7+bn8+PPb0/rh0kna j/uqb+INBYNrEwIQOgtF8HNGK3swtpa7TcklsL8y34HE4CwzZGipC+NbANxLNheltvXZ X/OzgjgY8Ef9/BGlHP7IxTDSc4XAdDFjKcftq2Qnabq4v1nOrWmCEKMCDvKx3RelD73H yy3813zrtjsncs9EC/gtkqXU/YbvVccW4EMAdZrIrnIrsqdjm3CoXu9/dXVcMBcG1MLs fQDkwA8hqe2Jo/jSqS2/Ct5pz03+R9+5Q6bVRH5fMzFOkC+SRt8BmGGvG6rPDDOMqBuV Wudw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=7i2JmSY9J3aXJvNYPDUup2Ul0DqDLcLtP/gbsQnodQE=; b=C9BHUMaVL8NuRQcC2dmKQbOf0BR2dxrpgXRiF1wtJO4XoqRDjsVyGWFf3oEL8SlxYl G89CXw5HZ/ivE4qBKhqGuVFEy1phSKDqJCkk3A7LQ3ZhA/UXjq0jVc+7RkWGGBMPzzo+ jt2plcFNcjWbS3OuAY2Yvd22A89cxrZNc7UbnjcUvPga/OPXrYMjGECQp/RYVgv2lBiV UQE9KbTUjx+tHgZJWQTg07jGLyAtnIu2GqoDHV0Yce78lmXibIO8IWKWY94wB2n7sQ7t 99lsh294zLAzcrrLoy8Tqm2uXNf1+E2uiH6+m5M1enoEyBCEEhqGfhu/BOxh4rPZ/LPd iolA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=W8W+BdRt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h184-20020a6383c1000000b0053f01212571si2406437pge.257.2023.06.20.14.01.50; Tue, 20 Jun 2023 14:02:08 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=W8W+BdRt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjFTUTN (ORCPT + 99 others); Tue, 20 Jun 2023 16:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbjFTUSo (ORCPT ); Tue, 20 Jun 2023 16:18:44 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2742C1BE2; Tue, 20 Jun 2023 13:18:24 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-25e8545ea28so3967855a91.0; Tue, 20 Jun 2023 13:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687292303; x=1689884303; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=7i2JmSY9J3aXJvNYPDUup2Ul0DqDLcLtP/gbsQnodQE=; b=W8W+BdRt47e/1zKvDQJQnbDBHt7693qHLovnUIQ4uE5CXmd9dMCfnD2MGkzow/fKZB oX826Ny5CGbeXF7gc3uzhRp6pX+oi6bdQV+8+Tc67ZQIXRHBunU+rxV9uf7n7rdGnoi3 pine2IzdUCi28NsDa+D1A0HeMv5EtmmGzCcdrH69IiyU58mOGhQntPVmOFuV4Dwh082I XXEoNlyXPNrIfs/d842vRHoCEMeoLhbJaPAUciK+hIZF3ZcihjdrswIHe/QKSihZzVvJ 3MAxxBrr66S3SmDW3ifM25R53thQ4Y+Zhhjbe3x7ftfBIN3loCKIEYC080Fd0+Vz9v/a NnWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687292303; x=1689884303; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7i2JmSY9J3aXJvNYPDUup2Ul0DqDLcLtP/gbsQnodQE=; b=Bt8B27D5PoUsSNaBZzBklVXUP30kVfoMesUHXiOIUo8Ninb+oxRgP2SxqAfUe7gxkV 2vnNTt4sBx+hHYISoDsJ9491bL4dZSjDSZtEb7UNQ7TY5U9Wt47yIbqSYrj0SuHnyA6o d1WsGmgSB67vM2jjMOHdCmqgoK3JDIwUz7OeveEgUKeiNihcBcFSDuMc83oGAc49Enal uPTh+HgsVbtw+0x5/AsHtzlNWqkAVAwGIuQ0YrOG7bTiCoe3u9Wg80Vtf8T9f3Pnkkf7 8JW0HXL8G+gdOd5lrjAe8OSEHFwlecw9LHQevpjUD+4DiKU5dOeTXW8CiI1Q1CnlJ0qL xunA== X-Gm-Message-State: AC+VfDzSjnwCBz1S/fmMcQDCGfZP8gUN2zI6DIbFRXeuguesND24idLr xACXaUDKSjB8XkFxgrVWfrO3d7Z6bSg= X-Received: by 2002:a17:90a:35b:b0:259:bf40:b571 with SMTP id 27-20020a17090a035b00b00259bf40b571mr13450471pjf.45.1687292303485; Tue, 20 Jun 2023 13:18:23 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6700:7f00:2824:dc1c:af73:dbd8]) by smtp.gmail.com with ESMTPSA id 27-20020a17090a01db00b0025c23bb7fdasm8191774pjd.16.2023.06.20.13.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 13:18:23 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 3/3] perf machine: Include data symbols in the kernel map Date: Tue, 20 Jun 2023 13:18:18 -0700 Message-ID: <20230620201818.1670753-3-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.185.g7c58973941-goog In-Reply-To: <20230620201818.1670753-1-namhyung@kernel.org> References: <20230620201818.1670753-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1769256967100033431?= X-GMAIL-MSGID: =?utf-8?q?1769256967100033431?= When perf record -d is used, it needs data mmaps to symbolize global data. But it missed to collect kernel data maps so it cannot symbolize them. Instead of having a separate map, just increase the kernel map size to include the data section. Probably we can have a separate kernel map for data, but the current code assumes a single kernel map. So it'd require more changes in other places and looks error-prone. I decided not to go that way for now. Also it seems the kernel module size already includes the data section. For example, my system has the following. $ grep -e _stext -e _etext -e _edata /proc/kallsyms ffffffff99800000 T _stext ffffffff9a601ac8 T _etext ffffffff9b446a00 D _edata Size of the text section is (0x9a601ac8 - 0x99800000 = 0xe01ac8) and size of the data section is (0x9b446a00 - 0x99800000 = 0x1c46a00). Before: $ perf record -d true $ perf report -D | grep MMAP | head -1 0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0xe01ac8) @ 0xffffffff99800000]: x [kernel.kallsyms]_text ^^^^^^^^ here After: $ perf report -D | grep MMAP | head -1 0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0x1c46a00) @ 0xffffffff99800000]: x [kernel.kallsyms]_text ^^^^^^^^^ Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index ddc0a2130caf..e93a66f6e0b3 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1218,7 +1218,10 @@ static int machine__get_running_kernel_start(struct machine *machine, *start = addr; - err = kallsyms__get_function_start(filename, "_etext", &addr); + if (machine->has_data_mmap) + err = kallsyms__get_symbol_start(filename, "_edata", &addr); + else + err = kallsyms__get_function_start(filename, "_etext", &addr); if (!err) *end = addr;