From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030393AbcGKLGZ (ORCPT ); Mon, 11 Jul 2016 07:06:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:62790 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758106AbcGKLGW (ORCPT ); Mon, 11 Jul 2016 07:06:22 -0400 X-IBM-Helo: d01dlp03.pok.ibm.com X-IBM-MailFrom: gongss@linux.vnet.ibm.com Subject: Re: [PATCH] [RFC V1]s390/perf: fix 'start' address of module's map To: Jiri Olsa References: <1467856176-8712-1-git-send-email-gongss@linux.vnet.ibm.com> <20160708152133.GK31763@krava> Cc: acme@kernel.org, jolsa@kernel.org, dsahern@gmail.com, linux-kernel@vger.kernel.org From: Songshan Gong Date: Mon, 11 Jul 2016 19:06:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160708152133.GK31763@krava> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16071111-0044-0000-0000-0000009ED58A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16071111-0045-0000-0000-000004B4F09F Message-Id: <657df05c-c0d9-7490-d374-f2fa4cdd7344@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-11_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607110114 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 7/8/2016 11:21 PM, Jiri Olsa 写道: > On Thu, Jul 07, 2016 at 09:49:36AM +0800, Song Shan Gong wrote: > > SNIP > >> + char *line = NULL; >> + size_t n; >> + char *sep; >> + >> + module_name[len - 1] = '\0'; >> + module_name += 1; >> + snprintf(path, PATH_MAX, "%s/sys/module/%s/sections/.text", >> + machine->root_dir, module_name); >> + file = fopen(path, "r"); >> + if (file == NULL) >> + return -1; >> + >> + len = getline(&line, &n, file); >> + if (len < 0) { >> + err = -1; >> + goto out; >> + } >> + line[--len] = '\0'; /* \n */ >> + sep = strrchr(line, 'x'); >> + if (sep == NULL) { >> + err = -1; >> + goto out; >> + } >> + hex2u64(sep + 1, &text_start); > > we have following functions in tools/lib/api/fs to read > single number from file, which I assume you do above: > > int sysfs__read_int(const char *entry, int *value); > int sysfs__read_ull(const char *entry, unsigned long long *value); > > please check if you could use some of them, > we could add some more generic one if needed It seems infeasible. Each value in /sys/module/[module name]/sections/.text is a string like "0x000003ff8130078\n". But the core function 'strtoull(line, NULL, 10)' in sysfs__read_ull is based on decimal. Maybe you can introduce a new argument indicating the value is based on hex or decimal, or binary? > thanks, > jirka > -- SongShan Gong