2020-04-14 06:59:50

by 王擎

[permalink] [raw]
Subject: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

We have no interface whether the task is running,
so we need to add an interface and distinguish CONFIG_SMP.

Signed-off-by: Wang Qing <[email protected]>
---
include/linux/sched.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4418f5c..13cc8f5 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)

extern void set_task_cpu(struct task_struct *p, unsigned int cpu);

+static inline int task_running_oncpu(const struct task_struct *p)
+{
+ return p->on_cpu;
+}
+
#else

static inline unsigned int task_cpu(const struct task_struct *p)
@@ -1854,6 +1859,11 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
{
}

+static inline int task_running_oncpu(const struct task_struct *p)
+{
+ return p == current;
+}
+
#endif /* CONFIG_SMP */

/*
--
2.7.4


2020-04-14 14:47:57

by Vincent Guittot

[permalink] [raw]
Subject: Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

On Mon, 13 Apr 2020 at 14:04, Wang Qing <[email protected]> wrote:
>
> We have no interface whether the task is running,
> so we need to add an interface and distinguish CONFIG_SMP.
>
> Signed-off-by: Wang Qing <[email protected]>
> ---
> include/linux/sched.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 4418f5c..13cc8f5 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
>
> extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
>
> +static inline int task_running_oncpu(const struct task_struct *p)

This function name is too close from task_running_on_cpu() and can be
misleading as the difference is only "_"
Also, how task_running_oncpu() is different from task_running() ?

> +{
> + return p->on_cpu;
> +}
> +
> #else
>
> static inline unsigned int task_cpu(const struct task_struct *p)
> @@ -1854,6 +1859,11 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
> {
> }
>
> +static inline int task_running_oncpu(const struct task_struct *p)
> +{
> + return p == current;
> +}
> +
> #endif /* CONFIG_SMP */
>
> /*
> --
> 2.7.4
>

2020-04-15 18:26:10

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

On Tue, Apr 14, 2020 at 09:20:57AM +0200, Vincent Guittot wrote:
> On Mon, 13 Apr 2020 at 14:04, Wang Qing <[email protected]> wrote:
> >
> > We have no interface whether the task is running,
> > so we need to add an interface and distinguish CONFIG_SMP.
> >
> > Signed-off-by: Wang Qing <[email protected]>
> > ---
> > include/linux/sched.h | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index 4418f5c..13cc8f5 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
> >
> > extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
> >
> > +static inline int task_running_oncpu(const struct task_struct *p)
>
> This function name is too close from task_running_on_cpu() and can be
> misleading as the difference is only "_"
> Also, how task_running_oncpu() is different from task_running() ?

It doesn't have the (arguably superfluous) rq argument. But yes, agreed,
if anything lift that thing (without the argument).

2020-04-15 20:18:35

by 王擎

[permalink] [raw]
Subject: Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

>On Mon, 13 Apr 2020 at 14:04, Wang Qing <[email protected]> wrote:
>>
>> We have no interface whether the task is running,
>> so we need to add an interface and distinguish CONFIG_SMP.
>>
>> Signed-off-by: Wang Qing <[email protected]>
>> ---
>> include/linux/sched.h | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/include/linux/sched.h b/include/linux/sched.h
>> index 4418f5c..13cc8f5 100644
>> --- a/include/linux/sched.h
>> +++ b/include/linux/sched.h
>> @@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
>>
>> extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
>>
>> +static inline int task_running_oncpu(const struct task_struct *p)
>
>This function name is too close from task_running_on_cpu() and can be
>misleading as the difference is only "_"
>Also, how task_running_oncpu() is different from task_running() ?

I think task_running() should be renamed to task_running_on_rq(), this is what
it originally mean. And the task_running_oncpu I added should be called
task_running(). This solves the confusing naming problem that already exists.

Thanks,
Wang Qing.

>
>> +{
>> + return p->on_cpu;
>> +}
>> +
>> #else
>>
>> static inline unsigned int task_cpu(const struct task_struct *p)
>> @@ -1854,6 +1859,11 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
>> {
>> }
>>
>> +static inline int task_running_oncpu(const struct task_struct *p)
>> +{
>> + return p == current;
>> +}
>> +
>> #endif /* CONFIG_SMP */
>>
>> /*
>> --
>> 2.7.4
>>

2020-04-15 22:34:48

by 王擎

[permalink] [raw]
Subject: Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

>On Tue, Apr 14, 2020 at 09:20:57AM +0200, Vincent Guittot wrote:
>> On Mon, 13 Apr 2020 at 14:04, Wang Qing <[email protected]> wrote:
>> >
>> > We have no interface whether the task is running,
>> > so we need to add an interface and distinguish CONFIG_SMP.
>> >
>> > Signed-off-by: Wang Qing <[email protected]>
>> > ---
>> > include/linux/sched.h | 10 ++++++++++
>> > 1 file changed, 10 insertions(+)
>> >
>> > diff --git a/include/linux/sched.h b/include/linux/sched.h
>> > index 4418f5c..13cc8f5 100644
>> > --- a/include/linux/sched.h
>> > +++ b/include/linux/sched.h
>> > @@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
>> >
>> > extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
>> >
>> > +static inline int task_running_oncpu(const struct task_struct *p)
>>
>> This function name is too close from task_running_on_cpu() and can be
>> misleading as the difference is only "_"
>> Also, how task_running_oncpu() is different from task_running() ?
>
>It doesn't have the (arguably superfluous) rq argument. But yes, agreed,
>if anything lift that thing (without the argument).

I think task_running() should be renamed to task_running_on_rq() like
the naming of task_running_on_cpu(), this is what it originally mean,
and add task_running() (with the task argument only).

I updated the patch for that.