From: Laurent Dufour <ldufour@linux.ibm.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Michael Ellerman <mpe@ellerman.id.au>,
linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, dave.hansen@linux.intel.com,
x86@kernel.org, mingo@redhat.com, bp@alien8.de,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 3/9] cpu/SMT: Store the current/max number of threads
Date: Tue, 13 Jun 2023 19:16:54 +0200 [thread overview]
Message-ID: <d42e9452-8210-a06a-4c91-6c2f1d038a61@linux.ibm.com> (raw)
In-Reply-To: <87fs6z80w5.ffs@tglx>
On 10/06/2023 23:26:18, Thomas Gleixner wrote:
> On Thu, May 25 2023 at 01:56, Michael Ellerman wrote:
>> #ifdef CONFIG_HOTPLUG_SMT
>> enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
>> +static unsigned int cpu_smt_max_threads __ro_after_init;
>> +unsigned int cpu_smt_num_threads;
>
> Why needs this to be global? cpu_smt_control is pointlessly global already.
I agree that cpu_smt_*_threads should be static.
Howwever, regarding cpu_smt_control, it is used in 2 places in the x86 code:
- arch/x86/power/hibernate.c in arch_resume_nosmt()
- arch/x86/kernel/cpu/bugs.c in spectre_v2_user_select_mitigation()
An accessor function may be introduced to read that value in these 2
functions, but I'm wondering if that's really the best option.
Unless there is a real need to change this through this series, I think
cpu_smt_control can remain global.
Thomas, are you ok with that?
>
>> void __init cpu_smt_disable(bool force)
>> {
>> @@ -433,10 +435,18 @@ void __init cpu_smt_disable(bool force)
>> * The decision whether SMT is supported can only be done after the full
>> * CPU identification. Called from architecture code.
>> */
>> -void __init cpu_smt_check_topology(void)
>> +void __init cpu_smt_check_topology(unsigned int num_threads)
>> {
>> if (!topology_smt_supported())
>> cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
>> +
>> + cpu_smt_max_threads = num_threads;
>> +
>> + // May already be disabled by nosmt command line parameter
>> + if (cpu_smt_control != CPU_SMT_ENABLED)
>> + cpu_smt_num_threads = 1;
>> + else
>> + cpu_smt_num_threads = num_threads;
>
> Taking Laurents findings into account this should be something like
> the incomplete below.
>
> x86 would simply invoke cpu_smt_set_num_threads() with both arguments as
> smp_num_siblings while PPC can funnel its command line parameter through
> the num_threads argument.
I do prefer cpu_smt_set_num_threads() also.
Thanks,
Laurent
>
> Thanks,
>
> tglx
> ---
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -414,6 +414,8 @@ void __weak arch_smt_update(void) { }
>
> #ifdef CONFIG_HOTPLUG_SMT
> enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
> +static unsigned int cpu_smt_max_threads __ro_after_init;
> +static unsigned int cpu_smt_num_threads = UINT_MAX;
>
> void __init cpu_smt_disable(bool force)
> {
> @@ -427,24 +429,31 @@ void __init cpu_smt_disable(bool force)
> pr_info("SMT: disabled\n");
> cpu_smt_control = CPU_SMT_DISABLED;
> }
> + cpu_smt_num_threads = 1;
> }
>
> /*
> * The decision whether SMT is supported can only be done after the full
> * CPU identification. Called from architecture code.
> */
> -void __init cpu_smt_check_topology(void)
> +void __init cpu_smt_set_num_threads(unsigned int max_threads, unsigned int num_threads)
> {
> - if (!topology_smt_supported())
> + if (max_threads == 1)
> cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
> -}
>
> -static int __init smt_cmdline_disable(char *str)
> -{
> - cpu_smt_disable(str && !strcmp(str, "force"));
> - return 0;
> + cpu_smt_max_threads = max_threads;
> +
> + /*
> + * If SMT has been disabled via the kernel command line or SMT is
> + * not supported, set cpu_smt_num_threads to 1 for consistency.
> + * If enabled, take the architecture requested number of threads
> + * to bring up into account.
> + */
> + if (cpu_smt_control != CPU_SMT_ENABLED)
> + cpu_smt_num_threads = 1;
> + else if (num_threads < cpu_smt_num_threads)
> + cpu_smt_num_threads = num_threads;
> }
> -early_param("nosmt", smt_cmdline_disable);
>
> static inline bool cpu_smt_allowed(unsigned int cpu)
> {
> @@ -463,6 +472,13 @@ static inline bool cpu_smt_allowed(unsig
> return !cpumask_test_cpu(cpu, &cpus_booted_once_mask);
> }
>
> +static int __init smt_cmdline_disable(char *str)
> +{
> + cpu_smt_disable(str && !strcmp(str, "force"));
> + return 0;
> +}
> +early_param("nosmt", smt_cmdline_disable);
> +
> /* Returns true if SMT is not supported of forcefully (irreversibly) disabled */
> bool cpu_smt_possible(void)
> {
next prev parent reply other threads:[~2023-06-13 17:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 15:56 [PATCH 1/9] cpu/SMT: Move SMT prototypes into cpu_smt.h Michael Ellerman
2023-05-24 15:56 ` [PATCH 2/9] cpu/SMT: Move smt/control simple exit cases earlier Michael Ellerman
2023-05-24 15:56 ` [PATCH 3/9] cpu/SMT: Store the current/max number of threads Michael Ellerman
2023-06-10 21:26 ` Thomas Gleixner
2023-06-10 22:08 ` Thomas Gleixner
2023-06-13 17:16 ` Laurent Dufour [this message]
2023-06-13 18:53 ` Thomas Gleixner
2023-06-14 12:27 ` Laurent Dufour
2023-05-24 15:56 ` [PATCH 4/9] cpu/SMT: Create topology_smt_threads_supported() Michael Ellerman
2023-06-10 22:15 ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 5/9] cpu/SMT: Create topology_smt_thread_allowed() Michael Ellerman
2023-06-10 22:35 ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 6/9] cpu/SMT: Allow enabling partial SMT states via sysfs Michael Ellerman
2023-06-10 20:09 ` Thomas Gleixner
2023-06-10 20:13 ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 7/9] powerpc/pseries: Initialise CPU hotplug callbacks earlier Michael Ellerman
2023-05-24 15:56 ` [PATCH 8/9] powerpc: Add HOTPLUG_SMT support Michael Ellerman
2023-06-01 13:27 ` Laurent Dufour
2023-06-01 16:19 ` Laurent Dufour
2023-06-10 21:10 ` Thomas Gleixner
2023-06-12 15:20 ` Laurent Dufour
2023-06-12 16:34 ` Thomas Gleixner
2023-05-24 15:56 ` [PATCH 9/9] powerpc/pseries: Honour current SMT state when DLPAR onlining CPUs Michael Ellerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d42e9452-8210-a06a-4c91-6c2f1d038a61@linux.ibm.com \
--to=ldufour@linux.ibm.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).