From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, tglx@linutronix.de,
maddy@linux.ibm.com, vschneid@redhat.com,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
kprateek.nayak@amd.com, huschle@linux.ibm.com,
srikar@linux.ibm.com, linux-kernel@vger.kernel.org,
christophe.leroy@csgroup.eu, linuxppc-dev@lists.ozlabs.org,
gregkh@linuxfoundation.org
Subject: Re: [RFC v2 9/9] [DEBUG] powerpc: add debug file for set/unset cpu avoid
Date: Thu, 26 Jun 2025 19:09:13 +0530 [thread overview]
Message-ID: <760e230c-5699-485c-910b-ebeaa9f9bd09@linux.ibm.com> (raw)
In-Reply-To: <aFx94BDKk_WJ48pK@yury>
Hi Yury, Thanks for taking a look at this.
> On Thu, Jun 26, 2025 at 12:41:08AM +0530, Shrikanth Hegde wrote:
>> Reference patch for how an architecture can make use of this infra.
>>
>> This is not meant to be merged. Instead the vp_manual_hint should either
>> come from hardware or could be derived using steal time.
>
> If you don't add any code that manages the 'avoid' mask on the host
> side, all this becomes a dead code.
Ok.
Maybe I can keep this debug file, until we get the infra where
the hint derivation would be done by hardware by means of hcall or gets
calculated based on steal time.
I think i will have polish this a bit and move it to appropriate place
if this is to be kept.
>
>> When the provided hint is less than the total CPUs in the system, it
>> will enable the cpu avoid static key and set those CPUs as avoid.
>>
>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>> ---
>> arch/powerpc/include/asm/paravirt.h | 2 ++
>> arch/powerpc/kernel/smp.c | 50 +++++++++++++++++++++++++++++
>> 2 files changed, 52 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/paravirt.h b/arch/powerpc/include/asm/paravirt.h
>> index b78b82d66057..b6497e0b60d8 100644
>> --- a/arch/powerpc/include/asm/paravirt.h
>> +++ b/arch/powerpc/include/asm/paravirt.h
>> @@ -10,6 +10,8 @@
>> #include <asm/hvcall.h>
>> #endif
>>
>> +DECLARE_STATIC_KEY_FALSE(paravirt_cpu_avoid_enabled);
>> +
>> #ifdef CONFIG_PPC_SPLPAR
>> #include <linux/smp.h>
>> #include <asm/kvm_guest.h>
>> diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
>> index 5ac7084eebc0..e00cdc4de441 100644
>> --- a/arch/powerpc/kernel/smp.c
>> +++ b/arch/powerpc/kernel/smp.c
>> @@ -64,6 +64,7 @@
>> #include <asm/systemcfg.h>
>>
>> #include <trace/events/ipi.h>
>> +#include <linux/debugfs.h>
>>
>> #ifdef DEBUG
>> #include <asm/udbg.h>
>> @@ -82,6 +83,7 @@ bool has_big_cores __ro_after_init;
>> bool coregroup_enabled __ro_after_init;
>> bool thread_group_shares_l2 __ro_after_init;
>> bool thread_group_shares_l3 __ro_after_init;
>> +static int vp_manual_hint = NR_CPUS;
>>
>> DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
>> DEFINE_PER_CPU(cpumask_var_t, cpu_smallcore_map);
>> @@ -1727,6 +1729,7 @@ static void __init build_sched_topology(void)
>> BUG_ON(i >= ARRAY_SIZE(powerpc_topology) - 1);
>>
>> set_sched_topology(powerpc_topology);
>> + vp_manual_hint = num_present_cpus();
>> }
>>
>> void __init smp_cpus_done(unsigned int max_cpus)
>> @@ -1807,4 +1810,51 @@ void __noreturn arch_cpu_idle_dead(void)
>> start_secondary_resume();
>> }
>>
>> +/*
>> + * sysfs hint to mark CPUs as Avoid. This will help in restricting
>> + * the workload to specified number of CPUs.
>> + * For example 40 > vp_manual_hint means, workload will run on
>> + * 0-39 CPUs.
>> + */
>> +
>> +static int pv_vp_manual_hint_set(void *data, u64 val)
>> +{
>> + int cpu;
>> +
>> + if (val == 0 || vp_manual_hint > num_present_cpus())
This should be
if (val == 0 || val > num_present_cpus())
>> + vp_manual_hint = num_present_cpus();
>> +
>> + if (val != vp_manual_hint)
>> + vp_manual_hint = val;
>
> This all is effectively just:
>
> vp_manual_hint = val;
>
> Isn't?
Yes, With some checks for sane values.
>
>> + if (vp_manual_hint < num_present_cpus())
>> + static_branch_enable(¶virt_cpu_avoid_enabled);
>> + else
>> + static_branch_disable(¶virt_cpu_avoid_enabled);
>> +
>> + for_each_present_cpu(cpu) {
>> + if (cpu >= vp_manual_hint)
>> + set_cpu_avoid(cpu, true);
>> + else
>> + set_cpu_avoid(cpu, false);
>> + }
>> + return 0;
>> +}
>> +
>> +static int pv_vp_manual_hint_get(void *data, u64 *val)
>> +{
>> + *val = vp_manual_hint;
>> + return 0;
>> +}
>> +
>> +DEFINE_SIMPLE_ATTRIBUTE(fops_pv_vp_manual_hint, pv_vp_manual_hint_get, pv_vp_manual_hint_set, "%llu\n");
>> +
>> +static __init int paravirt_debugfs_init(void)
>> +{
>> + if (is_shared_processor())
>> + debugfs_create_file("vp_manual_hint", 0600, arch_debugfs_dir, NULL, &fops_pv_vp_manual_hint);
>> + return 0;
>> +}
>> +
>> +device_initcall(paravirt_debugfs_init)
>> #endif
>> --
>> 2.43.0
next prev parent reply other threads:[~2025-06-26 13:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 19:10 [RFC v2 0/9] cpu avoid state and push task mechanism Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 1/9] sched/docs: Document avoid_cpu_mask and avoid CPU concept Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 2/9] cpumask: Introduce cpu_avoid_mask Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 3/9] sched/core: Dont allow to use CPU marked as avoid Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 4/9] sched/fair: Don't use CPU marked as avoid for wakeup and load balance Shrikanth Hegde
2025-06-26 0:02 ` Yury Norov
2025-06-26 13:42 ` Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 5/9] sched/rt: Don't select CPU marked as avoid for wakeup and push/pull rt task Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 6/9] sched/core: Push current task out if CPU is marked as avoid Shrikanth Hegde
2025-08-12 18:40 ` Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 7/9] sched: Add static key check for cpu_avoid Shrikanth Hegde
2025-06-26 0:12 ` Yury Norov
2025-06-25 19:11 ` [RFC v2 8/9] sysfs: Add cpu_avoid file Shrikanth Hegde
2025-07-01 9:35 ` Greg KH
2025-07-02 6:05 ` Shrikanth Hegde
2025-06-25 19:11 ` [RFC v2 9/9] [DEBUG] powerpc: add debug file for set/unset cpu avoid Shrikanth Hegde
2025-06-25 22:53 ` Yury Norov
2025-06-26 13:39 ` Shrikanth Hegde [this message]
2025-06-25 21:55 ` [RFC v2 0/9] cpu avoid state and push task mechanism Yury Norov
2025-06-26 14:33 ` Shrikanth Hegde
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=760e230c-5699-485c-910b-ebeaa9f9bd09@linux.ibm.com \
--to=sshegde@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dietmar.eggemann@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=huschle@linux.ibm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.ibm.com \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yury.norov@gmail.com \
/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).