From nobody Fri Dec 19 07:17:18 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 A197B77F1B; Mon, 1 Jul 2024 04:35:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719808516; cv=none; b=C3EPDTXlicJUqVAlrHihTp9EtcSJdTf1McXH4oPW6BbmvlfBrvseOAZ7Ux9xPu0640t7H8UpTE6nEHgPIKGpDr8C2LyvNU2RnZ17FzszL1NQYUIemOCiA3lBVvWT5zef2Isb+lYVZlXyHcTT4aeYioUHEQnIj3wwyKk3s7xYz0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719808516; c=relaxed/simple; bh=WDWJYBhqRYvbHxqZr0+1AOnKI0o5xz2Qm5ydLttdc84=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iLY1x4LjrgzCkVGS+QqdzjmHSF3CdN0cuJrDYiusvzAhagGkGt1WupQiYGInB13D9uU9PbIojnCFHK91u+KwFvUeR6wPhWWltBfregfpbPKzH87se8cHWGtVoUxvyI2gulwlcbayVRckIzFYGQ/rK6UTJ3L59L+sDO5EXH+fXn8= 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=lvXZX/lU; arc=none smtp.client-ip=148.163.158.5 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="lvXZX/lU" Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4614T4kW008539; Mon, 1 Jul 2024 04:35:08 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=6f8S5mIWenR1o QYGAOKmK3S1hZlCFEiLtwHpc90HZ+g=; b=lvXZX/lUNhsIh0THOFZio2o6ssUqS 7rFlnjfmD7vl9VCkeNL4WXWLj1ykJ9sN8b1fdsRzvJEqJYxFfo23HyzXr66kfIYq i0p44RSpV554M0Z3VNgRHIztYk2hzIN8A1gC6Py0eBDlAF9VXByVm1nSaO2dPBAN m8R5WmVmuChVYoTp0BuXIBmkVFs/pkFX0kGaRgcHJKX85KAA6VN8gqzEpW9Elkkl Fcsb2YCiJnivPflaAmSKD6cTRr7uvdxaZoU4McqYV+fVNZyq0hyaklYcK1XpKyOP Wd4bbRlZ8/GvcIZu8gNpuK56WOjQkVTqnXgD4k4VFrFNFCywWlcyY+lwg== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 403nfgr0kr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jul 2024 04:35:08 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4614DCik026417; Mon, 1 Jul 2024 04:35:07 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 402wkpnb4v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jul 2024 04:35:07 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4614Z2Ec18415882 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Jul 2024 04:35:04 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E16B92004D; Mon, 1 Jul 2024 04:35:01 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 161AF20040; Mon, 1 Jul 2024 04:34:59 +0000 (GMT) Received: from localhost.localdomain (unknown [9.43.21.126]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 1 Jul 2024 04:34:58 +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: [PATCH V5 08/17] tools/perf: Add support to identify memory instructions of opcode 31 in powerpc Date: Mon, 1 Jul 2024 10:04:21 +0530 Message-Id: <20240701043430.66666-9-atrajeev@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20240701043430.66666-1-atrajeev@linux.vnet.ibm.com> References: <20240701043430.66666-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 7jB9egVIJ8FRvI1ilOsro3pyB5uvR8Co X-Proofpoint-GUID: 7jB9egVIJ8FRvI1ilOsro3pyB5uvR8Co 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-07-01_03,2024-06-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=961 mlxscore=0 impostorscore=0 phishscore=0 adultscore=0 spamscore=0 malwarescore=0 clxscore=1015 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407010030 Content-Type: text/plain; charset="utf-8" There are memory instructions in powerpc with opcode as 31. Example: "ldx RT,RA,RB" , Its X form is as below: ______________________________________ | 31 | RT | RA | RB | 21 |/| -------------------------------------- 0 6 11 16 21 30 31 The opcode for "ldx" is 31. There are other instructions also with opcode 31 which are memory insn like ldux, stbx, lwzx, lhaux But all instructions with opcode 31 are not memory. Example is add instruction: "add RT,RA,RB" The value in bit 21-30 [ 21 for ldx ] is different for these instructions. Patch uses this value to assign instruction ops for these cases. The naming convention and value to identify these are picked from defines in "arch/powerpc/include/asm/ppc-opcode.h" Signed-off-by: Athira Rajeev --- .../perf/arch/powerpc/annotate/instructions.c | 107 +++++++++++++++++- tools/perf/util/disasm.c | 3 + 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/a= rch/powerpc/annotate/instructions.c index b084423d8477..1ffb64c6bd0d 100644 --- a/tools/perf/arch/powerpc/annotate/instructions.c +++ b/tools/perf/arch/powerpc/annotate/instructions.c @@ -49,18 +49,121 @@ static struct ins_ops *powerpc__associate_instruction_= ops(struct arch *arch, con return ops; } =20 -#define PPC_OP(op) (((op) >> 26) & 0x3F) +#define PPC_OP(op) (((op) >> 26) & 0x3F) +#define PPC_21_30(R) (((R) >> 1) & 0x3ff) + +struct insn_offset { + const char *name; + int value; +}; + +/* + * There are memory instructions with opcode 31 which are + * of X Form, Example: + * ldx RT,RA,RB + * ______________________________________ + * | 31 | RT | RA | RB | 21 |/| + * -------------------------------------- + * 0 6 11 16 21 30 31 + * + * But all instructions with opcode 31 are not memory. + * Example: add RT,RA,RB + * + * Use bits 21 to 30 to check memory insns with 31 as opcode. + * In ins_array below, for ldx instruction: + * name =3D> OP_31_XOP_LDX + * value =3D> 21 + */ + +static struct insn_offset ins_array[] =3D { + { .name =3D "OP_31_XOP_LXSIWZX", .value =3D 12, }, + { .name =3D "OP_31_XOP_LWARX", .value =3D 20, }, + { .name =3D "OP_31_XOP_LDX", .value =3D 21, }, + { .name =3D "OP_31_XOP_LWZX", .value =3D 23, }, + { .name =3D "OP_31_XOP_LDUX", .value =3D 53, }, + { .name =3D "OP_31_XOP_LWZUX", .value =3D 55, }, + { .name =3D "OP_31_XOP_LXSIWAX", .value =3D 76, }, + { .name =3D "OP_31_XOP_LDARX", .value =3D 84, }, + { .name =3D "OP_31_XOP_LBZX", .value =3D 87, }, + { .name =3D "OP_31_XOP_LVX", .value =3D 103, }, + { .name =3D "OP_31_XOP_LBZUX", .value =3D 119, }, + { .name =3D "OP_31_XOP_STXSIWX", .value =3D 140, }, + { .name =3D "OP_31_XOP_STDX", .value =3D 149, }, + { .name =3D "OP_31_XOP_STWX", .value =3D 151, }, + { .name =3D "OP_31_XOP_STDUX", .value =3D 181, }, + { .name =3D "OP_31_XOP_STWUX", .value =3D 183, }, + { .name =3D "OP_31_XOP_STBX", .value =3D 215, }, + { .name =3D "OP_31_XOP_STVX", .value =3D 231, }, + { .name =3D "OP_31_XOP_STBUX", .value =3D 247, }, + { .name =3D "OP_31_XOP_LHZX", .value =3D 279, }, + { .name =3D "OP_31_XOP_LHZUX", .value =3D 311, }, + { .name =3D "OP_31_XOP_LXVDSX", .value =3D 332, }, + { .name =3D "OP_31_XOP_LWAX", .value =3D 341, }, + { .name =3D "OP_31_XOP_LHAX", .value =3D 343, }, + { .name =3D "OP_31_XOP_LWAUX", .value =3D 373, }, + { .name =3D "OP_31_XOP_LHAUX", .value =3D 375, }, + { .name =3D "OP_31_XOP_STHX", .value =3D 407, }, + { .name =3D "OP_31_XOP_STHUX", .value =3D 439, }, + { .name =3D "OP_31_XOP_LXSSPX", .value =3D 524, }, + { .name =3D "OP_31_XOP_LDBRX", .value =3D 532, }, + { .name =3D "OP_31_XOP_LSWX", .value =3D 533, }, + { .name =3D "OP_31_XOP_LWBRX", .value =3D 534, }, + { .name =3D "OP_31_XOP_LFSUX", .value =3D 567, }, + { .name =3D "OP_31_XOP_LXSDX", .value =3D 588, }, + { .name =3D "OP_31_XOP_LSWI", .value =3D 597, }, + { .name =3D "OP_31_XOP_LFDX", .value =3D 599, }, + { .name =3D "OP_31_XOP_LFDUX", .value =3D 631, }, + { .name =3D "OP_31_XOP_STXSSPX", .value =3D 652, }, + { .name =3D "OP_31_XOP_STDBRX", .value =3D 660, }, + { .name =3D "OP_31_XOP_STXWX", .value =3D 661, }, + { .name =3D "OP_31_XOP_STWBRX", .value =3D 662, }, + { .name =3D "OP_31_XOP_STFSX", .value =3D 663, }, + { .name =3D "OP_31_XOP_STFSUX", .value =3D 695, }, + { .name =3D "OP_31_XOP_STXSDX", .value =3D 716, }, + { .name =3D "OP_31_XOP_STSWI", .value =3D 725, }, + { .name =3D "OP_31_XOP_STFDX", .value =3D 727, }, + { .name =3D "OP_31_XOP_STFDUX", .value =3D 759, }, + { .name =3D "OP_31_XOP_LXVW4X", .value =3D 780, }, + { .name =3D "OP_31_XOP_LHBRX", .value =3D 790, }, + { .name =3D "OP_31_XOP_LXVD2X", .value =3D 844, }, + { .name =3D "OP_31_XOP_LFIWAX", .value =3D 855, }, + { .name =3D "OP_31_XOP_LFIWZX", .value =3D 887, }, + { .name =3D "OP_31_XOP_STXVW4X", .value =3D 908, }, + { .name =3D "OP_31_XOP_STHBRX", .value =3D 918, }, + { .name =3D "OP_31_XOP_STXVD2X", .value =3D 972, }, + { .name =3D "OP_31_XOP_STFIWX", .value =3D 983, }, +}; + +static int cmp_offset(const void *a, const void *b) +{ + const struct insn_offset *val1 =3D a; + const struct insn_offset *val2 =3D b; + + return (val1->value - val2->value); +} =20 static struct ins_ops *check_ppc_insn(u32 raw_insn) { int opcode =3D PPC_OP(raw_insn); + int mem_insn_31 =3D PPC_21_30(raw_insn); + struct insn_offset *ret; + struct insn_offset mem_insns_31_opcode =3D { + "OP_31_INSN", + mem_insn_31 + }; =20 /* * Instructions with opcode 32 to 63 are memory * instructions in powerpc */ - if ((opcode & 0x20)) + if ((opcode & 0x20)) { return &load_store_ops; + } else if (opcode =3D=3D 31) { + /* Check for memory instructions with opcode 31 */ + ret =3D bsearch(&mem_insns_31_opcode, ins_array, ARRAY_SIZE(ins_array), = sizeof(ins_array[0]), cmp_offset); + if (ret !=3D NULL) + return &load_store_ops; + } =20 return NULL; } diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 1396df1b138a..fdfd4b0a3172 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -698,6 +698,9 @@ static int load_store__parse(struct arch *arch __maybe_= unused, struct ins_operan { ops->source.mem_ref =3D true; ops->source.multi_regs =3D false; + /* opcode 31 is of X form */ + if (PPC_OP(dl->raw.raw_insn) =3D=3D 31) + ops->source.multi_regs =3D true; =20 ops->target.mem_ref =3D false; ops->target.multi_regs =3D false; --=20 2.43.0