Skip to contentSkip to conversation

x86/time: PVCLOCK_TSC_STABLE_BIT support

PATCH In review Joao Martins 2 participants 8 messages Sep 23, 2016

lore
Share & tools
lore
#0 lore raw

v5 cover x86/time: PVCLOCK_TSC_STABLE_BIT support

Hey,

This is v5 on the pvclock TSC series addressing comments from previous version, see individual patches for complete changelog.

This series is divided as follows:

R * Patch 1: Small refactor around init_platform_time to reuse
initialization code when switching to TSC.

 A      * Patch 2: Prerequisite for patch 3
 U      * Patch 3: Adds a new clocksource based on TSC
 R      * Patch 4: Implements the PVCLOCK_TSC_STABLE_BIT
 U      * Patch 5: Extend "tsc" param to relax monotonicity restriction

across sockets.

[ A := Acked-by ;; R := Reviewed-by ;; U := Updated ]

The benefit of this series is two-fold:

1. Provide the guarantee of monotonic results on xen own system time as seen by any cpu when using TSC as clocksource.

2. Provide this same guarantee to guests and thus set the TSC_STABLE_BIT (both FreeBSD and Linux support it) which then allows guests to skip expensive monotonicity check between PV CPU time infos. Plus, on Linux specifically this also means that it could support vDSO which greatly increases performance (x10) for gettimeofday and clock_gettime since it would no longer need to do the system call to get a reliable snapshot of system time. For a reference on my laptop the speed of gettimeofday under xen pvclock is ~2 Mops/sec (Million ops per sec) whereas with vDSO it's on the range of ~22 Mops/sec on <= 4.4 kernels and ~37 Mops on >= 4.5.

Doing a long running time warp test for >2 weeks on a dual-socket Haswell machine and I haven't yet seen time going backwards (plus tests on older multi socket machines). Furthermore double checked migration to/from hosts with/without the bit while guest was running the time warp test and no issues occurred too.

Thanks!

Joao Martins (5):
x86/time: refactor init_platform_time() x86/time: refactor read_platform_stime() x86/time: implement tsc as clocksource x86/time: implement PVCLOCK_TSC_STABLE_BIT x86/time: extend "tsc" param with "stable:socket"

 docs/misc/xen-command-line.markdown |  10 +-
 xen/arch/x86/platform_hypercall.c   |   3 +-
 xen/arch/x86/time.c                 | 230 +++++++++++++++++++++++++++++++-----
 xen/include/asm-x86/time.h          |   1 +
 4 files changed, 210 insertions(+), 34 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v5 1/5 x86/time: refactor init_platform_time()

And accomodate platform time source initialization in try_platform_time(). This is a preparatory patch for deferring TSC clocksource initialization to the stage where all CPUS are up (verify_tsc_reliability init call).

---
 xen/arch/x86/time.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
xen/arch/x86/time.c +20 -10
index 73e0f98..0c1ad45 100644
@@ -576,6 +576,24 @@ static void resume_platform_timer(void)
     plt_stamp = plt_src.read_counter();
 }
 
+static s64 __init try_platform_timer(struct platform_timesource *pts)
+{
+    s64 rc = pts->init(pts);
+
+    if ( rc <= 0 )
+        return rc;
+
+    plt_mask = (u64)~0ull >> (64 - pts->counter_bits);
+
+    set_time_scale(&plt_scale, pts->frequency);
+
+    plt_overflow_period = scale_delta(
+        1ull << (pts->counter_bits - 1), &plt_scale);
+    plt_src = *pts;
+
+    return rc;
+}
+
 static u64 __init init_platform_timer(void)
 {
     static struct platform_timesource * __initdata plt_timers[] = {
@@ -593,7 +611,7 @@ static u64 __init init_platform_timer(void)
             pts = plt_timers[i];
             if ( !strcmp(opt_clocksource, pts->id) )
             {
-                rc = pts->init(pts);
+                rc = try_platform_timer(pts);
                 break;
             }
         }
@@ -609,21 +627,13 @@ static u64 __init init_platform_timer(void)
         for ( i = 0; i < ARRAY_SIZE(plt_timers); i++ )
         {
             pts = plt_timers[i];
-            if ( (rc = pts->init(pts)) > 0 )
+            if ( (rc = try_platform_timer(pts)) > 0 )
                 break;
         }
     }
 
     BUG_ON(rc <= 0);
 
-    plt_mask = (u64)~0ull >> (64 - pts->counter_bits);
-
-    set_time_scale(&plt_scale, pts->frequency);
-
-    plt_overflow_period = scale_delta(
-        1ull << (pts->counter_bits-1), &plt_scale);
-    plt_src = *pts;
-
     printk("Platform timer is %s %s\n",
            freq_string(pts->frequency), pts->name);
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

PATCH v5 2/5 x86/time: refactor read_platform_stime()

In reply to Joao Martins

To allow the caller to fetch the last read from the clocksource which was used to calculate system_time. This is a prerequisite for a subsequent patch that will use this last read.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes since v4:
- Add unlikely when callers provide a stamp argument
- Add Acked-by from Jan

Changes since v3:
- Add mention of this being a prerequisite to a later patch.

---
 xen/arch/x86/time.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
xen/arch/x86/time.c +13 -9
index 0c1ad45..6305a84 100644
@@ -537,18 +537,22 @@ static void plt_overflow(void *unused)
     set_timer(&plt_overflow_timer, NOW() + plt_overflow_period);
 }
 
-static s_time_t read_platform_stime(void)
+static s_time_t read_platform_stime(u64 *stamp)
 {
-    u64 count;
+    u64 plt_counter, count;
     s_time_t stime;
 
     ASSERT(!local_irq_is_enabled());
 
     spin_lock(&platform_timer_lock);
-    count = plt_stamp64 + ((plt_src.read_counter() - plt_stamp) & plt_mask);
+    plt_counter = plt_src.read_counter();
+    count = plt_stamp64 + ((plt_counter - plt_stamp) & plt_mask);
     stime = __read_platform_stime(count);
     spin_unlock(&platform_timer_lock);
 
+    if ( unlikely(stamp) )
+        *stamp = plt_counter;
+
     return stime;
 }
 
@@ -661,7 +665,7 @@ void cstate_restore_tsc(void)
     if ( boot_cpu_has(X86_FEATURE_NONSTOP_TSC) )
         return;
 
-    write_tsc(stime2tsc(read_platform_stime()));
+    write_tsc(stime2tsc(read_platform_stime(NULL)));
 }
 
 /***************************************************************************
@@ -980,7 +984,7 @@ int cpu_frequency_change(u64 freq)
 
     local_irq_disable();
     /* Platform time /first/, as we may be delayed by platform_timer_lock. */
-    t->stamp.master_stime = read_platform_stime();
+    t->stamp.master_stime = read_platform_stime(NULL);
     curr_tsc = rdtsc_ordered();
     /* TSC-extrapolated time may be bogus after frequency change. */
     /*t->stamp.local_stime = get_s_time_fixed(curr_tsc);*/
@@ -1285,7 +1289,7 @@ static void time_calibration_tsc_rendezvous(void *_r)
 
             if ( r->master_stime == 0 )
             {
-                r->master_stime = read_platform_stime();
+                r->master_stime = read_platform_stime(NULL);
                 r->master_tsc_stamp = rdtsc_ordered();
             }
             atomic_inc(&r->semaphore);
@@ -1325,7 +1329,7 @@ static void time_calibration_std_rendezvous(void *_r)
     {
         while ( atomic_read(&r->semaphore) != (total_cpus - 1) )
             cpu_relax();
-        r->master_stime = read_platform_stime();
+        r->master_stime = read_platform_stime(NULL);
         smp_wmb(); /* write r->master_stime /then/ signal */
         atomic_inc(&r->semaphore);
     }
@@ -1364,7 +1368,7 @@ void time_latch_stamps(void)
     unsigned long flags;
 
     local_irq_save(flags);
-    ap_bringup_ref.master_stime = read_platform_stime();
+    ap_bringup_ref.master_stime = read_platform_stime(NULL);
     ap_bringup_ref.local_tsc = rdtsc_ordered();
     local_irq_restore(flags);
 
@@ -1382,7 +1386,7 @@ void init_percpu_time(void)
     t->tsc_scale = per_cpu(cpu_time, 0).tsc_scale;
 
     local_irq_save(flags);
-    now = read_platform_stime();
+    now = read_platform_stime(NULL);
     tsc = rdtsc_ordered();
     local_irq_restore(flags);
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

PATCH v5 3/5 x86/time: implement tsc as clocksource

In reply to Joao Martins

Recent x86/time changes improved a lot of the monotonicity in xen timekeeping, making it much harder to observe time going backwards. Although platform timer can't be expected to be perfectly in sync with TSC and so get_s_time won't be guaranteed to always return monotonically increasing values across cpus. This is the case in some of the boxes I am testing with, observing sometimes ~100 warps (of very few nanoseconds each) after a few hours.

This patch introduces support for using TSC as platform time source which is the highest resolution time and most performant to get. Though there are also several problems associated with its usage, and there isn't a complete (and architecturally defined) guarantee that all machines will provide reliable and monotonic TSC in all cases (I believe Intel to be the only that can guarantee that?). For this reason it's not used unless administrator changes "clocksource" boot option to "tsc". Initializing TSC clocksource requires all CPUs up to have the tsc reliability checks performed. init_xen_time is called before all CPUs are up, so for example we would start with HPET (or ACPI, PIT) at boot time, and switch later to TSC. The switch then happens on verify_tsc_reliability initcall that is invoked when all CPUs are up. When attempting to initialize TSC we also check for time warps and if it has invariant TSC. Note that while we deem reliable a CONSTANT_TSC with no deep C-states, it might not always be the case, so we're conservative and allow TSC to be used as platform timer only with invariant TSC. Additionally we check if CPU Hotplug isn't meant to be performed on the host which will either be when max vcpus and num_present_cpu are the same. This is because a newly hotplugged CPU may not satisfy the condition of having all TSCs synchronized - so when having tsc clocksource being used we allow offlining CPUs but not onlining any ones back. Finally we prevent TSC from being used as clocksource on multiple sockets because it isn't guaranteed to be invariant. Further relaxing of this last requirement is added in a separate patch, such that we allow vendors with such guarantee to use TSC as clocksource. In case any of these conditions is not met, we keep the clocksource that was previously initialized on init_xen_time.

Since b64438c7c ("x86/time: use correct (local) time stamp in constant-TSC calibration fast path") updates to cpu time use local stamps, which means platform timer is only used to seed the initial cpu time. We further introduce a new rendezvous function (nop_rendezvous) which doesn't require synchronization between master and slave CPUS and just reads calibration_rendezvous struct and writes it down the stime and stamp to the cpu_calibration struct to be used later on. With clocksource=tsc there is no need to be in sync with another clocksource, so we reseed the local/master stamps to be values of TSC and update the platform time stamps accordingly. Time calibration is set to 1sec after we switch to TSC, thus these stamps are reseeded to also ensure monotonic returning values right after the point we switch to TSC. This is to remove the possibility of having inconsistent readings in this short period (i.e. until calibration fires).

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes sinve v4:
- Moved nop_rendezvous to this patch and along with its mention in the commit message.
- Remove mention of HPET priority vs other clocksources.
- Change "to avoid the possibility" into "to remove (...)"
- Change TSC init messages to use warning log level and leave the last one as debug.
- Change "Switched to Platform timer" message to same loglevel as the one in init_platform_timer()
- Introduce "late" boolean function parameter in try_platform_timer_tail.
- Do not split the if (checking for clocksource=tsc) into two lines.
- Add brief comment about why TSC .counter_bits is not 64

Changes since v3:
- Really fix "HPET switching to TSC" comment. Despite mentioned in the in previous version, the change wasn't there.
- Remove parenthesis around the function call in init_platform_timer
- Merge if on verify_tsc_reliability with opt_clocksource check
- Removed comment above ".init = init_tsctimer"
- Fixup docs updated into this patch.
- Move host_tsc_is_clocksource() and CPU hotplug possibility check to this patch.
- s/host_tsc_is_clocksource/clocksource_is_tsc
- Use bool instead of bool_t
- Add a comment above init_tsctimer() declaration mentioning the reliable TSC checks on verify_tsc_reliability(), under which the function is invoked.
- Prevent clocksource=tsc on platforms with multiple-sockets. Further relaxing of this requirement is added in a separate patch, as extension of "tsc" boot parameter.
- Removed control group to update cpu_time and do instead with on_selected_cpus to avoid any potential races.
- Accomodate common path between init_xen_time and TSC switch into try_platform_timer_tail, such that finishing platform timer initialization is done in the same place (including platform timer overflow which was previously was removed in previous versions).
- Changed TSC counter_bits 63 to avoid mishandling of TSC counter wrap-around in platform timer overflow timer.
- Moved paragraph CPU Hotplug from last patch and add comment on commit message about multiple sockets TSC sync.
- s/init_tsctimer/init_tsc/g to be consistent with other TSC platform timer functions.

Changes since v2:
- Suggest "HPET switching to TSC" only as an example as otherwise it would be misleading on platforms not having one.
- Change init_tsctimer to skip all the tests and assume it's called only on reliable TSC conditions and no warps observed. Tidy initialization on verify_tsc_reliability as suggested by Konrad.
- CONSTANT_TSC and max_cstate <= 2 case removed and only allow tsc clocksource in invariant TSC boxes.
- Prefer omit !=0 on init_platform_timer for tsc case.
- Change comment on init_platform_timer.
- Add comment on plt_tsc declaration.
- Reinit CPU time for all online cpus instead of just CPU 0.
- Use rdtsc_ordered() as opposed to rdtsc()
- Remove tsc_freq variable and set plt_tsc clocksource frequency with the refined tsc calibration.
- Rework a bit the commit message.

Changes since v1:
- s/printk/printk(XENLOG_INFO
- Remove extra space on inner brackets
- Add missing space around brackets
- Defer TSC initialization when all CPUs are up.

Changes since RFC:
- Spelling fixes in the commit message.
- Remove unused clocksource_is_tsc variable and introduce it instead on the patch that uses it.
- Move plt_tsc from second to last in the available clocksources.

---
 docs/misc/xen-command-line.markdown |   6 +-
 xen/arch/x86/platform_hypercall.c   |   3 +-
 xen/arch/x86/time.c                 | 161 +++++++++++++++++++++++++++++++++---
 xen/include/asm-x86/time.h          |   1 +
 4 files changed, 159 insertions(+), 12 deletions(-)
docs/misc/xen-command-line.markdown +5 -1
index 3a250cb..f92fb3f 100644
@@ -264,9 +264,13 @@ minimum of 32M, subject to a suitably aligned and sized contiguous
 region of memory being available.
 
 ### clocksource
-> `= pit | hpet | acpi`
+> `= pit | hpet | acpi | tsc`
 
 If set, override Xen's default choice for the platform timer.
+Having TSC as platform timer requires being explicitly set. This is because
+TSC can only be safely used if CPU hotplug isn't performed on the system. In
+some platforms, "maxcpus" parameter may require further adjustment to the
+number of online cpus.
 
 ### cmci-threshold
 > `= <integer>`
xen/arch/x86/platform_hypercall.c +2 -1
index 780f22d..0879e19 100644
@@ -631,7 +631,8 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op)
         if ( ret )
             break;
 
-        if ( cpu >= nr_cpu_ids || !cpu_present(cpu) )
+        if ( cpu >= nr_cpu_ids || !cpu_present(cpu) ||
+             clocksource_is_tsc() )
         {
             ret = -EINVAL;
             break;
xen/arch/x86/time.c +151 -10

227 lines not on this page · raw message

xen/include/asm-x86/time.h +1 -0
index 971883a..6d704b4 100644
@@ -69,6 +69,7 @@ void tsc_get_info(struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_nsec,
 
 void force_update_vcpu_system_time(struct vcpu *v);
 
+bool clocksource_is_tsc(void);
 int host_tsc_is_safe(void);
 void cpuid_time_leaf(uint32_t sub_idx, uint32_t *eax, uint32_t *ebx,
                      uint32_t *ecx, uint32_t *edx);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v5 3/5
#4 lore raw

Re: [PATCH v5 3/5] x86/time: implement tsc as clocksource

Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 23.09.16 at 12:42, <[email protected]> wrote:

Recent x86/time changes improved a lot of the monotonicity in xen timekeeping, making it much harder to observe time going backwards. Although platform timer can't be expected to be perfectly in sync with TSC and so get_s_time won't be guaranteed to always return monotonically increasing values across cpus. This is the case in some of the boxes I am testing with, observing sometimes ~100 warps (of very few nanoseconds each) after a few hours.

This patch introduces support for using TSC as platform time source which is the highest resolution time and most performant to get. Though there are also several problems associated with its usage, and there isn't a complete (and architecturally defined) guarantee that all machines will provide reliable and monotonic TSC in all cases (I believe Intel to be the only that can guarantee that?). For this reason it's not used unless administrator changes "clocksource" boot option to "tsc". Initializing TSC clocksource requires all CPUs up to have the tsc reliability checks performed. init_xen_time is called before all CPUs are up, so for example we would start with HPET (or ACPI, PIT) at boot time, and switch later to TSC. The switch then happens on verify_tsc_reliability initcall that is invoked when all CPUs are up. When attempting to initialize TSC we also check for time warps and if it has invariant TSC. Note that while we deem reliable a CONSTANT_TSC with no deep C-states, it might not always be the case, so we're conservative and allow TSC to be used as platform timer only with invariant TSC. Additionally we check if CPU Hotplug isn't meant to be performed on the host which will either be when max vcpus and num_present_cpu are the same. This is because a newly hotplugged CPU may not satisfy the condition of having all TSCs synchronized - so when having tsc clocksource being used we allow offlining CPUs but not onlining any ones back. Finally we prevent TSC from being used as clocksource on multiple sockets because it isn't guaranteed to be invariant. Further relaxing of this last requirement is added in a separate patch, such that we allow vendors with such guarantee to use TSC as clocksource. In case any of these conditions is not met, we keep the clocksource that was previously initialized on init_xen_time.

Since b64438c7c ("x86/time: use correct (local) time stamp in constant-TSC calibration fast path") updates to cpu time use local stamps, which means platform timer is only used to seed the initial cpu time. We further introduce a new rendezvous function (nop_rendezvous) which doesn't require synchronization between master and slave CPUS and just reads calibration_rendezvous struct and writes it down the stime and stamp to the cpu_calibration struct to be used later on. With clocksource=tsc there is no need to be in sync with another clocksource, so we reseed the local/master stamps to be values of TSC and update the platform time stamps accordingly. Time calibration is set to 1sec after we switch to TSC, thus these stamps are reseeded to also ensure monotonic returning values right after the point we switch to TSC. This is to remove the possibility of having inconsistent readings in this short period (i.e. until calibration fires).

Quoted 1 line

with one further adjustment (no need to re-send):

Quoted 4 lines
docs/misc/xen-command-line.markdown +0 -0
@@ -264,9 +264,13 @@ minimum of 32M, subject to a suitably aligned and sized contiguous
 region of memory being available.

docs/misc/xen-command-line.markdown minimum of 32M, subject to a suitably aligned and sized contiguous · line 273

Quoted 10 lines
docs/misc/xen-command-line.markdown +5 -1
 
 ### clocksource
-> `= pit | hpet | acpi`
+> `= pit | hpet | acpi | tsc`
 
 If set, override Xen's default choice for the platform timer.
+Having TSC as platform timer requires being explicitly set. This is because
+TSC can only be safely used if CPU hotplug isn't performed on the system. In
+some platforms, "maxcpus" parameter may require further adjustment to the
+number of online cpus.

I think I'll re-write this last sentence to "On some platforms, the "maxcpus" option may need to be used to further adjust the number of allowed CPUs."

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH v5 4/5 x86/time: implement PVCLOCK_TSC_STABLE_BIT

In reply to Joao Martins

This patch proposes relying on host TSC synchronization and passthrough to the guest, when running on a TSC-safe platform. On time_calibration we retrieve the platform time in ns and the counter read by the clocksource that was used to compute system time. We can guarantee that on a platform with a constant and reliable TSC, that the time read on vcpu B right after A is bigger independently of the VCPU calibration error. Since pvclock time infos are monotonic as seen by any vCPU set PVCLOCK_TSC_STABLE_BIT, which then enables usage of VDSO on Linux. IIUC, this is similar to how it's implemented on KVM. Add also a comment regarding this bit changing and that guests are expected to check this bit on every read.

Should note that I've yet to see time going backwards in a long running test I ran for 2 weeks (in a dual socket machine), plus few other tests I did on older platforms.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes since v4:
- Remove blanks from flag assignment.
- Added "Reviewed-by" from Jan Beulich.
- Move nop_rendezvous introduction (and the mention in the commit message) into the patch introducing clocksource=tsc.
[I kept the Reviewed-by as there was no functional change but rather only
moving things out (as from discussion in the other patch). I wasn't sure if I should have kept it, so if it was a wrong assumption in the protocol, let me know.]

Changes since v3:
- Do not adjust time_calibration_rendezvous_tail for nop_rendezvous and instead set cpu_time_stamp directly on the rendezvous function.
- Move CPU Hotplug checks into patch 2
- Add a commit and code comment regarding guests cope with this bit changing on hosts.
- s/host_tsc_is_clocksource/clocksource_is_tsc

Changes since v2:
- Add XEN_ prefix to pvclock flags.
- Adapter time_calibration_rendezvous_tail to have the case of setting master tsc/stime and use it for the nop_rendezvous.
- Removed hotplug CPU option that was added in v1
- Prevent online of CPUs when clocksource is tsc.
- Remove use_tsc_stable_bit, since clocksource is only used to seed values. So instead we test if hotplug is possible, and prevent clocksource=tsc to be used.
- Remove 1st paragrah of commit message since the behaviour described no longer applies since b64438c.

Changes since v1:
- Change approach to skip std_rendezvous by introducing a nop_rendezvous
- Change commit message reflecting the change above.
- Use TSC_STABLE_BIT only if cpu hotplug isn't possible.
- Add command line option to override it if no cpu hotplug is intended.

---
 xen/arch/x86/time.c | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/arch/x86/time.c +8 -0
index 128e653..d307d93 100644
@@ -955,6 +955,14 @@ static void __update_vcpu_system_time(struct vcpu *v, int force)
     _u.tsc_timestamp = tsc_stamp;
     _u.system_time   = t->stamp.local_stime;
 
+    /*
+     * It's expected that domains cope with this bit changing on every
+     * pvclock read to check whether they can resort solely on this tuple
+     * or if it further requires monotonicity checks with other vcpus.
+     */
+    if ( clocksource_is_tsc() )
+        _u.flags |= XEN_PVCLOCK_TSC_STABLE_BIT;
+
     if ( is_hvm_domain(d) )
         _u.tsc_timestamp += v->arch.hvm_vcpu.cache_tsc_offset;
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

PATCH v5 5/5 x86/time: extend "tsc" param with "stable:socket"

In reply to Joao Martins

Extend the "tsc" boot parameter is to further relax TSC restrictions and allow it to be used on machines that guarantee reliable TSC across sockets. This is up to board manufacturers and there's no way for the OS to probe this property, therefore user needs to explicitly set this option.

Also make one style adjustment that is to remove the unnecessary parenthesis around clearing TSC_RELIABLE.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes since v4:
- Fix documentation spelling mistakes namely repeated use of "parameter"; matching option name ("stable:socket"); s/running under/running under/g; and wording from require to adjustment suggestion.
- Use __initdata instead of __read_mostly

---
 docs/misc/xen-command-line.markdown |  6 ++++--
 xen/arch/x86/time.c                 | 11 ++++++++---
 2 files changed, 12 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.markdown +4 -2
index f92fb3f..962a18f 100644
@@ -270,7 +270,9 @@ If set, override Xen's default choice for the platform timer.
 Having TSC as platform timer requires being explicitly set. This is because
 TSC can only be safely used if CPU hotplug isn't performed on the system. In
 some platforms, "maxcpus" parameter may require further adjustment to the
-number of online cpus.
+number of online cpus. When running on platforms that can guarantee a
+monotonic TSC across sockets you may want to adjust the "tsc" command line
+parameter to "stable:socket".
 
 ### cmci-threshold
 > `= <integer>`
@@ -1508,7 +1510,7 @@ pages) must also be specified via the tbuf\_size parameter.
 > `= <integer>`
 
 ### tsc
-> `= unstable | skewed`
+> `= unstable | skewed | stable:socket`
 
 ### ucode
 > `= [<integer> | scan]`
xen/arch/x86/time.c +8 -3
index d307d93..dda89d8 100644
@@ -477,6 +477,10 @@ uint64_t ns_to_acpi_pm_tick(uint64_t ns)
 /************************************************************
  * PLATFORM TIMER 4: TSC
  */
+static unsigned int __initdata tsc_flags;
+
+/* TSC is reliable across sockets */
+#define TSC_RELIABLE_SOCKET (1 << 0)
 
 /*
  * Called in verify_tsc_reliability() under reliable TSC conditions
@@ -492,7 +496,7 @@ static s64 __init init_tsc(struct platform_timesource *pts)
         ret = 0;
     }
 
-    if ( nr_sockets > 1 )
+    if ( nr_sockets > 1 && !(tsc_flags & TSC_RELIABLE_SOCKET) )
     {
         printk(XENLOG_WARNING "TSC: Not invariant across sockets\n");
         ret = 0;
@@ -1855,6 +1859,7 @@ int hwdom_pit_access(struct ioreq *ioreq)
 /*
  * tsc=unstable: Override all tests; assume TSC is unreliable.
  * tsc=skewed: Assume TSCs are individually reliable, but skewed across CPUs.
+ * tsc=stable:socket: Assume TSCs are reliable across sockets.
  */
 static void __init tsc_parse(const char *s)
 {
@@ -1865,9 +1870,9 @@ static void __init tsc_parse(const char *s)
         setup_clear_cpu_cap(X86_FEATURE_TSC_RELIABLE);
     }
     else if ( !strcmp(s, "skewed") )
-    {
         setup_clear_cpu_cap(X86_FEATURE_TSC_RELIABLE);
-    }
+    else if ( !strcmp(s, "stable:socket") )
+        tsc_flags |= TSC_RELIABLE_SOCKET;
 }
 custom_param("tsc", tsc_parse);
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v5 5/5
#7 lore raw

Re: [PATCH v5 5/5] x86/time: extend "tsc" param with "stable:socket"

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 23.09.16 at 12:42, <[email protected]> wrote:

Extend the "tsc" boot parameter is to further relax TSC restrictions and allow it to be used on machines that guarantee reliable TSC across sockets. This is up to board manufacturers and there's no way for the OS to probe this property, therefore user needs to explicitly set this option.

Also make one style adjustment that is to remove the unnecessary parenthesis around clearing TSC_RELIABLE.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel