lkml.org 
[lkml]   [2024]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2 1/2] sched/fair: Return NULL when entity isn't a task in task_of()
From

On 2024/1/23 11:48, Steven Rostedt wrote:
> On Wed, 6 Dec 2023 14:33:59 +0800
> Yajun Deng <yajun.deng@linux.dev> wrote:
>
>> Before calling task_of(), we need to make sure that the entity is a task.
>> There is also a warning in task_of() if the entity isn't a task. That
>> means we need to check the entity twice. If the entity isn't a task,
> Does it really check it twice? Have you disassembled it to see if the code
> is any better?
>
> #define entity_is_task(se) (!se->my_q)
> static inline struct task_struct *task_of(struct sched_entity *se)
> {
> SCHED_WARN_ON(!entity_is_task(se));
> return container_of(se, struct task_struct, se);
> }
>
> The above is a macro and a static inline, which means that the compiler
> should optimized out that second check.


Yes, the second check should be optimized.

>
>> return the task struct is meaningless.
>>
>> Return NULL when entity isn't a task in task_of(), and call task_of()
>> instead of entity_is_task() when we need a task_struct.
> I'm not against the change, as it could be considered a clean up. But it is
> up to the sched maintainers to decide if it's worth the churn.


Return NULL in task_of() makes the code cleaner.

>
> -- Steve
>
>
>> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>

\
 
 \ /
  Last update: 2024-05-27 14:31    [W:0.037 / U:0.492 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site