Re: [PATCH v2 1/2] sched/fair: Return NULL when entity isn't a task in task_of()

From: Yajun Deng
Date: Wed Jan 24 2024 - 03:08:33 EST



On 2024/1/23 11:48, Steven Rostedt wrote:
On Wed, 6 Dec 2023 14:33:59 +0800
Yajun Deng <yajun.deng@xxxxxxxxx> 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@xxxxxxxxx>