*Re: Setting CPU affinity for current process on kernel module?
2019-09-11 18:52 Setting CPU affinity for current process on kernel module? Martin Galvan
@ 2019-09-11 19:16 ` Bharath Vedartham
2019-09-11 19:19 ` Martin Galvan0 siblings, 1 reply; 10+ messages in thread
From: Bharath Vedartham @ 2019-09-11 19:16 UTC (permalink / raw)
To: Martin Galvan; +Cc: kernelnewbies
On Wed, Sep 11, 2019 at 03:52:06PM -0300, Martin Galvan wrote:
> Hi,
>
> I have a kernel module which needs to perform CPU core-specific
> operations. I know that there's a kernel mode version of
> sched_setaffinity, however it's not exported to modules and can only
> be accessed through e.g. kallsyms_lookup_name, which is ugly. The
> alternative is to spawn a new kthread and bind it to the desired CPU
> before starting it, but I was wondering if there's a more
> straightforward method of doing this. Thanks!
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbiesSo one thing that pops to my head is using cgroups. Create a cgroup,
modify the cpu file in cpusets cgroup and add the required task to it.
But I am not sure whether you can do all of this from a kernel module...
Thanks
Bharath
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies^permalinkrawreply [flat|nested] 10+ messages in thread

*Re: Setting CPU affinity for current process on kernel module?
2019-09-11 19:19 ` Martin Galvan@ 2019-09-12 9:26 ` Bharath Vedartham
2019-09-12 14:03 ` Martin Galvan0 siblings, 1 reply; 10+ messages in thread
From: Bharath Vedartham @ 2019-09-12 9:26 UTC (permalink / raw)
To: Martin Galvan; +Cc: kernelnewbies
On Wed, Sep 11, 2019 at 04:19:41PM -0300, Martin Galvan wrote:
> El mié., 11 sept. 2019 a las 16:17, Bharath Vedartham
> (<linux.bhar@gmail.com>) escribió:
> > So one thing that pops to my head is using cgroups. Create a cgroup,
> > modify the cpu file in cpusets cgroup and add the required task to it.
> > But I am not sure whether you can do all of this from a kernel module...
>
> Thanks, but that's not feasible. This should all be done
> programmatically from the module, and be as minimally invasive as
> possible.
Just to be clear, What do you mean by current process. Is it the process
which is executing the kernel module? That would be a kernel thread I
believe or do you want to be able to set the cpu affinity for any
process given its PID?
And are you looking at setting CPU affinity of kernel threads or user
threads.
Thank you
Bharath
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies^permalinkrawreply [flat|nested] 10+ messages in thread

*Re: Setting CPU affinity for current process on kernel module?
2019-09-12 9:26 ` Bharath Vedartham@ 2019-09-12 14:03 ` Martin Galvan
2019-09-13 4:50 ` Greg KH0 siblings, 1 reply; 10+ messages in thread
From: Martin Galvan @ 2019-09-12 14:03 UTC (permalink / raw)
To: Bharath Vedartham; +Cc: kernelnewbies
El jue., 12 sept. 2019 a las 6:26, Bharath Vedartham
(<linux.bhar@gmail.com>) escribió:
> Just to be clear, What do you mean by current process. Is it the process
> which is executing the kernel module? That would be a kernel thread I
> believe or do you want to be able to set the cpu affinity for any
> process given its PID?
> And are you looking at setting CPU affinity of kernel threads or user
> threads.
Sorry, I wasn't clear: I want to set the affinity of 'current', which
is a kernel thread.
El jue., 12 sept. 2019 a las 6:38, Piotr Figiel (<figiel@gmail.com>) escribió:
> set_cpus_allowed_ptr() is exported, maybe this is what you're looking for?
Yes, that's exactly what I needed. Thanks! I actually ended up using
work_on_cpu, which fits my use case better.
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies^permalinkrawreply [flat|nested] 10+ messages in thread

*Re: Setting CPU affinity for current process on kernel module?
2019-09-12 14:03 ` Martin Galvan@ 2019-09-13 4:50 ` Greg KH
2019-09-13 12:43 ` Martin Galvan0 siblings, 1 reply; 10+ messages in thread
From: Greg KH @ 2019-09-13 4:50 UTC (permalink / raw)
To: Martin Galvan; +Cc: Bharath Vedartham, kernelnewbies
On Thu, Sep 12, 2019 at 11:03:20AM -0300, Martin Galvan wrote:
> El jue., 12 sept. 2019 a las 6:26, Bharath Vedartham
> (<linux.bhar@gmail.com>) escribió:
> > Just to be clear, What do you mean by current process. Is it the process
> > which is executing the kernel module? That would be a kernel thread I
> > believe or do you want to be able to set the cpu affinity for any
> > process given its PID?
> > And are you looking at setting CPU affinity of kernel threads or user
> > threads.
>
> Sorry, I wasn't clear: I want to set the affinity of 'current', which
> is a kernel thread.
I really hate to ask, but _why_ do you feel that this is the correct
solution to your problem? What is the problem you are attempting to
solve by doing this?
thanks,
greg k-h
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies^permalinkrawreply [flat|nested] 10+ messages in thread