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

[Xen-devel] [PATCH v2 2/2] x86/mtrr: Skip cache flushes on CPUs with cache self-snooping


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Fri, 19 Jul 2019 10:29:36 +0000
  • Accept-language: en-US
  • 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-SenderADCheck; bh=AXO7ZHh8KO9QySatYEKjIhxrXNYQLgOP6fVcipQY5aM=; b=PoHG6DBMjH/Qzg0ZAC96ritAnhUvqnuY3x2nUVRhpDGOb4SnuSI3o7tIWqtA9xUcN27pYqP3hTLQ64FI8T9lyTSwAJxZQC8MVFmq0HwNAf1nhedRVLhrwBbnYujyGO86mVlQMBktXz2V0I3RZxH3Xqd3m/qRhSnUfi//Jd/gfGLRC3G0sqAZsr+mW0T8sVmcbuZgwKIDm1+bgD0wrCDkG5fmVrbZqBFGls4jiAo89B8nTK5oqji5v58crhGGxjUOyIc3/vQoQuWgrx2B+690/PSGqJ0OOynVKzYk6cEvSRmPxwew8OJAD+ImvDBrNvyomjW+fD60ekYZNtMcMVzTRQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N+SbXQCmb0EG2MpDimHimQFRqRCy+uEHAbFLD7mhZVfiivL6rKs2dJGyyJIk7YVSrkr2dDrJBI2QJFPNj7tAmZLcxIJnPVYtTqAhdZfCw+ycAsFlAxahCcXZMxy00Y44fye2+lubtvmx+j1oHewAxS0rNMDdqRqlHLPNL04TGSA6AG65qNwS8I97/eAeQH7ItBx5qrQ7MqdwzhxPFQWjbvKIBFJg9x9jtfq6YBiiJwN0/jtZQ3bVWIhqcYn+y7gKxIBrYY6R0QoFueYCIPdcWQkYUAQU3cADQSGb0sY2GS+w1I1Kh6UYICZG/dnuYF5sEemrOw3H15fJSyulk7gsXw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 19 Jul 2019 10:30:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVPhzduXN26MwI5kWBrLOv0yjR7g==
  • Thread-topic: [PATCH v2 2/2] x86/mtrr: Skip cache flushes on CPUs with cache self-snooping

From: Ricardo Neri <ricardo.neri-calderon@xxxxxxxxxxxxxxx>

Programming MTRR registers in multi-processor systems is a rather lengthy
process. Furthermore, all processors must program these registers in lock
step and with interrupts disabled; the process also involves flushing
caches and TLBs twice. As a result, the process may take a considerable
amount of time.

On some platforms, this can lead to a large skew of the refined-jiffies
clock source. Early when booting, if no other clock is available (e.g.,
booting with hpet=disabled), the refined-jiffies clock source is used to
monitor the TSC clock source. If the skew of refined-jiffies is too large,
Linux wrongly assumes that the TSC is unstable:

   clocksource: timekeeping watchdog on CPU1: Marking clocksource
                'tsc-early' as unstable because the skew is too large:
   clocksource: 'refined-jiffies' wd_now: fffedc10 wd_last:
                fffedb90 mask: ffffffff
   clocksource: 'tsc-early' cs_now: 5eccfddebc cs_last: 5e7e3303d4
                mask: ffffffffffffffff
   tsc: Marking TSC unstable due to clocksource watchdog

As per measurements, around 98% of the time needed by the procedure to
program MTRRs in multi-processor systems is spent flushing caches with
wbinvd(). As per the Section 11.11.8 of the Intel 64 and IA 32
Architectures Software Developer's Manual, it is not necessary to flush
caches if the CPU supports cache self-snooping. Thus, skipping the cache
flushes can reduce by several tens of milliseconds the time needed to
complete the programming of the MTRR registers:

Platform                        Before     After
104-core (208 Threads) Skylake  1437ms      28ms
   2-core (  4 Threads) Haswell   114ms       2ms

Reported-by: Mohammad Etemadi <mohammad.etemadi@xxxxxxxxx>
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@xxxxxxxxxxxxxxx>
[Linux commit fd329f276ecaad7a371d6f91b9bbea031d0c3440]

Use alternatives patching instead of static_cpu_has() (which we don't
have [yet]).

Interestingly we've been lacking the 2nd wbinvd(), which I'm taking the
liberty here.

Requested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
v2: Re-base (use XEN_SELFSNOOP).

--- a/xen/arch/x86/cpu/mtrr/generic.c
+++ b/xen/arch/x86/cpu/mtrr/generic.c
@@ -450,7 +450,14 @@ static bool prepare_set(void)
  
        /*  Enter the no-fill (CD=1, NW=0) cache mode and flush caches. */
        write_cr0(read_cr0() | X86_CR0_CD);
-       wbinvd();
+
+       /*
+        * Cache flushing is the most time-consuming step when programming
+        * the MTRRs. Fortunately, as per the Intel Software Development
+        * Manual, we can skip it if the processor supports cache self-
+        * snooping.
+        */
+       alternative("wbinvd", "", X86_FEATURE_XEN_SELFSNOOP);
  
        cr4 = read_cr4();
        if (cr4 & X86_CR4_PGE)
@@ -466,6 +473,9 @@ static bool prepare_set(void)
        /*  Disable MTRRs, and set the default type to uncached  */
        mtrr_wrmsr(MSR_MTRRdefType, deftype & ~0xcff);
  
+       /* Again, only flush caches if we have to. */
+       alternative("wbinvd", "", X86_FEATURE_XEN_SELFSNOOP);
+
        return cr4 & X86_CR4_PGE;
  }
  

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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