Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2760256rda; Wed, 25 Oct 2023 11:26:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbBtP3nDzlNAtV1zHO/sNw4YMqSh2bFyLueqhehTxa03nxBTmgTh9N8RIBCBo3kYzKyn1B X-Received: by 2002:a05:6830:440c:b0:6cd:914f:2e20 with SMTP id q12-20020a056830440c00b006cd914f2e20mr16343748otv.5.1698258406262; Wed, 25 Oct 2023 11:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698258406; cv=none; d=google.com; s=arc-20160816; b=gv/l+o/FU7MVnxdAuU/k/0zZZN7wfh/vUvDeOVgRZLJICqmmzD+1+MGagYbXTYXyl1 eRXAp2t4dQnKcNBWq1ZMMn0UmzkpIR5KD5t480Lx/N1v4UBYkDMDrnDX4zu6WV32cI7f KKKHUumEgztCLdFUy0SkKYslaLqbx4+fCriOauMA+WliBKoD/XPyE4887QWDF6wwzZjQ udLTaiLX/QLjwojLUplmjzXllRRbhPirceyj6/laJrg73vsQAEzU2FCD5HcBK0SBw/OD bibRkPwd6X9O7Z7rikP1EnriiB79oT8Lhu3hjSRPDGZqiUsWzc58467xJ56QufBKQ80X 84rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=c7VnkcWX/nxjPWsTFvJo+l8u6kp67jWl0r47V2eAxdU=; fh=oYH90ll5Qo2wD573LC7tOw4S9tbIOO96EVwYzD4dfVw=; b=fjyapeKZHEZFaldhOutu/NUfd7m/cieVkmJMM+i4VdDeNHO8By0q5LqHRur4WmJonG FwBvkIMJb78tvVA7cvpFx+MsCQxo1MKFNB+1gDbCjzlODQD5bg2dIb8pN3HkCMP3hqTi Xt11ftfpu/Hk0E8PdXu6XA6y9Jubq4NBvOeN2qZpwJBgAqDKy6Vyub63VxN3DN1aW+Rv 06pld9gnwlbmvqgW/3qkFKKbXu6Jra2QWPqGARIclNVpnB4ffXlaNIMAm5PmFn7gOA5Y eYC3idzZkzb4YozRXPS0byfVxmRvlUl/Ps2RNZ4l4X+ftjnFNwQPZ691lDuoR44K8ysE dAIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id y192-20020a0dd6c9000000b0059f527e8546si11929948ywd.103.2023.10.25.11.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 11:26:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 212228077531; Wed, 25 Oct 2023 11:26:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229522AbjJYSZ7 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 25 Oct 2023 14:25:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJYSZ6 (ORCPT ); Wed, 25 Oct 2023 14:25:58 -0400 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F4030AB; Wed, 25 Oct 2023 11:25:55 -0700 (PDT) Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so84461a12.1; Wed, 25 Oct 2023 11:25:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698258355; x=1698863155; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WJAKpnqddCDWndjCGlgQHJV2XSPFHdKSadNoAg1lWyE=; b=Tu2uzjQST82b/x5Uo0QC1cwz3vfcxo8UYq96MU3AIf2YlCOZ/qpXoFXPHQzcHzZP/z yTrj1YqnDTQ0PLceNVqKmVyuDYxwuHyC0XZECnrNTyxaw8TzPCllo40JUlY26DIlIYYc uA/9Ja61pyKt/EIo53yqTL2d2tqUpPkGZp/hB3c+iMSdLTf8LkjQAGR5FtNWCcoRIhoM pHtm5y2mxEZSJWymc6cCPrJX9jEq17Fdxyjw4f4I6f6Duwz9wCGPyi0uyDudG8a5QdVF 7JxIEI/+hdY43KFVGczpCJ6bytxpR+etZ/jc3YrmBPVaE4rvR4/yPC0vq/DEOfRKrBod Uitw== X-Gm-Message-State: AOJu0YzQlubwt9uBA2XWLXpmJTFuBGSLZZHZ6guPAtM1HRP7B7+Cl747 uIHCtzhgOELFcartdW7P3MEZUysVAq1EK32qv6c= X-Received: by 2002:a17:90b:f10:b0:27d:12e1:7e20 with SMTP id br16-20020a17090b0f1000b0027d12e17e20mr15200810pjb.12.1698258355242; Wed, 25 Oct 2023 11:25:55 -0700 (PDT) MIME-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> <20231024222353.3024098-13-irogers@google.com> In-Reply-To: <20231024222353.3024098-13-irogers@google.com> From: Namhyung Kim Date: Wed, 25 Oct 2023 11:25:44 -0700 Message-ID: Subject: Re: [PATCH v3 12/50] perf record: Lazy load kernel symbols To: Ian Rogers , Adrian Hunter Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Nick Terrell , Kan Liang , Andi Kleen , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 25 Oct 2023 11:26:09 -0700 (PDT) Hi Ian, On Tue, Oct 24, 2023 at 3:24 PM Ian Rogers wrote: > > Commit 5b7ba82a7591 ("perf symbols: Load kernel maps before using") > changed it so that loading a kernel dso would cause the symbols for > the dso to be eagerly loaded. For perf record this is overhead as the > symbols won't be used. Add a symbol_conf to control the behavior and > disable it for perf record and perf inject. I'm curious if it can simply move to lazy loading unconditionally. In most cases, the code calls machine__resolve() which calls thread__find_map() and map__find_symbol() to load symbols. So I think it's unnecessary to do it in the thread__find_map(). If it needs a symbol, it should call map__find_symbol() first and it'll load the symbol table. Adrian, what's special in inject or Intel-PT on this? Thanks, Namhyung > > Signed-off-by: Ian Rogers > --- > tools/perf/builtin-inject.c | 6 ++++++ > tools/perf/builtin-record.c | 2 ++ > tools/perf/util/event.c | 4 ++-- > tools/perf/util/symbol_conf.h | 3 ++- > 4 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c > index c8cf2fdd9cff..eb3ef5c24b66 100644 > --- a/tools/perf/builtin-inject.c > +++ b/tools/perf/builtin-inject.c > @@ -2265,6 +2265,12 @@ int cmd_inject(int argc, const char **argv) > "perf inject []", > NULL > }; > + > + if (!inject.itrace_synth_opts.set) { > + /* Disable eager loading of kernel symbols that adds overhead to perf inject. */ > + symbol_conf.lazy_load_kernel_maps = true; > + } > + > #ifndef HAVE_JITDUMP > set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true); > #endif > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index dcf288a4fb9a..8ec818568662 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -3989,6 +3989,8 @@ int cmd_record(int argc, const char **argv) > # undef set_nobuild > #endif > > + /* Disable eager loading of kernel symbols that adds overhead to perf record. */ > + symbol_conf.lazy_load_kernel_maps = true; > rec->opts.affinity = PERF_AFFINITY_SYS; > > rec->evlist = evlist__new(); > diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c > index 923c0fb15122..68f45e9e63b6 100644 > --- a/tools/perf/util/event.c > +++ b/tools/perf/util/event.c > @@ -617,13 +617,13 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, > if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { > al->level = 'k'; > maps = machine__kernel_maps(machine); > - load_map = true; > + load_map = !symbol_conf.lazy_load_kernel_maps; > } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) { > al->level = '.'; > } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { > al->level = 'g'; > maps = machine__kernel_maps(machine); > - load_map = true; > + load_map = !symbol_conf.lazy_load_kernel_maps; > } else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) { > al->level = 'u'; > } else { > diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h > index 0b589570d1d0..2b2fb9e224b0 100644 > --- a/tools/perf/util/symbol_conf.h > +++ b/tools/perf/util/symbol_conf.h > @@ -42,7 +42,8 @@ struct symbol_conf { > inline_name, > disable_add2line_warn, > buildid_mmap2, > - guest_code; > + guest_code, > + lazy_load_kernel_maps; > const char *vmlinux_name, > *kallsyms_name, > *source_prefix, > -- > 2.42.0.758.gaed0368e0e-goog >