Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2704116pxv; Sun, 27 Jun 2021 06:19:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaKwc1Tg+gv8/N2OTcQNXg5qZ/TFmSOp/XVA6ch/uCwZaXjK0XkuPjiMOP89B42zkPctQF X-Received: by 2002:a92:b004:: with SMTP id x4mr14915178ilh.121.1624799996227; Sun, 27 Jun 2021 06:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624799996; cv=none; d=google.com; s=arc-20160816; b=M3736qwpDJvM+U0x58RQ069ywy0adAtZ4dx6e3lSkHEXVLNqyaqViZcfvaKNzNYaSg UMa8AzK/NSK8di017pOHDhL+AojGb5Am7eEbYxEOCtsw8f0Zz0WuPV2L9qk6Je2nPWzx mVwOO9q3M85GYrFpbYhXNECZKe9XkCMZ2B/yJeO+/Juu1Tp5rjA9yC9TZgAYyw4jHuiU KH1OX+OI0TQM4eJjb2uXm64ANmHfykEhAFWQzDVFT9ca/wjevwYj++arStAmyi71ChTB uTz+S+miNvZfQcRBG0Bn1hiZ8m7tNfe0TW8ElTwAV6MaGJpt+0MwTxq2bADdDsi+pYHz 5CGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:references:in-reply-to:message-id :date:subject:cc:to:from; bh=MKajTqhNZpR9O9R1tkSaGuVUgtxd4H1GN7ybcstu6cs=; b=rPwgoqLoCvqW4zk9OIzcQORPz5igP7vkMwh3d/Y/2Hnsdy/HxowPfk1JEsdanOWzBG wQuZTWraPgrd5k7Yuf3PlMBBPushGqQS9GfE+DdY9cEw5C3MEDSK7iTKKwXXv5XZB3vJ /8/hOm6yXS785FBitX84VXG1bGlCWefmqv3Uhl2LAXIIs+RJT/9ohlCRUCmgU18By2Dd bduO9o62EwZ0v/b8Z9ulNhWPQmt48qR97HtH9IlXeNu2r9m6RZKuQYVm125/ZANEAhDv SPndAackdy7C8kOgTE1oHb8mWH/VpH05w38gghEugQZ6xN5TWBSPDHGGYEhxH+x/IWA7 ioPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si9428996ilt.111.2021.06.27.06.19.44; Sun, 27 Jun 2021 06:19:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbhF0NVD (ORCPT + 99 others); Sun, 27 Jun 2021 09:21:03 -0400 Received: from mga01.intel.com ([192.55.52.88]:6344 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbhF0NU7 (ORCPT ); Sun, 27 Jun 2021 09:20:59 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10027"; a="229454388" X-IronPort-AV: E=Sophos;i="5.83,302,1616482800"; d="scan'208";a="229454388" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2021 06:18:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,302,1616482800"; d="scan'208";a="640589119" Received: from ahunter-desktop.fi.intel.com ([10.237.72.79]) by fmsmga006.fm.intel.com with ESMTP; 27 Jun 2021 06:18:31 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Andi Kleen , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Leo Yan , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 10/10] perf dlfilter: Add object_code() to perf_dlfilter_fns Date: Sun, 27 Jun 2021 16:18:18 +0300 Message-Id: <20210627131818.810-11-adrian.hunter@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210627131818.810-1-adrian.hunter@intel.com> References: <20210627131818.810-1-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function, for use by dlfilters, to read object code. Signed-off-by: Adrian Hunter --- tools/perf/Documentation/perf-dlfilter.txt | 5 +++- tools/perf/util/dlfilter.c | 34 ++++++++++++++++++++++ tools/perf/util/perf_dlfilter.h | 4 ++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-dlfilter.txt b/tools/perf/Documentation/perf-dlfilter.txt index 6b1d9da16feb..02842cb4cf90 100644 --- a/tools/perf/Documentation/perf-dlfilter.txt +++ b/tools/perf/Documentation/perf-dlfilter.txt @@ -127,7 +127,8 @@ struct perf_dlfilter_fns { const __u8 *(*insn)(void *ctx, __u32 *length); const char *(*srcline)(void *ctx, __u32 *line_number); struct perf_event_attr *(*attr)(void *ctx); - void *(*reserved[121])(void *); + __s32 (*object_code)(void *ctx, __u64 ip, void *buf, __u32 len); + void *(*reserved[120])(void *); }; ---- @@ -146,6 +147,8 @@ before calling. Returns 0 on success, -1 otherwise. 'attr' returns perf_event_attr, refer . +'object_code' reads object code and returns the number of bytes read. + The perf_dlfilter_al structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index e50d524906d6..ca33fbc5efde 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -245,6 +245,39 @@ static struct perf_event_attr *dlfilter__attr(void *ctx) return &d->evsel->core.attr; } +static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len) +{ + struct dlfilter *d = (struct dlfilter *)ctx; + struct addr_location *al; + struct addr_location a; + struct map *map; + u64 offset; + + if (!d->ctx_valid) + return -1; + + al = get_al(d); + if (!al) + return -1; + + map = al->map; + + if (map && ip >= map->start && ip < map->end && + machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip)) + goto have_map; + + thread__find_map_fb(al->thread, d->sample->cpumode, ip, &a); + if (!a.map) + return -1; + + map = a.map; +have_map: + offset = map->map_ip(map, ip); + if (ip + len >= map->end) + len = map->end - ip; + return dso__data_read_offset(map->dso, d->machine, offset, buf, len); +} + static const struct perf_dlfilter_fns perf_dlfilter_fns = { .resolve_ip = dlfilter__resolve_ip, .resolve_addr = dlfilter__resolve_addr, @@ -253,6 +286,7 @@ static const struct perf_dlfilter_fns perf_dlfilter_fns = { .insn = dlfilter__insn, .srcline = dlfilter__srcline, .attr = dlfilter__attr, + .object_code = dlfilter__object_code, }; static char *find_dlfilter(const char *file) diff --git a/tools/perf/util/perf_dlfilter.h b/tools/perf/util/perf_dlfilter.h index f3fc92fcb3c0..3eef03d661b4 100644 --- a/tools/perf/util/perf_dlfilter.h +++ b/tools/perf/util/perf_dlfilter.h @@ -103,8 +103,10 @@ struct perf_dlfilter_fns { const char *(*srcline)(void *ctx, __u32 *line_number); /* Return perf_event_attr, refer */ struct perf_event_attr *(*attr)(void *ctx); + /* Read object code, return numbers of bytes read */ + __s32 (*object_code)(void *ctx, __u64 ip, void *buf, __u32 len); /* Reserved */ - void *(*reserved[121])(void *); + void *(*reserved[120])(void *); }; /* -- 2.17.1