From patchwork Fri Sep 23 08:47:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 608584 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp149649pvb; Fri, 23 Sep 2022 01:59:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6n7lZH1ybOLqfK9B5Nct/gc35BMEAeXU2jyE5Tt9W9rEEpK4AdcqK21CfZEFrTBeg9liQh X-Received: by 2002:ac8:7a8e:0:b0:35b:b23f:d03 with SMTP id x14-20020ac87a8e000000b0035bb23f0d03mr6250730qtr.665.1663923543802; Fri, 23 Sep 2022 01:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663923543; cv=none; d=google.com; s=arc-20160816; b=YUE6LUt+lEIMRvmtJoS/6XTDEyF0lpmuCEBJZ7A+GJh6itcMobzXxz21m97LE7fAJd 105cXKiKaNhmlk9c4eZkh99nQddZv7rerIhvDsizIsZOEhFnZL4PqDd6QnEPSjKIUM/9 Hd3SeS4sSVC+nQJNXjcXecljNPGqv4C9LulolpQtihq+TftjgJdHl9KFBr5Yx4re++bH IMN7rFOvDDlb8k38hXPsmgkD6zYrGu7urlA8FNxHRs46OfF0lf12MNi61gZP//Hq+k2H MNKYxjhKfb0lqndhAbt27VRIJGITq6hrePavtOKEG1PxdBp+KxhQKe41eZTQJjUQCW2x x9BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=p3eRUasVvLycMkHCR1+QZ5Saom4oB8d9AFSscOTb4Lk=; b=sANHhgI43Au4oXpBACazAUhh7Y8SBBe3DZ70WvV4QuB3m+ns0N49K26u8uY4ZVBDfu JIkAny0Fynj3iunaW1hmclRwFpW3KH2TMTVL9u/LxtQpmaYWm7wlkrT0srY1so0j0r3Y I85kYQ0uqcG1fE/oFN10qqoRgenwoTpDveCa349eugp2485o8Lx6Ao0YYwpHM/rlS9mJ wPVh8eFv8hD3T2c3RmZvnSVXi/LQ+hEI+42ZbardfDAzIY0dMZNarNZT2zAu8aRF+sQn esqGOLZcv/3VZZqG784vDn0cBfREk8mnkOLZpltOFRMDync4GJhUGj3rjfBnXC1I6C9+ OOvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id if10-20020a0562141c4a00b0049bb7f7041dsi4639253qvb.140.2022.09.23.01.59.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Sep 2022 01:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:53414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obeWV-0003wn-9J for patch@linaro.org; Fri, 23 Sep 2022 04:59:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMQ-0005Ac-4M; Fri, 23 Sep 2022 04:48:41 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]:49141) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMB-0005J7-F8; Fri, 23 Sep 2022 04:48:33 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MYm5F6b6Qz4xGG; Fri, 23 Sep 2022 18:48:17 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4MYm5C2j1zz4xGN; Fri, 23 Sep 2022 18:48:15 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Joel Stanley , Andrew Jeffery , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= Subject: [PATCH 2/6] cpu: cache CPUClass in CPUState for hot code paths Date: Fri, 23 Sep 2022 10:47:59 +0200 Message-Id: <20220923084803.498337-3-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220923084803.498337-1-clg@kaod.org> References: <20220923084803.498337-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=gbDQ=Z2=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée The class cast checkers are quite expensive and always on (unlike the dynamic case who's checks are gated by CONFIG_QOM_CAST_DEBUG). To avoid the overhead of repeatedly checking something which should never change we cache the CPUClass reference for use in the hot code paths. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-Id: <20220811151413.3350684-3-alex.bennee@linaro.org> Signed-off-by: Cédric Le Goater --- include/hw/core/cpu.h | 9 +++++++++ cpu.c | 9 ++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 500503da1316..1a7e1a93804a 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -51,6 +51,13 @@ typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size, */ #define CPU(obj) ((CPUState *)(obj)) +/* + * The class checkers bring in CPU_GET_CLASS() which is potentially + * expensive given the eventual call to + * object_class_dynamic_cast_assert(). Because of this the CPUState + * has a cached value for the class in cs->cc which is set up in + * cpu_exec_realizefn() for use in hot code paths. + */ typedef struct CPUClass CPUClass; DECLARE_CLASS_CHECKERS(CPUClass, CPU, TYPE_CPU) @@ -317,6 +324,8 @@ struct qemu_work_item; struct CPUState { /*< private >*/ DeviceState parent_obj; + /* cache to avoid expensive CPU_GET_CLASS */ + CPUClass *cc; /*< public >*/ int nr_cores; diff --git a/cpu.c b/cpu.c index 584ac78baf96..14365e36f3a1 100644 --- a/cpu.c +++ b/cpu.c @@ -131,9 +131,8 @@ const VMStateDescription vmstate_cpu_common = { void cpu_exec_realizefn(CPUState *cpu, Error **errp) { -#ifndef CONFIG_USER_ONLY - CPUClass *cc = CPU_GET_CLASS(cpu); -#endif + /* cache the cpu class for the hotpath */ + cpu->cc = CPU_GET_CLASS(cpu); cpu_list_add(cpu); if (!accel_cpu_realizefn(cpu, errp)) { @@ -151,8 +150,8 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); } - if (cc->sysemu_ops->legacy_vmsd != NULL) { - vmstate_register(NULL, cpu->cpu_index, cc->sysemu_ops->legacy_vmsd, cpu); + if (cpu->cc->sysemu_ops->legacy_vmsd != NULL) { + vmstate_register(NULL, cpu->cpu_index, cpu->cc->sysemu_ops->legacy_vmsd, cpu); } #endif /* CONFIG_USER_ONLY */ } From patchwork Fri Sep 23 08:48:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 608582 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp147328pvb; Fri, 23 Sep 2022 01:52:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lvrOMc/NK81YYTLj+cHmMX8gkrPxawpmt15TSLvejtL7tgF0FRJebyA3O0uEIz/MTonTG X-Received: by 2002:a05:620a:170d:b0:6ce:9bad:13c6 with SMTP id az13-20020a05620a170d00b006ce9bad13c6mr4690292qkb.683.1663923164940; Fri, 23 Sep 2022 01:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663923164; cv=none; d=google.com; s=arc-20160816; b=Lhp8NGpYh7fPnEINfHFW+nxN/fy7KaUBL+b6vN4pfN6Af5H/vr7G/5J9rjED2AUWVR 4XZtTJRJPlUO7GvFEr/tyIxptwaOAaj/4ON6lpL82IXdTKkdkjT3pOyL4TnG8T1bcSkA lX9haoKMMp0mYbVz1JW/7s6dgax03+1v08cxXluarD7KwFNFSD620HM8Z4mDn7qDQO6u ktwuw5OUlJIaCSPu23glAep24cdVWAX3td5QPwq7acKRO32Nh9ky6BqHtUpsWySj/VS+ p6JU/nYlIh+f/4yEY8JT7DidwiwaQYcgBfWrlQdVbYazB5gJgb3eN3YJyX9/f2lW+bTy Jk6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=r5tNkPu//c2nqMt3oS3wMQk+F0hTNh/wM2KTW+bR4FM=; b=DIzbX+bIWoYn80U6sR1GDMS21OB1KeuotEiBwicuxtw+QcPvfGCgfXTsxzyat8rW3V ckKT1klhBEfAku0tJfYj6otDsE3wqDIr1FUvxOQXuAh9zV5qkx9xdGV3wKD8NzzxxCAE veN/YAG8KdBDfJ1IlaloaW0p3KaT0QAaBtHxD/RnVLqWsXdMYPaCV1UMVLOGK3bz6SpH Db+1TO8gLvt2/UH9c57G4Kpyl8902U8itGF3khDqu5BlFOuUhItUMCE/97+hXmdovESb /2YgXIJuNa+pYPAJ82N4nD1uJIscWmHbo/e7OMF4afRvb7kdiyDF//Tqy9gYvW0ZXS6q lcFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m9-20020a05620a24c900b006ce550324ecsi4643551qkn.701.2022.09.23.01.52.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Sep 2022 01:52:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:44902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obeQO-0005ye-FJ for patch@linaro.org; Fri, 23 Sep 2022 04:52:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMK-00059L-DW; Fri, 23 Sep 2022 04:48:35 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3]:58847 helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMB-0005Jk-PW; Fri, 23 Sep 2022 04:48:29 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MYm5J6vpRz4xGR; Fri, 23 Sep 2022 18:48:20 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4MYm5G344Dz4x3w; Fri, 23 Sep 2022 18:48:18 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Joel Stanley , Andrew Jeffery , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= Subject: [PATCH 3/6] hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs Date: Fri, 23 Sep 2022 10:48:00 +0200 Message-Id: <20220923084803.498337-4-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220923084803.498337-1-clg@kaod.org> References: <20220923084803.498337-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=gbDQ=Z2=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée This is a heavily used function so lets avoid the cost of CPU_GET_CLASS. On the romulus-bmc run it has a modest effect: Before: 36.812 s ± 0.506 s After: 35.912 s ± 0.168 s Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-Id: <20220811151413.3350684-4-alex.bennee@linaro.org> Signed-off-by: Cédric Le Goater --- hw/core/cpu-sysemu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c index 00253f89293a..5eaf2e79e66c 100644 --- a/hw/core/cpu-sysemu.c +++ b/hw/core/cpu-sysemu.c @@ -69,11 +69,10 @@ hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs) { - CPUClass *cc = CPU_GET_CLASS(cpu); int ret = 0; - if (cc->sysemu_ops->asidx_from_attrs) { - ret = cc->sysemu_ops->asidx_from_attrs(cpu, attrs); + if (cpu->cc->sysemu_ops->asidx_from_attrs) { + ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs); assert(ret < cpu->num_ases && ret >= 0); } return ret; From patchwork Fri Sep 23 08:48:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 608585 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp151624pvb; Fri, 23 Sep 2022 02:03:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+E/rCpuP9+9RhSvuDhNIxH8QHRstRUBP7Dcso21RMF/lpV+nLu4WnPycYPmCJqBBUORqk X-Received: by 2002:a05:622a:150:b0:35d:2492:3a83 with SMTP id v16-20020a05622a015000b0035d24923a83mr537586qtw.164.1663923796457; Fri, 23 Sep 2022 02:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663923796; cv=none; d=google.com; s=arc-20160816; b=TproIhuHMuTxC8su7fplHFXoi4uO2M7DtHif40KAkGIfH4XofoZJ2xsQRgw3NbwkvM cp7zeHc00jSGKtddulQ5sOp/QXfoyr7LIR3Ez2tUJ0beg8y8k0HLDSal9mUIxa9GA8HG uxiIFugZ3Nu4sWIKxd6RWCN3ky9NUuiMfe94nziLjIdJdsPuZKj+bQ/r4HchUzZZgOqj 8hXyr1J3czPbbtEngXqweg3n/oQHuRnntY52sESB8Ymz3fwFZRMvL/BVSd4cy5lzXQel ryuQxo8Kw1JUVMOwOy/imVocRPCfCZx+lt7T+W2ByP17PMfRAy2huntUoJbD/rHa2X6E tEbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=wbXSuRf4qmE+Uq+zXXjsfsn3zGXpuZ80Hj3mjIa2b1Y=; b=rRiNXdrpKqJdcea+0qYVdjPyfIKqJpLQk0oHLy3zQDM6aZEBe/Dfr35Mk6MDw1byOT xW12TxIwQQGRfTn2ap2nJyyRkXSh/pzwvkeh+sPzbNJn7F461/6d1vq5zZnw8tCs9X/F oUNThgiXJs2wdAK0vFG4iE3Ak4GroDqj1SStKkNKteucyz5bOHHuCBtY8HaAegj9cFXU Y/+3M6BuM2iYaU+kYImOUIU60I7tBZe6TsOpCNxKhOgEGksNf1dePZP1kPC2MtSmJ99p sWHbvWUt1+/ZuGolzhNxc3+yeBMyMokB/4IYgZqHDlcIqbuAq0mR75gr7jCRsM2I+oA1 UdOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id cc5-20020a05622a410500b0035ce726b2d5si4266514qtb.398.2022.09.23.02.03.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Sep 2022 02:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:38334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obeaZ-0007CN-RN for patch@linaro.org; Fri, 23 Sep 2022 05:03:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMK-00059N-Dw; Fri, 23 Sep 2022 04:48:35 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]:57019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeME-0005Lt-T7; Fri, 23 Sep 2022 04:48:30 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MYm5N04WGz4xGg; Fri, 23 Sep 2022 18:48:24 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4MYm5K3NT2z4xGN; Fri, 23 Sep 2022 18:48:21 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Joel Stanley , Andrew Jeffery , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= Subject: [PATCH 4/6] cputlb: used cached CPUClass in our hot-paths Date: Fri, 23 Sep 2022 10:48:01 +0200 Message-Id: <20220923084803.498337-5-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220923084803.498337-1-clg@kaod.org> References: <20220923084803.498337-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=gbDQ=Z2=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Before: 35.912 s ± 0.168 s After: 35.565 s ± 0.087 s Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-Id: <20220811151413.3350684-5-alex.bennee@linaro.org> Signed-off-by: Cédric Le Goater --- accel/tcg/cputlb.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 8fad2d9b83cd..193bfc1cfc14 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1291,15 +1291,14 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, static void tlb_fill(CPUState *cpu, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { - CPUClass *cc = CPU_GET_CLASS(cpu); bool ok; /* * This is not a probe, so only valid return is success; failure * should result in exception + longjmp to the cpu loop. */ - ok = cc->tcg_ops->tlb_fill(cpu, addr, size, - access_type, mmu_idx, false, retaddr); + ok = cpu->cc->tcg_ops->tlb_fill(cpu, addr, size, + access_type, mmu_idx, false, retaddr); assert(ok); } @@ -1307,9 +1306,8 @@ static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { - CPUClass *cc = CPU_GET_CLASS(cpu); - - cc->tcg_ops->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr); + cpu->cc->tcg_ops->do_unaligned_access(cpu, addr, access_type, + mmu_idx, retaddr); } static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, @@ -1539,10 +1537,9 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, if (!tlb_hit_page(tlb_addr, page_addr)) { if (!victim_tlb_hit(env, mmu_idx, index, elt_ofs, page_addr)) { CPUState *cs = env_cpu(env); - CPUClass *cc = CPU_GET_CLASS(cs); - if (!cc->tcg_ops->tlb_fill(cs, addr, fault_size, access_type, - mmu_idx, nonfault, retaddr)) { + if (!cs->cc->tcg_ops->tlb_fill(cs, addr, fault_size, access_type, + mmu_idx, nonfault, retaddr)) { /* Non-faulting page table read failed. */ *phost = NULL; return TLB_INVALID_MASK; From patchwork Fri Sep 23 08:48:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 608583 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp147808pvb; Fri, 23 Sep 2022 01:53:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ckct5gUb8+FH0SmkkxUzmdZUYZAjjjxPBPSWrBgTNCyAtbpNXlnZdHQ/7HhsKOWrMxLdf X-Received: by 2002:a05:622a:14a:b0:35d:54:a00a with SMTP id v10-20020a05622a014a00b0035d0054a00amr6259004qtw.307.1663923226899; Fri, 23 Sep 2022 01:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663923226; cv=none; d=google.com; s=arc-20160816; b=MtxiOf9yqLk823YZhWVhizaZ6UdN9Vad4carx8q3V18gRLJUqQZ4qmKAqQmlTITk4b DosefjZdOcc92ZU/OHhSGTAET5B0STRgMY6NQzhY9d/x5FPv/y+CDqGkSulvp5tsJuOF O8nO76+TNrbaWbOjK35AybotTvIBD5819L+s4RBlU0b6fpjN73PDrraW0N+OeKGb/3J4 sM6pQI7/jkMPS2yglkCvEyUA5YPVOIP23qFqNqeBSLuGlc3LcIgCmkOnfq706UhKTYTH 5eltA3C6bbUVSPJ3QUHR4BCXRWsJ4yQ2lLu/segvf1Cd+ClkccntF6CDsmtP0x4RkaKz +Y7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=RLodW1RGB3Ig4Jk4s09PC93PTQ+o6wIE1lXDJxrSApA=; b=qMGMxNE2agz4OYPOqc/FeZMCQ5EUCK0M/RT613B88PtGdg4hHamNmJe1Y3ia6uURpt u8RkXIwLJCbA12/W1242+B9dBeTeYZzXP33/Uh3lWXTl8NHVX7EyNP+9iDP9CG78MuqR ZoYtAynHdPBOcTULi/2PzboWXlz+roBVkDjR+UMMTgpP1E3DyZB0FRZMwZHNVkZG8eml PJuef9uMWk3ej2y8PYPEHPIuupYsLh7HRROGNLvfo7iT2SbFAYien8hq4uf2bjNBN5Eq 6kuc8UiqwXSjTXYxDu7Pr9wSuBwKtYAqSUg8KK7KARFIliGA4QZjJZbe7Wq7i99Zcrvm b2+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t4-20020a0562140c6400b0049915000526si4225401qvj.450.2022.09.23.01.53.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Sep 2022 01:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:51536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obeRO-00070J-F0 for patch@linaro.org; Fri, 23 Sep 2022 04:53:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMT-0005BA-EN; Fri, 23 Sep 2022 04:48:42 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3]:53011 helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obeMP-0005Pu-RW; Fri, 23 Sep 2022 04:48:41 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MYm5R0QtNz4xGT; Fri, 23 Sep 2022 18:48:27 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4MYm5N3jsHz4xGN; Fri, 23 Sep 2022 18:48:24 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Joel Stanley , Andrew Jeffery , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= Subject: [PATCH 5/6] ssi: cache SSIPeripheralClass to avoid GET_CLASS() Date: Fri, 23 Sep 2022 10:48:02 +0200 Message-Id: <20220923084803.498337-6-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220923084803.498337-1-clg@kaod.org> References: <20220923084803.498337-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=gbDQ=Z2=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Investigating why some BMC models are so slow compared to a plain ARM virt machines I did some profiling of: ./qemu-system-arm -M romulus-bmc -nic user \ -drive file=obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \ -nographic -serial mon:stdio And saw that object_class_dynamic_cast_assert was dominating the profile times. We have a number of cases in this model of the SSI bus. As the class is static once the object is created we just cache it and use it instead of the dynamic case macros. Profiling against: ./tests/venv/bin/avocado run \ tests/avocado/machine_aspeed.py:test_arm_ast2500_romulus_openbmc_v2_9_0 Before: 35.565 s ± 0.087 s After: 15.713 s ± 0.287 s Signed-off-by: Alex Bennée Cc: Cédric Le Goater Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20220811151413.3350684-6-alex.bennee@linaro.org> Signed-off-by: Cédric Le Goater --- include/hw/ssi/ssi.h | 3 +++ hw/ssi/ssi.c | 18 ++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/hw/ssi/ssi.h b/include/hw/ssi/ssi.h index f411858ab083..6950f86810d3 100644 --- a/include/hw/ssi/ssi.h +++ b/include/hw/ssi/ssi.h @@ -59,6 +59,9 @@ struct SSIPeripheralClass { struct SSIPeripheral { DeviceState parent_obj; + /* cache the class */ + SSIPeripheralClass *spc; + /* Chip select state */ bool cs; }; diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c index 003931fb509e..d54a109beeb5 100644 --- a/hw/ssi/ssi.c +++ b/hw/ssi/ssi.c @@ -38,9 +38,8 @@ static void ssi_cs_default(void *opaque, int n, int level) bool cs = !!level; assert(n == 0); if (s->cs != cs) { - SSIPeripheralClass *ssc = SSI_PERIPHERAL_GET_CLASS(s); - if (ssc->set_cs) { - ssc->set_cs(s, cs); + if (s->spc->set_cs) { + s->spc->set_cs(s, cs); } } s->cs = cs; @@ -48,11 +47,11 @@ static void ssi_cs_default(void *opaque, int n, int level) static uint32_t ssi_transfer_raw_default(SSIPeripheral *dev, uint32_t val) { - SSIPeripheralClass *ssc = SSI_PERIPHERAL_GET_CLASS(dev); + SSIPeripheralClass *ssc = dev->spc; if ((dev->cs && ssc->cs_polarity == SSI_CS_HIGH) || - (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) || - ssc->cs_polarity == SSI_CS_NONE) { + (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) || + ssc->cs_polarity == SSI_CS_NONE) { return ssc->transfer(dev, val); } return 0; @@ -67,6 +66,7 @@ static void ssi_peripheral_realize(DeviceState *dev, Error **errp) ssc->cs_polarity != SSI_CS_NONE) { qdev_init_gpio_in_named(dev, ssi_cs_default, SSI_GPIO_CS, 1); } + s->spc = ssc; ssc->realize(s, errp); } @@ -115,13 +115,11 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val) { BusState *b = BUS(bus); BusChild *kid; - SSIPeripheralClass *ssc; uint32_t r = 0; QTAILQ_FOREACH(kid, &b->children, sibling) { - SSIPeripheral *peripheral = SSI_PERIPHERAL(kid->child); - ssc = SSI_PERIPHERAL_GET_CLASS(peripheral); - r |= ssc->transfer_raw(peripheral, val); + SSIPeripheral *p = SSI_PERIPHERAL(kid->child); + r |= p->spc->transfer_raw(p, val); } return r;