Received: by 10.192.165.148 with SMTP id m20csp3407459imm; Mon, 7 May 2018 11:45:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrLIOG8DWCXCQOSroh+LpUyJ16npZh/xoEZw7gUIVrIg0TCtlhvhOPGlzkexJXWpXpW1rXy X-Received: by 2002:aca:4e43:: with SMTP id c64-v6mr22981901oib.343.1525718713299; Mon, 07 May 2018 11:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525718713; cv=none; d=google.com; s=arc-20160816; b=kmMlPhUMVNzTzWOssIX362/g2yVEO68nwnnjWBfPlw0dU+eHVEdyf8ueoAyqCGneIW wsa2N8DkGVTn34xMT8NoLoXJOPx3cMmLhfyD41L62ZSNXwTOV6cF3eTdrqO1dG7OtmHq ctZTIaU1xj1S1iYy2pIVL87KfvM39mHj/UTX2I7qPNwuoAa9MUrokVek+4ruobM2JNsG iJeshotgoJx+5nfNtUiCFR1ThDNSC3uSQdGoRviJ2zK6/aWC3cLIPYyHg6/CjzrzG1xp 2gKbIptFdnlB+J2KFloCrDInXANt8KrPv38QAZ/4S4ZH8FxtKl/ph+ZsSwugtARj03UD oOYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Uu7Tf7qhPJm/tMM+l2yJBTSUSyaBwxYv6xkgJuj0Es8=; b=fPHdWZxt3Fcrs0GClLP3hnd+CNhJR4VbSI2YVOUZjV/9e/jvf2HOzj23kGfHZXwKJW jVGniP9FDhrnemOEbqbbNK8k2ZZ2JWQmSfUWEF5feG6lmg9m+B/bIjMNch2cTPf5KwTZ bHUXWfYDCa8HTwfKd633VJFs1PJDSv0wqdITAhoGYUMnwlCSMDnjqs6rXB4JjLE1Nr8X 3u5iRMx1C3kBBFm1mPuSRoDMWQM2t4DLq8RIxIJGiknZSyWgpoogqGTNhSdP0z2hAKIV /wsVBCq7r9MI5+Qda74wf4boMYuvh54wEKgtnUarqoVTd3lJQdDrY3y0mVQvlFOSzNib cuzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@akamai.com header.s=jan2016.eng header.b=XPm8gJG/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7-v6si4089584otc.44.2018.05.07.11.44.59; Mon, 07 May 2018 11:45:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@akamai.com header.s=jan2016.eng header.b=XPm8gJG/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752749AbeEGSoi (ORCPT + 99 others); Mon, 7 May 2018 14:44:38 -0400 Received: from mx0a-00190b01.pphosted.com ([67.231.149.131]:47272 "EHLO mx0a-00190b01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752352AbeEGSog (ORCPT ); Mon, 7 May 2018 14:44:36 -0400 X-Greylist: delayed 1165 seconds by postgrey-1.27 at vger.kernel.org; Mon, 07 May 2018 14:44:35 EDT Received: from pps.filterd (m0050095.ppops.net [127.0.0.1]) by m0050095.ppops.net-00190b01. (8.16.0.22/8.16.0.22) with SMTP id w47IHgVN006209; Mon, 7 May 2018 19:24:20 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h=from : to : cc : subject : date : message-id; s=jan2016.eng; bh=Uu7Tf7qhPJm/tMM+l2yJBTSUSyaBwxYv6xkgJuj0Es8=; b=XPm8gJG/FZMd37nKwMLvAfaM44urA5OJ0lo+UNlOiU0ymsufKu/sATd54AxbeM1pYWYx zDH0HqpGu0LQlJnV/mZhjZEvuSB65nVjYhD2tEpshp7f8o8WM47QCfydTvP5vMDOZMah Bs6eqiTCR3qKXOOVKrtai3W1ztpMu2ruSSmOQx/IHo0zNizTJYtnuw3Hu5rH+kN158PE hDVhstNQQuX+RqzxsWaonocUrXZKEqbI6/k5rbGOVc6xptmGm3QGMY7o2D1s9Cnm8eUr PFGadsxonFAACJQA+mlBBi8pCCulrVW9QSv1DoC4tTeU056uK1pOLZXj7VDt0ZtB3G6G yQ== Received: from prod-mail-ppoint2 (prod-mail-ppoint2.akamai.com [184.51.33.19]) by m0050095.ppops.net-00190b01. with ESMTP id 2hs4535rpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 May 2018 19:24:20 +0100 Received: from pps.filterd (prod-mail-ppoint2.akamai.com [127.0.0.1]) by prod-mail-ppoint2.akamai.com (8.16.0.21/8.16.0.21) with SMTP id w47IGtPV024303; Mon, 7 May 2018 14:24:19 -0400 Received: from prod-mail-relay11.akamai.com ([172.27.118.250]) by prod-mail-ppoint2.akamai.com with ESMTP id 2hs7xv95u9-1; Mon, 07 May 2018 14:24:18 -0400 Received: from bos-lpwg1 (bos-lpwg1.kendall.corp.akamai.com [172.28.12.251]) by prod-mail-relay11.akamai.com (Postfix) with ESMTP id EC2431FC0C; Mon, 7 May 2018 18:24:18 +0000 (GMT) Received: from johunt by bos-lpwg1 with local (Exim 4.82) (envelope-from ) id 1fFko6-0005az-Ry; Mon, 07 May 2018 14:24:18 -0400 From: Josh Hunt To: mingo@redhat.com, acme@kernel.org Cc: peterz@infradead.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, wangnan0@huawei.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, ak@linux.intel.com, eranian@google.com, Josh Hunt Subject: [PATCH v2] perf tools: allow map files to specify DSO Date: Mon, 7 May 2018 14:24:16 -0400 Message-Id: <1525717456-21475-1-git-send-email-johunt@akamai.com> X-Mailer: git-send-email 1.9.1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-07_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805070183 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-07_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805070183 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the ability to specify a DSO in the /tmp/perf-.map file. The DSO should be the first line in the file and readable by the running user. If a valid DSO is found all other contents of the file will be ignored. This allows things like callchain unwinding with DWARF to work. Suggested-by: Wang Nan Signed-off-by: Josh Hunt --- We have an application which uses huge pages for its text section, but still needs the ability to do callchain unwinding with DWARF. We use the perf-.map file setup to do symbol resolution and that works great, but callchain unwinding fails. A few months ago I mentioned this to Wang Nan and he suggested a way around this problem could be to specify the path of the DSO in the map file. The attached patch is my initial hack at this. Running with this patch I can now get full callchain unwinding with DWARF. FWIW LBR + map file works with callchains, but unfortunately there are some cases where we still need DWARF. I submitted an RFC as an earlier draft: https://lkml.org/lkml/2018/4/24/1070 v2: 1. Rebase RFC patch to git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core 2. Update jit-interface.txt as per Arnaldo's request tools/perf/Documentation/jit-interface.txt | 8 +++++--- tools/perf/util/map.c | 32 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/tools/perf/Documentation/jit-interface.txt b/tools/perf/Documentation/jit-interface.txt index a8656f564915..8a25b979802f 100644 --- a/tools/perf/Documentation/jit-interface.txt +++ b/tools/perf/Documentation/jit-interface.txt @@ -3,13 +3,15 @@ by a JIT. The JIT has to write a /tmp/perf-%d.map (%d = pid of process) file -This is a text file. +This is a text file and can have one of the following formats: -Each line has the following format, fields separated with spaces: +1) Each line has the following format, fields separated with spaces: START SIZE symbolname START and SIZE are hex numbers without 0x. symbolname is the rest of the line, so it could contain special characters. -The ownership of the file has to match the process. +2) A single line with the full pathname of the DSO to use. + +For both formats, the ownership of the file has to match the process. diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index c8fe836e4c3c..da3050b18e34 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -139,6 +139,31 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso) refcount_set(&map->refcnt, 1); } +static bool replace_anon(char *mapfilename) +{ + FILE *file = NULL; + bool ret = false; + + file = fopen(mapfilename, "r"); + if (file != NULL) { + char *line = NULL; + size_t line_len, linesz=0; + + line_len = getline(&line, &linesz, file); + if (line_len > 0) { + line[line_len-1] = '\0'; /* null terminate */ + if (!access(line, R_OK)) { + strlcpy(mapfilename, line, line_len); + ret = true; + } + } + free(line); + fclose(file); + } + + return ret; +} + struct map *map__new(struct machine *machine, u64 start, u64 len, u64 pgoff, u32 d_maj, u32 d_min, u64 ino, u64 ino_gen, u32 prot, u32 flags, char *filename, @@ -170,6 +195,13 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", nsi->pid); filename = newfilename; + /* + * Check to see if map file references DSO to use, if so, use it. + */ + if (anon && replace_anon(newfilename)) { + anon = 0; + filename = newfilename; + } } if (android) { -- 1.9.1