treewide: Use clocksource ID for get_device_system_crosststamp()
Subsystems (10)
v3 cover treewide: Use clocksource ID for get_device_system_crosststamp()
Overview
--------
This patch series changes struct system_counterval_t to identify the clocksource through enum clocksource_ids, rather than through struct clocksource *. The net effect of the patch series is that get_device_system_crosststamp() callers can supply clocksource ids instead of clocksource pointers. The pointers can be problematic to get hold of.
The series is also available at
https://github.com/OpenSynergy/linux clocksource-id-for-xtstamp-v3
Motivation
----------
The immediate motivation for this patch series is to enable the virtio_rtc RFC driver (v3 cf. [1]) to refer to the Arm Generic Timer clocksource without requiring new helper functions in the arm_arch_timer driver. Other future get_device_system_crosststamp() users may profit from this change as well.
Clocksource structs are normally private to clocksource drivers. Therefore, get_device_system_crosststamp() callers require that clocksource drivers expose the clocksource of interest in some way.
Drivers such as virtio_rtc could obtain all information for calling get_device_system_crosststamp() from their bound device, except for clocksource identification. Often, such drivers' only direct relation with the clocksource driver is clocksource identification. So using the clocksource enum, rather than obtaining pointers in a clocksource driver specific way, would reduce the coupling between the get_device_system_crosststamp() callers and clocksource drivers.
Affected Code
-------------
This series modifies code which is relevant to get_device_system_crosststamp(), in timekeeping, ptp/kvm, x86/kvm, and x86/tsc.
There are two sorts of get_device_system_crosststamp() callers in the current kernel:
1) On Intel platforms, some PTP hardware clocks, and the HDA controller, obtain the clocksource pointer for get_device_system_crosststamp() using convert_art_to_tsc() or convert_art_ns_to_tsc() from arch/x86.
2) The ptp_kvm driver uses kvm_arch_ptp_get_crosststamp(), which is implemented for platforms with kvm_clock (x86) or arm_arch_timer. Amongst other things, kvm_arch_ptp_get_crosststamp() returns a clocksource pointer. The Arm implementation is in the arm_arch_timer driver.
Changes
-------
The series does the following:
- add clocksource ID to the get_device_system_crosststamp() param type
- add required clocksource ids and set them in
get_device_system_crosststamp() users
- evaluate clocksource ID in get_device_system_crosststamp(), rather than clocksource pointer
- remove now obsolete clocksource pointer field and related code
This series should not alter any behavior. This series is a prerequisite for the virtio_rtc driver [1].
Verification
------------
Out of the existing get_device_system_crosststamp() users, only ptp_kvm has been tested (on x86-64 and arm64).
For each patch, with next-20240131 and mainline 1bbb19b6eb1b, on x86-64 and arm64:
- built allmodconfig, allyesconfig, tinyconfig with GCC and LLVM (with a few unrelated features turned off)
- runtime-tested ptp_kvm, checking ioctl PTP_SYS_OFFSET_PRECISE return codes and clock synchronization success (reverted unrelated "tty: serial: amba-pl011: Remove QDF2xxx workarounds" from linux-next on arm64, to get QEMU with console working)
Changelog
---------
v3:
- Drop RFC.
- Omit redundant clocksource_ids.h includes (Andy Shevchenko).
- Fix tsc.c kernel-doc warnings, omitting some redundant documentation (Simon Horman).
- Document relevant verification.
- Improve commit message wording.
v2:
- Align existing changes with sketch [2] by Thomas Gleixner (omitting additional clocksource base changes from [2]).
- Add follow-up improvements in ptp_kvm and kvmclock.
- Split patches differently (Thomas Gleixner).
- Refer to clocksource IDs as such in comments (Thomas Gleixner).
- Update comments which were still referring to clocksource pointers.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/87lec15i4b.ffs@tglx/
Peter Hilber (8):
x86/tsc: Fix major kernel-doc warnings for tsc.c
timekeeping: Add clocksource ID to struct system_counterval_t x86/tsc: Add clocksource ID, set system_counterval_t.cs_id x86/kvm, ptp/kvm: Add clocksource ID, set system_counterval_t.cs_id ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
timekeeping: Evaluate system_counterval_t.cs_id instead of .cs
treewide: Remove system_counterval_t.cs, which is never read
kvmclock: Unexport kvmclock clocksource
arch/x86/include/asm/kvmclock.h | 2 -- arch/x86/kernel/kvmclock.c | 4 ++-- arch/x86/kernel/tsc.c | 28 +++++++++++++++------------- drivers/clocksource/arm_arch_timer.c | 6 +++--- drivers/ptp/ptp_kvm_common.c | 10 +++++----- drivers/ptp/ptp_kvm_x86.c | 4 ++-- include/linux/clocksource_ids.h | 3 +++ include/linux/ptp_kvm.h | 4 ++-- include/linux/timekeeping.h | 10 ++++++---- kernel/time/timekeeping.c | 9 +++++---- 10 files changed, 43 insertions(+), 37 deletions(-)
base-commit: 06f658aadff0e483ee4f807b0b46c9e5cba62bfa
Signature · 1 line
2.40.1
PATCH v3 1/8 x86/tsc: Fix major kernel-doc warnings for tsc.c
Fix the kernel-doc warnings which show up with default arguments for tsc.c:
$ ./scripts/kernel-doc arch/x86/kernel/tsc.c >/dev/null arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cycles' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cs' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1373: warning: Function parameter or struct member 'work' not described in 'tsc_refine_calibration_work'
The first two warnings stem from members of the convert_art_ns_to_tsc() return type (struct system_counterval_t). For convert_art_ns_to_tsc(), the return type members are documented like parameters.
Since these members are already documented with the struct system_counterval_t definition, remove the redundant documentation for convert_art_ns_to_tsc(). This resolves the first two warnings.
Fix the third warning by appending a ':' instead of a '-' to the '@work' documentation parameter.
---
Notes:
v3: Added on suggestion of Simon Horman.
arch/x86/kernel/tsc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/kernel/tsc.c +1 -5
@@ -1329,10 +1329,6 @@ EXPORT_SYMBOL(convert_art_to_tsc);* 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 convert_art_ns_to_tsc (u64 art_ns)
@@ -1357,7 +1353,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
Signature · 1 line
2.40.1
Re: [PATCH v3 1/8] x86/tsc: Fix major kernel-doc warnings for tsc.c
Quoted 15 lines · Peter Hilber
Fix the kernel-doc warnings which show up with default arguments for
tsc.c:$ ./scripts/kernel-doc arch/x86/kernel/tsc.c >/dev/null arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cycles' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cs' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1373: warning: Function parameter or struct member 'work' not described in 'tsc_refine_calibration_work'The first two warnings stem from members of the
convert_art_ns_to_tsc()return type (structsystem_counterval_t). Forconvert_art_ns_to_tsc(), the return type members are documented like parameters.Since these members are already documented with the struct
system_counterval_tdefinition, remove the redundant documentation forconvert_art_ns_to_tsc(). This resolves the first two warnings.
Quoted 5 lines
Fix the third warning by appending a ':' instead of a '-' to the '@work' documentation parameter.
Suggested-by Simon Horman <[email protected]>Signed-off-by Peter Hilber <[email protected]>
Hi,
or this way:
https://lore.kernel.org/lkml/[email protected]/
Thanks.
Quoted 32 lines
---
Notes:
v3: Added on suggestion of Simon Horman.arch/x86/kernel/tsc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)arch/x86/kernel/tsc.c +1
-5@@ -1329,10 +1329,6 @@ EXPORT_SYMBOL(convert_art_to_tsc);* 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 convert_art_ns_to_tsc (u64 art_ns)@@ -1357,7 +1353,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
Signature · 1 line
#Randy
Re: [PATCH v3 1/8] x86/tsc: Fix major kernel-doc warnings for tsc.c
Quoted 21 lines · Randy Dunlap
Quoted 18 lines · Peter Hilber
Fix the kernel-doc warnings which show up with default arguments for
tsc.c:$ ./scripts/kernel-doc arch/x86/kernel/tsc.c >/dev/null arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cycles' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cs' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1373: warning: Function parameter or struct member 'work' not described in 'tsc_refine_calibration_work'The first two warnings stem from members of the
convert_art_ns_to_tsc()return type (structsystem_counterval_t). Forconvert_art_ns_to_tsc(), the return type members are documented like parameters.Since these members are already documented with the struct
system_counterval_tdefinition, remove the redundant documentation forconvert_art_ns_to_tsc(). This resolves the first two warnings.Fix the third warning by appending a ':' instead of a '-' to the '@work' documentation parameter.
Quoted 7 lines
Quoted 2 lines
Suggested-by Simon Horman <[email protected]>Signed-off-by Peter Hilber <[email protected]>Hi,
or this way:
Thanks for the link! I did not see your patch, I think I could add it to my patch series instead of my patch.
Best regards,
Peter
Re: [PATCH v3 1/8] x86/tsc: Fix major kernel-doc warnings for tsc.c
Quoted 25 lines · Peter Hilber
Quoted 24 lines · Randy Dunlap
Quoted 20 lines · Peter Hilber
Fix the kernel-doc warnings which show up with default arguments for
tsc.c:$ ./scripts/kernel-doc arch/x86/kernel/tsc.c >/dev/null arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cycles' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1339: warning: Excess function parameter 'cs' description in 'convert_art_ns_to_tsc' arch/x86/kernel/tsc.c:1373: warning: Function parameter or struct member 'work' not described in 'tsc_refine_calibration_work'The first two warnings stem from members of the
convert_art_ns_to_tsc()return type (structsystem_counterval_t). Forconvert_art_ns_to_tsc(), the return type members are documented like parameters.Since these members are already documented with the struct
system_counterval_tdefinition, remove the redundant documentation forconvert_art_ns_to_tsc(). This resolves the first two warnings.Fix the third warning by appending a ':' instead of a '-' to the '@work' documentation parameter.
Suggested-by Simon Horman <[email protected]>Signed-off-by Peter Hilber <[email protected]>
Quoted 7 lines
Quoted 4 lines
Hi,
or this way:Thanks for the link! I did not see your patch, I think I could add it to my patch series instead of my patch.
Sure, go with it. :)
thanks.
Signature · 1 line
#Randy
PATCH v3 2/8 timekeeping: Add clocksource ID to struct system_counterval_t
In reply to Peter HilberClocksource pointers can be problematic to obtain for drivers which are not clocksource drivers themselves. In particular, the RFC virtio_rtc driver
[1] would require a new helper function to obtain a pointer to the Arm Generic Timer clocksource. The ptp_kvm driver also required a similar workaround.
Add a clocksource ID member to struct system_counterval_t, which in the future shall identify the clocksource, and which shall replace the struct clocksource * member. By this, get_device_system_crosststamp() callers (such as virtio_rtc and ptp_kvm) will be able to supply easily accessible clocksource ids instead of clocksource pointers.
[1] https://lore.kernel.org/lkml/[email protected]/
---
Notes:
v2:
- Refer to clocksource IDs as such in comments (Thomas Gleixner).
include/linux/timekeeping.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/timekeeping.h +5 -0
@@ -273,10 +273,15 @@ struct system_device_crosststamp {* @cycles: System counter value * @cs: Clocksource corresponding to system counter value. Used by * timekeeping code to verify comparibility of two cycle values +* @cs_id: Clocksource ID corresponding to system counter value. To be +* used instead of cs in the future. +* The default ID, CSID_GENERIC, does not identify a specific +* clocksource. */ struct system_counterval_t {u64 cycles;struct clocksource *cs; +enum clocksource_ids cs_id; };/*
Signature · 1 line
2.40.1
[tip: timers/ptp] timekeeping: Add clocksource ID to struct system_counterval_t
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 93630d6df7507fa4e664110b1878c06a0c00b0b9 Gitweb: https://git.kernel.org/tip/93630d6df7507fa4e664110b1878c06a0c00b0b9 Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:47 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
timekeeping: Add clocksource ID to struct system_counterval_t
Clocksource pointers can be problematic to obtain for drivers which are not clocksource drivers themselves. In particular, the RFC virtio_rtc driver
[1] would require a new helper function to obtain a pointer to the ARM Generic Timer clocksource. The ptp_kvm driver also required a similar workaround.
Add a clocksource ID member to struct system_counterval_t, which in the future shall identify the clocksource, and which shall replace the struct clocksource * member. By this, get_device_system_crosststamp() callers (such as virtio_rtc and ptp_kvm) will be able to supply easily accessible clocksource ids instead of clocksource pointers.
[1] https://lore.kernel.org/lkml/[email protected]/
--- include/linux/timekeeping.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/timekeeping.h +5 -0
@@ -273,10 +273,15 @@ struct system_device_crosststamp {* @cycles: System counter value * @cs: Clocksource corresponding to system counter value. Used by * timekeeping code to verify comparibility of two cycle values +* @cs_id: Clocksource ID corresponding to system counter value. To be +* used instead of cs in the future. +* The default ID, CSID_GENERIC, does not identify a specific +* clocksource. */ struct system_counterval_t {u64 cycles;struct clocksource *cs; +enum clocksource_ids cs_id; };/*
PATCH v3 3/8 x86/tsc: Add clocksource ID, set system_counterval_t.cs_id
In reply to Peter HilberAdd a clocksource ID for TSC and a distinct one for the early TSC.
Use distinct IDs for TSC and early TSC, since those also have distinct clocksource structs. This should help to keep existing semantics when comparing clocksources.
Also, set the recently added struct system_counterval_t member cs_id to the TSC ID in the cases where the clocksource member is being set to the TSC clocksource. In the future, get_device_system_crosststamp() will compare the clocksource ID in struct system_counterval_t, rather than the clocksource.
For the x86 ART related code, system_counterval_t.cs == NULL corresponds to system_counterval_t.cs_id == CSID_GENERIC (0).
---
Notes:
v3:
- Omit redundant clocksource_ids.h include (Andy Shevchenko).
- Omit struct system_counterval_t member documentation, to resolve kernel-doc warning pointed out by Simon Horman.
v2:
- Name clock id according to Thomas Gleixner's mockup.
- Refer to clocksource IDs as such in comments (Thomas Gleixner).
- Update comments which were still referring to clocksource pointers.
arch/x86/kernel/tsc.c | 27 ++++++++++++++++++++------- include/linux/clocksource_ids.h | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-)
arch/x86/kernel/tsc.c +20 -7
@@ -54,6 +54,7 @@ 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 */
@@ -1168,6 +1169,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 +1192,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 +1312,11 @@ 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 = art_related_clocksource, + .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , + .cycles = res + }; }EXPORT_SYMBOL (convert_art_to_tsc);
@@ -1327,7 +1333,7 @@ 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 +* struct system_counterval_t - system counter value with the ID of the * corresponding clocksource */
@@ -1343,8 +1349,11 @@ 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 = art_related_clocksource, + .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , + .cycles = res + }; }EXPORT_SYMBOL (convert_art_ns_to_tsc);
@@ -1450,8 +1459,10 @@ static void tsc_refine_calibration_work(struct work_struct *work)if (tsc_unstable) goto unreg; -if (boot_cpu_has (X86_FEATURE_ART )) +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);
@@ -1476,8 +1487,10 @@ static int __init init_tsc_clocksource(void)* the refined calibration and directly register it as a clocksource. */ if (boot_cpu_has (X86_FEATURE_TSC_KNOWN_FREQ )) { -if (boot_cpu_has (X86_FEATURE_ART )) +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);
include/linux/clocksource_ids.h +2 -0
@@ -6,6 +6,8 @@enum clocksource_ids {CSID_GENERIC =0 ,CSID_ARM_ARCH_COUNTER , +CSID_X86_TSC_EARLY , +CSID_X86_TSC ,CSID_MAX , };
Signature · 1 line
2.40.1
[tip: timers/ptp] x86/tsc: Add clocksource ID, set system_counterval_t.cs_id
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: a2c1fe72062a5dd69de4dfe892f6436d6c0479dd Gitweb: https://git.kernel.org/tip/a2c1fe72062a5dd69de4dfe892f6436d6c0479dd Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:48 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
x86/tsc: Add clocksource ID, set system_counterval_t.cs_id
Add a clocksource ID for TSC and a distinct one for the early TSC.
Use distinct IDs for TSC and early TSC, since those also have distinct clocksource structs. This should help to keep existing semantics when comparing clocksources.
Also, set the recently added struct system_counterval_t member cs_id to the TSC ID in the cases where the clocksource member is being set to the TSC clocksource. In the future, get_device_system_crosststamp() will compare the clocksource ID in struct system_counterval_t, rather than the clocksource.
For the x86 ART related code, system_counterval_t.cs == NULL corresponds to system_counterval_t.cs_id == CSID_GENERIC (0).
--- arch/x86/kernel/tsc.c | 28 +++++++++++++++++++++------- include/linux/clocksource_ids.h | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-)
arch/x86/kernel/tsc.c +21 -7
@@ -54,6 +54,7 @@ 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 */
@@ -1168,6 +1169,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 +1192,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 +1312,11 @@ 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 = art_related_clocksource, + .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , + .cycles = res, + }; }EXPORT_SYMBOL (convert_art_to_tsc);
@@ -1327,9 +1333,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 +* 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 * cs: Clocksource corresponding to system counter value. Used * by timekeeping code to verify comparability of two cycle * values.
@@ -1347,8 +1354,11 @@ 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 = art_related_clocksource, + .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , + .cycles = res, + }; }EXPORT_SYMBOL (convert_art_ns_to_tsc);
@@ -1454,8 +1464,10 @@ out:if (tsc_unstable) goto unreg; -if (boot_cpu_has (X86_FEATURE_ART )) +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);
@@ -1480,8 +1492,10 @@ static int __init init_tsc_clocksource(void)* the refined calibration and directly register it as a clocksource. */ if (boot_cpu_has (X86_FEATURE_TSC_KNOWN_FREQ )) { -if (boot_cpu_has (X86_FEATURE_ART )) +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);
include/linux/clocksource_ids.h +2 -0
@@ -6,6 +6,8 @@enum clocksource_ids {CSID_GENERIC =0 ,CSID_ARM_ARCH_COUNTER , +CSID_X86_TSC_EARLY , +CSID_X86_TSC ,CSID_MAX , };
PATCH v3 4/8 x86/kvm, ptp/kvm: Add clocksource ID, set system_counterval_t.cs_id
In reply to Peter HilberAdd a clocksource ID for the x86 kvmclock.
Also, for ptp_kvm, set the recently added struct system_counterval_t member cs_id to the clocksource ID (x86 kvmclock or Arm Generic Timer). In the future, get_device_system_crosststamp() will compare the clocksource ID in struct system_counterval_t, rather than the clocksource.
For now, to avoid touching too many subsystems at once, extract the clocksource ID from the clocksource. The clocksource dereference will be removed in the following.
---
Notes:
v3:
- Omit redundant clocksource_ids.h include (Andy Shevchenko).
v2:
- Name clock id according to Thomas Gleixner's mockup.
arch/x86/kernel/kvmclock.c | 1 + drivers/ptp/ptp_kvm_common.c | 2 ++ include/linux/clocksource_ids.h | 1 + 3 files changed, 4 insertions(+)
arch/x86/kernel/kvmclock.c +1 -0
@@ -160,6 +160,7 @@ struct clocksource kvm_clock = { .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);
drivers/ptp/ptp_kvm_common.c +2 -0
@@ -4,6 +4,7 @@* * Copyright (C) 2017 Red Hat Inc. */ +#include <linux/clocksource.h> #include <linux/device.h> #include <linux/err.h> #include <linux/init.h>
@@ -47,6 +48,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, system_counter->cycles = cycle; system_counter->cs = cs; + system_counter->cs_id = cs->id; *device_time =timespec64_to_ktime (tspec);
include/linux/clocksource_ids.h +1 -0
@@ -8,6 +8,7 @@ enum clocksource_ids {CSID_ARM_ARCH_COUNTER ,CSID_X86_TSC_EARLY ,CSID_X86_TSC , +CSID_X86_KVM_CLK , CSID_MAX, };
Signature · 1 line
2.40.1
[tip: timers/ptp] x86/kvm, ptp/kvm: Add clocksource ID, set system_counterval_t.cs_id
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 576bd4962f19bb8f437f8cecbb25e4202438c41e Gitweb: https://git.kernel.org/tip/576bd4962f19bb8f437f8cecbb25e4202438c41e Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:49 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
x86/kvm, ptp/kvm: Add clocksource ID, set system_counterval_t.cs_id
Add a clocksource ID for the x86 kvmclock.
Also, for ptp_kvm, set the recently added struct system_counterval_t member cs_id to the clocksource ID (x86 kvmclock or ARM Generic Timer). In the future, get_device_system_crosststamp() will compare the clocksource ID in struct system_counterval_t, rather than the clocksource.
For now, to avoid touching too many subsystems at once, extract the clocksource ID from the clocksource. The clocksource dereference will be removed once everything is converted over..
--- arch/x86/kernel/kvmclock.c | 1 + drivers/ptp/ptp_kvm_common.c | 2 ++ include/linux/clocksource_ids.h | 1 + 3 files changed, 4 insertions(+)
arch/x86/kernel/kvmclock.c +1 -0
@@ -160,6 +160,7 @@ struct clocksource kvm_clock = { .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);
drivers/ptp/ptp_kvm_common.c +2 -0
@@ -4,6 +4,7 @@* * Copyright (C) 2017 Red Hat Inc. */ +#include <linux/clocksource.h> #include <linux/device.h> #include <linux/err.h> #include <linux/init.h>
@@ -47,6 +48,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, system_counter->cycles = cycle; system_counter->cs = cs; + system_counter->cs_id = cs->id; *device_time =timespec64_to_ktime (tspec);
include/linux/clocksource_ids.h +1 -0
@@ -8,6 +8,7 @@ enum clocksource_ids {CSID_ARM_ARCH_COUNTER ,CSID_X86_TSC_EARLY ,CSID_X86_TSC , +CSID_X86_KVM_CLK , CSID_MAX, };
PATCH v3 5/8 ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
In reply to Peter HilberIdentify the clocksources used by ptp_kvm by setting clocksource ID enum constants. This avoids dereferencing struct clocksource. Once the system_counterval_t.cs member will be removed, this will also avoid the need to obtain clocksource pointers from kvm_arch_ptp_get_crosststamp().
The clocksource IDs are associated to timestamps requested from the KVM hypervisor, so the proper clocksource ID is known at the ptp_kvm request site.
While at it, also rectify the ptp_kvm_get_time_fn() ret type.
---
Notes:
v2:
Added in v2.
drivers/clocksource/arm_arch_timer.c | 5 ++++- drivers/ptp/ptp_kvm_arm.c | 2 +- drivers/ptp/ptp_kvm_common.c | 10 +++++----- drivers/ptp/ptp_kvm_x86.c | 4 +++- include/linux/ptp_kvm.h | 4 +++- 5 files changed, 16 insertions(+), 9 deletions(-)
drivers/clocksource/arm_arch_timer.c +4 -1
@@ -1807,7 +1807,8 @@ 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) +struct clocksource **cs, +enum clocksource_ids *cs_id) {struct arm_smccc_res hvc_res;u32 ptp_counter;
@@ -1833,6 +1834,8 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts, *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 ; }
drivers/ptp/ptp_kvm_arm.c +1 -1
@@ -28,5 +28,5 @@ void kvm_arch_ptp_exit(void)int kvm_arch_ptp_get_clock (struct timespec64 *ts) { -return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ); +return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ,NULL ); }
drivers/ptp/ptp_kvm_common.c +5 -5
@@ -4,7 +4,6 @@* * Copyright (C) 2017 Red Hat Inc. */ -#include <linux/clocksource.h> #include <linux/device.h> #include <linux/err.h> #include <linux/init.h>
@@ -29,15 +28,16 @@ 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, &cs_id);if (ret) {spin_unlock (&kvm_ptp_lock);preempt_enable_notrace ();
@@ -48,7 +48,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, system_counter->cycles = cycle; system_counter->cs = cs; - system_counter->cs_id = cs->id; + system_counter->cs_id = cs_id; *device_time =timespec64_to_ktime (tspec);
drivers/ptp/ptp_kvm_x86.c +3 -1
@@ -93,7 +93,8 @@ int kvm_arch_ptp_get_clock(struct timespec64 *ts) }int kvm_arch_ptp_get_crosststamp (u64 *cycle,struct timespec64 *tspec, -struct clocksource **cs) +struct clocksource **cs, +enum clocksource_ids *cs_id) {struct pvclock_vcpu_time_info *src;unsigned int version;
@@ -124,6 +125,7 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *tspec, }while (pvclock_read_retry (src, version)); *cs = &kvm_clock; + *cs_id =CSID_X86_KVM_CLK ;return 0 ; }
include/linux/ptp_kvm.h +3 -1
@@ -8,6 +8,7 @@#ifndef _PTP_KVM_H_#define _PTP_KVM_H_ +#include <linux/clocksource_ids.h> #include <linux/types.h> struct timespec64 ;
@@ -17,6 +18,7 @@ int kvm_arch_ptp_init(void);void kvm_arch_ptp_exit (void );int kvm_arch_ptp_get_clock (struct timespec64 *ts);int kvm_arch_ptp_get_crosststamp (u64 *cycle, -struct timespec64 *tspec,struct clocksource **cs); +struct timespec64 *tspec,struct clocksource **cs, +enum clocksource_ids *cs_id);#endif /* _PTP_KVM_H_ */
Signature · 1 line
2.40.1
Marc Zyngier
maintainerRe: [PATCH v3 5/8] ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
Quoted 11 lines · Peter Hilber
Identify the clocksources used by
ptp_kvmby setting clocksource ID enum constants. This avoids dereferencing struct clocksource. Once the system_counterval_t.cs member will be removed, this will also avoid the need to obtain clocksource pointers fromkvm_arch_ptp_get_crosststamp().The clocksource IDs are associated to timestamps requested from the KVM hypervisor, so the proper clocksource ID is known at the
ptp_kvmrequest site.While at it, also rectify the
ptp_kvm_get_time_fn()ret type.
Not sure what is wrong with that return type, but this patch doesn't seem to affect it.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v3 5/8] ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
Quoted 8 lines · Marc Zyngier
Quoted 6 lines · Peter Hilber
Identify the clocksources used by
ptp_kvmby setting clocksource ID enum constants. This avoids dereferencing struct clocksource. Once the system_counterval_t.cs member will be removed, this will also avoid the need to obtain clocksource pointers fromkvm_arch_ptp_get_crosststamp().
Quoted 9 lines
Quoted 5 lines
The clocksource IDs are associated to timestamps requested from the KVM hypervisor, so the proper clocksource ID is known at the
ptp_kvmrequest site.While at it, also rectify the
ptp_kvm_get_time_fn()ret type.Not sure what is wrong with that return type, but this patch doesn't seem to affect it.
I meant to refer to the type of the variable ret declared in ptp_kvm_get_time_fn(). I will reword the commit message to make this clear.
Thanks for the comment,
Peter
[tip: timers/ptp] ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
In reply to Peter HilberThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 9be3b2f057d7a6752e8cf25c1d456198b4d3bd6a Gitweb: https://git.kernel.org/tip/9be3b2f057d7a6752e8cf25c1d456198b4d3bd6a Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:50 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
Identify the clocksources used by ptp_kvm by setting the clocksource ID enum constants. This avoids dereferencing struct clocksource. Once the system_counterval_t.cs member will be removed, this will also avoid the need to obtain clocksource pointers from kvm_arch_ptp_get_crosststamp().
The clocksource IDs are associated to timestamps requested from the KVM hypervisor, so the proper clocksource ID is known at the ptp_kvm request site.
While at it, also make the ptp_kvm_get_time_fn() 'ret' variable type int as that's what the function return value is.
--- drivers/clocksource/arm_arch_timer.c | 5 ++++- drivers/ptp/ptp_kvm_arm.c | 2 +- drivers/ptp/ptp_kvm_common.c | 10 +++++----- drivers/ptp/ptp_kvm_x86.c | 4 +++- include/linux/ptp_kvm.h | 4 +++- 5 files changed, 16 insertions(+), 9 deletions(-)
drivers/clocksource/arm_arch_timer.c +4 -1
@@ -1807,7 +1807,8 @@ 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) +struct clocksource **cs, +enum clocksource_ids *cs_id) {struct arm_smccc_res hvc_res;u32 ptp_counter;
@@ -1833,6 +1834,8 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts, *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 ; }
drivers/ptp/ptp_kvm_arm.c +1 -1
@@ -28,5 +28,5 @@ void kvm_arch_ptp_exit(void)int kvm_arch_ptp_get_clock (struct timespec64 *ts) { -return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ); +return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ,NULL ); }
drivers/ptp/ptp_kvm_common.c +5 -5
@@ -4,7 +4,6 @@* * Copyright (C) 2017 Red Hat Inc. */ -#include <linux/clocksource.h> #include <linux/device.h> #include <linux/err.h> #include <linux/init.h>
@@ -29,15 +28,16 @@ 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, &cs_id);if (ret) {spin_unlock (&kvm_ptp_lock);preempt_enable_notrace ();
@@ -48,7 +48,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, system_counter->cycles = cycle; system_counter->cs = cs; - system_counter->cs_id = cs->id; + system_counter->cs_id = cs_id; *device_time =timespec64_to_ktime (tspec);
drivers/ptp/ptp_kvm_x86.c +3 -1
@@ -93,7 +93,8 @@ int kvm_arch_ptp_get_clock(struct timespec64 *ts) }int kvm_arch_ptp_get_crosststamp (u64 *cycle,struct timespec64 *tspec, -struct clocksource **cs) +struct clocksource **cs, +enum clocksource_ids *cs_id) {struct pvclock_vcpu_time_info *src;unsigned int version;
@@ -124,6 +125,7 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *tspec, }while (pvclock_read_retry (src, version)); *cs = &kvm_clock; + *cs_id =CSID_X86_KVM_CLK ;return 0 ; }
include/linux/ptp_kvm.h +3 -1
@@ -8,6 +8,7 @@#ifndef _PTP_KVM_H_#define _PTP_KVM_H_ +#include <linux/clocksource_ids.h> #include <linux/types.h> struct timespec64 ;
@@ -17,6 +18,7 @@ int kvm_arch_ptp_init(void);void kvm_arch_ptp_exit (void );int kvm_arch_ptp_get_clock (struct timespec64 *ts);int kvm_arch_ptp_get_crosststamp (u64 *cycle, -struct timespec64 *tspec,struct clocksource **cs); +struct timespec64 *tspec,struct clocksource **cs, +enum clocksource_ids *cs_id);#endif /* _PTP_KVM_H_ */
PATCH v3 6/8 timekeeping: Evaluate system_counterval_t.cs_id instead of .cs
In reply to Peter HilberClocksource pointers can be problematic to obtain for drivers which are not clocksource drivers themselves. In particular, the RFC virtio_rtc driver
[1] would require a new helper function to obtain a pointer to the Arm Generic Timer clocksource. The ptp_kvm driver also required a similar workaround.
Address this by evaluating the clocksource ID, rather than the clocksource pointer, of struct system_counterval_t. By this, setting the clocksource pointer becomes unneeded, and it will be dropped from struct system_counterval_t in the future. By this, get_device_system_crosststamp() callers (such as virtio_rtc and ptp_kvm) will no longer need to supply clocksource pointers.
This change should not alter any behavior, as the struct system_counterval_t clocksource ID is already being set wherever the clocksource pointer is set. get_device_system_crosststamp() will now fail if the clocksource has ID CSID_GENERIC, but all currently relevant clocksources have a custom clocksource ID.
[1] https://lore.kernel.org/lkml/[email protected]/
---
Notes:
v2:
- Refer to clocksource IDs as such in comments (Thomas Gleixner).
- Update comments which were still referring to clocksource pointers.
include/linux/timekeeping.h | 10 +++++----- kernel/time/timekeeping.c | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-)
include/linux/timekeeping.h +5 -5
@@ -268,13 +268,13 @@ struct system_device_crosststamp { };/** -* struct system_counterval_t - system counter value with the pointer to the +* struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value -* @cs: Clocksource corresponding to system counter value. Used by -* timekeeping code to verify comparibility of two cycle values -* @cs_id: Clocksource ID corresponding to system counter value. To be -* used instead of cs in the future. +* @cs: Clocksource corresponding to system counter value. Timekeeping +* code now evaluates cs_id instead. +* @cs_id: Clocksource ID corresponding to system counter value. Used by +* timekeeping code to verify comparability of two cycle values. * The default ID, CSID_GENERIC, does not identify a specific * clocksource. */
kernel/time/timekeeping.c +5 -4
@@ -1232,11 +1232,12 @@ int get_device_system_crosststamp(int (*get_time_fn)return ret;/* -* Verify that the clocksource associated with the captured -* system counter value is the same as the currently installed -* timekeeper clocksource +* Verify that the clocksource ID associated with the captured +* system counter value is the same as for the currently +* installed timekeeper clocksource */ -if (tk->tkr_mono.clock != system_counterval.cs) +if (system_counterval.cs_id ==CSID_GENERIC || + tk->tkr_mono.clock->id != system_counterval.cs_id)return -ENODEV ; cycles = system_counterval.cycles;
Signature · 1 line
2.40.1
[tip: timers/ptp] timekeeping: Evaluate system_counterval_t.cs_id instead of .cs
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 4b7f521229ef4eee06848427d865954e6e0e3675 Gitweb: https://git.kernel.org/tip/4b7f521229ef4eee06848427d865954e6e0e3675 Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:51 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
timekeeping: Evaluate system_counterval_t.cs_id instead of .cs
Clocksource pointers can be problematic to obtain for drivers which are not clocksource drivers themselves. In particular, the RFC virtio_rtc driver
[1] would require a new helper function to obtain a pointer to the ARM Generic Timer clocksource. The ptp_kvm driver also required a similar workaround.
Address this by evaluating the clocksource ID, rather than the clocksource pointer, of struct system_counterval_t. By this, setting the clocksource pointer becomes unneeded, and get_device_system_crosststamp() callers will no longer need to supply clocksource pointers.
All relevant clocksource drivers provide the ID, so this change is not changing the behaviour.
[1] https://lore.kernel.org/lkml/[email protected]/
--- include/linux/timekeeping.h | 10 +++++----- kernel/time/timekeeping.c | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-)
include/linux/timekeeping.h +5 -5
@@ -268,13 +268,13 @@ struct system_device_crosststamp { };/** -* struct system_counterval_t - system counter value with the pointer to the +* struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value -* @cs: Clocksource corresponding to system counter value. Used by -* timekeeping code to verify comparibility of two cycle values -* @cs_id: Clocksource ID corresponding to system counter value. To be -* used instead of cs in the future. +* @cs: Clocksource corresponding to system counter value. Timekeeping +* code now evaluates cs_id instead. +* @cs_id: Clocksource ID corresponding to system counter value. Used by +* timekeeping code to verify comparability of two cycle values. * The default ID, CSID_GENERIC, does not identify a specific * clocksource. */
kernel/time/timekeeping.c +5 -4
@@ -1232,11 +1232,12 @@ int get_device_system_crosststamp(int (*get_time_fn)return ret;/* -* Verify that the clocksource associated with the captured -* system counter value is the same as the currently installed -* timekeeper clocksource +* Verify that the clocksource ID associated with the captured +* system counter value is the same as for the currently +* installed timekeeper clocksource */ -if (tk->tkr_mono.clock != system_counterval.cs) +if (system_counterval.cs_id ==CSID_GENERIC || + tk->tkr_mono.clock->id != system_counterval.cs_id)return -ENODEV ; cycles = system_counterval.cycles;
PATCH v3 7/8 treewide: Remove system_counterval_t.cs, which is never read
In reply to Peter HilberThe clocksource pointer in struct system_counterval_t is not evaluated any more. Remove the code setting the member, and the member itself.
--- arch/x86/kernel/tsc.c | 11 ++--------- drivers/clocksource/arm_arch_timer.c | 3 --- drivers/ptp/ptp_kvm_arm.c | 2 +- drivers/ptp/ptp_kvm_common.c | 4 +--- drivers/ptp/ptp_kvm_x86.c | 2 -- include/linux/ptp_kvm.h | 4 +--- include/linux/timekeeping.h | 3 --- 7 files changed, 5 insertions(+), 24 deletions(-)
arch/x86/kernel/tsc.c +2 -9
@@ -53,7 +53,6 @@ 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 {
@@ -1313,7 +1312,6 @@ struct system_counterval_t convert_art_to_tsc(u64 art) res += tmp + art_to_tsc_offset;return (struct system_counterval_t ) { - .cs = art_related_clocksource, .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , .cycles = res };
@@ -1350,7 +1348,6 @@ struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns) res += tmp;return (struct system_counterval_t ) { - .cs = art_related_clocksource, .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , .cycles = res };
@@ -1459,10 +1456,8 @@ static void tsc_refine_calibration_work(struct work_struct *work)if (tsc_unstable) goto unreg; -if (boot_cpu_has (X86_FEATURE_ART )) { - art_related_clocksource = &clocksource_tsc; +if (boot_cpu_has (X86_FEATURE_ART )) have_art = true; - }clocksource_register_khz (&clocksource_tsc, tsc_khz); unreg:clocksource_unregister (&clocksource_tsc_early);
@@ -1487,10 +1482,8 @@ static int __init init_tsc_clocksource(void)* the refined calibration and directly register it as a clocksource. */ if (boot_cpu_has (X86_FEATURE_TSC_KNOWN_FREQ )) { -if (boot_cpu_has (X86_FEATURE_ART )) { - art_related_clocksource = &clocksource_tsc; +if (boot_cpu_has (X86_FEATURE_ART )) have_art = true; - }clocksource_register_khz (&clocksource_tsc, tsc_khz);clocksource_unregister (&clocksource_tsc_early);
drivers/clocksource/arm_arch_timer.c +0 -3
@@ -1807,7 +1807,6 @@ 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;
@@ -1832,8 +1831,6 @@ 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 ;
drivers/ptp/ptp_kvm_arm.c +1 -1
@@ -28,5 +28,5 @@ void kvm_arch_ptp_exit(void)int kvm_arch_ptp_get_clock (struct timespec64 *ts) { -return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ,NULL ); +return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ); }
drivers/ptp/ptp_kvm_common.c +1 -3
@@ -30,14 +30,13 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, {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, &cs_id); + ret =kvm_arch_ptp_get_crosststamp (&cycle, &tspec, &cs_id);if (ret) {spin_unlock (&kvm_ptp_lock);preempt_enable_notrace ();
@@ -47,7 +46,6 @@ 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);
drivers/ptp/ptp_kvm_x86.c +0 -2
@@ -93,7 +93,6 @@ int kvm_arch_ptp_get_clock(struct timespec64 *ts) }int kvm_arch_ptp_get_crosststamp (u64 *cycle,struct timespec64 *tspec, -struct clocksource **cs,enum clocksource_ids *cs_id) {struct pvclock_vcpu_time_info *src;
@@ -124,7 +123,6 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *tspec, *cycle =__pvclock_read_cycles (src, clock_pair->tsc); }while (pvclock_read_retry (src, version)); - *cs = &kvm_clock; *cs_id =CSID_X86_KVM_CLK ;return 0 ;
include/linux/ptp_kvm.h +1 -3
@@ -12,13 +12,11 @@#include <linux/types.h> struct timespec64 ; -struct clocksource ;int kvm_arch_ptp_init (void );void kvm_arch_ptp_exit (void );int kvm_arch_ptp_get_clock (struct timespec64 *ts);int kvm_arch_ptp_get_crosststamp (u64 *cycle, -struct timespec64 *tspec,struct clocksource **cs, -enum clocksource_ids *cs_id); +struct timespec64 *tspec,enum clocksource_ids *cs_id);#endif /* _PTP_KVM_H_ */
include/linux/timekeeping.h +0 -3
@@ -271,8 +271,6 @@ struct system_device_crosststamp {* struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value -* @cs: Clocksource corresponding to system counter value. Timekeeping -* code now evaluates cs_id instead. * @cs_id: Clocksource ID corresponding to system counter value. Used by * timekeeping code to verify comparability of two cycle values. * The default ID, CSID_GENERIC, does not identify a specific
@@ -280,7 +278,6 @@ struct system_device_crosststamp {*/ struct system_counterval_t {u64 cycles; -struct clocksource *cs;enum clocksource_ids cs_id; };
Signature · 1 line
2.40.1
[tip: timers/ptp] treewide: Remove system_counterval_t.cs, which is never read
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: b152688c91313ab4073cff4a5e63ff4cc491c358 Gitweb: https://git.kernel.org/tip/b152688c91313ab4073cff4a5e63ff4cc491c358 Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:52 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
treewide: Remove system_counterval_t.cs, which is never read
The clocksource pointer in struct system_counterval_t is not evaluated any more. Remove the code setting the member, and the member itself.
--- arch/x86/kernel/tsc.c | 14 ++------------ drivers/clocksource/arm_arch_timer.c | 3 --- drivers/ptp/ptp_kvm_arm.c | 2 +- drivers/ptp/ptp_kvm_common.c | 4 +--- drivers/ptp/ptp_kvm_x86.c | 2 -- include/linux/ptp_kvm.h | 4 +--- include/linux/timekeeping.h | 3 --- 7 files changed, 5 insertions(+), 27 deletions(-)
arch/x86/kernel/tsc.c +2 -12
@@ -53,7 +53,6 @@ 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 {
@@ -1313,7 +1312,6 @@ struct system_counterval_t convert_art_to_tsc(u64 art) res += tmp + art_to_tsc_offset;return (struct system_counterval_t ) { - .cs = art_related_clocksource, .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , .cycles = res, };
@@ -1337,9 +1335,6 @@ EXPORT_SYMBOL(convert_art_to_tsc);* corresponding clocksource: * cycles: System counter value * cs_id: The clocksource ID for validating comparability -* cs: Clocksource corresponding to system counter value. Used -* by timekeeping code to verify comparability of two cycle -* values. */ struct system_counterval_t convert_art_ns_to_tsc (u64 art_ns)
@@ -1355,7 +1350,6 @@ struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns) res += tmp;return (struct system_counterval_t ) { - .cs = art_related_clocksource, .cs_id = have_art ?CSID_X86_TSC :CSID_GENERIC , .cycles = res, };
@@ -1464,10 +1458,8 @@ out:if (tsc_unstable) goto unreg; -if (boot_cpu_has (X86_FEATURE_ART )) { - art_related_clocksource = &clocksource_tsc; +if (boot_cpu_has (X86_FEATURE_ART )) have_art = true; - }clocksource_register_khz (&clocksource_tsc, tsc_khz); unreg:clocksource_unregister (&clocksource_tsc_early);
@@ -1492,10 +1484,8 @@ static int __init init_tsc_clocksource(void)* the refined calibration and directly register it as a clocksource. */ if (boot_cpu_has (X86_FEATURE_TSC_KNOWN_FREQ )) { -if (boot_cpu_has (X86_FEATURE_ART )) { - art_related_clocksource = &clocksource_tsc; +if (boot_cpu_has (X86_FEATURE_ART )) have_art = true; - }clocksource_register_khz (&clocksource_tsc, tsc_khz);clocksource_unregister (&clocksource_tsc_early);
drivers/clocksource/arm_arch_timer.c +0 -3
@@ -1807,7 +1807,6 @@ 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;
@@ -1832,8 +1831,6 @@ 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 ;
drivers/ptp/ptp_kvm_arm.c +1 -1
@@ -28,5 +28,5 @@ void kvm_arch_ptp_exit(void)int kvm_arch_ptp_get_clock (struct timespec64 *ts) { -return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ,NULL ); +return kvm_arch_ptp_get_crosststamp (NULL , ts,NULL ); }
drivers/ptp/ptp_kvm_common.c +1 -3
@@ -30,14 +30,13 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, {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, &cs_id); + ret =kvm_arch_ptp_get_crosststamp (&cycle, &tspec, &cs_id);if (ret) {spin_unlock (&kvm_ptp_lock);preempt_enable_notrace ();
@@ -47,7 +46,6 @@ 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);
drivers/ptp/ptp_kvm_x86.c +0 -2
@@ -93,7 +93,6 @@ int kvm_arch_ptp_get_clock(struct timespec64 *ts) }int kvm_arch_ptp_get_crosststamp (u64 *cycle,struct timespec64 *tspec, -struct clocksource **cs,enum clocksource_ids *cs_id) {struct pvclock_vcpu_time_info *src;
@@ -124,7 +123,6 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *tspec, *cycle =__pvclock_read_cycles (src, clock_pair->tsc); }while (pvclock_read_retry (src, version)); - *cs = &kvm_clock; *cs_id =CSID_X86_KVM_CLK ;return 0 ;
include/linux/ptp_kvm.h +1 -3
@@ -12,13 +12,11 @@#include <linux/types.h> struct timespec64 ; -struct clocksource ;int kvm_arch_ptp_init (void );void kvm_arch_ptp_exit (void );int kvm_arch_ptp_get_clock (struct timespec64 *ts);int kvm_arch_ptp_get_crosststamp (u64 *cycle, -struct timespec64 *tspec,struct clocksource **cs, -enum clocksource_ids *cs_id); +struct timespec64 *tspec,enum clocksource_ids *cs_id);#endif /* _PTP_KVM_H_ */
include/linux/timekeeping.h +0 -3
@@ -271,8 +271,6 @@ struct system_device_crosststamp {* struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value -* @cs: Clocksource corresponding to system counter value. Timekeeping -* code now evaluates cs_id instead. * @cs_id: Clocksource ID corresponding to system counter value. Used by * timekeeping code to verify comparability of two cycle values. * The default ID, CSID_GENERIC, does not identify a specific
@@ -280,7 +278,6 @@ struct system_device_crosststamp {*/ struct system_counterval_t {u64 cycles; -struct clocksource *cs;enum clocksource_ids cs_id; };
PATCH v3 8/8 kvmclock: Unexport kvmclock clocksource
In reply to Peter HilberThe KVM PTP driver now refers to the clocksource ID CSID_X86_KVM_CLK, not to the clocksource itself any more. There are no remaining users of the clocksource export.
Therefore, make the clocksource static again.
---
Notes:
v2:
Added in v2.
arch/x86/include/asm/kvmclock.h | 2 -- arch/x86/kernel/kvmclock.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-)
arch/x86/include/asm/kvmclock.h +0 -2
@@ -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)
arch/x86/kernel/kvmclock.c +1 -2
@@ -154,7 +154,7 @@ 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 ,
@@ -163,7 +163,6 @@ struct clocksource kvm_clock = { .id = CSID_X86_KVM_CLK, .enable = kvm_cs_enable, }; -EXPORT_SYMBOL_GPL (kvm_clock);static void kvm_register_clock (char *txt) {
Signature · 1 line
2.40.1
[tip: timers/ptp] kvmclock: Unexport kvmclock clocksource
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 27f6a9c87a97f5ea7459be08d5be231af6b32c20 Gitweb: https://git.kernel.org/tip/27f6a9c87a97f5ea7459be08d5be231af6b32c20 Author: Peter Hilber <[email protected]> AuthorDate: Thu, 01 Feb 2024 02:04:53 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 07 Feb 2024 17:05:21 +01:00
kvmclock: Unexport kvmclock clocksource
The KVM PTP driver now refers to the clocksource ID CSID_X86_KVM_CLK, not to the clocksource itself any more. There are no remaining users of the clocksource export.
Therefore, make the clocksource static again.
--- arch/x86/include/asm/kvmclock.h | 2 -- arch/x86/kernel/kvmclock.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-)
arch/x86/include/asm/kvmclock.h +0 -2
@@ -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)
arch/x86/kernel/kvmclock.c +1 -2
@@ -154,7 +154,7 @@ 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 ,
@@ -163,7 +163,6 @@ struct clocksource kvm_clock = { .id = CSID_X86_KVM_CLK, .enable = kvm_cs_enable, }; -EXPORT_SYMBOL_GPL (kvm_clock);static void kvm_register_clock (char *txt) {