Reputation: 20119
A few questions like this have been asked here, but I've not been able to answer the following one: when the kernel schedules process P to run on processor S, how does the scheduler signal this affinity? Thanks.
Upvotes: 1
Views: 423
Reputation: 11
Let's consider we want to run a normal user task,Whenever a new task is scheduled to run in SMP system,It first put in one of per cpu runqueue with the help of load balancer(Each cpu maintain's own runqueue of type struct rq), based on the proirity, load wieght,vruntime attributes it will get allocated to the cpu, this is done by periodic timer called scheduler_tick() which internally calls pick_next_task() to run, periodic timer runs at a rate of HZ/sec, once it completes it's time quantum it's context switched and other task will be scheduled.
Upvotes: 0
Reputation: 7
In a few scenario, kernel bind a cpu to task.
1) when a task is forked 2) when a task is woken up after sleep 2) when a task is migrated
Upvotes: -1
Reputation: 84151
The kernel has a run-queue per CPU. Moving a task from one core to another involves removing it from one queue and putting it into the other. See, for example, http://lxr.linux.no/#linux+v2.6.37/kernel/sched.c#L5859.
Upvotes: 2
Reputation: 99879
Look at sched_getaffinity()
and pthread_getaffinity_np()
.
Upvotes: 0