Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp503391imm; Wed, 4 Jul 2018 00:38:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcaBPBTdZt4mO6UCa4PW+VFr9ky8Ky2nbC2QNGd7oh6b7t9Ii2YPlO2pK7PFpnf+Sbrv7Sz X-Received: by 2002:a17:902:9693:: with SMTP id n19-v6mr1015160plp.212.1530689897169; Wed, 04 Jul 2018 00:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530689897; cv=none; d=google.com; s=arc-20160816; b=jXy3fzJL1whvxXyP8w5dCz1LTO1tdk7bxZvmXZeeRfebN1sXh5E2hKC8Uj8rMVu1bf XvRkPdg22V8mV/fWX8pBVND+3XG/oBkOgJ5IH5Q+uOJkYJrY+aM61DoFdzsH8CdaqTGf wIUZrI7ysaqn29zm2ArIsr7Gm4erzkj39h68gZdL1Jt9kh05Qu34uQMwuWB3p5HpkeHo 9py1jpjOMAX+T+mEhsq/amUDz8BLm+hPfkCNsaUw2/IIl37wjlI7NFwV2/z89ChBbsV+ TKpgwpQeU6CChZJDaDJ8EFU2GbGPu+A+Md+TxaQEKl9gKIBt+4Qich5FqTRwa9QwaCg0 rxAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :arc-authentication-results; bh=u/Dmywei7tB2tReYxctbQbK992eEgzRMUhfYF1pDdbM=; b=OIrP41BKIKHUVVs3I0bXwPjYQieHWbyErfypfL0kBfPYcoDEMpsW2ldDJA4iJO998w OaA0mhKVL0ceJYU29hke72zf/qImiWcrEUgnBtiWScoLQe2RwQMutgoJ7neGn+tecjz2 68hOyeARojqihfveeKkCeiPW+wbeBkZ62nBDe2Q+4/9aCbAycAC/CDTZO5lpmPFtUFIP 6BvosPpq69MGbCoMSFy1ClsUQdr5zt0xWKbRTwnHOljFGdIpmhR+RoIjs3PFHOAK0w3N JQB1BXxBXF8buLTS/1nB7um+PAsE/FzXNYLZuEVYMRzIsyfYOK9KmJK7zCy07ffgV61G QJnQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f24-v6si2802517pgh.287.2018.07.04.00.38.02; Wed, 04 Jul 2018 00:38:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933616AbeGDHhE (ORCPT + 99 others); Wed, 4 Jul 2018 03:37:04 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32986 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932188AbeGDHhC (ORCPT ); Wed, 4 Jul 2018 03:37:02 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w647XkPR066215 for ; Wed, 4 Jul 2018 03:37:02 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k0s68j5b6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 04 Jul 2018 03:37:01 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Jul 2018 08:36:59 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 4 Jul 2018 08:36:54 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w647as8h31522996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 4 Jul 2018 07:36:54 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F22752054; Wed, 4 Jul 2018 10:37:19 +0100 (BST) Received: from lynx.boeblingen.de.ibm.com (unknown [9.152.212.204]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 1C21E52052; Wed, 4 Jul 2018 10:37:19 +0100 (BST) Received: from brueckh by lynx.boeblingen.de.ibm.com with local (Exim 4.90_1) (envelope-from ) id 1facLN-0002wE-Jg; Wed, 04 Jul 2018 09:36:53 +0200 Date: Wed, 4 Jul 2018 09:36:53 +0200 From: Hendrik Brueckner To: Kim Phillips Cc: Arnaldo Carvalho de Melo , Ravi Bangoria , Alexander Shishkin , Hendrik Brueckner , Jiri Olsa , Michael Ellerman , Namhyung Kim , Thomas Richter , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] perf arm64: Generate system call table from asm/unistd.h References: <20180703123228.eca1b003e51d5ced01317575@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180703123228.eca1b003e51d5ced01317575@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18070407-0012-0000-0000-0000028691ED X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18070407-0013-0000-0000-000020B8128E Message-Id: <20180704073653.GA4680@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-04_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807040090 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kim, On Tue, Jul 03, 2018 at 12:32:28PM -0500, Kim Phillips wrote: > This should speed up accessing new system calls introduced with the > kernel rather than waiting for libaudit updates to include them. > > Using the existing other arch scripts resulted in this error: > > tools/perf/arch/arm64/entry/syscalls//mksyscalltbl: 25: printf: __NR3264_ftruncate: expected numeric value > > because, unlike other arches, asm-generic's unistd.h does things like: > > #define __NR_ftruncate __NR3264_ftruncate > > Turning the scripts printf's %d into a %s resulted in this in the > generated syscalls.c file: > > static const char *syscalltbl_arm64[] = { > [__NR3264_ftruncate] = "ftruncate", > > So we use the host C compiler to fold the macros, and print them out > from within a temporary C program, in order to get the correct output: > > static const char *syscalltbl_arm64[] = { > [46] = "ftruncate", > > Cc: Ravi Bangoria > Cc: Alexander Shishkin > Cc: Hendrik Brueckner > Cc: Jiri Olsa > Cc: Michael Ellerman > Cc: Namhyung Kim > Cc: Thomas Richter > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Arnaldo Carvalho de Melo > Signed-off-by: Kim Phillips > --- > tools/perf/arch/arm64/Makefile | 21 ++++++++ > .../arch/arm64/entry/syscalls/mksyscalltbl | 54 +++++++++++++++++++ > 2 files changed, 75 insertions(+) > create mode 100755 tools/perf/arch/arm64/entry/syscalls/mksyscalltbl > > diff --git a/tools/perf/arch/arm64/Makefile b/tools/perf/arch/arm64/Makefile > index 91de4860faad..85fdf4949db3 100644 > --- a/tools/perf/arch/arm64/Makefile > +++ b/tools/perf/arch/arm64/Makefile > @@ -4,3 +4,24 @@ PERF_HAVE_DWARF_REGS := 1 > endif > PERF_HAVE_JITDUMP := 1 > PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1 > + > +# > +# Syscall table generation for perf > +# > + > +out := $(OUTPUT)arch/arm64/include/generated/asm > +header := $(out)/syscalls.c > +sysdef := $(srctree)/tools/arch/arm64/include/uapi/asm/unistd.h > +sysprf := $(srctree)/tools/perf/arch/arm64/entry/syscalls/ > +systbl := $(sysprf)/mksyscalltbl > + > +# Create output directory if not already present > +_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)') > + > +$(header): $(sysdef) $(systbl) > + $(Q)$(SHELL) '$(systbl)' '$(CC)' '$(HOSTCC)' $(sysdef) > $@ > + > +clean:: > + $(call QUIET_CLEAN, arm64) $(RM) $(header) > + > +archheaders: $(header) > diff --git a/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl > new file mode 100755 > index 000000000000..1148302b7194 > --- /dev/null > +++ b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl > @@ -0,0 +1,54 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Generate system call table for perf. Derived from > +# powerpc script. > +# > +# Copyright IBM Corp. 2017 > +# Author(s): Hendrik Brueckner > +# Changed by: Ravi Bangoria > +# Changed by: Kim Phillips > + > +gcc=$1 > +hostcc=$2 > +input=$3 > + > +if ! test -r $input; then > + echo "Could not read input file" >&2 > + exit 1 > +fi > + > +create_table_from_c() > +{ > + local last_sc For the sake of completion, also add the "sc" and "nr" local variables. > + > + create_table_base=`mktemp -u /tmp/create-table-XXX` - The -u is considered to be unsafe. But from below, I think you require this for the .c/.x file. Alternatively, you could create the file (and prefer using more X for the template) and append to it. Or pipe the C code to the $hostcc command, e.g., $hostcc -o $create_table_base -x c - which would require a single temp file that would be overwritten by gcc. > + echo "#include " > ${create_table_base}.c > + echo "#include \"$input\"" >> ${create_table_base}.c > + > + echo "int main(int argc, char *argv[])" >> ${create_table_base}.c > + echo "{" >> ${create_table_base}.c As alternative to these echos, use cat >> ${create_table_base}.c <<-EoHEADER #include #include "$input" int main(int argc, char *argv[]) { EoHeader which is at least for larger portions a bit more readable. > + while read sc nr; do > + echo " printf(\"\\\t[%d] = \\\"$sc\\\",\\\n\", __NR_$sc);" >> ${create_table_base}.c > + last_sc=$sc > + done > + echo " printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\\n\", __NR_$last_sc);" >> ${create_table_base}.c > + echo "}" >> ${create_table_base}.c > + > + $hostcc -o ${create_table_base}.x ${create_table_base}.c > + ${create_table_base}.x > +} > + > +create_table() > +{ > + echo "static const char *syscalltbl_arm64[] = {" > + create_table_from_c > + echo '};' > + > + $RM -f ${create_table_base}.[cx] The $RM is obtained from the (make) environment. I would prefer using rm here to be able to run as standalone. > +} > + > +$gcc -E -dM -x c $input \ > + |sed -ne 's/^#define __NR_//p' \ > + |sort -t' ' -k2 -nu \ > + |create_table > -- > 2.17.1 > Kind regards, Hendrik -- Hendrik Brueckner brueckner@linux.ibm.com | IBM Deutschland Research & Development GmbH Linux on z Systems Development | Schoenaicher Str. 220, 71032 Boeblingen IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martina Koederitz Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294