Merge tag 'drm-next-2020-10-15' of git://anongit.freedesktop.org/drm/drm
[linux-2.6-microblaze.git] / arch / x86 / kernel / tsc.c
index fdd4c10..f70dffc 100644 (file)
@@ -41,6 +41,7 @@ EXPORT_SYMBOL(tsc_khz);
  * TSC can be unstable due to cpufreq or due to unsynced TSCs
  */
 static int __read_mostly tsc_unstable;
+static unsigned int __initdata tsc_early_khz;
 
 static DEFINE_STATIC_KEY_FALSE(__use_tsc);
 
@@ -53,12 +54,18 @@ struct clocksource *art_related_clocksource;
 
 struct cyc2ns {
        struct cyc2ns_data data[2];     /*  0 + 2*16 = 32 */
-       seqcount_t         seq;         /* 32 + 4    = 36 */
+       seqcount_latch_t   seq;         /* 32 + 4    = 36 */
 
 }; /* fits one cacheline */
 
 static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns);
 
+static int __init tsc_early_khz_setup(char *buf)
+{
+       return kstrtouint(buf, 0, &tsc_early_khz);
+}
+early_param("tsc_early_khz", tsc_early_khz_setup);
+
 __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data)
 {
        int seq, idx;
@@ -66,14 +73,14 @@ __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data)
        preempt_disable_notrace();
 
        do {
-               seq = this_cpu_read(cyc2ns.seq.sequence);
+               seq = this_cpu_read(cyc2ns.seq.seqcount.sequence);
                idx = seq & 1;
 
                data->cyc2ns_offset = this_cpu_read(cyc2ns.data[idx].cyc2ns_offset);
                data->cyc2ns_mul    = this_cpu_read(cyc2ns.data[idx].cyc2ns_mul);
                data->cyc2ns_shift  = this_cpu_read(cyc2ns.data[idx].cyc2ns_shift);
 
-       } while (unlikely(seq != this_cpu_read(cyc2ns.seq.sequence)));
+       } while (unlikely(seq != this_cpu_read(cyc2ns.seq.seqcount.sequence)));
 }
 
 __always_inline void cyc2ns_read_end(void)
@@ -179,7 +186,7 @@ static void __init cyc2ns_init_boot_cpu(void)
 {
        struct cyc2ns *c2n = this_cpu_ptr(&cyc2ns);
 
-       seqcount_init(&c2n->seq);
+       seqcount_latch_init(&c2n->seq);
        __set_cyc2ns_scale(tsc_khz, smp_processor_id(), rdtsc());
 }
 
@@ -196,7 +203,7 @@ static void __init cyc2ns_init_secondary_cpus(void)
 
        for_each_possible_cpu(cpu) {
                if (cpu != this_cpu) {
-                       seqcount_init(&c2n->seq);
+                       seqcount_latch_init(&c2n->seq);
                        c2n = per_cpu_ptr(&cyc2ns, cpu);
                        c2n->data[0] = data[0];
                        c2n->data[1] = data[1];
@@ -1412,7 +1419,10 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
 
        if (early) {
                cpu_khz = x86_platform.calibrate_cpu();
-               tsc_khz = x86_platform.calibrate_tsc();
+               if (tsc_early_khz)
+                       tsc_khz = tsc_early_khz;
+               else
+                       tsc_khz = x86_platform.calibrate_tsc();
        } else {
                /* We should not be here with non-native cpu calibration */
                WARN_ON(x86_platform.calibrate_cpu != native_calibrate_cpu);