Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp478715rdb; Tue, 16 Jan 2024 06:27:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgmRU9iPWUD44FklJ2+FJFII/Cws+rdIx2I1fpT2aDMt4gJaelnCQq0kQjEx0DmQEy587C X-Received: by 2002:a05:6214:2427:b0:681:35b:ff6f with SMTP id gy7-20020a056214242700b00681035bff6fmr9643463qvb.29.1705415250239; Tue, 16 Jan 2024 06:27:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705415250; cv=none; d=google.com; s=arc-20160816; b=uXYoNCacEniAdWk81vP2ocv2+ct19C7ua0SbFUAtT+fGLYT7PFOKzQUdRgbzf5lh5F 2ED5dMvLLPbDB4u0/yB0rcvgh6gA6s4YVHExngHhJ8fh7U09oZXMBrE+0vOXXxW2X1fc mOz3QCWdjIH47t9crqJm/2olUy91l7t2AiA640QatwaAtRM1fskbmUc2/h87LablV558 DGsX3ub3rASOQdPDyZTLWvUQRXtLZFNbrGNGXeo+E8dRpoi8HlrUYKaFGZ/iD1Z/AkUy vH4JRrfeJrWSffpH3nxVJMfzBaatWi/3MJCnwIW3lrw4bhu24Zm+UQUTQGMKCwGY9MWd tkrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=P7lcOH0BlnnAFjPZ/dEcrzPLF3VLMEorytvu4RQbaOg=; fh=YzheiIq3Za3ojODLvZMNKRhTny68zHPnnNf/kdKuFjk=; b=jsx0otQrH+tsTbtzS2HMOVbIKwdBNHEx4KXUUDQpn8p00+i80Tgv6BFbofZsIUT0ni OyNpWYuRPesPI/SGY/HC4RgYSQBlJOGkRytpUDIy1dsJeDdF3VEHoASnfbQarROZdMvJ YgRy57IdI7bqT3M81wqbYeuI3QSgGg5E5fpQEoVpAxqJBz32QIqy/YyP/fckYdw6Qjnx Pc6vBZNGzIKVygSpjWeQUo4nR9y7iQBJthWM5TJah+Y+3syY9LZ1KMQ2B3y5iXou+htW fcL2y9HCC4THA/c733EVEBx1gTpIVO51E3WJsB7n6wsBKx8pUaTtzVofrYhdtrsuT0/T XBqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ibm.com header.s=pp1 header.b=BtjL7S50; spf=pass (google.com: domain of linux-kernel+bounces-27463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q13-20020a0ce20d000000b0067ee84abca1si10026657qvl.105.2024.01.16.06.27.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 06:27:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ibm.com header.s=pp1 header.b=BtjL7S50; spf=pass (google.com: domain of linux-kernel+bounces-27463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E11B51C2341A for ; Tue, 16 Jan 2024 14:27:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 234761BF2D; Tue, 16 Jan 2024 14:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="BtjL7S50" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D8861BF22; Tue, 16 Jan 2024 14:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40GDcBnL020915; Tue, 16 Jan 2024 14:26:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=563hyhN6PruHR//yyU44tkKDZlemsjBJokIOuA8XpMA=; b=BtjL7S50WEvXsNpcdzEbQUc1ivUL2sQFXg4WkrZQSI7WSFdhJa8JFvzVPq5ETXNKO7R2 dYvYk6AZjLfuJffgjzqyofmGovNATSgPKCJzhrUNo8sOXUgsWe6Uejxw3L+NPyig9ZJT /7Zi0EM6s6q593SXRtNlQy2kmQCsWGFj0uz3DQkcE1Q/D4SlXbSvxXPTUi9nizn9fJ4B olbsGXHj8W/ch6ArpjHUpjW2GJR6/2xagGA7Dod8/fLwgP/EO/lB/BD+H2+9GI910nZV 3mm6cSMj8Zg/Jb7rgeJ1HFoZ/QG/Sy2HQxY51EphaF/xEqyQFVIhac0htg+ftkjZPU4+ 8Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vntutht8d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 Jan 2024 14:26:57 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40GDcEPP021008; Tue, 16 Jan 2024 14:26:56 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vntutht79-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 Jan 2024 14:26:56 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40GDUd2P011053; Tue, 16 Jan 2024 14:26:55 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm57yf7cf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 Jan 2024 14:26:55 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40GEQrIK8520338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Jan 2024 14:26:53 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E744220040; Tue, 16 Jan 2024 14:26:52 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B08BA20049; Tue, 16 Jan 2024 14:26:52 +0000 (GMT) Received: from [9.152.212.51] (unknown [9.152.212.51]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 16 Jan 2024 14:26:52 +0000 (GMT) Message-ID: Date: Tue, 16 Jan 2024 15:26:52 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] perf: script: use capstone disasm engine to show assembly instructions Content-Language: en-US To: Changbin Du , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org References: <20240116113437.1507537-1-changbin.du@huawei.com> <20240116113437.1507537-3-changbin.du@huawei.com> From: Thomas Richter Organization: IBM In-Reply-To: <20240116113437.1507537-3-changbin.du@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Dmeu7BjrOZpCuXbYqStmWBaO4GpsXjVx X-Proofpoint-ORIG-GUID: XeZRs5Dnq8rPoViFwKzkFA_oD2NSIE7d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-16_08,2024-01-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 malwarescore=0 clxscore=1011 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401160113 On 1/16/24 12:34, Changbin Du wrote: > Currently, the instructions of samples are shown as raw hex strings > which are hard to read. x86 has a special option '--xed' to disassemble > the hex string via intel XED tool. > > Here we use capstone as our disassembler engine to give more friendly > instructions. We select libcapstone because capstone can provide more > insn details. Perf will fallback to raw instructions if libcapstone is > not available. > > The advantages compared to XED tool: > * Support arm, arm64, x86-32, x86_64 (more could be supported), > xed only for x86_64. > * Immediate address operands are shown as symbol+offs. > > Before: > $ sudo perf record --event intel_pt//u -- ls > $ sudo perf script --insn-trace > perf 17423 [000] 423271.557970005: 7f2d95f16217 __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.27.so) insn: 48 3d 01 f0 ff ff > perf 17423 [000] 423271.557970005: 7f2d95f1621d __GI___ioctl+0xd (/lib/x86_64-linux-gnu/libc-2.27.so) insn: 73 01 > perf 17423 [000] 423271.557970338: 7f2d95f1621f __GI___ioctl+0xf (/lib/x86_64-linux-gnu/libc-2.27.so) insn: c3 > perf 17423 [000] 423271.557970338: 5593ad3346d7 perf_evsel__enable_cpu+0x97 (/work/linux/tools/perf/perf) insn: 85 c0 > perf 17423 [000] 423271.557970338: 5593ad3346d9 perf_evsel__enable_cpu+0x99 (/work/linux/tools/perf/perf) insn: 75 12 > perf 17423 [000] 423271.557970338: 5593ad3346db perf_evsel__enable_cpu+0x9b (/work/linux/tools/perf/perf) insn: 49 8b 84 24 a8 00 00 00 > perf 17423 [000] 423271.557970338: 5593ad3346e3 perf_evsel__enable_cpu+0xa3 (/work/linux/tools/perf/perf) insn: 48 8b 50 20 > > After: > $ sudo perf script --insn-trace > perf 17423 [000] 423271.557970005: 7f2d95f16217 __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.27.so) insn: cmpq $-0xfff, %rax > perf 17423 [000] 423271.557970005: 7f2d95f1621d __GI___ioctl+0xd (/lib/x86_64-linux-gnu/libc-2.27.so) insn: jae __GI___ioctl+0x10 > perf 17423 [000] 423271.557970338: 7f2d95f1621f __GI___ioctl+0xf (/lib/x86_64-linux-gnu/libc-2.27.so) insn: retq > perf 17423 [000] 423271.557970338: 5593ad3346d7 perf_evsel__enable_cpu+0x97 (/work/linux/tools/perf/perf) insn: testl %eax, %eax > perf 17423 [000] 423271.557970338: 5593ad3346d9 perf_evsel__enable_cpu+0x99 (/work/linux/tools/perf/perf) insn: jne perf_evsel__enable_cpu+0xad > perf 17423 [000] 423271.557970338: 5593ad3346db perf_evsel__enable_cpu+0x9b (/work/linux/tools/perf/perf) insn: movq 0xa8(%r12), %rax > perf 17423 [000] 423271.557970338: 5593ad3346e3 perf_evsel__enable_cpu+0xa3 (/work/linux/tools/perf/perf) insn: movq 0x20(%rax), %rdx > perf 17423 [000] 423271.557970338: 5593ad3346e7 perf_evsel__enable_cpu+0xa7 (/work/linux/tools/perf/perf) insn: cmpl %edx, %ebx > perf 17423 [000] 423271.557970338: 5593ad3346e9 perf_evsel__enable_cpu+0xa9 (/work/linux/tools/perf/perf) insn: jl perf_evsel__enable_cpu+0x60 > perf 17423 [000] 423271.557970338: 5593ad3346eb perf_evsel__enable_cpu+0xab (/work/linux/tools/perf/perf) insn: xorl %eax, %eax > > Signed-off-by: Changbin Du > --- ... > diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c > new file mode 100644 > index 000000000000..c8d9741748cd > --- /dev/null > +++ b/tools/perf/util/print_insn.c > @@ -0,0 +1,118 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Instruction binary disassembler based on capstone. > + * > + * Author(s): Changbin Du > + */ > +#include "print_insn.h" > +#include > +#include > +#include > +#include "util/debug.h" > +#include "util/symbol.h" > +#include "machine.h" > + > +size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp) > +{ > + int printed = 0; > + > + for (int i = 0; i < sample->insn_len; i++) > + printed += fprintf(fp, "%02x ", (unsigned char)sample->insn[i]); > + return printed; > +} > + > +#ifdef HAVE_LIBCAPSTONE_SUPPORT > +#include > + > +static int capstone_init(struct machine *machine, csh *cs_handle) > +{ > + cs_arch arch; > + cs_mode mode; > + > + if (machine__is(machine, "x86_64")) { > + arch = CS_ARCH_X86; > + mode = CS_MODE_64; > + } else if (machine__normalized_is(machine, "x86")) { > + arch = CS_ARCH_X86; > + mode = CS_MODE_32; > + } else if (machine__normalized_is(machine, "arm64")) { > + arch = CS_ARCH_ARM64; > + mode = CS_MODE_ARM; > + } else if (machine__normalized_is(machine, "arm")) { > + arch = CS_ARCH_ARM; > + mode = CS_MODE_ARM + CS_MODE_V8; > + } else { > + return -1; > + } > ... Did you forgot to support s390? Or was it omitted on intention? Something along the lines will support s390: # git diff util/print_insn.c diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c index c8d9741748cd..c5127910c75b 100644 --- a/tools/perf/util/print_insn.c +++ b/tools/perf/util/print_insn.c @@ -41,6 +41,9 @@ static int capstone_init(struct machine *machine, csh *cs_handle) } else if (machine__normalized_is(machine, "arm")) { arch = CS_ARCH_ARM; mode = CS_MODE_ARM + CS_MODE_V8; + } else if (machine__normalized_is(machine, "s390x")) { + arch = CS_ARCH_SYSZ; + mode = CS_MODE_BIG_ENDIAN; } else { return -1; } # Thanks a lot for including these line in your next version. -- Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany -- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Wolfgang Wendt Geschäftsführung: David Faller Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294