Hi all:<br><br>I am implementing a global scheduler. However, a process migration problem makes me confused for a couple of days. Let me first describe my problem first.<br><br>I have a processor with two cores. And each core maintains a rq. I want to migrate a running processor(1401) from RQ1 to RQ0 in the following case. When a tick occurs on CPU0, it goes into my scheduling algorithm, a piece of code about process migration as followings cause my system frozen, since it does not break while loop.<br>
<br> <span style="background-color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255)"> <span style="color:rgb(51,102,255)"> int this_cpu = smp_processor_id();</span></span></span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> src_rq = task_rq(job->task) ; //(my Target Task with PID:1401, which is currently running on and located at CPU1)</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> des_rq = cpu_rq(job->mapping_info[0].cpu); //(my target task's target cpu is CPU0) </span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<br style="background-color:rgb(255,255,255);color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> if(src_rq != des_rq){</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> //count = 100</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> while( task_running(src_rq,job->task) /* && count > 0*/){</span><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> </span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> smp_send_reschedule(src_rq->cpu);</span> or <span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> //set_tsk_need_resched(src_rq->curr);</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> //count--;</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> }</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> /*if( task_running(src_rq,job->task) ){</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> snprintf(msg,MSG_SIZE,"zigzag_pack src_rq:%d des_rq:%d src_rq_curr_pid:%d pid:%d ", src_rq->cpu, des_rq->cpu,src_rq->curr->pid, job->task->pid);</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> registerr_event(sched_clock(), msg, this_cpu);</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> return 1;</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> }*/</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> } </span><br>
<br>However, my tracing info shows that my target task(PID:1401) has switched out and replaced by a process with PID:23. At that time, rq(1)->curr is 23. So I do not know why my piece of code on CPU0 can not break the while loop. My scheduling algorithm is protected by a single and global spin_lock.<br>
<br><span style="color:rgb(255,0,0)">Time:63625164872 MSG:context_switch prev->(<span style="background-color:rgb(255,255,255);color:rgb(51,51,255)">1401</span>),next->(23)</span><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)">Time:63625166671 MSG:rq:1 curr(23)</span><span style="background-color:rgb(255,255,255)"></span><br>
<br><br>In order to avoid system frozen and print error information, I have to change my code as:<br><br> <span style="background-color:rgb(51,102,255)"><span style="background-color:rgb(255,255,255)"> <span style="color:rgb(51,102,255)"> int this_cpu = smp_processor_id();</span></span></span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> src_rq = task_rq(job->task) ; //(my Target Task with PID:1401, which is currently running on and at CPU1)</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> des_rq = cpu_rq(job->mapping_info[0].cpu); //(my target task's target cpu is CPU0) </span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> if(src_rq != des_rq){</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> count = 100</span>0;<br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> while( task_running(src_rq,job->task) && count > 0 ){</span><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> </span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> smp_send_reschedule(src_rq->cpu);</span> or <span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> //set_tsk_need_resched(src_rq->curr);</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> count--;</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> }</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> if( task_running(src_rq,job->task) ){</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
snprintf(msg,MSG_SIZE,"zigzag_pack src_rq:%d des_rq:%d
src_rq_curr_pid:%d pid:%d ", src_rq->cpu,
des_rq->cpu,src_rq->curr->pid, job->task->pid);</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> register_event(sched_clock(), msg, this_cpu);</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> return 1;</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> }</span><br style="background-color:rgb(255,255,255);color:rgb(51,102,255)">
<span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> } </span><br><br>The tracing info at CPU0 is:<br><span style="color:rgb(255,0,0)">Time:63625166136 MSG:zigzag_pack src_rq:1 des_rq:0 src_rq_curr_pid:1401 pid:1401</span><br>
<br>I try both of the solutions to trigger CPU1 to reschedule, <span style="background-color:rgb(255,255,255);color:rgb(51,102,255)"> smp_send_reschedule(src_rq->cpu) and </span><span style="background-color:rgb(255,255,255);color:rgb(51,102,255)">set_tsk_need_resched(src_rq->curr), <span style="color:rgb(0,0,0)">neither works.<br>
<br><br>If you guys who are experts on this issue, please help me some tips.<br><br>Thanks.<br><br></span></span>