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);