Skip to contentSkip to conversation

Drop tasklist lock in do_sched_setscheduler

PATCH Oleg Nesterov 2 participants 2 messages Jun 24, 2006 – Jun 25, 2006

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · Thomas Gleixner

There is no need to hold tasklist_lock across the setscheduler call, when we pin the task structure with get_task_struct(). Interrupts are disabled in setscheduler anyway and the permission checks do not need interrupts disabled.

kernel/sched.c line 4148

Quoted 10 lines
kernel/sched.c +3 -1
@@ -4140,8 +4140,10 @@
 		read_unlock_irq(&tasklist_lock);
 		return -ESRCH;
 	}
-	retval = sched_setscheduler(p, policy, &lparam);
+	get_task_struct(p);
 	read_unlock_irq(&tasklist_lock);
+	retval = sched_setscheduler(p, policy, &lparam);
+	put_task_struct(p);
 	return retval;
 }

But we don't need read_lock(tasklist) and get_task_struct(p) at all?

rcu_read_lock/rcu_read_unlock is enough, no?

Oleg.

#1 lore raw
Quoted 22 lines · Oleg Nesterov
Quoted 8 lines · Thomas Gleixner

There is no need to hold tasklist_lock across the setscheduler call, when we pin the task structure with get_task_struct(). Interrupts are disabled in setscheduler anyway and the permission checks do not need interrupts disabled.

kernel/sched.c line 4148

Quoted 10 lines
kernel/sched.c +3 -1
@@ -4140,8 +4140,10 @@
 		read_unlock_irq(&tasklist_lock);
 		return -ESRCH;
 	}
-	retval = sched_setscheduler(p, policy, &lparam);
+	get_task_struct(p);
 	read_unlock_irq(&tasklist_lock);
+	retval = sched_setscheduler(p, policy, &lparam);
+	put_task_struct(p);
 	return retval;
 }

But we don't need read_lock(tasklist) and get_task_struct(p) at all?

Quoted 1 line

rcu_read_lock/rcu_read_unlock is enough, no?

Probably yes, did not think about that

tglx