From nobody Sun Nov 29 02:11:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1795718335; cv=none; d=zohomail.com; s=zohoarc; b=nzn01InLC/OOVnXemHZJUYbTbMvGy33JVDNOSArnp3yt139nkGgpctWDT9YiFXMueNxlayKjXoLJrJ5+6JEm/GOU6lo+jtLgI+YkAWINLW31P1bwG7x72VXEToVqQ2BRG0awYRqVROJGvE2TwHMa4aU+F1ZJS5mimQwI28ByOGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795718335; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z6ZWUf9cwYAJcb+rP/Zlh1yK5obcYoaAmw9bZBlCj+4=; b=RCy7oVLNcV8PZJ9MVNjUpK9VMuSyRTy+uYJOVW77UyowdVNXUjHpVicmx87YM8//Mux4jxS36WFs04pcjQ/fSfkUMPf/LT5gcPid74nAG0jvYapZH7+wYhtXD+P9lGqbv1mL2Vnq1nWO86wU8HBzSavhuMsYekBej5OXEkam2kA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179571833536781.92682690211541; Thu, 26 Nov 2026 10:38:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWeMY-0006ZF-M0; Thu, 26 Nov 2026 13:38:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWeMO-0006XY-Q5 for qemu-devel@nongnu.org; Thu, 26 Nov 2026 13:38:23 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWeMM-0008Na-Io for qemu-devel@nongnu.org; Thu, 26 Nov 2026 13:38:20 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AQGc8tB596793 for ; Thu, 26 Nov 2026 18:38:16 GMT Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j6rf90c03-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 26 Nov 2026 18:38:16 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-33713e5e6daso11624277eec.0 for ; Thu, 26 Nov 2026 10:38:16 -0800 (PST) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385665f21aesm78687512eec.4.2026.11.26.10.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2026 10:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Z6ZWUf9cwYAJcb+rP/Zlh1yK5obcYoaAmw9bZBlCj+4=; b=mQIiuYyhSZK994jW nn+l5PRRxZt4UltpLFULtar36ozujJkPvnto/ejlK4A9zyD4gOLZegOqB5/0nise NnRrZ+gkKe5iO84BgVY0f2DQSQaz4E5znwz7SwmImvvFmr8gydI7Wljc3Js2LAWy okWNyJpOIvFC6dtV8w/bq20ik6CGFduZVpM3ird+W2d6G2AwoDTqTjKKPgwBvymU pLxVwg9aPWV6sQsuXskYKunv+67T9qlQhrOAsAgvcy1rnE2MusoNsvlouVkDU+rh 7aWmKs3g9E75uNWF7ZnYMQ6n2kPNZo7KDiCWrk7BBXpAS3GZPRUjjU8BwiJAdbyI hhCbFg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1795718296; x=1796323096; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Z6ZWUf9cwYAJcb+rP/Zlh1yK5obcYoaAmw9bZBlCj+4=; b=kEmiwHcoZV2kVssqcqbd74A8Gsp/0n9yBufhkprw9+EvAI/p5Mu+92Ys+VrKh73AlS L38u6HazWHjz5t4yB5dEOCtySWc2ytQI7A4GK/XpozHEcKR/rvOzjQF44Iz2KGRR4SbY rFepnbRsYmN9+Q83tnEb2k3OFZtj6ETwEhJeG9XuVtKfmS5fOXxcFtJzXcFIAe75Hc3s muZQjD4EES0PSk8TIU1VHEq/UGS0BK00rJ/H1ayRxHfRzwqUAfYyxop6k66CHv+r5Trr rGeQaqOY3rziSVUMQ54HCABoRwZ5JvYaKiW4zAKK5ahiXVfuS2k42a+KCBtkrwumOhjo V8fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795718296; x=1796323096; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Z6ZWUf9cwYAJcb+rP/Zlh1yK5obcYoaAmw9bZBlCj+4=; b=Yd81XWJQpG3K96Sm/fSdbs4CvJbtH7OnM/Wa/VB1CkSWha+NOE2RZB5Nc5mYs9LqCj RwJVKhFzZMCQLl6keQR69x5D9X7ptrsMbMkpSnpCTz3hnmxMldBDm4IQeLoO7GlAveeR cReYoMFSPsFSwQk7SacTdN8ZeHVuKU8Btw/ffedVtj+Okqt8lVeQj14RsOXHXe1TAr8I yXLAp0Kd8I0RH2m67p/s9VgscH0hrN6MzGpiPsVMtkSznfYRhMHQ0nCPSG0YPz3pr0ev P/fnvesYb4W8VsnuF3gxraWHJ8vanV0hw0uwhMyJA79GzGRDMNczpz3vXRfNMSCbiPH/ 8e3g== X-Gm-Message-State: APuU4Z/UdE+1WfDamnNpLzpJ7NrcR8RBJ7mB88FHx69SAP15qV8j2YHw XD3kJfpqB7/i4F4BuG2QF9oIj1vYYNRninN7CzfVgTBQcY8StJ/Kpx7mMGddXIpcSIR/nznvDMK dN3Gys0pIPfWGGOxmT2EvY4EgRJaIUaT0cB9cjJhbRA+irYX1pyaHzAwfIoPpM9ywTw== X-Gm-Gg: AZFdTZfErAoJC9KntEJ5yCh7g/Pf9shhHL+8RPWP9TqJ5aX7CJ1i3UIiGByULameEji PFftxbOJ2LxGnE9GkUwxM3aY7Qejo4/56UHSFrPrMaJzuVZr9jpYck6T1NSYVM1KeBHcgMy65qT C0UoFaoCgldhQ1USit/VJZHDB/i9tCr/StqGBEXhtu7ISJUQ9d3jmKm3uTj/7X3/v/+Ay/aUJuG b1ntylIvr38Cc1Rdn56jANNq7axw58VXVelf9kUtwAa7e4GSauPYGkyzsOGBr3+3O1glDR9rvMg J0VCzlrL/IByyCCK0GPl6N0hKYG+N8XwI7c/ckHVJi6aY+E2SsDxDTIhkbWemKI3lZzP2R1Oaso 8uLbetUoqRuLm2ag3dHyWVG3XmStNO2PqqIKB2zdtPk6zyN601ofcyJvTAIxXRqc/5DZbhYzk5x JbmOO8s0e/sfaV8tX3VEBolQ== X-Received: by 2002:a05:693c:8803:20b0:386:9b9c:ef1b with SMTP id 5a478bee46e88-3869b9cf99amr16626273eec.3.1795718295534; Thu, 26 Nov 2026 10:38:15 -0800 (PST) X-Received: by 2002:a05:693c:8803:20b0:386:9b9c:ef1b with SMTP id 5a478bee46e88-3869b9cf99amr16626252eec.3.1795718295013; Thu, 26 Nov 2026 10:38:15 -0800 (PST) From: Brian Cain To: qemu-devel@nongnu.org Cc: Brian Cain , Pierrick Bouvier Subject: [PATCH for-12.0 1/3] target/hexagon: remove QEMU-private execution counters Date: Thu, 26 Nov 2026 10:38:10 -0800 Message-Id: <20261126183812.1366883-2-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261126183812.1366883-1-brian.cain@oss.qualcomm.com> References: <20261126183812.1366883-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: hZbbkftmlKgT3md28dhcRcyqRORYLVi0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTI2MDA3MyBTYWx0ZWRfX8XZ36arKYaIN gmVhqhbWa2Q3wNTJ3N47nLzNan7GfHmWDEVfhnFMslSztjZjpCeBzfPP+hFkXpTqNjPThDLsQnO OLCXtau1kKZpRHnqpsTtUgE1665VmoafeC4cdoa8IN+Ni5ppv/RzHA0KMAAftgTm9/c2lVP4V5O bjasEZt3UfnrzQwDj9W7Y232tBLSymgfmknhAlGZxNSr9tHjITN9oT61CoCBy5Zo/xMmffRBzks Pjj0y11a4it40J1WU04GnRlB/s1+ftl10Z0D9V5XKoXFfm58rsOcnmS7jJK5jJngCkOeMKzE8ul 1Mo8GJRJ2EWGZ7/B4KNdmnIfmKBQ0j0oY8lNC9+FQ7cLy1A4cR1YgR6k+se/fs3qcK4ovQfYi6x 2hLKa49usVdeQiHwjdj3PmGOeE4cAvyufZmGQUL0C+eqX2/QtRWuZVyFOmBZbShz3T/noj7B7s7 eB/dCQQzPZPT98LesOA== X-Authority-Analysis: v=2.4 cv=cpkOAF4i c=1 sm=1 tr=0 ts=6b087c98 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=JZmrEF4LRwlIdQqdpIIA:9 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI2MDA3MyBTYWx0ZWRfX3/y/vpqCz0gE EEVDX/FLMceq7nXcr33eTxowDbJo5KqNqB82g6egCyamuCB0YsrgVwYZqlTQKYDh6UqQNFeHPkb 5Zne3x+iwasw2+HBy+BwqB6Oz6okcN0= X-Proofpoint-GUID: hZbbkftmlKgT3md28dhcRcyqRORYLVi0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-26_04,2026-11-26_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611260073 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1795718337626158500 The instruction counters occupy user control-register slots 52 through 54. Those encodings are assigned to UPMUCNT0-2, so remove the debug-only feature before adding the real PMU support. Signed-off-by: Brian Cain Reviewed-by: Pierrick Bouvier --- target/hexagon/hex_regs.h | 4 ---- target/hexagon/translate.h | 3 --- target/hexagon/genptr.c | 35 --------------------------------- target/hexagon/translate.c | 40 -------------------------------------- 4 files changed, 82 deletions(-) diff --git a/target/hexagon/hex_regs.h b/target/hexagon/hex_regs.h index 03feca477b6..254f935e323 100644 --- a/target/hexagon/hex_regs.h +++ b/target/hexagon/hex_regs.h @@ -73,10 +73,6 @@ enum { HEX_REG_FRAMEKEY =3D 49, HEX_REG_PKTCNTLO =3D 50, HEX_REG_PKTCNTHI =3D 51, - /* Use reserved control registers for qemu execution counts */ - HEX_REG_QEMU_PKT_CNT =3D 52, - HEX_REG_QEMU_INSN_CNT =3D 53, - HEX_REG_QEMU_HVX_CNT =3D 54, HEX_REG_VFRAMELIMIT =3D 60, HEX_REG_VSP =3D 61, HEX_REG_UTIMERLO =3D 62, diff --git a/target/hexagon/translate.h b/target/hexagon/translate.h index bc3b49ab06d..b2573f051b2 100644 --- a/target/hexagon/translate.h +++ b/target/hexagon/translate.h @@ -33,9 +33,6 @@ typedef struct DisasContext { const HexagonCPUDef *hex_def; uint32_t next_PC; uint32_t mem_idx; - uint32_t num_packets; - uint32_t num_insns; - uint32_t num_hvx_insns; int reg_log[REG_WRITES_MAX]; int reg_log_idx; DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS); diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c index 52615628e3f..4688afb16d2 100644 --- a/target/hexagon/genptr.c +++ b/target/hexagon/genptr.c @@ -437,8 +437,6 @@ static inline void gen_read_p3_0(TCGv control_reg) * -> concat the 4 predicate registers together * HEX_REG_PC actual value stored in DisasContext * -> assign from ctx->base.pc_next - * HEX_REG_QEMU_*_CNT changes in current TB in DisasContext - * -> add current TB changes to existing reg val= ue */ static inline void gen_read_ctrl_reg(DisasContext *ctx, const int reg_num, TCGv dest) @@ -447,15 +445,6 @@ static inline void gen_read_ctrl_reg(DisasContext *ctx= , const int reg_num, gen_read_p3_0(dest); } else if (reg_num =3D=3D HEX_REG_PC) { tcg_gen_movi_tl(dest, ctx->base.pc_next); - } else if (reg_num =3D=3D HEX_REG_QEMU_PKT_CNT) { - tcg_gen_addi_tl(dest, hex_gpr[HEX_REG_QEMU_PKT_CNT], - ctx->num_packets); - } else if (reg_num =3D=3D HEX_REG_QEMU_INSN_CNT) { - tcg_gen_addi_tl(dest, hex_gpr[HEX_REG_QEMU_INSN_CNT], - ctx->num_insns); - } else if (reg_num =3D=3D HEX_REG_QEMU_HVX_CNT) { - tcg_gen_addi_tl(dest, hex_gpr[HEX_REG_QEMU_HVX_CNT], - ctx->num_hvx_insns); #ifndef CONFIG_USER_ONLY } else if (reg_num =3D=3D HEX_REG_UTIMERLO) { translator_io_start(&ctx->base); @@ -498,19 +487,6 @@ static inline void gen_read_ctrl_reg_pair(DisasContext= *ctx, const int reg_num, } else if (reg_num =3D=3D HEX_REG_PC - 1) { TCGv pc =3D tcg_constant_tl(ctx->base.pc_next); tcg_gen_concat_i32_i64(dest, hex_gpr[reg_num], pc); - } else if (reg_num =3D=3D HEX_REG_QEMU_PKT_CNT) { - TCGv pkt_cnt =3D tcg_temp_new(); - TCGv insn_cnt =3D tcg_temp_new(); - tcg_gen_addi_tl(pkt_cnt, hex_gpr[HEX_REG_QEMU_PKT_CNT], - ctx->num_packets); - tcg_gen_addi_tl(insn_cnt, hex_gpr[HEX_REG_QEMU_INSN_CNT], - ctx->num_insns); - tcg_gen_concat_i32_i64(dest, pkt_cnt, insn_cnt); - } else if (reg_num =3D=3D HEX_REG_QEMU_HVX_CNT) { - TCGv hvx_cnt =3D tcg_temp_new(); - tcg_gen_addi_tl(hvx_cnt, hex_gpr[HEX_REG_QEMU_HVX_CNT], - ctx->num_hvx_insns); - tcg_gen_concat_i32_i64(dest, hvx_cnt, hex_gpr[reg_num + 1]); #ifndef CONFIG_USER_ONLY } else if (reg_num =3D=3D HEX_REG_UTIMERLO) { translator_io_start(&ctx->base); @@ -547,8 +523,6 @@ static void gen_write_p3_0(DisasContext *ctx, TCGv cont= rol_reg) * Certain control registers require special handling on write * HEX_REG_P3_0_ALIASED aliased to the predicate registers * -> break the value across 4 predicate registe= rs - * HEX_REG_QEMU_*_CNT changes in current TB in DisasContext - * -> clear the changes */ static inline void gen_write_ctrl_reg(DisasContext *ctx, int reg_num, TCGv val) @@ -564,15 +538,6 @@ static inline void gen_write_ctrl_reg(DisasContext *ct= x, int reg_num, } gen_masked_reg_write(val, hex_gpr[reg_num], reg_mask); tcg_gen_mov_tl(get_result_gpr(ctx, reg_num), val); - if (reg_num =3D=3D HEX_REG_QEMU_PKT_CNT) { - ctx->num_packets =3D 0; - } - if (reg_num =3D=3D HEX_REG_QEMU_INSN_CNT) { - ctx->num_insns =3D 0; - } - if (reg_num =3D=3D HEX_REG_QEMU_HVX_CNT) { - ctx->num_hvx_insns =3D 0; - } } } =20 diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index 11b3917b96c..cfb2de97281 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -149,16 +149,6 @@ void gen_precise_exception(int cause, uint32_t PC) tcg_constant_i32(PC)); } =20 -static void gen_exec_counters(DisasContext *ctx) -{ - tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_PKT_CNT], - hex_gpr[HEX_REG_QEMU_PKT_CNT], ctx->num_packets); - tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_INSN_CNT], - hex_gpr[HEX_REG_QEMU_INSN_CNT], ctx->num_insns); - tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_HVX_CNT], - hex_gpr[HEX_REG_QEMU_HVX_CNT], ctx->num_hvx_insns); -} - static bool use_goto_tb(DisasContext *ctx, target_ulong dest) { return translator_use_goto_tb(&ctx->base, dest); @@ -214,8 +204,6 @@ static void gen_end_tb_singlestep(DisasContext *ctx) =20 static void gen_end_tb(DisasContext *ctx) { - gen_exec_counters(ctx); - #ifndef CONFIG_USER_ONLY if (ctx->ss_active) { gen_end_tb_singlestep(ctx); @@ -260,7 +248,6 @@ static void gen_end_tb(DisasContext *ctx) =20 void hex_gen_exception_end_tb(DisasContext *ctx, int cause) { - gen_exec_counters(ctx); gen_precise_exception(cause, ctx->pkt.pc); ctx->base.is_jmp =3D DISAS_NORETURN; } @@ -273,7 +260,6 @@ static void gen_exception_decode_fail(DisasContext *ctx= , int nwords, int cause) { target_ulong fail_pc =3D ctx->base.pc_next + nwords * sizeof(uint32_t); =20 - gen_exec_counters(ctx); tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], fail_pc); gen_precise_exception(cause, fail_pc); ctx->base.is_jmp =3D DISAS_NORETURN; @@ -1321,27 +1307,6 @@ static void gen_commit_hmx(DisasContext *ctx) } } =20 -static void update_exec_counters(DisasContext *ctx) -{ - int num_real_insns =3D 0; - int num_hvx_insns =3D 0; - - for (int i =3D 0; i < ctx->pkt.num_insns; i++) { - if (!ctx->pkt.insn[i].is_endloop && - !ctx->pkt.insn[i].part1 && - !GET_ATTRIB(ctx->pkt.insn[i].opcode, A_IT_NOP)) { - num_real_insns++; - } - if (GET_ATTRIB(ctx->pkt.insn[i].opcode, A_CVI)) { - num_hvx_insns++; - } - } - - ctx->num_packets++; - ctx->num_insns +=3D num_real_insns; - ctx->num_hvx_insns +=3D num_hvx_insns; -} - #ifndef CONFIG_USER_ONLY /* * A tlbp instruction may detect multiple TLB matches and set a pending @@ -1466,7 +1431,6 @@ static void gen_commit_packet(DisasContext *ctx) if (ctx->pkt.pkt_has_hmx) { gen_commit_hmx(ctx); } - update_exec_counters(ctx); =20 if (ctx->pkt.vhist_insn !=3D NULL) { ctx->pre_commit =3D false; @@ -1573,9 +1537,6 @@ static void hexagon_tr_init_disas_context(DisasContex= tBase *dcbase, uint32_t hex_flags =3D dcbase->tb->flags; =20 ctx->mem_idx =3D FIELD_EX32(hex_flags, TB_FLAGS, MMU_INDEX); - ctx->num_packets =3D 0; - ctx->num_insns =3D 0; - ctx->num_hvx_insns =3D 0; #ifndef CONFIG_USER_ONLY ctx->hlx_coproc_enabled =3D hex_cpu->hlx !=3D NULL && hex_cpu->hlx->contexts_bitmap !=3D 0; @@ -1665,7 +1626,6 @@ static void hexagon_tr_tb_stop(DisasContextBase *dcba= se, CPUState *cpu) =20 switch (ctx->base.is_jmp) { case DISAS_TOO_MANY: - gen_exec_counters(ctx); tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next); #ifndef CONFIG_USER_ONLY if (ctx->ss_active) { --=20 2.34.1 From nobody Sun Nov 29 02:11:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1795718358; cv=none; d=zohomail.com; s=zohoarc; b=QWKhDP52JdHCNAzx0p0EE0x/R6IkPGZ01IXFN5fbGMO1283rYnrdcJXq8Yjo3+sbjhLfwPyepDGiy/j11T/2OJjuM1tQvFIqocEBxRgHpnLUuX/06kr62GhoKWa7TqvUBcbZZnWGZZ2IzRjXUjCySncUgSFq1ZIZUBFtDTDo00k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795718358; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CjEypSa1iZLUiRYhw1VeC7guFdIiuzz2AzldYXPHW9s=; b=NXXlGukkOIG6iMKYUmoLBEVusZhlcqOmpnveQke9e4IK/eeWZGqKb4BDGvOp8UYscItJcnls7PdhBfgEXm0OfhxBeepAji7gzbajQYldawrHknoq5S53PuEKITiibodBwIS5Czu+YiJBbC9hwv0dh80r6oEqiq8qwpEVPIlcOVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179571835799878.35151207441481; Thu, 26 Nov 2026 10:39:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWeMa-0006ar-D5; Thu, 26 Nov 2026 13:38:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWeMU-0006Z7-Vs for qemu-devel@nongnu.org; Thu, 26 Nov 2026 13:38:27 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWeMP-0008O3-53 for qemu-devel@nongnu.org; Thu, 26 Nov 2026 13:38:26 -0500 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AQFtwvu2835004 for ; Thu, 26 Nov 2026 18:38:19 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j6pgqgsjv-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 26 Nov 2026 18:38:19 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-383ec96a7deso7720817eec.1 for ; Thu, 26 Nov 2026 10:38:19 -0800 (PST) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385665f21aesm78687512eec.4.2026.11.26.10.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2026 10:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= CjEypSa1iZLUiRYhw1VeC7guFdIiuzz2AzldYXPHW9s=; b=nUatQTvDdXF5vt54 7TrBwyVGeR8Mraf3bFxrugshKCkkkRUWj5nk2XvZTPk0hK0wIjai5JgnffY8rlrq xQ5J3G2HCBYRGf8yMT2F3uw6P/eAHa5X5kCmEO7ghrwrKWYesCq14clome55WexW T4pJjGk+3iCC0f5v97S/5IbAZqr3gW8vdK5K7WdCJCzUmgNOzVHEdp6RFrACmYPO QQuWp4ofYadeok/aU6jCWYiQQhQwsJbplXUxurcjdMPd0nvjapS2sCbMFo8cPADm Qo9gv2PWP9HPYJs1Axe89clRs1ZrJEkNs5jVsP4DbhHHm8kihhqbAdxoShpmk37e kwrtZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1795718299; x=1796323099; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=CjEypSa1iZLUiRYhw1VeC7guFdIiuzz2AzldYXPHW9s=; b=IB35HN+mc1ipcS0naBAszikM81X4Ht1V/BzNJ5tTVix1dSPN4kWxGNTfz36xjvGMOg /tUnkm5bknEE8gbQSFIQ/Ou9PNi15pm2pgtCLHSRD0Kyk909Nou3Dfi9yyrElU4hkBKN HWwidPmbMi8lakxF6zVDweZ/VZBwUZU+62Uy5LYOVe3FsgQAl9RaNJEBm4rc72/qslyG tP9pp7nnaTRP9bQFLdELkx7drUR0Vw19UHsS0gOX8352zjYMWQjcM8SLef2vKftpDFe0 GgMqlEWmbbBMR0RV3FMxdysrT3kozEvvrivuZEklvb4Ld49zB1ZC/SL9bKXzgYuKs0mx I7Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795718299; x=1796323099; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CjEypSa1iZLUiRYhw1VeC7guFdIiuzz2AzldYXPHW9s=; b=IJnnNiYGv56Kt/1icBtIMM2DhmcySnJ5vLqlF3Ro+RasRJrtggF/Rt5Cpx5tr0TXGh zJnPgUiMW3b2MOxd77VTl09/a6vHRF4gcbX3YU7eXXXS40JjAqTAgBvUt3ivXJPqcY59 S8iLX0lI2EXA7FYVsBaDAhFhTGwOEHYFS0r+KoiW5pzQhOKFOHwky2RRv4hN8ItoxagC NG4HqvlkOVmhdBUgnF3qje/SrX9brPtOFyLxlwYkJfb89ZkE90PuUgurSBrco+nvk3B4 eQHuedluzKDZM9ACOtDa4tl2YeRa5SXU4WJMbP3j9aYQJUNJoEbX72bIIHqU1Q2HcRyH 8mTQ== X-Gm-Message-State: APuU4Z+TSyBD2de3aCbetp23sinulL5sjIbdSTW2O5ekBHpRHyImtMI4 rrLGv1W56jCpyStqS+2w58SctNYu285/udDJFUen6YT+IsO0gANSmPegwWTMBPz2XjOtYyZ9OR8 uwebySOgOiuH01vHEcdNpE5F59lODhxciPBdNLsfrTTCDRu3SIn4kN/Jy9qt3K58VOA== X-Gm-Gg: AZFdTZdHpvmL4rvHabqxN8yIKLu60+60SF3PgMOhG9XtQbgihz+Zf7SzcsRYRTvAIwH MgHf1FWf4KIamJnZOuo+3yL0hn4+97IziNQU3NtnZ2YQebvzY33JuRcw1PjfqIbM42tE0OD0sml l4xYwwOYm1gKJCKy3cE9OWUnYadcm4gBg1rAYfBYkaKVLF1XuB4nvroep5TNgU/6yWTE4w0jxG/ JNsT/DdUvekVUGdgCdJ1loqiWzqNg/keljcqinMn2Oz94tf+r68tNgf4KIQjYIqBD78DFdDi41y Hr25hGSaXtfFQcDj5mquZWe5ld4y+SrWdz0lJ+y8vmyGQpYADaFDUnMZliNrfQLmMzG04Or/IoM +txTLjfleAQ99NB7n+KqjK7L3SEAASr4QIBxob3vydYoo+5ol78g8u5pw8G9X6Lxf3qGZW109Ai xMe2y0D6MEeuNhl28PCWtm8w== X-Received: by 2002:a05:7301:4301:b0:386:548e:e533 with SMTP id 5a478bee46e88-386548ee6c3mr20646233eec.18.1795718297794; Thu, 26 Nov 2026 10:38:17 -0800 (PST) X-Received: by 2002:a05:7301:4301:b0:386:548e:e533 with SMTP id 5a478bee46e88-386548ee6c3mr20646189eec.18.1795718296618; Thu, 26 Nov 2026 10:38:16 -0800 (PST) From: Brian Cain To: qemu-devel@nongnu.org Cc: Brian Cain , Pierrick Bouvier Subject: [PATCH for-12.0 2/3] target/hexagon: implement PMU Date: Thu, 26 Nov 2026 10:38:11 -0800 Message-Id: <20261126183812.1366883-3-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261126183812.1366883-1-brian.cain@oss.qualcomm.com> References: <20261126183812.1366883-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: QWgAr1gbmE4T3hJWpllUqoPzb90PgqSX X-Proofpoint-ORIG-GUID: QWgAr1gbmE4T3hJWpllUqoPzb90PgqSX X-Authority-Analysis: v=2.4 cv=A7H5rKWG c=1 sm=1 tr=0 ts=6b087c9b cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=fNicDYcq0P4AbHJzJHIA:9 a=QEXdDO2ut3YA:10 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI2MDA3MyBTYWx0ZWRfX2ZJzOC18tQms t3slBGIudzhuG/fLPORifjJwaz/KE1CNunFwQtrQz9hc9Ib/wvaeo941rL6LJ0/CP8SpZg1C+mT Ylqgv5E4EgeoVnYywdP+7xugC17zgtI= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTI2MDA3MyBTYWx0ZWRfXx8E/Ij8+LPSI Z4ClnMN/+wUXGuXTv8ASmK18ennVU1cCRopLJ5NCP3MmeTPvQFRWH7gJln14NrgGSfsCdwYTljv kstJ0OpziHxJ3dQrrUIce+J9tFuApfXcogHiviVmdqwjt3PCEzjRf5Ve4+h5ZKFK6rsT2p42WEW cl/zBKo8OxqMbtNjjyHrt+vqth+EaSSOqyMSi6KE9IRTEdQoQG2KRsTly/JNPGl3HKzO2+GQRMc 2NIup0HCE1JtYC/bq2UxRwWhexYjr0kHKqP5+LM1HmsQci4R2gGXYVnNunEcu+b8IRKmcwtBXhi iTMk3WB121tSET/DNDQQL7vvr0rL2FkRiZaqnRUMAU9gKad9PoNiDoJ5QfcZaOxPR5MWuQPaj0o 9CPb/i1kPsxmINn6pvUgO81rjpltVyxms0PLyRsDlFJVeea59GokGKr2FweyEpsK33uOUx+LhdD Ir1ssiFR6Soj9i2JdMA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-26_04,2026-11-26_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 malwarescore=0 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611260073 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1795718359522158500 Add a Hexagon PMU with event counters. Counting is gated by SYSCFG.PM and covers the events from packet decode and commit: packet, load/store and HVX/HLX counts. Other events are accepted and logged as unimplemented. Signed-off-by: Brian Cain --- include/hw/hexagon/hexagon.h | 1 + include/hw/hexagon/hexagon_pmu.h | 51 +++++ target/hexagon/cpu.h | 36 +++- target/hexagon/cpu_helper.h | 3 + target/hexagon/helper.h | 1 + target/hexagon/hex_regs.h | 20 +- target/hexagon/pmu.h | 200 ++++++++++++++++++++ target/hexagon/translate.h | 35 ++++ target/hexagon/reg_fields_def.h.inc | 21 +++ hw/hexagon/hex-subsys.c | 14 ++ hw/hexagon/hexagon_globalreg.c | 23 ++- hw/hexagon/hexagon_pmu.c | 113 +++++++++++ target/hexagon/cpu.c | 27 ++- target/hexagon/cpu_helper.c | 280 +++++++++++++++++++++++++++- target/hexagon/gdbstub.c | 6 +- target/hexagon/genptr.c | 23 +++ target/hexagon/machine.c | 40 +++- target/hexagon/op_helper.c | 22 +++ target/hexagon/translate.c | 209 +++++++++++++++++++++ gdbstub/gdb-xml/hexagon-sys.xml | 79 ++++---- hw/hexagon/meson.build | 1 + 21 files changed, 1153 insertions(+), 52 deletions(-) create mode 100644 include/hw/hexagon/hexagon_pmu.h create mode 100644 target/hexagon/pmu.h create mode 100644 hw/hexagon/hexagon_pmu.c diff --git a/include/hw/hexagon/hexagon.h b/include/hw/hexagon/hexagon.h index 2ca4a518dbe..fb81a2cadd3 100644 --- a/include/hw/hexagon/hexagon.h +++ b/include/hw/hexagon/hexagon.h @@ -193,6 +193,7 @@ struct HexagonCommonMachineState { DeviceState *glob_regs; DeviceState *tlb; DeviceState *hlx; + DeviceState *pmu; unsigned num_hvx_ctx; }; =20 diff --git a/include/hw/hexagon/hexagon_pmu.h b/include/hw/hexagon/hexagon_= pmu.h new file mode 100644 index 00000000000..69de3ae03ea --- /dev/null +++ b/include/hw/hexagon/hexagon_pmu.h @@ -0,0 +1,51 @@ +/* + * Hexagon PMU QOM Object + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HEXAGON_PMU_H +#define HEXAGON_PMU_H + +#include "hw/core/sysbus.h" +#include "qom/object.h" +#include "target/hexagon/cpu.h" +#include "target/hexagon/pmu.h" + +#define TYPE_HEXAGON_PMU "hexagon-pmu" +OBJECT_DECLARE_SIMPLE_TYPE(HexagonPMUState, HEXAGON_PMU) + +struct HexagonPMUState { + SysBusDevice parent_obj; + + /* Event selected for each of the NUM_PMU_CTRS counters. */ + uint16_t events[NUM_PMU_CTRS]; + + /* Per-counter rebase offset; see hexagon_get_pmu_counter(). */ + uint32_t ctr_offset[NUM_PMU_CTRS]; + + /* PMUCFG[20:16] thread mode; only mode 0 (no qualification) is used. = */ + uint32_t thread_mask; + + /* Raw PMUSTID0-2; not yet implemented beyond being stored. */ + uint32_t stid[3]; + + /* Events already reported as unimplemented; not migrated. */ + DECLARE_BITMAP(unimp_logged, PMU_NUM_EVENT_IDS); +}; + +uint16_t hexagon_pmu_get_event(HexagonPMUState *s, unsigned int index); +void hexagon_pmu_set_event(HexagonPMUState *s, unsigned int index, + uint16_t event); +uint32_t hexagon_pmu_get_offset(HexagonPMUState *s, unsigned int index); +void hexagon_pmu_set_offset(HexagonPMUState *s, unsigned int index, + uint32_t offset); +uint32_t hexagon_pmu_get_thread_mask(HexagonPMUState *s); +void hexagon_pmu_set_thread_mask(HexagonPMUState *s, uint32_t mask); +bool hexagon_pmu_test_and_set_unimp_logged(HexagonPMUState *s, int event); +uint32_t hexagon_pmu_get_stid(HexagonPMUState *s, unsigned int index); +void hexagon_pmu_set_stid(HexagonPMUState *s, unsigned int index, + uint32_t value); + +#endif /* HEXAGON_PMU_H */ diff --git a/target/hexagon/cpu.h b/target/hexagon/cpu.h index 5739254f1f6..69062a5eb40 100644 --- a/target/hexagon/cpu.h +++ b/target/hexagon/cpu.h @@ -30,7 +30,7 @@ typedef struct HexagonHLXContext HexagonHLXContext; #ifndef CONFIG_USER_ONLY #define NUM_GREGS 32 #define GREG_WRITES_MAX 2 -#define NUM_SREGS 106 +#define NUM_SREGS 121 #define SREG_WRITES_MAX 2 #endif =20 @@ -39,6 +39,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegStat= e; typedef struct HexagonHVXContextState HexagonHVXContextState; typedef struct HexagonHLXState HexagonHLXState; typedef struct HexagonHMXContextState HexagonHMXContextState; +typedef struct HexagonPMUState HexagonPMUState; =20 #include "cpu-qom.h" #include "exec/cpu-common.h" @@ -148,6 +149,35 @@ typedef struct HexagonHVXContext { MMQReg QRegs[NUM_QREGS]; } QEMU_ALIGNED(16) HexagonHVXContext; =20 +#ifndef CONFIG_USER_ONLY +/* + * Per-vCPU PMU tallies. Translated code addresses these fields directly + * (see hex_pmu_* TCG globals in translate.c), so they can't live in the + * "hexagon-pmu" QOM device -- that device only holds the guest-configurab= le, + * cross-thread state (which event each counter watches, and each counter's + * rebase offset). See target/hexagon/pmu.h for the event list and + * hexagon_get_pmu_counter() in cpu_helper.c for how the two combine. + */ +typedef struct PMUCounters { + uint32_t num_packets; + uint32_t xe_packets; + uint32_t committed_loads; + uint32_t committed_stores; + uint32_t committed_memops; + uint32_t hvx_packets; + uint32_t hvx_pipe_alu; + uint32_t hvx_pipe_mpy; + uint32_t hvx_pipe_shift; + uint32_t hvx_pipe_perm; + uint32_t hlx_packets; + uint32_t hlx_slot_alu; + uint32_t hlx_slot_shift; + uint32_t hlx_slot_mpy; + uint32_t hlx_slot_ld; + uint32_t hlx_slot_st; +} PMUCounters; +#endif + typedef struct CPUArchState { target_ulong gpr[TOTAL_PER_THREAD_REGS]; target_ulong pred[NUM_PREGS]; @@ -174,6 +204,8 @@ typedef struct CPUArchState { hex_lock_state_t k0_lock_state; uint32_t tlb_lock_count; uint32_t k0_lock_count; + + PMUCounters pmu; #endif uint32_t imprecise_exception; target_ulong new_value_usr; @@ -252,6 +284,7 @@ struct ArchCPU { uint32_t htid; HexL2VicInterface *l2vic; HexagonHLXState *hlx; + HexagonPMUState *pmu; #endif HmxState *hmx; HmxConfig hmx_cfg; @@ -271,6 +304,7 @@ FIELD(TB_FLAGS, MMU_INDEX, 1, 3) FIELD(TB_FLAGS, HVX_COPROC_ENABLED, 5, 1) FIELD(TB_FLAGS, CPU_MODE, 6, 2) FIELD(TB_FLAGS, SS_ACTIVE, 8, 1) +FIELD(TB_FLAGS, PMU_ENABLED, 9, 1) FIELD(TB_FLAGS, HMX_COPROC_ENABLED, 15, 1) =20 G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, diff --git a/target/hexagon/cpu_helper.h b/target/hexagon/cpu_helper.h index 5c0c129dfdb..3cf77a8fd0b 100644 --- a/target/hexagon/cpu_helper.h +++ b/target/hexagon/cpu_helper.h @@ -12,6 +12,9 @@ void hexagon_write_memory(CPUHexagonState *env, target_ul= ong vaddr, void hexagon_peek_memory_range(CPUHexagonState *env, uint32_t start_addr, uint32_t length, uintptr_t retaddr); uint32_t hexagon_get_pmu_counter(CPUHexagonState *cur_env, int index); +uint32_t hexagon_pmu_sreg_read(CPUHexagonState *env, uint32_t reg); +void hexagon_pmu_sreg_write(CPUHexagonState *env, uint32_t reg, uint32_t v= al); +uint32_t hexagon_get_pmu_greg(CPUHexagonState *env, uint32_t greg); void hexagon_modify_ssr(CPUHexagonState *env, uint32_t new, uint32_t old); void hexagon_modify_ccr(CPUHexagonState *env, uint32_t new, uint32_t old); unsigned hexagon_hvx_select_context(CPUHexagonState *env, uint32_t ssr); diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h index 292ca8eb7c5..4aee023adf4 100644 --- a/target/hexagon/helper.h +++ b/target/hexagon/helper.h @@ -170,6 +170,7 @@ DEF_HELPER_3(setimask, void, env, i32, i32) DEF_HELPER_2(sreg_read, i32, env, i32) DEF_HELPER_2(sreg_read_pair, i64, env, i32) DEF_HELPER_2(upcycle_read, i32, env, i32) +DEF_HELPER_2(upmucnt_read, i32, env, i32) DEF_HELPER_1(upcycle_read_pair, i64, env) DEF_HELPER_2(greg_read, i32, env, i32) DEF_HELPER_2(greg_read_pair, i64, env, i32) diff --git a/target/hexagon/hex_regs.h b/target/hexagon/hex_regs.h index 254f935e323..0752c7eadeb 100644 --- a/target/hexagon/hex_regs.h +++ b/target/hexagon/hex_regs.h @@ -75,6 +75,14 @@ enum { HEX_REG_PKTCNTHI =3D 51, HEX_REG_VFRAMELIMIT =3D 60, HEX_REG_VSP =3D 61, + HEX_REG_UPMUCNT0 =3D 52, + HEX_REG_UPMUCNT1 =3D 53, + HEX_REG_UPMUCNT2 =3D 54, + HEX_REG_UPMUCNT3 =3D 55, + HEX_REG_UPMUCNT4 =3D 56, + HEX_REG_UPMUCNT5 =3D 57, + HEX_REG_UPMUCNT6 =3D 58, + HEX_REG_UPMUCNT7 =3D 59, HEX_REG_UTIMERLO =3D 62, HEX_REG_UTIMERHI =3D 63, }; @@ -106,6 +114,8 @@ enum { DECL_HEX_GREG(GPMUCNT1, 27) \ DECL_HEX_GREG(GPMUCNT2, 28) \ DECL_HEX_GREG(GPMUCNT3, 29) \ + DECL_HEX_GREG(GPMUCNT8, 30) \ + DECL_HEX_GREG(GPMUCNT9, 31) \ DECL_HEX_GREG_DONE =20 #define DECL_HEX_GREG_DONE @@ -123,8 +133,8 @@ static inline bool greg_implemented(enum hex_greg greg) #if NUM_GREGS > 32 #error "NUM_GREGS too large for greg_implemented(): update `impl_bitmap`" #endif - static int32_t impl_bitmap =3D HEX_GREG_VALUES; - return impl_bitmap & (1 << greg); + static uint32_t impl_bitmap =3D HEX_GREG_VALUES; + return impl_bitmap & (1u << greg); } #undef DECL_HEX_GREG #undef DECL_HEX_GREG_DONE @@ -235,6 +245,12 @@ enum { HEX_SREG_ISDBST1 =3D 103, HEX_SREG_ISDBST2 =3D 104, HEX_SREG_BRKPTINFO1 =3D 105, + HEX_SREG_PMUEVTCFG2 =3D 111, + HEX_SREG_PMUCNT8 =3D 116, + HEX_SREG_PMUCNT9 =3D 117, + HEX_SREG_PMUCNT10 =3D 118, + HEX_SREG_PMUCNT11 =3D 119, + HEX_SREG_PMUSTID2 =3D 120, }; #endif /* !CONFIG_USER_ONLY */ =20 diff --git a/target/hexagon/pmu.h b/target/hexagon/pmu.h new file mode 100644 index 00000000000..60737e383b5 --- /dev/null +++ b/target/hexagon/pmu.h @@ -0,0 +1,200 @@ +/* + * Hexagon PMU event definitions + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HEXAGON_TARGET_PMU_H +#define HEXAGON_TARGET_PMU_H + +#include "hex_regs.h" + +enum { + PMU_NO_EVENT =3D 0x000, + COMMITTED_PKT_ANY =3D 0x003, + COMMITTED_PKT_T0 =3D 0x00c, + COMMITTED_PKT_T1 =3D 0x00d, + COMMITTED_PKT_T2 =3D 0x00e, + COMMITTED_PKT_T3 =3D 0x00f, + COMMITTED_PKT_T4 =3D 0x010, + COMMITTED_PKT_T5 =3D 0x011, + COMMITTED_PKT_T6 =3D 0x015, + COMMITTED_PKT_T7 =3D 0x016, + COMMITTED_PKT_T8 =3D 0x1c5, + COMMITTED_PKT_T9 =3D 0x1c6, + COMMITTED_PKT_T10 =3D 0x1c7, + COMMITTED_PKT_T11 =3D 0x1c8, + COMMITTED_PKT_T12 =3D 0x1c9, + COMMITTED_PKT_T13 =3D 0x1ca, + COMMITTED_PKT_T14 =3D 0x1cb, + COMMITTED_PKT_T15 =3D 0x1cc, + COMMITTED_LD =3D 0x030, + COMMITTED_ST =3D 0x031, + COMMITTED_MEMOP =3D 0x032, + HVX_PKT =3D 0x111, + HVX_PKT_THREAD =3D 0x112, + HVXPIPE_ALU =3D 0x128, + HVXPIPE_MPY =3D 0x129, + HVXPIPE_SHIFT =3D 0x12a, + HVXPIPE_PERM =3D 0x12b, + HLXFIFO_PKT =3D 0x1a2, + HLXLD =3D 0x1a6, + HLXST =3D 0x1aa, + HLXSLOT_ALU =3D 0x1af, + HLXSLOT_SHIFT =3D 0x1b0, + HLXSLOT_MPY =3D 0x1b1, + HLXSLOT_LD =3D 0x1b2, + HLXSLOT_ST =3D 0x1b3, + CYCLES_1_HVX_CONTEXTS_RUNNING =3D 0x115, + CYCLES_2_HVX_CONTEXTS_RUNNING =3D 0x116, + CYCLES_3_HVX_CONTEXTS_RUNNING =3D 0x117, + CYCLES_4_HVX_CONTEXTS_RUNNING =3D 0x12c, + CYCLES_5_HVX_CONTEXTS_RUNNING =3D 0x191, + CYCLES_6_HVX_CONTEXTS_RUNNING =3D 0x192, +}; + +#define HEX_PMU_IMPLEMENTED_EVENTS \ + DECL_PMU_EVENT(PMU_NO_EVENT, 0x000) \ + DECL_PMU_EVENT(COMMITTED_PKT_ANY, 0x003) \ + DECL_PMU_EVENT(COMMITTED_PKT_T0, 0x00c) \ + DECL_PMU_EVENT(COMMITTED_PKT_T1, 0x00d) \ + DECL_PMU_EVENT(COMMITTED_PKT_T2, 0x00e) \ + DECL_PMU_EVENT(COMMITTED_PKT_T3, 0x00f) \ + DECL_PMU_EVENT(COMMITTED_PKT_T4, 0x010) \ + DECL_PMU_EVENT(COMMITTED_PKT_T5, 0x011) \ + DECL_PMU_EVENT(COMMITTED_PKT_T6, 0x015) \ + DECL_PMU_EVENT(COMMITTED_PKT_T7, 0x016) \ + DECL_PMU_EVENT(COMMITTED_PKT_T8, 0x1c5) \ + DECL_PMU_EVENT(COMMITTED_PKT_T9, 0x1c6) \ + DECL_PMU_EVENT(COMMITTED_PKT_T10, 0x1c7) \ + DECL_PMU_EVENT(COMMITTED_PKT_T11, 0x1c8) \ + DECL_PMU_EVENT(COMMITTED_PKT_T12, 0x1c9) \ + DECL_PMU_EVENT(COMMITTED_PKT_T13, 0x1ca) \ + DECL_PMU_EVENT(COMMITTED_PKT_T14, 0x1cb) \ + DECL_PMU_EVENT(COMMITTED_PKT_T15, 0x1cc) \ + DECL_PMU_EVENT(COMMITTED_LD, 0x030) \ + DECL_PMU_EVENT(COMMITTED_ST, 0x031) \ + DECL_PMU_EVENT(COMMITTED_MEMOP, 0x032) \ + DECL_PMU_EVENT(HVX_PKT, 0x111) \ + DECL_PMU_EVENT(HVX_PKT_THREAD, 0x112) \ + DECL_PMU_EVENT(HVXPIPE_ALU, 0x128) \ + DECL_PMU_EVENT(HVXPIPE_MPY, 0x129) \ + DECL_PMU_EVENT(HVXPIPE_SHIFT, 0x12a) \ + DECL_PMU_EVENT(HVXPIPE_PERM, 0x12b) \ + DECL_PMU_EVENT(HLXFIFO_PKT, 0x1a2) \ + DECL_PMU_EVENT(HLXLD, 0x1a6) \ + DECL_PMU_EVENT(HLXST, 0x1aa) \ + DECL_PMU_EVENT(HLXSLOT_ALU, 0x1af) \ + DECL_PMU_EVENT(HLXSLOT_SHIFT, 0x1b0) \ + DECL_PMU_EVENT(HLXSLOT_MPY, 0x1b1) \ + DECL_PMU_EVENT(HLXSLOT_LD, 0x1b2) \ + DECL_PMU_EVENT(HLXSLOT_ST, 0x1b3) + +/* + * HLXLD/HLXST count in units of one 128-byte HVX-sized beat, so a full + * 2KB HLX vector access adds HLX_PMU_BEATS_PER_ACCESS to the event. This = is + * the unit the reference simulator's derived statistics assume + * (VTCM_RD_BW_HLX =3D HLXLD * 128 bytes per cycle). + */ +#define HLX_PMU_BEAT_BYTES 128 + +#define NUM_PMU_CTRS 12 + +/* An event id is 10 bits: PMUEVTCFG[7:0] and PMUCFG.MSBCNT[1:0]. */ +#define PMU_NUM_EVENT_IDS 1024 + +/* + * PMU sregs are defined in this order: 4, 5, 6, 7, 0, 1, 2, 3. + * The gregs are ordered the same way. + */ +#define IS_PMU_CNT_SREG(REG) \ + (((REG) >=3D HEX_SREG_PMUCNT4 && (REG) <=3D HEX_SREG_PMUCNT3) || \ + ((REG) >=3D HEX_SREG_PMUCNT8 && (REG) <=3D HEX_SREG_PMUCNT11)) +#define IS_PMU_CFG_SREG(REG) \ + ((REG) =3D=3D HEX_SREG_PMUEVTCFG || (REG) =3D=3D HEX_SREG_PMUEVTCFG1 |= | \ + (REG) =3D=3D HEX_SREG_PMUEVTCFG2 || (REG) =3D=3D HEX_SREG_PMUCFG || \ + (REG) =3D=3D HEX_SREG_PMUSTID0 || (REG) =3D=3D HEX_SREG_PMUSTID1 || \ + (REG) =3D=3D HEX_SREG_PMUSTID2) +#define IS_PMU_SREG(REG) (IS_PMU_CNT_SREG(REG) || IS_PMU_CFG_SREG(REG)) + +#ifndef CONFIG_USER_ONLY +#define IS_PMU_GREG(REG) \ + (((REG) >=3D HEX_GREG_GPMUCNT4 && (REG) <=3D HEX_GREG_GPMUCNT7) || \ + ((REG) >=3D HEX_GREG_GPMUCNT0 && (REG) <=3D HEX_GREG_GPMUCNT3) || \ + ((REG) >=3D HEX_GREG_GPMUCNT8 && (REG) <=3D HEX_GREG_GPMUCNT9)) + +static inline unsigned int pmu_index_from_sreg(int reg) +{ + g_assert(IS_PMU_CNT_SREG(reg)); + if (reg >=3D HEX_SREG_PMUCNT8) { + return 8 + reg - HEX_SREG_PMUCNT8; + } + if (reg >=3D HEX_SREG_PMUCNT0) { + return reg - HEX_SREG_PMUCNT0; + } + return 4 + reg - HEX_SREG_PMUCNT4; +} + +/* The first counter whose event is selected by this PMUEVTCFG register */ +static inline unsigned int pmu_evtcfg_base(int reg) +{ + switch (reg) { + case HEX_SREG_PMUEVTCFG: + return 0; + case HEX_SREG_PMUEVTCFG1: + return 4; + default: + g_assert(reg =3D=3D HEX_SREG_PMUEVTCFG2); + return 8; + } +} + +/* Which PMUSTID register holds the STID match of this counter */ +static inline unsigned int pmu_stid_index(int reg) +{ + switch (reg) { + case HEX_SREG_PMUSTID0: + return 0; + case HEX_SREG_PMUSTID1: + return 1; + default: + g_assert(reg =3D=3D HEX_SREG_PMUSTID2); + return 2; + } +} + +/* + * Where PMUCFG holds bits 9:8 of counter @index's event: bits 15:0 for + * the first 8 counters, and bits 28:21, past the thread mode, for the res= t. + */ +static inline unsigned int pmu_cfg_msb_shift(unsigned int index) +{ + return index < 8 ? index * 2 : 21 + (index - 8) * 2; +} + +static inline unsigned int pmu_index_from_greg(int reg) +{ + g_assert(IS_PMU_GREG(reg)); + if (reg >=3D HEX_GREG_GPMUCNT8) { + return 8 + reg - HEX_GREG_GPMUCNT8; + } + if (reg >=3D HEX_GREG_GPMUCNT0) { + return reg - HEX_GREG_GPMUCNT0; + } + return 4 + reg - HEX_GREG_GPMUCNT4; +} + +static inline int pmu_committed_pkt_thread(int event) +{ + /* Note that the COMMITTED_PKT_T* event numbers are not contiguous. */ + if (event >=3D COMMITTED_PKT_T8) { + return 8 + event - COMMITTED_PKT_T8; + } + return event < COMMITTED_PKT_T6 ? + event - COMMITTED_PKT_T0 : + 6 + event - COMMITTED_PKT_T6; +} +#endif /* !CONFIG_USER_ONLY */ + +#endif /* HEXAGON_TARGET_PMU_H */ diff --git a/target/hexagon/translate.h b/target/hexagon/translate.h index b2573f051b2..0762ad700c4 100644 --- a/target/hexagon/translate.h +++ b/target/hexagon/translate.h @@ -111,6 +111,14 @@ typedef struct DisasContext { DECLARE_BITMAP(lregs_updated_tmp, NUM_LREGS); bool hmx_coproc_enabled; bool hmx_check_emitted; +#ifndef CONFIG_USER_ONLY + bool pmu_enabled; + /* + * PMU events from packets already translated in this TB but not yet + * added to the vCPU's tallies; see gen_pmu_flush(). + */ + PMUCounters pmu_pend; +#endif } DisasContext; =20 bool is_gather_store_insn(DisasContext *ctx); @@ -426,10 +434,37 @@ extern TCGv_ptr hex_hvx_ptr; #ifndef CONFIG_USER_ONLY extern TCGv_i32 hex_greg[NUM_GREGS]; extern TCGv_i32 hex_t_sreg[NUM_SREGS]; + +/* + * Per-vCPU PMU tallies, mapped onto CPUHexagonState's embedded PMUCounters + * (see cpu.h). Packet commit only accumulates translation-time constants + * in DisasContext.pmu_pend; gen_pmu_flush() adds them to these at the poi= nts + * where the tallies can be observed. See update_pmu_counters() in + * translate.c. + */ +extern TCGv_i32 hex_pmu_num_packets; +extern TCGv_i32 hex_pmu_xe_packets; +extern TCGv_i32 hex_pmu_committed_loads; +extern TCGv_i32 hex_pmu_committed_stores; +extern TCGv_i32 hex_pmu_committed_memops; +extern TCGv_i32 hex_pmu_hvx_packets; +extern TCGv_i32 hex_pmu_hvx_pipe_alu; +extern TCGv_i32 hex_pmu_hvx_pipe_mpy; +extern TCGv_i32 hex_pmu_hvx_pipe_shift; +extern TCGv_i32 hex_pmu_hvx_pipe_perm; +extern TCGv_i32 hex_pmu_hlx_packets; +extern TCGv_i32 hex_pmu_hlx_slot_alu; +extern TCGv_i32 hex_pmu_hlx_slot_shift; +extern TCGv_i32 hex_pmu_hlx_slot_mpy; +extern TCGv_i32 hex_pmu_hlx_slot_ld; +extern TCGv_i32 hex_pmu_hlx_slot_st; #endif =20 =20 void hex_gen_exception_end_tb(DisasContext *ctx, int cause); +#ifndef CONFIG_USER_ONLY +void gen_pmu_flush(DisasContext *ctx); +#endif =20 void process_store(DisasContext *ctx, int slot_num); =20 diff --git a/target/hexagon/reg_fields_def.h.inc b/target/hexagon/reg_field= s_def.h.inc index 32dbb2da30d..2eedc6f4a02 100644 --- a/target/hexagon/reg_fields_def.h.inc +++ b/target/hexagon/reg_fields_def.h.inc @@ -159,3 +159,24 @@ DEF_REG_FIELD(ISDBST_MBXINSTATUS, 2, 1) DEF_REG_FIELD(ISDBST_MBXOUTSTATUS, 1, 1) DEF_REG_FIELD(ISDBST_READY, 0, 1) DEF_REG_FIELD(ISDBST2_DEBUGMODE, 16, 16) + +/* PMUEVTCFG/PMUEVTCFG1 fields: low 8 bits of each counter's event id */ +DEF_REG_FIELD(PMUEVTCFG_CNT0_LSB, 0, 8) +DEF_REG_FIELD(PMUEVTCFG_CNT1_LSB, 8, 8) +DEF_REG_FIELD(PMUEVTCFG_CNT2_LSB, 16, 8) +DEF_REG_FIELD(PMUEVTCFG_CNT3_LSB, 24, 8) + +/* PMUCFG fields: high 2 bits of each counter's event id, plus thread mode= */ +DEF_REG_FIELD(PMUCFG_CNT0_MSB, 0, 2) +DEF_REG_FIELD(PMUCFG_CNT1_MSB, 2, 2) +DEF_REG_FIELD(PMUCFG_CNT2_MSB, 4, 2) +DEF_REG_FIELD(PMUCFG_CNT3_MSB, 6, 2) +DEF_REG_FIELD(PMUCFG_CNT4_MSB, 8, 2) +DEF_REG_FIELD(PMUCFG_CNT5_MSB, 10, 2) +DEF_REG_FIELD(PMUCFG_CNT6_MSB, 12, 2) +DEF_REG_FIELD(PMUCFG_CNT7_MSB, 14, 2) +DEF_REG_FIELD(PMUCFG_THMODE, 16, 5) +DEF_REG_FIELD(PMUCFG_CNT8_MSB, 21, 2) +DEF_REG_FIELD(PMUCFG_CNT9_MSB, 23, 2) +DEF_REG_FIELD(PMUCFG_CNT10_MSB, 25, 2) +DEF_REG_FIELD(PMUCFG_CNT11_MSB, 27, 2) diff --git a/hw/hexagon/hex-subsys.c b/hw/hexagon/hex-subsys.c index 52ec0cadacc..5c2ce970c56 100644 --- a/hw/hexagon/hex-subsys.c +++ b/hw/hexagon/hex-subsys.c @@ -12,6 +12,7 @@ #include "hw/hexagon/hexagon_hlx.h" #include "hw/hexagon/hexagon_hvx_context.h" #include "hw/hexagon/hexagon_hmx_context.h" +#include "hw/hexagon/hexagon_pmu.h" #include "hw/hexagon/hexagon_tlb.h" #include "hw/intc/hex-l2vic.h" #include "hw/timer/qct-qtimer.h" @@ -148,6 +149,16 @@ static void hmx_context_create(HexagonCommonMachineSta= te *hms, sysbus_realize_and_unref(SYS_BUS_DEVICE(ctx), &error_fatal); } =20 +static DeviceState *pmu_create(HexagonCommonMachineState *hms) +{ + DeviceState *pmu =3D qdev_new(TYPE_HEXAGON_PMU); + + object_property_add_child(OBJECT(hms), "pmu", OBJECT(pmu)); + sysbus_realize_and_unref(SYS_BUS_DEVICE(pmu), &error_fatal); + + return pmu; +} + static DeviceState *cluster_create(HexagonCommonMachineState *hms) { DeviceState *cluster =3D qdev_new(TYPE_CPU_CLUSTER); @@ -197,6 +208,7 @@ void hex_subsys_create(HexagonCommonMachineState *hms, hvx_contexts_create(hms, m_cfg); hms->hlx =3D hlx_create(hms, m_cfg); hmx_context_create(hms, m_cfg); + hms->pmu =3D pmu_create(hms); } =20 void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu) @@ -212,6 +224,8 @@ void hex_subsys_add_cpu(HexagonCommonMachineState *hms,= DeviceState *cpu) &error_fatal); object_property_set_link(OBJECT(cpu), "hlx", OBJECT(hms->hlx), &error_fatal); + object_property_set_link(OBJECT(cpu), "pmu", OBJECT(hms->pmu), + &error_fatal); for (unsigned i =3D 0; i < hms->num_hvx_ctx; i++) { g_autofree char *name =3D g_strdup_printf("hvx-context[%u]", i); Object *ctx =3D object_resolve_path_component(OBJECT(hms), name); diff --git a/hw/hexagon/hexagon_globalreg.c b/hw/hexagon/hexagon_globalreg.c index 8b50fec770a..fa9e1b0cd93 100644 --- a/hw/hexagon/hexagon_globalreg.c +++ b/hw/hexagon/hexagon_globalreg.c @@ -396,14 +396,6 @@ static void do_hexagon_globalreg_reset(HexagonGlobalRe= gState *s) s->regs[HEX_SREG_PCYCLEHI] =3D INVALID_REG_VAL; s->regs[HEX_SREG_TIMERLO] =3D INVALID_REG_VAL; s->regs[HEX_SREG_TIMERHI] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT0] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT1] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT2] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT3] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT4] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT5] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT6] =3D INVALID_REG_VAL; - s->regs[HEX_SREG_PMUCNT7] =3D INVALID_REG_VAL; } =20 static void hexagon_globalreg_reset_hold(Object *obj, ResetType type) @@ -448,14 +440,21 @@ static int hexagon_globalreg_post_load(void *opaque, return 0; } =20 +/* + * The registers the device had in version 1 of its migration state. The + * ones that were added since follow the other fields, in version 2. + */ +#define HEX_GLOBALREG_MIGRATED_V1 106 + static const VMStateDescription vmstate_hexagon_globalreg =3D { .name =3D "hexagon_globalreg", - .version_id =3D 1, + .version_id =3D 2, .minimum_version_id =3D 1, .pre_save =3D hexagon_globalreg_pre_save, .post_load =3D hexagon_globalreg_post_load, .fields =3D (const VMStateField[]){ - VMSTATE_UINT32_ARRAY(regs, HexagonGlobalRegState, NUM_SREGS), + VMSTATE_UINT32_SUB_ARRAY(regs, HexagonGlobalRegState, 0, + HEX_GLOBALREG_MIGRATED_V1), VMSTATE_UINT64(g_pcycle_base, HexagonGlobalRegState), VMSTATE_UINT32(boot_evb, HexagonGlobalRegState), VMSTATE_UINT64(config_table_addr, HexagonGlobalRegState), @@ -464,6 +463,10 @@ static const VMStateDescription vmstate_hexagon_global= reg =3D { VMSTATE_BOOL(isdben_dfd_enable, HexagonGlobalRegState), VMSTATE_BOOL(isdben_trusted, HexagonGlobalRegState), VMSTATE_BOOL(isdben_secure, HexagonGlobalRegState), + VMSTATE_SUB_ARRAY(regs, HexagonGlobalRegState, + HEX_GLOBALREG_MIGRATED_V1, + NUM_SREGS - HEX_GLOBALREG_MIGRATED_V1, 2, + vmstate_info_uint32, uint32_t), VMSTATE_END_OF_LIST() } }; diff --git a/hw/hexagon/hexagon_pmu.c b/hw/hexagon/hexagon_pmu.c new file mode 100644 index 00000000000..29f9ef38e1a --- /dev/null +++ b/hw/hexagon/hexagon_pmu.c @@ -0,0 +1,113 @@ +/* + * Hexagon PMU QOM Object + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/hexagon/hexagon_pmu.h" +#include "hw/core/qdev-properties.h" +#include "migration/vmstate.h" + +uint16_t hexagon_pmu_get_event(HexagonPMUState *s, unsigned int index) +{ + g_assert(index < NUM_PMU_CTRS); + return s->events[index]; +} + +void hexagon_pmu_set_event(HexagonPMUState *s, unsigned int index, + uint16_t event) +{ + g_assert(index < NUM_PMU_CTRS); + s->events[index] =3D event; +} + +uint32_t hexagon_pmu_get_offset(HexagonPMUState *s, unsigned int index) +{ + g_assert(index < NUM_PMU_CTRS); + return s->ctr_offset[index]; +} + +void hexagon_pmu_set_offset(HexagonPMUState *s, unsigned int index, + uint32_t offset) +{ + g_assert(index < NUM_PMU_CTRS); + s->ctr_offset[index] =3D offset; +} + +uint32_t hexagon_pmu_get_thread_mask(HexagonPMUState *s) +{ + return s->thread_mask; +} + +void hexagon_pmu_set_thread_mask(HexagonPMUState *s, uint32_t mask) +{ + s->thread_mask =3D mask; +} + +bool hexagon_pmu_test_and_set_unimp_logged(HexagonPMUState *s, int event) +{ + g_assert(event >=3D 0 && event < PMU_NUM_EVENT_IDS); + return test_and_set_bit(event, s->unimp_logged); +} + +uint32_t hexagon_pmu_get_stid(HexagonPMUState *s, unsigned int index) +{ + g_assert(index < ARRAY_SIZE(s->stid)); + return s->stid[index]; +} + +void hexagon_pmu_set_stid(HexagonPMUState *s, unsigned int index, + uint32_t value) +{ + g_assert(index < ARRAY_SIZE(s->stid)); + s->stid[index] =3D value; +} + +static void hexagon_pmu_reset_hold(Object *obj, ResetType type) +{ + HexagonPMUState *s =3D HEXAGON_PMU(obj); + + memset(s->events, 0, sizeof(s->events)); + memset(s->ctr_offset, 0, sizeof(s->ctr_offset)); + s->thread_mask =3D 0; + memset(s->stid, 0, sizeof(s->stid)); +} + +static const VMStateDescription vmstate_hexagon_pmu =3D { + .name =3D "hexagon_pmu", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT16_ARRAY(events, HexagonPMUState, NUM_PMU_CTRS), + VMSTATE_UINT32_ARRAY(ctr_offset, HexagonPMUState, NUM_PMU_CTRS), + VMSTATE_UINT32(thread_mask, HexagonPMUState), + VMSTATE_UINT32_ARRAY(stid, HexagonPMUState, 3), + VMSTATE_END_OF_LIST() + } +}; + +static void hexagon_pmu_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.hold =3D hexagon_pmu_reset_hold; + dc->vmsd =3D &vmstate_hexagon_pmu; + dc->user_creatable =3D false; +} + +static const TypeInfo hexagon_pmu_info =3D { + .name =3D TYPE_HEXAGON_PMU, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(HexagonPMUState), + .class_init =3D hexagon_pmu_class_init, +}; + +static void hexagon_pmu_register_types(void) +{ + type_register_static(&hexagon_pmu_info); +} + +type_init(hexagon_pmu_register_types) diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 3575b31d196..278bd439db7 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -47,6 +47,7 @@ #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_hvx_context.h" #include "hw/hexagon/hexagon_hmx_context.h" +#include "hw/hexagon/hexagon_pmu.h" #endif =20 static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model) @@ -76,6 +77,8 @@ static const Property hexagon_cpu_properties[] =3D { DEFINE_PROP_UINT32("htid", HexagonCPU, htid, 0), DEFINE_PROP_LINK("hlx", HexagonCPU, hlx, TYPE_HEXAGON_HLX, HexagonHLXState *), + DEFINE_PROP_LINK("pmu", HexagonCPU, pmu, TYPE_HEXAGON_PMU, + HexagonPMUState *), #endif DEFINE_PROP_BOOL("lldb-compat", HexagonCPU, cfg.lldb_compat, false), DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU, cfg.lldb_stack_a= djust, @@ -118,7 +121,10 @@ const char * const hexagon_sregnames[] =3D { "commit14t", "commit15t", "commit16t", "pcycle9t", "pcycle10t", "pcycle11t", "pcycle12t", "pcycle13t", "pcycle14t", "pcycle15t", "pcycle16t", "ipend", "iad", "isdbst1", "isdbst2", - "brkptinfo1", + "brkptinfo1", "s106", "s107", "s108", "s109", + "s110", "pmuevtcfg2", "s112", "s113", "s114", + "s115", "pmucnt8", "pmucnt9", "pmucnt10", "pmucnt11", + "pmustid2", }; =20 G_STATIC_ASSERT(NUM_SREGS =3D=3D ARRAY_SIZE(hexagon_sregnames)); @@ -130,7 +136,7 @@ const char * const hexagon_gregnames[] =3D { "gpcycle6t", "gpmucnt4", "gpmucnt5", "gpmucnt6", "gpmucnt7", "gcommit7t", "gcommit8t", "gpcycle7t", "gpcycle8t", "gpcyclelo", "gpcyclehi", "gpmucnt0", "gpmucnt1", "gpmucnt2", "gpmucnt3", - "g30", "g31", + "gpmucnt8", "gpmucnt9", }; #endif /* @@ -399,6 +405,11 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState= *cs) hex_flags =3D FIELD_DP32(hex_flags, TB_FLAGS, HMX_COPROC_ENABLED, cpu->hmx && GET_SSR_FIELD(SSR_XE2, env->t_sreg[HEX_SREG_SSR= ])); + /* Like the MMU index, this runs per TB lookup: read SYSCFG unlocked. = */ + hex_flags =3D FIELD_DP32(hex_flags, TB_FLAGS, PMU_ENABLED, + GET_SYSCFG_FIELD(SYSCFG_PM, + hexagon_globalreg_read_syscfg_unlocked( + cpu->globalregs))); #else hex_flags =3D FIELD_DP32(hex_flags, TB_FLAGS, MMU_INDEX, MMU_USER_IDX); #endif @@ -518,6 +529,7 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetTy= pe type) env->k0_lock_state =3D HEX_LOCK_UNLOCKED; env->tlb_lock_count =3D 0; env->k0_lock_count =3D 0; + memset(&env->pmu, 0, sizeof(env->pmu)); =20 env->t_sreg[HEX_SREG_HTID] =3D cpu->htid; env->threadId =3D cpu->htid; @@ -995,6 +1007,17 @@ uint32_t hexagon_greg_read(CPUHexagonState *env, uint= 32_t reg) return ssr_ce ? hexagon_globalreg_read(cpu->globalregs, HEX_SREG_PCYCLEHI, env->threadId) : 0; + case HEX_GREG_GPMUCNT0: + case HEX_GREG_GPMUCNT1: + case HEX_GREG_GPMUCNT2: + case HEX_GREG_GPMUCNT3: + case HEX_GREG_GPMUCNT4: + case HEX_GREG_GPMUCNT5: + case HEX_GREG_GPMUCNT6: + case HEX_GREG_GPMUCNT7: + case HEX_GREG_GPMUCNT8: + case HEX_GREG_GPMUCNT9: + return hexagon_get_pmu_greg(env, reg); default: return env->greg[reg]; } diff --git a/target/hexagon/cpu_helper.c b/target/hexagon/cpu_helper.c index f53d377ab14..3031fe24a61 100644 --- a/target/hexagon/cpu_helper.c +++ b/target/hexagon/cpu_helper.c @@ -12,6 +12,8 @@ #include "hw/hexagon/hexagon.h" #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_hvx_context.h" +#include "hw/hexagon/hexagon_pmu.h" +#include "pmu.h" #include "hex_interrupts.h" #include "hex_mmu.h" #include "system/runstate.h" @@ -88,9 +90,283 @@ void hexagon_peek_memory_range(CPUHexagonState *env, ui= nt32_t start_addr, =20 #endif =20 -uint32_t hexagon_get_pmu_counter(CPUHexagonState *cur_env, int index) +#define pmu_sum_all(field) ({ \ + uint32_t total_ =3D 0; \ + CPU_FOREACH(cs) { \ + total_ +=3D cpu_env(cs)->pmu.field; \ + } \ + total_; \ +}) + +static uint32_t hexagon_pmu_event_stats(CPUHexagonState *env, int event) { - g_assert_not_reached(); + CPUState *cs; + + g_assert(bql_locked()); + + switch (event) { + case PMU_NO_EVENT: + return 0; + + case COMMITTED_PKT_ANY: { + uint32_t total =3D 0; + CPU_FOREACH(cs) { + total +=3D cpu_env(cs)->pmu.num_packets; + } + return total; + } + case HVX_PKT: { + uint32_t total =3D 0; + CPU_FOREACH(cs) { + total +=3D cpu_env(cs)->pmu.hvx_packets; + } + return total; + } + + case COMMITTED_PKT_T0: + case COMMITTED_PKT_T1: + case COMMITTED_PKT_T2: + case COMMITTED_PKT_T3: + case COMMITTED_PKT_T4: + case COMMITTED_PKT_T5: + case COMMITTED_PKT_T6: + case COMMITTED_PKT_T7: + case COMMITTED_PKT_T8: + case COMMITTED_PKT_T9: + case COMMITTED_PKT_T10: + case COMMITTED_PKT_T11: + case COMMITTED_PKT_T12: + case COMMITTED_PKT_T13: + case COMMITTED_PKT_T14: + case COMMITTED_PKT_T15: { + unsigned int tid =3D pmu_committed_pkt_thread(event); + CPU_FOREACH(cs) { + CPUHexagonState *e =3D cpu_env(cs); + if (e->threadId =3D=3D tid) { + return e->pmu.num_packets; + } + } + return 0; + } + + case COMMITTED_LD: + return pmu_sum_all(committed_loads); + case COMMITTED_ST: + return pmu_sum_all(committed_stores); + case COMMITTED_MEMOP: + return pmu_sum_all(committed_memops); + case HVX_PKT_THREAD: + return env->pmu.xe_packets; + case HVXPIPE_ALU: + return pmu_sum_all(hvx_pipe_alu); + case HVXPIPE_MPY: + return pmu_sum_all(hvx_pipe_mpy); + case HVXPIPE_SHIFT: + return pmu_sum_all(hvx_pipe_shift); + case HVXPIPE_PERM: + return pmu_sum_all(hvx_pipe_perm); + + case HLXFIFO_PKT: + return pmu_sum_all(hlx_packets); + case HLXSLOT_ALU: + return pmu_sum_all(hlx_slot_alu); + case HLXSLOT_SHIFT: + return pmu_sum_all(hlx_slot_shift); + case HLXSLOT_MPY: + return pmu_sum_all(hlx_slot_mpy); + case HLXSLOT_LD: + return pmu_sum_all(hlx_slot_ld); + case HLXSLOT_ST: + return pmu_sum_all(hlx_slot_st); + case HLXLD: + return pmu_sum_all(hlx_slot_ld) * + (HLX_VEC_SIZE_BYTES / HLX_PMU_BEAT_BYTES); + case HLXST: + return pmu_sum_all(hlx_slot_st) * + (HLX_VEC_SIZE_BYTES / HLX_PMU_BEAT_BYTES); + + default: + return 0; + } +} + +#define DECL_PMU_EVENT(name, val) case name: +static bool hexagon_pmu_event_implemented(int event) +{ + switch (event) { + HEX_PMU_IMPLEMENTED_EVENTS + return true; + default: + return false; + } +} +#undef DECL_PMU_EVENT + +static void hexagon_pmu_log_if_unimplemented(HexagonPMUState *pmu, int eve= nt) +{ + if (!hexagon_pmu_event_implemented(event) && + !hexagon_pmu_test_and_set_unimp_logged(pmu, event)) { + qemu_log_mask(LOG_UNIMP, + "PMU event 0x%x is not implemented; the counter " + "watching it will not advance\n", event); + } +} + +static uint32_t hexagon_pmu_counter_value(CPUHexagonState *env, int index) +{ + HexagonCPU *cpu =3D env_archcpu(env); + uint16_t event; + + g_assert(bql_locked()); + g_assert(index >=3D 0 && index < NUM_PMU_CTRS); + event =3D hexagon_pmu_get_event(cpu->pmu, index); + return hexagon_pmu_get_offset(cpu->pmu, index) + + hexagon_pmu_event_stats(env, event); +} + +/* + * A guest read of a counter. An event is reported as unimplemented here = and + * not when it is selected: an event takes two register writes (PMUEVTCFG + * and PMUCFG) to select, so the first can briefly select another event. + */ +uint32_t hexagon_get_pmu_counter(CPUHexagonState *env, int index) +{ + HexagonCPU *cpu =3D env_archcpu(env); + + hexagon_pmu_log_if_unimplemented(cpu->pmu, + hexagon_pmu_get_event(cpu->pmu, index= )); + return hexagon_pmu_counter_value(env, index); +} + +/* Guest wrote PMUCNTn directly: rebase without disturbing the live tally.= */ +static void hexagon_set_pmu_counter(CPUHexagonState *env, uint32_t reg, + uint32_t val) +{ + HexagonCPU *cpu =3D env_archcpu(env); + unsigned int index =3D pmu_index_from_sreg(reg); + uint16_t event =3D hexagon_pmu_get_event(cpu->pmu, index); + uint32_t offset =3D val - hexagon_pmu_event_stats(env, event); + + hexagon_pmu_set_offset(cpu->pmu, index, offset); +} + +/* + * Guest switched counter @index to a new event: keep the counter's + * displayed value continuous across the switch (real HW counters aren't + * reset by re-pointing them at a different event). + */ +static void hexagon_set_pmu_event(CPUHexagonState *env, unsigned int index, + uint16_t event) +{ + HexagonCPU *cpu =3D env_archcpu(env); + uint32_t old_value =3D hexagon_pmu_counter_value(env, index); + uint32_t new_offset; + + hexagon_pmu_set_event(cpu->pmu, index, event); + new_offset =3D old_value - hexagon_pmu_event_stats(env, event); + hexagon_pmu_set_offset(cpu->pmu, index, new_offset); +} + +uint32_t hexagon_pmu_sreg_read(CPUHexagonState *env, uint32_t reg) +{ + HexagonCPU *cpu =3D env_archcpu(env); + + g_assert(bql_locked()); + if (IS_PMU_CNT_SREG(reg)) { + return hexagon_get_pmu_counter(env, pmu_index_from_sreg(reg)); + } + switch (reg) { + case HEX_SREG_PMUEVTCFG: + case HEX_SREG_PMUEVTCFG1: + case HEX_SREG_PMUEVTCFG2: { + uint32_t val =3D 0; + unsigned int base =3D pmu_evtcfg_base(reg); + for (unsigned int i =3D 0; i < 4; i++) { + uint16_t event =3D hexagon_pmu_get_event(cpu->pmu, base + i); + val =3D deposit32(val, i * 8, 8, event & 0xff); + } + return val; + } + case HEX_SREG_PMUCFG: { + uint32_t val =3D 0; + for (unsigned int i =3D 0; i < NUM_PMU_CTRS; i++) { + uint16_t event =3D hexagon_pmu_get_event(cpu->pmu, i); + val =3D deposit32(val, pmu_cfg_msb_shift(i), 2, (event >> 8) &= 0x3); + } + val =3D deposit32(val, 16, 5, hexagon_pmu_get_thread_mask(cpu->pmu= )); + return val; + } + case HEX_SREG_PMUSTID0: + case HEX_SREG_PMUSTID1: + case HEX_SREG_PMUSTID2: + return hexagon_pmu_get_stid(cpu->pmu, pmu_stid_index(reg)); + default: + g_assert_not_reached(); + } +} + +void hexagon_pmu_sreg_write(CPUHexagonState *env, uint32_t reg, uint32_t v= al) +{ + HexagonCPU *cpu =3D env_archcpu(env); + + g_assert(bql_locked()); + if (IS_PMU_CNT_SREG(reg)) { + hexagon_set_pmu_counter(env, reg, val); + return; + } + switch (reg) { + case HEX_SREG_PMUEVTCFG: + case HEX_SREG_PMUEVTCFG1: + case HEX_SREG_PMUEVTCFG2: { + unsigned int base =3D pmu_evtcfg_base(reg); + for (unsigned int i =3D 0; i < 4; i++) { + unsigned int index =3D base + i; + uint16_t old_event =3D hexagon_pmu_get_event(cpu->pmu, index); + uint16_t new_event =3D deposit32(old_event, 0, 8, + extract32(val, i * 8, 8)); + hexagon_set_pmu_event(env, index, new_event); + } + break; + } + case HEX_SREG_PMUCFG: { + uint32_t new_thmask =3D extract32(val, 16, 5); + + if (new_thmask !=3D 0) { + qemu_log_mask(LOG_UNIMP, + "PMUCFG: only thread mode 0 is implemented\n"); + } + hexagon_pmu_set_thread_mask(cpu->pmu, new_thmask); + for (unsigned int i =3D 0; i < NUM_PMU_CTRS; i++) { + uint16_t old_event =3D hexagon_pmu_get_event(cpu->pmu, i); + uint16_t new_event =3D deposit32(old_event, 8, 2, + extract32(val, pmu_cfg_msb_shif= t(i), + 2)); + hexagon_set_pmu_event(env, i, new_event); + } + break; + } + case HEX_SREG_PMUSTID0: + case HEX_SREG_PMUSTID1: + case HEX_SREG_PMUSTID2: + if (val !=3D 0) { + qemu_log_mask(LOG_UNIMP, "PMUSTID%u is not implemented\n", + pmu_stid_index(reg)); + } + hexagon_pmu_set_stid(cpu->pmu, pmu_stid_index(reg), val); + break; + default: + g_assert_not_reached(); + } +} + +uint32_t hexagon_get_pmu_greg(CPUHexagonState *env, uint32_t greg) +{ + uint32_t ssr =3D env->t_sreg[HEX_SREG_SSR]; + + if (!GET_SSR_FIELD(SSR_PE, ssr)) { + return 0; + } + return hexagon_get_pmu_counter(env, pmu_index_from_greg(greg)); } =20 static void hexagon_resume_thread(CPUHexagonState *env) diff --git a/target/hexagon/gdbstub.c b/target/hexagon/gdbstub.c index 1065f3a826a..bdb60b8c6e7 100644 --- a/target/hexagon/gdbstub.c +++ b/target/hexagon/gdbstub.c @@ -22,6 +22,7 @@ #include "internal.h" #ifndef CONFIG_USER_ONLY #include "cpu_helper.h" +#include "pmu.h" #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_hlx.h" #endif @@ -94,7 +95,8 @@ int hexagon_sys_gdb_read_register(CPUState *cs, GByteArra= y *mem_buf, int n) if (n < HEX_SREG_GLB_START) { val =3D env->t_sreg[n]; } else { - val =3D cpu->globalregs ? + val =3D IS_PMU_SREG(n) ? hexagon_pmu_sreg_read(env, n) : + cpu->globalregs ? hexagon_globalreg_read(cpu->globalregs, n, env->threadId) = : 0; } return gdb_get_reg32(mem_buf, val); @@ -127,6 +129,8 @@ int hexagon_sys_gdb_write_register(CPUState *cs, uint8_= t *mem_buf, int n) hexagon_modify_ccr(env, val, old); } else if (n < HEX_SREG_GLB_START) { env->t_sreg[n] =3D val; + } else if (IS_PMU_SREG(n)) { + hexagon_pmu_sreg_write(env, n, val); } else if (cpu->globalregs) { hexagon_globalreg_write(cpu->globalregs, n, val, env->threadId= ); } diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c index 4688afb16d2..fcdfff039ac 100644 --- a/target/hexagon/genptr.c +++ b/target/hexagon/genptr.c @@ -150,6 +150,14 @@ const target_ulong reg_immut_masks[TOTAL_PER_THREAD_RE= GS] =3D { [HEX_REG_GP] =3D 0x3f, [HEX_REG_UPCYCLELO] =3D IMMUTABLE, [HEX_REG_UPCYCLEHI] =3D IMMUTABLE, + [HEX_REG_UPMUCNT0] =3D IMMUTABLE, + [HEX_REG_UPMUCNT1] =3D IMMUTABLE, + [HEX_REG_UPMUCNT2] =3D IMMUTABLE, + [HEX_REG_UPMUCNT3] =3D IMMUTABLE, + [HEX_REG_UPMUCNT4] =3D IMMUTABLE, + [HEX_REG_UPMUCNT5] =3D IMMUTABLE, + [HEX_REG_UPMUCNT6] =3D IMMUTABLE, + [HEX_REG_UPMUCNT7] =3D IMMUTABLE, [HEX_REG_UTIMERLO] =3D IMMUTABLE, [HEX_REG_UTIMERHI] =3D IMMUTABLE, }; @@ -462,6 +470,14 @@ static inline void gen_read_ctrl_reg(DisasContext *ctx= , const int reg_num, translator_io_start(&ctx->base); gen_helper_upcycle_read(dest, tcg_env, tcg_constant_i32(HEX_SREG_PCYCLEHI)); + } else if (reg_num >=3D HEX_REG_UPMUCNT0 && reg_num <=3D HEX_REG_UPMUC= NT7) { + int index =3D reg_num - HEX_REG_UPMUCNT0; + int sreg =3D index < 4 ? HEX_SREG_PMUCNT0 + index : + HEX_SREG_PMUCNT4 + index - 4; + + gen_pmu_flush(ctx); + translator_io_start(&ctx->base); + gen_helper_upmucnt_read(dest, tcg_env, tcg_constant_i32(sreg)); #else } else if (reg_num =3D=3D HEX_REG_UTIMERLO) { TCGv_i64 utimer =3D tcg_temp_new_i64(); @@ -498,6 +514,13 @@ static inline void gen_read_ctrl_reg_pair(DisasContext= *ctx, const int reg_num, } else if (reg_num =3D=3D HEX_REG_UPCYCLELO) { translator_io_start(&ctx->base); gen_helper_upcycle_read_pair(dest, tcg_env); + } else if (reg_num >=3D HEX_REG_UPMUCNT0 && reg_num < HEX_REG_UPMUCNT7= ) { + TCGv lo =3D tcg_temp_new(); + TCGv hi =3D tcg_temp_new(); + + gen_read_ctrl_reg(ctx, reg_num, lo); + gen_read_ctrl_reg(ctx, reg_num + 1, hi); + tcg_gen_concat_i32_i64(dest, lo, hi); #else } else if (reg_num =3D=3D HEX_REG_UTIMERLO) { /* One helper call, so the pair is a coherent 64-bit snapshot. */ diff --git a/target/hexagon/machine.c b/target/hexagon/machine.c index 4d2b09c5195..d6424296fc9 100644 --- a/target/hexagon/machine.c +++ b/target/hexagon/machine.c @@ -63,15 +63,49 @@ static const VMStateInfo vmstate_info_hlxvector =3D { =20 #define VMSTATE_HLXVECTOR_ARRAY_V(_f, _s, _n, _v) \ VMSTATE_SUB_ARRAY(_f, _s, 0, _n, _v, vmstate_info_hlxvector, HLXVector) + +/* + * Only the per-thread system registers, which are below HEX_SREG_GLB_STAR= T, + * are used in t_sreg. Migrate the 106 entries that it once had, so that = the + * stream is unchanged by the addition of system registers past those. + */ +#define HEX_T_SREG_MIGRATED 106 + +static const VMStateDescription vmstate_hexagon_pmu_counters =3D { + .name =3D "hexagon_pmu_counters", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(num_packets, PMUCounters), + VMSTATE_UINT32(xe_packets, PMUCounters), + VMSTATE_UINT32(committed_loads, PMUCounters), + VMSTATE_UINT32(committed_stores, PMUCounters), + VMSTATE_UINT32(committed_memops, PMUCounters), + VMSTATE_UINT32(hvx_packets, PMUCounters), + VMSTATE_UINT32(hvx_pipe_alu, PMUCounters), + VMSTATE_UINT32(hvx_pipe_mpy, PMUCounters), + VMSTATE_UINT32(hvx_pipe_shift, PMUCounters), + VMSTATE_UINT32(hvx_pipe_perm, PMUCounters), + VMSTATE_UINT32(hlx_packets, PMUCounters), + VMSTATE_UINT32(hlx_slot_alu, PMUCounters), + VMSTATE_UINT32(hlx_slot_shift, PMUCounters), + VMSTATE_UINT32(hlx_slot_mpy, PMUCounters), + VMSTATE_UINT32(hlx_slot_ld, PMUCounters), + VMSTATE_UINT32(hlx_slot_st, PMUCounters), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_hexagon_cpu =3D { .name =3D "cpu", - .version_id =3D 4, + .version_id =3D 5, .minimum_version_id =3D 2, .post_load =3D hexagon_cpu_post_load, .fields =3D (const VMStateField[]) { VMSTATE_UINT32_ARRAY(env.gpr, HexagonCPU, TOTAL_PER_THREAD_REGS), VMSTATE_UINT32_ARRAY(env.pred, HexagonCPU, NUM_PREGS), - VMSTATE_UINT32_ARRAY(env.t_sreg, HexagonCPU, NUM_SREGS), + VMSTATE_UINT32_SUB_ARRAY(env.t_sreg, HexagonCPU, 0, + HEX_T_SREG_MIGRATED), VMSTATE_UINT32_ARRAY(env.greg, HexagonCPU, NUM_GREGS), VMSTATE_UINT32(env.tlb_lock_state, HexagonCPU), VMSTATE_UINT32(env.k0_lock_state, HexagonCPU), @@ -83,6 +117,8 @@ const VMStateDescription vmstate_hexagon_cpu =3D { VMSTATE_UINT32(env.imprecise_exception, HexagonCPU), VMSTATE_UINT32_V(env.cfi_active, HexagonCPU, 3), VMSTATE_HLXVECTOR_ARRAY_V(env.future_LRegs, HexagonCPU, NUM_LREGS,= 4), + VMSTATE_STRUCT(env.pmu, HexagonCPU, 5, vmstate_hexagon_pmu_counter= s, + PMUCounters), =20 VMSTATE_END_OF_LIST() }, diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c index 71b27ef07f1..57b88868856 100644 --- a/target/hexagon/op_helper.c +++ b/target/hexagon/op_helper.c @@ -47,6 +47,7 @@ #endif #ifndef CONFIG_USER_ONLY #include "hw/hexagon/hexagon_globalreg.h" +#include "pmu.h" #include "hex_mmu.h" #include "hw/hexagon/hexagon_tlb.h" #include "hw/intc/hex-l2vic.h" @@ -1999,6 +2000,8 @@ void HELPER(sreg_write_masked)(CPUHexagonState *env, = uint32_t reg, uint32_t val) val =3D deposit32(env->t_sreg[reg], 0, 16, val); } env->t_sreg[reg] =3D val; + } else if (IS_PMU_SREG(reg)) { + hexagon_pmu_sreg_write(env, reg, val); } else { HexagonCPU *cpu =3D env_archcpu(env); if (cpu->globalregs) { @@ -2031,6 +2034,9 @@ static inline QEMU_ALWAYS_INLINE uint32_t sreg_read(C= PUHexagonState *env, if (reg < HEX_SREG_GLB_START) { return env->t_sreg[reg]; } + if (IS_PMU_SREG(reg)) { + return hexagon_pmu_sreg_read(env, reg); + } return cpu->globalregs ? hexagon_globalreg_read(cpu->globalregs, reg, env->threadId) : 0; } @@ -2070,6 +2076,22 @@ uint32_t HELPER(upcycle_read)(CPUHexagonState *env, = uint32_t sreg) return sreg_read(env, sreg); } =20 +/* + * UPMUCNT0-7 are the user-visible alias of the PMU counters, readable + * without privilege but only once SSR[PE] is set. + */ +uint32_t HELPER(upmucnt_read)(CPUHexagonState *env, uint32_t sreg) +{ + uint32_t ssr; + + BQL_LOCK_GUARD(); + ssr =3D env->t_sreg[HEX_SREG_SSR]; + if (!GET_SSR_FIELD(SSR_PE, ssr)) { + return 0; + } + return sreg_read(env, sreg); +} + uint64_t HELPER(upcycle_read_pair)(CPUHexagonState *env) { HexagonCPU *cpu =3D env_archcpu(env); diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index cfb2de97281..39e18afcbb5 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -81,6 +81,22 @@ TCGv_ptr hex_hvx_ptr; #ifndef CONFIG_USER_ONLY TCGv_i32 hex_greg[NUM_GREGS]; TCGv_i32 hex_t_sreg[NUM_SREGS]; +TCGv_i32 hex_pmu_num_packets; +TCGv_i32 hex_pmu_xe_packets; +TCGv_i32 hex_pmu_committed_loads; +TCGv_i32 hex_pmu_committed_stores; +TCGv_i32 hex_pmu_committed_memops; +TCGv_i32 hex_pmu_hvx_packets; +TCGv_i32 hex_pmu_hvx_pipe_alu; +TCGv_i32 hex_pmu_hvx_pipe_mpy; +TCGv_i32 hex_pmu_hvx_pipe_shift; +TCGv_i32 hex_pmu_hvx_pipe_perm; +TCGv_i32 hex_pmu_hlx_packets; +TCGv_i32 hex_pmu_hlx_slot_alu; +TCGv_i32 hex_pmu_hlx_slot_shift; +TCGv_i32 hex_pmu_hlx_slot_mpy; +TCGv_i32 hex_pmu_hlx_slot_ld; +TCGv_i32 hex_pmu_hlx_slot_st; #endif static TCGv_i32 hex_cause_code; =20 @@ -205,6 +221,7 @@ static void gen_end_tb_singlestep(DisasContext *ctx) static void gen_end_tb(DisasContext *ctx) { #ifndef CONFIG_USER_ONLY + gen_pmu_flush(ctx); if (ctx->ss_active) { gen_end_tb_singlestep(ctx); return; @@ -248,6 +265,9 @@ static void gen_end_tb(DisasContext *ctx) =20 void hex_gen_exception_end_tb(DisasContext *ctx, int cause) { +#ifndef CONFIG_USER_ONLY + gen_pmu_flush(ctx); +#endif gen_precise_exception(cause, ctx->pkt.pc); ctx->base.is_jmp =3D DISAS_NORETURN; } @@ -260,6 +280,9 @@ static void gen_exception_decode_fail(DisasContext *ctx= , int nwords, int cause) { target_ulong fail_pc =3D ctx->base.pc_next + nwords * sizeof(uint32_t); =20 +#ifndef CONFIG_USER_ONLY + gen_pmu_flush(ctx); +#endif tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], fail_pc); gen_precise_exception(cause, fail_pc); ctx->base.is_jmp =3D DISAS_NORETURN; @@ -808,6 +831,23 @@ static void gen_start_packet(DisasContext *ctx) } #endif =20 +#ifndef CONFIG_USER_ONLY + /* + * Privileged and guest instructions can read or write the PMU + * registers (or stop the thread), and a memory access can fault, which + * abandons the translation block, so make the tallies current first. + */ + if (check_for_attrib(&ctx->pkt, A_PRIV) || + check_for_attrib(&ctx->pkt, A_GUEST) || + check_for_attrib(&ctx->pkt, A_LOAD) || + check_for_attrib(&ctx->pkt, A_STORE) || + check_for_attrib(&ctx->pkt, A_CVI_VM) || + check_for_attrib(&ctx->pkt, A_HLX_MEM) || + check_for_attrib(&ctx->pkt, A_HMX)) { + gen_pmu_flush(ctx); + } +#endif + /* Initialize the runtime state for packet semantics */ if (need_slot_cancelled(&ctx->pkt)) { tcg_gen_movi_tl(hex_slot_cancelled, 0); @@ -1307,6 +1347,132 @@ static void gen_commit_hmx(DisasContext *ctx) } } =20 +#ifndef CONFIG_USER_ONLY +#define PMU_COUNTER_FIELDS(X) \ + X(num_packets) X(xe_packets) X(committed_loads) X(committed_stores) \ + X(committed_memops) X(hvx_packets) X(hvx_pipe_alu) X(hvx_pipe_mpy) \ + X(hvx_pipe_shift) X(hvx_pipe_perm) X(hlx_packets) X(hlx_slot_alu) \ + X(hlx_slot_shift) X(hlx_slot_mpy) X(hlx_slot_ld) X(hlx_slot_st) + +/* + * Add the events accumulated in ctx->pmu_pend to the vCPU's tallies. The + * per-packet counts are translation-time constants, so packet commit only + * sums them in the DisasContext and this emits one update per event, not + * one per packet. It must run, in straight-line code, before anything that + * can observe or leave the tallies: every TB exit and exception, and any + * packet that reads or writes a PMU register (privileged and guest + * instructions, and UPMUCNT reads), and before any packet that can fault, + * so that a fault only loses the packet that raised it. + */ +void gen_pmu_flush(DisasContext *ctx) +{ +#define FLUSH_ONE(f) \ + if (ctx->pmu_pend.f) { \ + tcg_gen_addi_i32(hex_pmu_##f, hex_pmu_##f, ctx->pmu_pend.f); \ + } + if (!ctx->pmu_enabled) { + return; + } + PMU_COUNTER_FIELDS(FLUSH_ONE) +#undef FLUSH_ONE + memset(&ctx->pmu_pend, 0, sizeof(ctx->pmu_pend)); +} + +/* + * Account for the packet just committed. Emits no TCG ops itself: it only + * accumulates counts in ctx->pmu_pend (see gen_pmu_flush()), and only when + * PMU_ENABLED is set for this TB (ctx->pmu_enabled), computed once in + * hexagon_get_tb_cpu_state() from SYSCFG.PM -- so a guest that hasn't + * enabled the PMU generates none of this code. + */ +static void update_pmu_counters(DisasContext *ctx) +{ + PMUCounters *pend =3D &ctx->pmu_pend; + + if (!ctx->pmu_enabled) { + return; + } + + for (int i =3D 0; i < ctx->pkt.num_insns; i++) { + int opcode =3D ctx->pkt.insn[i].opcode; + + /* + * COMMITTED_LD/ST count scalar loads and stores only: memops have + * their own event, and loads and stores of the coprocessors are + * excluded. + */ + if (GET_ATTRIB(opcode, A_MEMOP)) { + pend->committed_memops++; + } else if (!GET_ATTRIB(opcode, A_CVI) && + !GET_ATTRIB(opcode, A_HLX) && + !GET_ATTRIB(opcode, A_HMX)) { + if (GET_ATTRIB(opcode, A_LOAD)) { + pend->committed_loads++; + } + if (GET_ATTRIB(opcode, A_STORE)) { + pend->committed_stores++; + } + } + if (GET_ATTRIB(opcode, A_HLX)) { + /* + * The HLX pipes are the slots the instruction is restricted t= o: + * loads in slot 1, stores in slot 0, shifts (including the + * paired ALU forms) in slot 2, multiplies in slot 3 and the + * common ALU in either of slots 2 and 3. + */ + if (GET_ATTRIB(opcode, A_HLX_MEM)) { + if (GET_ATTRIB(opcode, A_LOAD)) { + pend->hlx_slot_ld++; + } else if (GET_ATTRIB(opcode, A_STORE)) { + pend->hlx_slot_st++; + } + } else if (GET_ATTRIB(opcode, A_HLX_MPY)) { + pend->hlx_slot_mpy++; + } else if (GET_ATTRIB(opcode, A_HLX_SHIFT)) { + pend->hlx_slot_shift++; + } else if (GET_ATTRIB(opcode, A_HLX_COMMON_ALU)) { + pend->hlx_slot_alu++; + } + continue; + } + if (!GET_ATTRIB(opcode, A_CVI)) { + continue; + } + /* + * A double-vector ALU or multiply occupies two pipes of its kind,= as + * the maximum increments of HVXPIPE_ALU and HVXPIPE_MPY show. The + * dual-function ops (A_CVI_VP_VS, A_CVI_VS_VX) aren't attributed = to + * either HVXPIPE_* bucket below: which physical pipe executes them + * isn't derivable from decode attributes alone. + */ + if (GET_ATTRIB(opcode, A_CVI_VA)) { + pend->hvx_pipe_alu++; + } else if (GET_ATTRIB(opcode, A_CVI_VA_DV)) { + pend->hvx_pipe_alu +=3D 2; + } else if (GET_ATTRIB(opcode, A_CVI_VX)) { + pend->hvx_pipe_mpy++; + } else if (GET_ATTRIB(opcode, A_CVI_VX_DV)) { + pend->hvx_pipe_mpy +=3D 2; + } else if (GET_ATTRIB(opcode, A_CVI_VS)) { + pend->hvx_pipe_shift++; + } else if (GET_ATTRIB(opcode, A_CVI_VP)) { + pend->hvx_pipe_perm++; + } + } + + pend->num_packets++; + if (ctx->hvx_coproc_enabled) { + pend->xe_packets++; + } + if (ctx->pkt.pkt_has_hvx) { + pend->hvx_packets++; + } + if (ctx->pkt.pkt_has_hlx) { + pend->hlx_packets++; + } +} +#endif + #ifndef CONFIG_USER_ONLY /* * A tlbp instruction may detect multiple TLB matches and set a pending @@ -1431,6 +1597,9 @@ static void gen_commit_packet(DisasContext *ctx) if (ctx->pkt.pkt_has_hmx) { gen_commit_hmx(ctx); } +#ifndef CONFIG_USER_ONLY + update_pmu_counters(ctx); +#endif =20 if (ctx->pkt.vhist_insn !=3D NULL) { ctx->pre_commit =3D false; @@ -1551,6 +1720,8 @@ static void hexagon_tr_init_disas_context(DisasContex= tBase *dcbase, ctx->hvx_coproc_enabled =3D FIELD_EX32(hex_flags, TB_FLAGS, HVX_COPROC_ENABLED); ctx->hvx_check_emitted =3D false; + ctx->pmu_enabled =3D FIELD_EX32(hex_flags, TB_FLAGS, PMU_ENABLED); + memset(&ctx->pmu_pend, 0, sizeof(ctx->pmu_pend)); ctx->cpu_mode =3D FIELD_EX32(hex_flags, TB_FLAGS, CPU_MODE); ctx->ss_active =3D FIELD_EX32(hex_flags, TB_FLAGS, SS_ACTIVE); if (ctx->ss_active) { @@ -1626,6 +1797,9 @@ static void hexagon_tr_tb_stop(DisasContextBase *dcba= se, CPUState *cpu) =20 switch (ctx->base.is_jmp) { case DISAS_TOO_MANY: +#ifndef CONFIG_USER_ONLY + gen_pmu_flush(ctx); +#endif tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next); #ifndef CONFIG_USER_ONLY if (ctx->ss_active) { @@ -1690,6 +1864,41 @@ void hexagon_translate_init(void) hexagon_sregnames[i]); } } + hex_pmu_num_packets =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.num_packets), "pmu_num_packets"); + hex_pmu_xe_packets =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.xe_packets), "pmu_xe_packets"); + hex_pmu_committed_loads =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.committed_loads), + "pmu_committed_loads"); + hex_pmu_committed_stores =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.committed_stores), + "pmu_committed_stores"); + hex_pmu_committed_memops =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.committed_memops), + "pmu_committed_memops"); + hex_pmu_hvx_packets =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hvx_packets), "pmu_hvx_packets"); + hex_pmu_hvx_pipe_alu =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hvx_pipe_alu), "pmu_hvx_pipe_alu"); + hex_pmu_hvx_pipe_mpy =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hvx_pipe_mpy), "pmu_hvx_pipe_mpy"); + hex_pmu_hvx_pipe_shift =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hvx_pipe_shift), "pmu_hvx_pipe_shift= "); + hex_pmu_hvx_pipe_perm =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hvx_pipe_perm), "pmu_hvx_pipe_perm"); + hex_pmu_hlx_packets =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hlx_packets), "pmu_hlx_packets"); + hex_pmu_hlx_slot_alu =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hlx_slot_alu), "pmu_hlx_slot_alu"); + hex_pmu_hlx_slot_shift =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hlx_slot_shift), "pmu_hlx_slot_shift= "); + hex_pmu_hlx_slot_mpy =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hlx_slot_mpy), "pmu_hlx_slot_mpy"); + hex_pmu_hlx_slot_ld =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hlx_slot_ld), "pmu_hlx_slot_ld"); + hex_pmu_hlx_slot_st =3D tcg_global_mem_new_i32(tcg_env, + offsetof(CPUHexagonState, pmu.hlx_slot_st), "pmu_hlx_slot_st"); #endif for (i =3D 0; i < TOTAL_PER_THREAD_REGS; i++) { hex_gpr[i] =3D tcg_global_mem_new(tcg_env, diff --git a/gdbstub/gdb-xml/hexagon-sys.xml b/gdbstub/gdb-xml/hexagon-sys.= xml index 273850a733f..e1a3b34d28a 100644 --- a/gdbstub/gdb-xml/hexagon-sys.xml +++ b/gdbstub/gdb-xml/hexagon-sys.xml @@ -120,38 +120,53 @@ + + + + + + + + + + + + + + + =20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + =20 diff --git a/hw/hexagon/meson.build b/hw/hexagon/meson.build index c56cdb081e1..6e9c9b9f95b 100644 --- a/hw/hexagon/meson.build +++ b/hw/hexagon/meson.build @@ -3,6 +3,7 @@ hexagon_ss.add(files('hexagon_tlb.c')) hexagon_ss.add(files('hexagon_globalreg.c')) hexagon_ss.add(files('hexagon_hvx_context.c')) hexagon_ss.add(files('hexagon_hmx_context.c')) +hexagon_ss.add(files('hexagon_pmu.c')) hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hex-subsys.c')) hexagon_ss.add(files('hexagon_hlx.c')) hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c')) --=20 2.34.1 From nobody Sun Nov 29 02:11:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1795718362; cv=none; d=zohomail.com; s=zohoarc; b=YqiZH4iYQ2Qnjc1GzL58wRT7N9Gnwy9wEwt9mjYuxCDvEqk8G5E5rju7tSCVnhl+/HXLtai9r4cR11Xek7FAi1phxmx11ckN8OglcVl8lm5EFiwCuXZ8nGHYHNXf1+9lkAtvl9mp7Iq5Nqt4XL1F4hxfClG/jpIgLNoshZdwf+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795718362; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZuuKX3a7uGMSVMwRaCSuQ9SrUwzZg9q5wsIpTvhiL6E=; b=jQoWS01oH3D7yXKNwJDhkT+fCEcW0+7dKPwbJBBvyv7u0bCHft9fdrdeFydD/qDb6kIx40O2GADrzGP+QUwHlq3wHG+pSTGGpI/CQzEFbzsEVBKuDIw/gMAT2km8bJyCDYY1f+Mi+GD/It5deYo84XHuSE6o2jb0rxVRf3QyUhw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795718362165276.47903974471967; Thu, 26 Nov 2026 10:39:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWeMZ-0006an-4z; Thu, 26 Nov 2026 13:38:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWeMQ-0006Xr-NK for qemu-devel@nongnu.org; Thu, 26 Nov 2026 13:38:23 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWeMO-0008Ny-Oj for qemu-devel@nongnu.org; Thu, 26 Nov 2026 13:38:22 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AQGbwWV595610 for ; Thu, 26 Nov 2026 18:38:19 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j6rf90c08-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 26 Nov 2026 18:38:19 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-383ec96a7deso7720809eec.1 for ; Thu, 26 Nov 2026 10:38:18 -0800 (PST) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385665f21aesm78687512eec.4.2026.11.26.10.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2026 10:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ZuuKX3a7uGMSVMwRaCSuQ9SrUwzZg9q5wsIpTvhiL6E=; b=gx6dKgyse8OLx2Ay +OwNcFBt71gf6P3KbnQkNKiDmW8L3gJiZo5HwMR5mfE/X9G8jvh0EF2wDZ0R4OD3 N992PbBtFjkw0Fsa3PEIkYURjn/jT10EwfQ1oiUoA5KgcjmjHhILJxq5ILb+BsaJ ui5MtprOfzSM6UI/KsAMMYD+i5Sg93hRGVexF9FZ2RQ/O6HLji++bi8T34n0Fb19 fbBbMPF/5Ggzx5quuA+5xmD+oRRz0ugnWdNdHFTv5vfr+3RqhQN9eOeTy5c6ef+5 PRKLHmQFv5gzr8fn1hsDtmaouyIQgXrUfJVHeZqgOH1lxxgaKvv535zoKKE4o77G koPSaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1795718298; x=1796323098; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ZuuKX3a7uGMSVMwRaCSuQ9SrUwzZg9q5wsIpTvhiL6E=; b=F6gC2f9YZ2NLyWDhuJIMmpq3Ci3jjagTdSQKsGZjr2r1rMIpXsn5F26b4yg5Wci0RU QdkqwP2YP+ccswBXj44zFGumUOlQ3Cjo0czbRwBJyFPYlmzsQWK6peCcro+XImgp894h 7Jgql68cj96CVwBaY3xZLmZTJ5K3E+VhddYzHxlF7TURSTCzt6mfkdZNAZbWrVZcYpho Ld881d3GseYmR+3En66CzExG/fZfNTs1Kv0F/GKFumOeznQ5SFdZdbXWuZxKx39R9AWB 94Jj5bbSyzAspwZSfDSUNBECq7MBpOUPwmvFEi1scbWRbKBsxm0UHzYFvI02okK238+y qUZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795718298; x=1796323098; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZuuKX3a7uGMSVMwRaCSuQ9SrUwzZg9q5wsIpTvhiL6E=; b=Nifz7M3sE3P0cEjgPHjq1BiZws4L3X5SaRF3LSaOxkwIc6MK+KgE5H8a0Gn678ZymA HdBkgCuYliguQK6nUPWwB8haRaEaIuKmZHL7KCtLRbJNg0BUjLMDmYaGnph1SOS6NCAA 9Mk94gXiPbaoOg0alRXk/xhKhHec7eAOJuE/LTDHtwdfAdWNqYgvhhipad2g7Nem4tEh VACl39N7JImofJ8dxUuu7lGWAMmoN6BFu79YgcbndU73/nKxuY3JIqvXBXyNUnG3CgxS i95wc6AIh9nhF0OLd3DF5vQIGOh/uJq9eZN4k8XcpxxrpGWkCa9HoO5Buy3vxhpd637M kszQ== X-Gm-Message-State: APuU4Z/5ebFR+xXPO/oPPuZm4obb37ZXKND65Ohm2+5m0UnBGNIIynzn mBbaZpo7TC2SytJPJTt7jBRoVCpE0x70SnLSmj9KgpJovadYnuWSdQRtvdVjJOyxHzPdnBYE0JM Ix0C6cpM2/zpluqwv+LmJ5eZD+jq73gNfvmM4TRHFemYB3ZbmNgbTO69sZxTgMwo8yw== X-Gm-Gg: AZFdTZc8fzKZDQw6+OqGcaX0jocnR2PrXEXkMQ0mjWWFTK6wm/WRkQBfYgkVrK037Fk 98PJ6YihPMJl8VNSF/ZcrQFvDhtT6BlJ8+JvFlzpD3y1/UwHZO8suO0JmdDVPaAvR29nZHXHEfI z0Syub6AYm639du77r4iH4lH8ablHdb6iq1G7XdbkBdRLOJmzpwQvl7wI4UvfSp4MKiNn6OjCoE 3RFs/qUKPgb418tDbmhvykzQT3EH7Hh/5o9kSeSAliV2oeTE4MdczQVm8v5UcY42D+9XaJvExvC ytV2+Uo7bdL3Zn1b9tYALolckGjC4KnJZv1KY47+ZnM1T3eQs4zINdsd9hYr+myUOO+YGiw4oAD eYK9vK8vsTDAYFHSVECquQmcoslj/OIqW6VDXYEOT3cE+sgFLnbAQwSF9kbqmCGBDbj4CqiwGAY VAdPrUPf/Bqv8/rtCtJ80TeA== X-Received: by 2002:a05:7301:2e30:b0:376:19bd:2af9 with SMTP id 5a478bee46e88-3856c2c4a0dmr24520060eec.5.1795718298272; Thu, 26 Nov 2026 10:38:18 -0800 (PST) X-Received: by 2002:a05:7301:2e30:b0:376:19bd:2af9 with SMTP id 5a478bee46e88-3856c2c4a0dmr24520040eec.5.1795718297722; Thu, 26 Nov 2026 10:38:17 -0800 (PST) From: Brian Cain To: qemu-devel@nongnu.org Cc: Brian Cain , Pierrick Bouvier Subject: [PATCH for-12.0 3/3] docs/system/hexagon: document PMU and limitations Date: Thu, 26 Nov 2026 10:38:12 -0800 Message-Id: <20261126183812.1366883-4-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261126183812.1366883-1-brian.cain@oss.qualcomm.com> References: <20261126183812.1366883-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: DLBqz8pCNB3MG7yUnx35DYsh9JxVX5ms X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTI2MDA3MyBTYWx0ZWRfX2g6oTBKl3hAT CKtVAGjSdQIQW+UwWiSL2nHUpSBX+6I89hEyyas9j63+y/CaDsRXrjH32H4jbHa9Uawcu2cMHP9 ZNaMI4BLTZ1/LimM3YcM2kiy4Cl6cd2T1QEW4ovKtRgkK5vPqP7IUymUCTPTeHeJVX2A0ffxybl NBvc5GNcDLqep5BCqLhk/f8drH5OZ4E9wde63wlHQP4bCFTK6T6pm6HlgbxXrZd2ZdUntB4AgAR mxcw3OiezIq5IiUBer6nKDEM5TaWDrNyvwaO2RLWMskix5skoLZ1b2WOHD3sDK3XRDl/Luz+fV4 PpY9QFcjDQBKzsPWC8wmFetgKnr57+WynHmKrFIBKNINvnqZUY6r9FbSSJlFdJoSuU2ZqCMxhtZ x/4ST3uzBmuyQ8b229zEXIScbnb33blpI3vQlBiDWZREMW+Wi4pgEyXL14hkF5SB3IkLf4BXQPc 0VtzB6oxCEyTwP8D6Ag== X-Authority-Analysis: v=2.4 cv=cpkOAF4i c=1 sm=1 tr=0 ts=6b087c9b cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=J0RjullpXTW1Yh16hb0A:9 a=QEXdDO2ut3YA:10 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI2MDA3MyBTYWx0ZWRfX05uODg36o1yc sUQ/X3rCA7Oa25bvCkoi8CgQNUdT9SAzpK2b6OzOjg8324D7UE1uXrjCJU3EC/Ht1oKuF56UtP9 BA2s6d1I9WhSxO9NsgQnKsbEVYR4rPs= X-Proofpoint-GUID: DLBqz8pCNB3MG7yUnx35DYsh9JxVX5ms X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-26_04,2026-11-26_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611260073 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1795718363480158500 Describe the PMU registers, which kinds of events are counted, and the main limitations of counting from a functional emulator. Signed-off-by: Brian Cain Reviewed-by: Pierrick Bouvier --- docs/system/hexagon/emulation.rst | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/system/hexagon/emulation.rst b/docs/system/hexagon/emulat= ion.rst index 41a9a8467f9..b2649e16678 100644 --- a/docs/system/hexagon/emulation.rst +++ b/docs/system/hexagon/emulation.rst @@ -33,3 +33,37 @@ HVX uses 128-byte vectors; 64-byte mode is not implement= ed. See :doc:`../../devel/hexagon-sys` and :doc:`../../devel/hexagon-l2vic` for system-register, TLB, and interrupt details relevant to OS and firmware authors. + +Performance Monitoring Unit (PMU) +---------------------------------- + +Every Hexagon system machine has a PMU with 12 event counters (``PMUCNT0`` +to ``PMUCNT11``), selected through ``PMUEVTCFG``, ``PMUEVTCFG1``, +``PMUEVTCFG2`` and ``PMUCFG``. The ``GPMUCNT`` and ``UPMUCNT`` aliases are +readable when ``SSR.PE`` is set. Counting is enabled by ``SYSCFG.PM``; whi= le +it is clear, no counting code is generated, so an idle PMU costs nothing. + +Only events that follow from decoding and committing packets are counted: + +- committed packets, in total and per hw thread +- scalar loads, stores and memops +- HVX packets and the HVX ALU, multiply, shift and permute instructions +- HLX packets, loads, stores and the HLX execution slots + +When guests select other events the counter does not advance. + +Limitations +^^^^^^^^^^^ + +- The hardware threads of a machine share one bank of counters. Events that + have no per-thread variant are summed across all threads. +- ``PMUCFG`` thread mode and ``PMUSTID`` filtering are stored and read back + but not acted on. + +For the full event list and register layout, refer to the +`Hexagon V85 PMU Events reference +`_, the +`Hexagon V85 HVX PMU Events reference +`_ an= d, +for the HLX events, the `HLX reference manual +`_. --=20 2.34.1