Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1158950imm; Thu, 5 Jul 2018 16:14:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpclsITjqFL03tVhdlozJGEZdjF7/xTNk0o83UxL1O3Xz3SKrAlKm8EeGWyXyoHDCaxjPj29 X-Received: by 2002:a63:2404:: with SMTP id k4-v6mr7184550pgk.191.1530832486454; Thu, 05 Jul 2018 16:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530832486; cv=none; d=google.com; s=arc-20160816; b=bqoj4rWRZktBSNJGKzcvAO7n7etgsI/1VItJzQ/43SF+U7ztRW92OzG/PDwNMVKcbl 2hNwjEZ9h51IhxCVhbunj5iRjWowEEbeo0OLowp56OBJ05c9Ju/b1JnB6p6cIsjKXQt2 mOFrPoMCKfMHSQCScjuGOiUR/g+2XfDtPbbuTaDkOQdfjfVNc3U+A0Ry3bAIASdATRDr V+djElKRGB7StbrjNa3/dKQfPIkJaGKM+rDgStHR8GV1W0Q3tKdLyrOFY/lc43D9UudG WE6YaIN2vwcEV9nVO+ou204eoz36quf+fIYaU6C+9+KAbuUZ3wt57DwpniaA6Cox3wUY /hhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:message-id:subject:cc:to:from:date :arc-authentication-results; bh=5rzne0eXuwouUW8kOxMFNqVbmwUiasyWUQy0RlExH3w=; b=ELlki/GAU0e52sWIA9RUNxxC5UFFes1cluRumAzXvvyVtiepAbb3E837qVfbYk2POi mWXHjLOmjeb9/7XP6ZRLnLyUpvNzXWJDZA/sgpifXIeCsYu07Lrk1KKKStUN3dTfiH4t Ghm+VaWGI0bWmPAdYZLgf+2BlcNS3k4D9oHi7+RpSlte9RFyeapVQPqMxAu85WWWMla8 fwtbN4NJ+3OPguf3Xcg4TScFdfU7uSunGDLQ9Orgs5agRQDwCU7BUBGEdmO8YJXlw+pU lAR47+0ZgWfHaT9kwIDU7xMwMlnTnEOExcsFsalHX4Q3GB9Hsk4guCa1r3ulbG5qx50L 8x7w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17-v6si6264716pgv.383.2018.07.05.16.14.08; Thu, 05 Jul 2018 16:14:46 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753916AbeGEXMU (ORCPT + 99 others); Thu, 5 Jul 2018 19:12:20 -0400 Received: from foss.arm.com ([217.140.101.70]:57194 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753895AbeGEXMS (ORCPT ); Thu, 5 Jul 2018 19:12:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 064EF15B2; Thu, 5 Jul 2018 16:12:18 -0700 (PDT) Received: from dupont (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D0053F5BA; Thu, 5 Jul 2018 16:12:17 -0700 (PDT) Date: Thu, 5 Jul 2018 18:12:16 -0500 From: Kim Phillips To: Arnaldo Carvalho de Melo Cc: Ravi Bangoria , Alexander Shishkin , Hendrik Brueckner , Jiri Olsa , Michael Ellerman , Namhyung Kim , Thomas Richter , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] perf arm64: Generate system call table from asm/unistd.h Message-Id: <20180705181216.0cc737d217d9acda567bd519@arm.com> Organization: Arm X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in V2: - added the "sc" and "nr" local variables, for the sake of completion (Hendrik Brueckner) - Removed the unsafe -u from mktemp, added more X's, and now pipe the C code to the $hostcc command, so we now only require a single temp file that is written by gcc. (Hendrik Brueckner) - used cat << EoHEADER instead of echos for the c file header, to make it more readable (Hendrik Brueckner) - $RM -> rm, to be able to run standalone (Hendrik Brueckner) - moved the rm into the function that makes the file - converted other echos to printf "%s\n" for more portable printing of backslash characters (bash and dash built-in echo commands differ in how many escape backslashes are needed). The initial "%s\n" is needed in order to keep the external printf command from interpreting the %ds. tools/perf/arch/arm64/Makefile | 21 +++++++ .../arch/arm64/entry/syscalls/mksyscalltbl | 61 +++++++++++++++++++ 2 files changed, 82 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..f806542eb3cc --- /dev/null +++ b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl @@ -0,0 +1,61 @@ +#!/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 sc nr last_sc + + create_table_exe=`mktemp /tmp/create-table-XXXXXX` + + { + +cat << _EoHEADER +#include +#include "$input" +int main(int argc, char *argv[]) +{ +_EoHEADER + + while read sc nr; do + printf "%s\n" " printf(\"\\t[%d] = \\\"$sc\\\",\\n\", __NR_$sc);" + last_sc=$sc + done + + printf "%s\n" " printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);" + printf "}\n" + + } | $hostcc -o $create_table_exe -x c - + + $create_table_exe + + rm -f $create_table_exe +} + +create_table() +{ + echo "static const char *syscalltbl_arm64[] = {" + create_table_from_c + echo "};" +} + +$gcc -E -dM -x c $input \ + |sed -ne 's/^#define __NR_//p' \ + |sort -t' ' -k2 -nu \ + |create_table -- 2.17.1