Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp964909lqs; Fri, 14 Jun 2024 10:28:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVCr61QyTTj24lp7O4SvewEiZONG9QWuIApxn2osHmjHpqzw2ms6BtNK57O4HhOtPvDuO9RsvhLmn581cSCx+h1fZk1rSvOqjrBboZVMg== X-Google-Smtp-Source: AGHT+IGn2L2nXTYRaHt7MwTFkvVCldycXMSt9pAjrwuXgabsb5iBeIgCPkF0j04vnulIzR1rR8YJ X-Received: by 2002:a17:906:354b:b0:a6e:7e1f:2eae with SMTP id a640c23a62f3a-a6f60de624dmr226291066b.74.1718386139493; Fri, 14 Jun 2024 10:28:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718386139; cv=pass; d=google.com; s=arc-20160816; b=fzs2LgiU4ZVvsbKBxSGMIfJlzeK6V7Voj9X3O0w37kxb/Kx1gjo85p47RChyJPoWLX KH9bU+Eb5FO8QZehoKa3pcMZbzwxbCTs5UbvQLkwr5j/Wq+m06qHXV4c/uTmvP51esJg ov1O+ledue0n97JdF0ByTVkqa1Ts87qqx6mE9JsdbUxWxL9PUdC25DTLx+bOKlaSSvEg rlC/rkmkCv1ngyDTVy6YPbrv2YWHw6dgf5lwV6RABulKJXbl1Ynu3fgbz3VGVl8J84Ue fjYO6dKjBEOuAefY9a6qWAYF9uDfWjceXrcy22tRky745V9bnYLU73RHD/d+V8ZMRFH4 lg2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sgmw968iiu/aaVOyE76u4X22B6N4sViwogWFvODevxA=; fh=0PTwb2dctJdgxxdpEHLw2xTRIlYCAL+sOxDjzSKR2y4=; b=tazYcA16fyHPWVHM6yl5FbjQHN+WNT6LYuMp56hPr2JrZYqTw+AZM5gWKofAQttG8e spxnZAZcuWc5pQqRTm7NLaxVT3FyfTgoE4WPmVqz9OTLppy60Av52JvPcY0kdjZk0n6b uG29NSjW4Vef6bDt3ktpOH3ydqSfXJ2M6w/0REaNcSUnwDAOn/rl7EWduQo2uMqu4HXl VlIZ4w/JKwfNV/PuyDuzDyseaingFHsUsUdLtTRHd0XnDdorbBtwAlITg5Gi1uduOojS tZps1XHiyalYdzJh6G/aq+XhZAWNcOFb/dpD6olc/zbeqjNxBpzR96/0d91cFsLN4x8Q H9Vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=YVAveC0x; arc=pass (i=1 dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.vnet.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-215345-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215345-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56dd694asi183159166b.281.2024.06.14.10.28.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 10:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215345-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=YVAveC0x; arc=pass (i=1 dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.vnet.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-215345-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215345-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0AE281F23163 for ; Fri, 14 Jun 2024 17:28:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40C5D19E7C0; Fri, 14 Jun 2024 17:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="YVAveC0x" 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 A269F19DF6B; Fri, 14 Jun 2024 17:27:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718386044; cv=none; b=qLTqfByqXmU4YR6QZi+HOhRm9bjAKpmCMQz5t29u8M2FzZTybpysAH/jFmkCD9qJ7HgwDL9ZPP0U1DYam7SW91sr+c7XmUMQ8GNHKiMqR+ZtZfVhl3ZVv0T0p2EN6npK6WN35aTuMnU8+UcULZPp7ldmj/KZDOKyfWlK0HPKmzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718386044; c=relaxed/simple; bh=Hh9jNOotp/2Xzw0n8LTsU5yrIJBN/+ufOLXbAU3jrHA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MhuZasUazBwGTXh6Sl6PQDzpPzXdnRgHmpJg5GWF1M7ERfp9KO+Df6GRp97YUHWqJLJkOO4w8agSHJClsCnUQsg8U68xacwoiAxn0euXsvnlwxF1arYyOdXIfBQZ+crlRbxkYwOd2tRpF63VuKFcCjmtYLKSlW0ksRz6jQR9YsI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.vnet.ibm.com; spf=none smtp.mailfrom=linux.vnet.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=YVAveC0x; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.vnet.ibm.com Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45EHKUlU001012; Fri, 14 Jun 2024 17:27:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=sgmw968iiu/aa VOyE76u4X22B6N4sViwogWFvODevxA=; b=YVAveC0xyParOFd/Nt/I6adfaacVX 0jkQ7i2sIE4ohkycCXmdJOML5bUVGbwqgWdpR/UnpwAYgqZEsckuV8Yh0oHV28G0 jPt5SA7jYfuVxBVVIZwNlq9n/SgDMCpwpuvYStFsgngCtoWOUdkTdHQLjW2TSqyU fDhQlIlXGFZHhKnD4X8FnZvgUfAe+7Yfhnw8JU4VSeVxcVM+6ZJqMDKksiG7nVnq ZYy+isqGcwMbyc18IImSxoTkrPOwBCznBr8K/wUTRWf6LsNWgEUqj28PqhrWRKf8 YAdPRiLvuH+o4Uc18n+W3hCe9XiEdPGxIOrtnaUpcWhFSbkH9Hh1HqyNw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yrnwa0svb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jun 2024 17:27:13 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45EHRCYp011167; Fri, 14 Jun 2024 17:27:12 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yrnwa0sv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jun 2024 17:27:12 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45EGEn3f008879; Fri, 14 Jun 2024 17:27:11 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yn4b43075-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jun 2024 17:27:11 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45EHR6AI54723044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Jun 2024 17:27:08 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3729F20040; Fri, 14 Jun 2024 17:27:06 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AF5620043; Fri, 14 Jun 2024 17:27:03 +0000 (GMT) Received: from localhost.localdomain (unknown [9.43.82.18]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Jun 2024 17:27:03 +0000 (GMT) From: Athira Rajeev To: acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com, irogers@google.com, namhyung@kernel.org, segher@kernel.crashing.org, christophe.leroy@csgroup.eu Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, akanksha@linux.ibm.com, maddy@linux.ibm.com, atrajeev@linux.vnet.ibm.com, kjain@linux.ibm.com, disgoel@linux.vnet.ibm.com Subject: [V4 08/16] tools/perf: Add some of the arithmetic instructions to support instruction tracking in powerpc Date: Fri, 14 Jun 2024 22:56:23 +0530 Message-Id: <20240614172631.56803-9-atrajeev@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20240614172631.56803-1-atrajeev@linux.vnet.ibm.com> References: <20240614172631.56803-1-atrajeev@linux.vnet.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KEU4v7geWR34UdhmwZrkefTHiIwDEMYW X-Proofpoint-ORIG-GUID: jpsCmYTpD9-1Ds_BTjqrpGw5oPTm8E_3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-14_15,2024-06-14_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406140119 Data type profiling has concept of instruction tracking. Example sequence in powerpc: ld r10,264(r3) mr r31,r3 < ld r9,312(r31) or differently lwz r10,264(r3) add r31, r3, RB lwz r9, 0(r31) If a sample is hit at "lwz r9, 0(r31)", data type of r31 depends on previous instruction sequence here. So to track the previous instructions, patch adds changes to identify some of the arithmetic instructions which are having opcode as 31. Since memory instructions also has cases with opcode 31, use the bits 22:30 to filter the arithmetic instructions here. Also there are instructions with just two operands like addme, addze. Patch adds new instructions ops "arithmetic_ops" to handle this Signed-off-by: Athira Rajeev --- .../perf/arch/powerpc/annotate/instructions.c | 49 ++++++++++++++++++ tools/perf/util/disasm.c | 51 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/arch/powerpc/annotate/instructions.c index 4ee959a24738..bec8ab0ee18d 100644 --- a/tools/perf/arch/powerpc/annotate/instructions.c +++ b/tools/perf/arch/powerpc/annotate/instructions.c @@ -51,6 +51,7 @@ static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, con #define PPC_OP(op) (((op) >> 26) & 0x3F) #define PPC_21_30(R) (((R) >> 1) & 0x3ff) +#define PPC_22_30(R) (((R) >> 1) & 0x1ff) struct insn_offset { const char *name; @@ -134,6 +135,44 @@ static struct insn_offset ins_array[] = { { .name = "OP_31_XOP_STFIWX", .value = 983, }, }; +/* + * Arithmetic instructions which are having opcode as 31. + * These instructions are tracked to save the register state + * changes. Example: + * + * lwz r10,264(r3) + * add r31, r3, r3 + * lwz r9, 0(r31) + * + * Here instruction tracking needs to identify the "add" + * instruction and save data type of r3 to r31. If a sample + * is hit at next "lwz r9, 0(r31)", by this instruction tracking, + * data type of r31 can be resolved. + */ +static struct insn_offset arithmetic_ins_op_31[] = { + { .name = "SUB_CARRY_XO_FORM", .value = 8, }, + { .name = "MUL_HDW_XO_FORM1", .value = 9, }, + { .name = "ADD_CARRY_XO_FORM", .value = 10, }, + { .name = "MUL_HW_XO_FORM1", .value = 11, }, + { .name = "SUB_XO_FORM", .value = 40, }, + { .name = "MUL_HDW_XO_FORM", .value = 73, }, + { .name = "MUL_HW_XO_FORM", .value = 75, }, + { .name = "SUB_EXT_XO_FORM", .value = 136, }, + { .name = "ADD_EXT_XO_FORM", .value = 138, }, + { .name = "SUB_ZERO_EXT_XO_FORM", .value = 200, }, + { .name = "ADD_ZERO_EXT_XO_FORM", .value = 202, }, + { .name = "SUB_EXT_XO_FORM2", .value = 232, }, + { .name = "MUL_DW_XO_FORM", .value = 233, }, + { .name = "ADD_EXT_XO_FORM2", .value = 234, }, + { .name = "MUL_W_XO_FORM", .value = 235, }, + { .name = "ADD_XO_FORM", .value = 266, }, + { .name = "DIV_DW_XO_FORM1", .value = 457, }, + { .name = "DIV_W_XO_FORM1", .value = 459, }, + { .name = "DIV_DW_XO_FORM", .value = 489, }, + { .name = "DIV_W_XO_FORM", .value = 491, }, +}; + + static int cmp_offset(const void *a, const void *b) { const struct insn_offset *val1 = a; @@ -163,6 +202,16 @@ static struct ins_ops *check_ppc_insn(int raw_insn) ret = bsearch(&mem_insns_31_opcode, ins_array, ARRAY_SIZE(ins_array), sizeof(ins_array[0]), cmp_offset); if (ret != NULL) return &load_store_ops; + else { + mem_insns_31_opcode.value = PPC_22_30(raw_insn); + ret = bsearch(&mem_insns_31_opcode, arithmetic_ins_op_31, ARRAY_SIZE(arithmetic_ins_op_31), + sizeof(arithmetic_ins_op_31[0]), cmp_offset); + if (ret != NULL) + return &arithmetic_ops; + /* Bits 21 to 30 has value 444 for "mr" insn ie, OR X form */ + if (PPC_21_30(raw_insn) == 444) + return &arithmetic_ops; + } } return NULL; diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 4e605d082a02..2191a3ec6517 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -38,6 +38,7 @@ static struct ins_ops nop_ops; static struct ins_ops lock_ops; static struct ins_ops ret_ops; static struct ins_ops load_store_ops; +static struct ins_ops arithmetic_ops; static int jump__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); @@ -677,6 +678,56 @@ static struct ins_ops mov_ops = { .scnprintf = mov__scnprintf, }; +#define PPC_22_30(R) (((R) >> 1) & 0x1ff) +#define MINUS_EXT_XO_FORM 234 +#define SUB_EXT_XO_FORM 232 +#define ADD_ZERO_EXT_XO_FORM 202 +#define SUB_ZERO_EXT_XO_FORM 200 + +static int arithmetic__scnprintf(struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) +{ + return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, + ops->raw); +} + +/* + * Sets the fields: multi_regs and "mem_ref". + * "mem_ref" is set for ops->source which is later used to + * fill the objdump->memory_ref-char field. This ops is currently + * used by powerpc and since binary instruction code is used to + * extract opcode, regs and offset, no other parsing is needed here. + * + * Dont set multi regs for 4 cases since it has only one operand + * for source: + * - Add to Minus One Extended XO-form ( Ex: addme, addmeo ) + * - Subtract From Minus One Extended XO-form ( Ex: subfme ) + * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) + * - Subtract From Zero Extended XO-form ( Ex: subfze ) + */ +static int arithmetic__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, + struct map_symbol *ms __maybe_unused, struct disasm_line *dl) +{ + int opcode = PPC_OP(dl->raw.raw_insn); + + ops->source.mem_ref = false; + if (opcode == 31) { + if ((opcode != MINUS_EXT_XO_FORM) && (opcode != SUB_EXT_XO_FORM) \ + && (opcode != ADD_ZERO_EXT_XO_FORM) && (opcode != SUB_ZERO_EXT_XO_FORM)) + ops->source.multi_regs = true; + } + + ops->target.mem_ref = false; + ops->target.multi_regs = false; + + return 0; +} + +static struct ins_ops arithmetic_ops = { + .parse = arithmetic__parse, + .scnprintf = arithmetic__scnprintf, +}; + static int load_store__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { -- 2.43.0