Commit 80a76c60 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'timers-ptp-2024-03-10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull clocksource updates from Thomas Gleixner:
 "Updates for timekeeping and PTP core.

  The cross-timestamp mechanism which allows to correlate hardware
  clocks uses clocksource pointers for describing the correlation.

  That's suboptimal as drivers need to obtain the pointer, which
  requires needless exports and exposing internals. This can all be
  completely avoided by assigning clocksource IDs and using them for
  describing the correlated clock source.

  So this adds clocksource IDs to all clocksources in the tree which can
  be exposed to this mechanism and removes the pointer and now needless
  exports.

  A related improvement for the core and the correlation handling has
  not made it this time, but is expected to get ready for the next
  round"

* tag 'timers-ptp-2024-03-10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  kvmclock: Unexport kvmclock clocksource
  treewide: Remove system_counterval_t.cs, which is never read
  timekeeping: Evaluate system_counterval_t.cs_id instead of .cs
  ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
  x86/kvm, ptp/kvm: Add clocksource ID, set system_counterval_t.cs_id
  x86/tsc: Add clocksource ID, set system_counterval_t.cs_id
  timekeeping: Add clocksource ID to struct system_counterval_t
  x86/tsc: Correct kernel-doc notation
parents 397935e3 27f6a9c8
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@

#include <linux/percpu.h>

extern struct clocksource kvm_clock;

DECLARE_PER_CPU(struct pvclock_vsyscall_time_info *, hv_clock_per_cpu);

static __always_inline struct pvclock_vcpu_time_info *this_cpu_pvti(void)
+2 −2
Original line number Diff line number Diff line
@@ -154,15 +154,15 @@ static int kvm_cs_enable(struct clocksource *cs)
	return 0;
}

struct clocksource kvm_clock = {
static struct clocksource kvm_clock = {
	.name	= "kvm-clock",
	.read	= kvm_clock_get_cycles,
	.rating	= 400,
	.mask	= CLOCKSOURCE_MASK(64),
	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
	.id     = CSID_X86_KVM_CLK,
	.enable	= kvm_cs_enable,
};
EXPORT_SYMBOL_GPL(kvm_clock);

static void kvm_register_clock(char *txt)
{
+19 −15
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ static int __read_mostly tsc_force_recalibrate;
static u32 art_to_tsc_numerator;
static u32 art_to_tsc_denominator;
static u64 art_to_tsc_offset;
static struct clocksource *art_related_clocksource;
static bool have_art;

struct cyc2ns {
	struct cyc2ns_data data[2];	/*  0 + 2*16 = 32 */
@@ -652,7 +652,7 @@ static unsigned long quick_pit_calibrate(void)
}

/**
 * native_calibrate_tsc
 * native_calibrate_tsc - determine TSC frequency
 * Determine TSC frequency via CPUID, else return 0.
 */
unsigned long native_calibrate_tsc(void)
@@ -1168,6 +1168,7 @@ static struct clocksource clocksource_tsc_early = {
	.mask			= CLOCKSOURCE_MASK(64),
	.flags			= CLOCK_SOURCE_IS_CONTINUOUS |
				  CLOCK_SOURCE_MUST_VERIFY,
	.id			= CSID_X86_TSC_EARLY,
	.vdso_clock_mode	= VDSO_CLOCKMODE_TSC,
	.enable			= tsc_cs_enable,
	.resume			= tsc_resume,
@@ -1190,6 +1191,7 @@ static struct clocksource clocksource_tsc = {
				  CLOCK_SOURCE_VALID_FOR_HRES |
				  CLOCK_SOURCE_MUST_VERIFY |
				  CLOCK_SOURCE_VERIFY_PERCPU,
	.id			= CSID_X86_TSC,
	.vdso_clock_mode	= VDSO_CLOCKMODE_TSC,
	.enable			= tsc_cs_enable,
	.resume			= tsc_resume,
@@ -1309,8 +1311,10 @@ struct system_counterval_t convert_art_to_tsc(u64 art)
	do_div(tmp, art_to_tsc_denominator);
	res += tmp + art_to_tsc_offset;

	return (struct system_counterval_t) {.cs = art_related_clocksource,
			.cycles = res};
	return (struct system_counterval_t) {
		.cs_id	= have_art ? CSID_X86_TSC : CSID_GENERIC,
		.cycles	= res,
	};
}
EXPORT_SYMBOL(convert_art_to_tsc);

@@ -1327,12 +1331,10 @@ EXPORT_SYMBOL(convert_art_to_tsc);
 * that this flag is set before conversion to TSC is attempted.
 *
 * Return:
 * struct system_counterval_t - system counter value with the pointer to the
 *	corresponding clocksource
 *	@cycles:	System counter value
 *	@cs:		Clocksource corresponding to system counter value. Used
 *			by timekeeping code to verify comparability of two cycle
 *			values.
 * struct system_counterval_t - system counter value with the ID of the
 *	corresponding clocksource:
 *	cycles:		System counter value
 *	cs_id:		The clocksource ID for validating comparability
 */

struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns)
@@ -1347,8 +1349,10 @@ struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns)
	do_div(tmp, USEC_PER_SEC);
	res += tmp;

	return (struct system_counterval_t) { .cs = art_related_clocksource,
					      .cycles = res};
	return (struct system_counterval_t) {
		.cs_id	= have_art ? CSID_X86_TSC : CSID_GENERIC,
		.cycles	= res,
	};
}
EXPORT_SYMBOL(convert_art_ns_to_tsc);

@@ -1357,7 +1361,7 @@ static void tsc_refine_calibration_work(struct work_struct *work);
static DECLARE_DELAYED_WORK(tsc_irqwork, tsc_refine_calibration_work);
/**
 * tsc_refine_calibration_work - Further refine tsc freq calibration
 * @work - ignored.
 * @work: ignored.
 *
 * This functions uses delayed work over a period of a
 * second to further refine the TSC freq value. Since this is
@@ -1455,7 +1459,7 @@ static void tsc_refine_calibration_work(struct work_struct *work)
		goto unreg;

	if (boot_cpu_has(X86_FEATURE_ART))
		art_related_clocksource = &clocksource_tsc;
		have_art = true;
	clocksource_register_khz(&clocksource_tsc, tsc_khz);
unreg:
	clocksource_unregister(&clocksource_tsc_early);
@@ -1481,7 +1485,7 @@ static int __init init_tsc_clocksource(void)
	 */
	if (boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) {
		if (boot_cpu_has(X86_FEATURE_ART))
			art_related_clocksource = &clocksource_tsc;
			have_art = true;
		clocksource_register_khz(&clocksource_tsc, tsc_khz);
		clocksource_unregister(&clocksource_tsc_early);

+3 −3
Original line number Diff line number Diff line
@@ -1807,7 +1807,7 @@ TIMER_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
#endif

int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts,
				 struct clocksource **cs)
				 enum clocksource_ids *cs_id)
{
	struct arm_smccc_res hvc_res;
	u32 ptp_counter;
@@ -1831,8 +1831,8 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts,
	*ts = ktime_to_timespec64(ktime);
	if (cycle)
		*cycle = (u64)hvc_res.a2 << 32 | hvc_res.a3;
	if (cs)
		*cs = &clocksource_counter;
	if (cs_id)
		*cs_id = CSID_ARM_ARCH_COUNTER;

	return 0;
}
+5 −5
Original line number Diff line number Diff line
@@ -28,15 +28,15 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time,
			       struct system_counterval_t *system_counter,
			       void *ctx)
{
	long ret;
	u64 cycle;
	enum clocksource_ids cs_id;
	struct timespec64 tspec;
	struct clocksource *cs;
	u64 cycle;
	int ret;

	spin_lock(&kvm_ptp_lock);

	preempt_disable_notrace();
	ret = kvm_arch_ptp_get_crosststamp(&cycle, &tspec, &cs);
	ret = kvm_arch_ptp_get_crosststamp(&cycle, &tspec, &cs_id);
	if (ret) {
		spin_unlock(&kvm_ptp_lock);
		preempt_enable_notrace();
@@ -46,7 +46,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time,
	preempt_enable_notrace();

	system_counter->cycles = cycle;
	system_counter->cs = cs;
	system_counter->cs_id = cs_id;

	*device_time = timespec64_to_ktime(tspec);

Loading