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

Re: [PATCH] x86/hvm: Improve hvm_set_guest_pat() code generation again


  • To: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 19 Dec 2022 08:28:49 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=QqShiHs/qdT5HVXACcjVxKkEch/Gysh9LcccxIZTl80=; b=Cp60aGRkxsMZfCpubr99lvfq92wF+9hl6j7Zd8AHKY9VcXBotqukPk0b4U0fLkSxLIN2yLii08u+sOMgT+uIWzs/l2hd1lFGPQyWPBUKoFL3pIdkFPJDU8BFm9VqTAi3ToLYK0oOMSczS0608p6ITlZ5ZH1GHui3c+uo8tmtlieIXBYH0lDak3BPNEpe7PJSL2lbcJ21zwq4CYAsYzDz8RA8iDbnAjePd8rkKusI2T7qtCFIdXxTwikqvbBwdyaLRjLqfG/YXU1ga/UNFs+MV71jxJ28VSxXXmaGZVxk9eHY0TeICwcxbtrf2OLZ9y7lLyVWmiLtPYb/oCIGX8q/2w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OhwX6NyisTWnxXW8jx7E5tlbCf00WzEQbMKXsvSfjXauqzXbmcukWbAJHDcg9GnlTSlcCt0SxhOS2ytXj3Vts5vs/9VPvI7I6SZK+PeI8RGEchz5VVKSi0GjDSkjb266Xl7LTvi7ZyVyX83EOnGQJUJMrbkmHib7lc3MvpZXJskS4YULYwMn0lr1hqQOEMUP7HfZ6ZLQ1A/3bFXKlZs1+yoAMHMcBnaWSzo7GAxhxmB6RDtifoUQ6AYgsy9t3Javqp0W8D+6BwcHmKkS3LhtSA5qmPl9XIx8yfvHvO39+1uhzRaUMykuBW9d2BQez1qeO3ICF4vDcFyRQLDw09XNYQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx>, Edwin Torok <edvin.torok@xxxxxxxxxx>
  • Delivery-date: Mon, 19 Dec 2022 07:28:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 16.12.2022 21:53, Andrew Cooper wrote:
> On 10/08/2022 3:06 pm, Jan Beulich wrote:
>> On 10.08.2022 15:36, Andrew Cooper wrote:
>>> From: Edwin Török <edvin.torok@xxxxxxxxxx>
>>>
>>> Following on from cset 9ce0a5e207f3 ("x86/hvm: Improve hvm_set_guest_pat()
>>> code generation"), and the discovery that Clang/LLVM makes some especially
>>> disastrous code generation for the loop at -O2
>>>
>>>   https://github.com/llvm/llvm-project/issues/54644
>>>
>>> Edvin decided to remove the loop entirely by fully vectorising it.  This is
>>> substantially more efficient than the loop, and rather harder for a typical
>>> compiler to mess up.
>>>
>>> Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
>>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>> The main downside being that changing the code to fit in a new PAT
>> type will now be harder.
> 
> When was the last PAT type change?
> 
> Trick question.  Never, because PAT hasn't changed since it was
> introduced 24 years ago in the Pentium III.
> 
> I really don't think we're in danger of needing to change this logic.

One way to look at things, sure.

>> I wonder in particular whether with that
>> in mind it wouldn't be better to express the check not in terms of
>> relations, but in terms of set / clear bits ("bits 3-7 clear AND
>> (bit 2 set OR bit 1 clear)"). The code kind of does so already, but
>> the variable names don't reflect that (and would hence need to
>> change in such an event).
> 
> That would reduced clarity.
> 
> The bits being set or cleared are trivial for any developer, given the
> particularly basic RHS expressions.
> 
> The constant names are what relate the bit patterns to the description
> of the problem.

Again - one way to look at things. Plus, with Demi's series now also in
mind, what's done here is moving us in exactly the opposite direction.
Is this hot enough a function to warrant that?

>>> --- a/xen/arch/x86/hvm/hvm.c
>>> +++ b/xen/arch/x86/hvm/hvm.c
>>> @@ -302,24 +302,43 @@ void hvm_get_guest_pat(struct vcpu *v, u64 *guest_pat)
>>>          *guest_pat = v->arch.hvm.pat_cr;
>>>  }
>>>  
>>> -int hvm_set_guest_pat(struct vcpu *v, uint64_t guest_pat)
>>> +/*
>>> + * MSR_PAT takes 8 uniform fields, each of which must be a valid 
>>> architectural
>>> + * memory type (0, 1, 4-7).  This is a fully vectorised form of the
>>> + * 8-iteration loop over bytes looking for PAT_TYPE_* constants.
>> While grep-ing for PAT_TYPE_ will hit this line, I think we want
>> every individual type to also be found here when grep-ing for one.
>> The actual values aren't going to change, but perhaps the beast
>> way to do so would still be by way of BUILD_BUG_ON()s.
> 
> Why?  What does that solve or improve?
> 
> "pat" is the thing people are going to be looking for if they're
> actually trying to find this logic.
> 
> (And I bring this patch up specifically after reviewing Demi's series,
> where PAT_TYPE_* changes to X86_MT_* but "pat" is still the useful
> search term IMO.)

I don't think "PAT" is a good thing to grep for when trying to find uses
of particular memory types. Go grep for "_WP", "_WC", or "_WT" - you'll
find not overly many hits, and with the false positives filtered out
you'll have a good overview of which of these types is used in how many
places.

Jan



 


Rackspace

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