[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86emul: Cache the amd_like() output on x86_emulate() entry


  • To: "Jan Beulich" <jbeulich@xxxxxxxx>
  • From: "Alejandro Vallejo" <alejandro.garciavallejo@xxxxxxx>
  • Date: Tue, 22 Sep 2026 20:04:31 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KsafzPgXm+m80JgfRlY5/jcuPa28hbwq3sNzFBPowF0=; b=Mnd+qcZ27W86R+m58HSAjJ1rsBO1Nj3OV8ckO6rSYiA/BDp7JvgKDIMhJc7juKPhTm8GRxhvuuCVr1+rqsNrDvGBg03aFEke7at8cx9mZkcA6yhE6Z0E5N1lxWNXaPlbiWyigMWgklOBGFqZfc2sNl9d2DJnQziE9PaIdwuyfYB7w17fnpim0hHNX31V0x4JwwkXbjwHHVUOnqNS5PKR29ldD/1Ytm8BzNGtolyXxD1qDyo7Mw0L3hUeIRQ5QItb0Rl/a74YH1ecYwB457k201/eOuqI9cbPLx84hKirWI5iMJbaDm5XWK2ZUVcnUj/DnU5VwLKk0+scJpqz59l9PQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rIEghoqffS+B5m0AB8cm5VSOkz0gC4CoyLD+2wabmYutAxo5m8ItRo/pL0IbTwjUexjEGhkPIjhCEAq7ZbnK/jfMlHId6nLWLSiRoPYL8zXx6Cm/l86P1Hfy/75Ei3+A8M/wLmD8MqZYAZTXCuBRsm/9LIYpexDYf746w79wt8SNVN4itSLzuM1k4eHi0uJgSffW0USTOwmNAnuiFXa5DFBosMkEI85YcSZCUswk9clb3l7ky3D5Br0/WPjfRBw/yPWI5TS4IRwxYlg5CNQbciJHa1UsEFXSLioNj7pbvjGe7z2QS/NWqNKh4TiJ8H3NZMxUUPpQCIpgTMnfz1pxfg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, "Teddy Astie" <teddy.astie@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 22 Sep 2026 18:04:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue Sep 22, 2026 at 3:34 PM CEST, Jan Beulich wrote:
> On 21.09.2026 11:25, Alejandro Vallejo wrote:
> > The current code instantiates amd_like() way too many times, leading to
> > codegen explosion. Unconditionally call it early on, and use that
> > variable everywhere. This shrinks the emulator by ~3KiB.
> > 
> > No a functional change.
> > 
> > Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
> > ---
> > pipeline: 
> > https://gitlab.com/xen-project/people/agvallejo/xen/-/pipelines/2860748404
> >           (it's red because of an caching issue and personal branch name
> >            conventions it's just arm. x86 passes in full)
> > 
> > bloat-o-meter before-after patch.
> > 
> > add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3366 (-3366)
> > Function                                     old     new   delta
> > x86_emulate                               209351  205985   -3366
> > Total: Before=3617694, After=3614328, chg -0.09%
>
> That's surprisingly big a difference, considering how simple amd_like() is.
> I'm counting 24 instances, so the savings would be well over 100 bytes per
> instance.

I have some more interesting results. I can very much repro at that
commit with GCC 13 with debug=y, but ALSO the variable must be set at
the tail of all other locals. I never noticed the gain was gone after
moving where it is in this patch.

Clearly I misattributed the origin of the shrinkage. In retrospect, it
turns out to be an unrelated matter. I _THINK_ register pressure is
somehow precluding the inlining of a helper. The problem is gone in
debug=n where CSE ensures all is good.

If I find a way of shrinking debug builds in a way that's more resilient
to compiler specifics I'll push that as a separate patch, but for now
I'll just drop this. Clearly it doesn't matter here for a realistic
build.

Apologies for the noise. Codegen is hard :)

Alejandro



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.