2018-07-30 07:56:12

by Dou Liyang

[permalink] [raw]
Subject: [PATCH 0/2] Two cleanup patches

Here are two cleanup patches, When I test the early boot time stamps
with tip tree today.

Dou Liyang (2):
x86/tsc: Avoid a double call if tsc can initialize earlier.
x86/kvmclock: Mark kvm_get_preset_lpj() as __init

arch/x86/kernel/kvmclock.c | 2 +-
arch/x86/kernel/tsc.c | 22 ++++++++++++----------
2 files changed, 13 insertions(+), 11 deletions(-)

--
2.14.3





2018-07-30 07:56:18

by Dou Liyang

[permalink] [raw]
Subject: [PATCH 2/2] x86/kvmclock: Mark kvm_get_preset_lpj() as __init

kvm_get_preset_lpj() just be called at kvmclock_init(), So mark it
__init as well.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: [email protected]
Signed-off-by: Dou Liyang <[email protected]>
---
arch/x86/kernel/kvmclock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index 91b94c0ae4e3..d2edd7e6c294 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -145,7 +145,7 @@ static unsigned long kvm_get_tsc_khz(void)
return pvclock_tsc_khz(this_cpu_pvti());
}

-static void kvm_get_preset_lpj(void)
+static void __init kvm_get_preset_lpj(void)
{
unsigned long khz;
u64 lpj;
--
2.14.3




2018-07-30 07:56:19

by Dou Liyang

[permalink] [raw]
Subject: [PATCH 1/2] x86/tsc: Avoid a double call if TSC initializes earlier.

static_branch_enable(&__use_tsc) may be called twice in common case, that
is redundant. And there are also some common functions both in
tsc_early_init() and tsc_init().

Move them into a separate helper function, only call it once.
Also fix comments:
-s/authorative/authoritative
-s/cyc2ns_init/tsc_init

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Pavel Tatashin <[email protected]>
Signed-off-by: Dou Liyang <[email protected]>
---
arch/x86/kernel/tsc.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 02e416b87ac1..ba0a6b6e0726 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -182,7 +182,7 @@ static void __init cyc2ns_init_boot_cpu(void)
}

/*
- * Secondary CPUs do not run through cyc2ns_init(), so set up
+ * Secondary CPUs do not run through tsc_init(), so set up
* all the scale factors for all CPUs, assuming the same
* speed as the bootup CPU. (cpufreq notifiers will fix this
* up if their speed diverges)
@@ -1389,7 +1389,7 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
}

/*
- * Trust non-zero tsc_khz as authorative,
+ * Trust non-zero tsc_khz as authoritative,
* and use it to sanity check cpu_khz,
* which will be off if system timer is off.
*/
@@ -1421,6 +1421,14 @@ static unsigned long __init get_loops_per_jiffy(void)
return lpj;
}

+static void __init enable_use_tsc(void)
+{
+ /* Sanitize TSC ADJUST before cyc2ns gets initialized */
+ tsc_store_and_check_tsc_adjust(true);
+ cyc2ns_init_boot_cpu();
+ static_branch_enable(&__use_tsc);
+}
+
void __init tsc_early_init(void)
{
if (!boot_cpu_has(X86_FEATURE_TSC))
@@ -1429,10 +1437,7 @@ void __init tsc_early_init(void)
return;
loops_per_jiffy = get_loops_per_jiffy();

- /* Sanitize TSC ADJUST before cyc2ns gets initialized */
- tsc_store_and_check_tsc_adjust(true);
- cyc2ns_init_boot_cpu();
- static_branch_enable(&__use_tsc);
+ enable_use_tsc();
}

void __init tsc_init(void)
@@ -1456,13 +1461,10 @@ void __init tsc_init(void)
setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
return;
}
- /* Sanitize TSC ADJUST before cyc2ns gets initialized */
- tsc_store_and_check_tsc_adjust(true);
- cyc2ns_init_boot_cpu();
+ enable_use_tsc();
}

cyc2ns_init_secondary_cpus();
- static_branch_enable(&__use_tsc);

if (!no_sched_irq_time)
enable_sched_clock_irqtime();
--
2.14.3




2018-07-30 09:36:48

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86/tsc: Avoid a double call if TSC initializes earlier.

On Mon, Jul 30, 2018 at 03:54:20PM +0800, Dou Liyang wrote:
> static_branch_enable(&__use_tsc) may be called twice in common case, that
> is redundant.

It is also really not a problem...

2018-07-30 09:55:34

by Dou Liyang

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86/tsc: Avoid a double call if TSC initializes earlier.

Hi Peter,

At 07/30/2018 05:34 PM, Peter Zijlstra wrote:
> On Mon, Jul 30, 2018 at 03:54:20PM +0800, Dou Liyang wrote:
>> static_branch_enable(&__use_tsc) may be called twice in common case, that
>> is redundant.
>
> It is also really not a problem...
>

Yes, right. Just avoid the second useless setting.

Thanks,
dou

>
>



2018-07-30 14:11:01

by Pavel Tatashin

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86/tsc: Avoid a double call if TSC initializes earlier.

On Mon, Jul 30, 2018 at 3:55 AM Dou Liyang <[email protected]> wrote:
>
> static_branch_enable(&__use_tsc) may be called twice in common case, that
> is redundant. And there are also some common functions both in
> tsc_early_init() and tsc_init().
>
> Move them into a separate helper function, only call it once.
> Also fix comments:
> -s/authorative/authoritative
> -s/cyc2ns_init/tsc_init
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: "H. Peter Anvin" <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Pavel Tatashin <[email protected]>
> Signed-off-by: Dou Liyang <[email protected]>

Hi Dou,

Nice cleanup.
Reviewed-by: Pavel Tatashin <[email protected]>

Thank you,
Pavel

> ---
> arch/x86/kernel/tsc.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> index 02e416b87ac1..ba0a6b6e0726 100644
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -182,7 +182,7 @@ static void __init cyc2ns_init_boot_cpu(void)
> }
>
> /*
> - * Secondary CPUs do not run through cyc2ns_init(), so set up
> + * Secondary CPUs do not run through tsc_init(), so set up
> * all the scale factors for all CPUs, assuming the same
> * speed as the bootup CPU. (cpufreq notifiers will fix this
> * up if their speed diverges)
> @@ -1389,7 +1389,7 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
> }
>
> /*
> - * Trust non-zero tsc_khz as authorative,
> + * Trust non-zero tsc_khz as authoritative,
> * and use it to sanity check cpu_khz,
> * which will be off if system timer is off.
> */
> @@ -1421,6 +1421,14 @@ static unsigned long __init get_loops_per_jiffy(void)
> return lpj;
> }
>
> +static void __init enable_use_tsc(void)
> +{
> + /* Sanitize TSC ADJUST before cyc2ns gets initialized */
> + tsc_store_and_check_tsc_adjust(true);
> + cyc2ns_init_boot_cpu();
> + static_branch_enable(&__use_tsc);
> +}
> +
> void __init tsc_early_init(void)
> {
> if (!boot_cpu_has(X86_FEATURE_TSC))
> @@ -1429,10 +1437,7 @@ void __init tsc_early_init(void)
> return;
> loops_per_jiffy = get_loops_per_jiffy();
>
> - /* Sanitize TSC ADJUST before cyc2ns gets initialized */
> - tsc_store_and_check_tsc_adjust(true);
> - cyc2ns_init_boot_cpu();
> - static_branch_enable(&__use_tsc);
> + enable_use_tsc();
> }
>
> void __init tsc_init(void)
> @@ -1456,13 +1461,10 @@ void __init tsc_init(void)
> setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
> return;
> }
> - /* Sanitize TSC ADJUST before cyc2ns gets initialized */
> - tsc_store_and_check_tsc_adjust(true);
> - cyc2ns_init_boot_cpu();
> + enable_use_tsc();
> }
>
> cyc2ns_init_secondary_cpus();
> - static_branch_enable(&__use_tsc);
>
> if (!no_sched_irq_time)
> enable_sched_clock_irqtime();
> --
> 2.14.3
>
>
>

2018-07-30 14:19:42

by Pavel Tatashin

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86/kvmclock: Mark kvm_get_preset_lpj() as __init

On Mon, Jul 30, 2018 at 3:55 AM Dou Liyang <[email protected]> wrote:
>
> kvm_get_preset_lpj() just be called at kvmclock_init(), So mark it
> __init as well.

Reviewed-by: Pavel Tatashin <[email protected]>

Thank you,
Pavel

Subject: [tip:x86/timers] x86/tsc: Consolidate init code

Commit-ID: 608008a45798fe9e2aee04f99b5270ea57c1376f
Gitweb: https://git.kernel.org/tip/608008a45798fe9e2aee04f99b5270ea57c1376f
Author: Dou Liyang <[email protected]>
AuthorDate: Mon, 30 Jul 2018 15:54:20 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Mon, 30 Jul 2018 19:33:35 +0200

x86/tsc: Consolidate init code

Split out suplicated code from tsc_early_init() and tsc_init() into a
common helper and fixup some comment typos.

[ tglx: Massaged changelog and renamed function ]

Signed-off-by: Dou Liyang <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Pavel Tatashin <[email protected]>
Cc: <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/kernel/tsc.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 02e416b87ac1..1463468ba9a0 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -182,7 +182,7 @@ static void __init cyc2ns_init_boot_cpu(void)
}

/*
- * Secondary CPUs do not run through cyc2ns_init(), so set up
+ * Secondary CPUs do not run through tsc_init(), so set up
* all the scale factors for all CPUs, assuming the same
* speed as the bootup CPU. (cpufreq notifiers will fix this
* up if their speed diverges)
@@ -1389,7 +1389,7 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
}

/*
- * Trust non-zero tsc_khz as authorative,
+ * Trust non-zero tsc_khz as authoritative,
* and use it to sanity check cpu_khz,
* which will be off if system timer is off.
*/
@@ -1421,6 +1421,14 @@ static unsigned long __init get_loops_per_jiffy(void)
return lpj;
}

+static void __init tsc_enable_sched_clock(void)
+{
+ /* Sanitize TSC ADJUST before cyc2ns gets initialized */
+ tsc_store_and_check_tsc_adjust(true);
+ cyc2ns_init_boot_cpu();
+ static_branch_enable(&__use_tsc);
+}
+
void __init tsc_early_init(void)
{
if (!boot_cpu_has(X86_FEATURE_TSC))
@@ -1429,10 +1437,7 @@ void __init tsc_early_init(void)
return;
loops_per_jiffy = get_loops_per_jiffy();

- /* Sanitize TSC ADJUST before cyc2ns gets initialized */
- tsc_store_and_check_tsc_adjust(true);
- cyc2ns_init_boot_cpu();
- static_branch_enable(&__use_tsc);
+ tsc_enable_sched_clock();
}

void __init tsc_init(void)
@@ -1456,13 +1461,10 @@ void __init tsc_init(void)
setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
return;
}
- /* Sanitize TSC ADJUST before cyc2ns gets initialized */
- tsc_store_and_check_tsc_adjust(true);
- cyc2ns_init_boot_cpu();
+ tsc_enable_sched_clock();
}

cyc2ns_init_secondary_cpus();
- static_branch_enable(&__use_tsc);

if (!no_sched_irq_time)
enable_sched_clock_irqtime();

Subject: [tip:x86/timers] x86/kvmclock: Mark kvm_get_preset_lpj() as __init

Commit-ID: 1088c6eef261939bda8346ec35b513790a2111d5
Gitweb: https://git.kernel.org/tip/1088c6eef261939bda8346ec35b513790a2111d5
Author: Dou Liyang <[email protected]>
AuthorDate: Mon, 30 Jul 2018 15:54:21 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Mon, 30 Jul 2018 19:33:35 +0200

x86/kvmclock: Mark kvm_get_preset_lpj() as __init

kvm_get_preset_lpj() is only called from kvmclock_init(), so mark it __init
as well.

Signed-off-by: Dou Liyang <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Pavel Tatashin <[email protected]>
Cc: <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Radim Krčmář<[email protected]>
Cc: <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/kernel/kvmclock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index 91b94c0ae4e3..d2edd7e6c294 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -145,7 +145,7 @@ static unsigned long kvm_get_tsc_khz(void)
return pvclock_tsc_khz(this_cpu_pvti());
}

-static void kvm_get_preset_lpj(void)
+static void __init kvm_get_preset_lpj(void)
{
unsigned long khz;
u64 lpj;