Re: [PATCH 1/2] sched/core: switch struct rq->nr_iowait to an unsigned int

From: Jens Axboe
Date: Tue Feb 27 2024 - 18:17:57 EST


On 2/27/24 4:05 PM, David Wei wrote:
>> @@ -4354,8 +4354,13 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
>> cpu = select_task_rq(p, p->wake_cpu, wake_flags | WF_TTWU);
>> if (task_cpu(p) != cpu) {
>> if (p->in_iowait) {
>> + struct rq *rq = task_rq(p);
>> + struct rq_flags rf;
>> +
>> + rq_lock(rq, &rf);
>> + task_rq(p)->nr_iowait--;
>
> Could this use rq directly, or does it not matter?

It certainly could, I'll make that edit. Same thing, but may as well use
the variable as defined. Also makes it clear we're modifying the one
we've locked.

>> @@ -10029,7 +10034,7 @@ void __init sched_init(void)
>> #endif
>> #endif /* CONFIG_SMP */
>> hrtick_rq_init(rq);
>> - atomic_set(&rq->nr_iowait, 0);
>> + rq->nr_iowait = 0;
>
> I checked that both ttwu_do_activate() and __schedule() have the rq lock
> held, but I couldn't find it for this. Is it under the assumption that
> the rq is in a pre-init state (maybe because scheduler_running = 0?) so
> no lock is needed?

This is run at boot time (it's __init), so it's before anything is
running.

--
Jens Axboe