Hi,<div>i have one basic doubt in the CFS algorithm. </div><div>Following is my doubts. I am using 2.6.23 as the kernel version</div><div><br></div><div>In CFS , when a Sleeping task wants to get inside the Running Queue ( cfs_rq ) , Then it calcluates the its own "vruntime" depend on "cfs_rq->min_vruntime" and "sysctl_sched_latency". In function "place_entity" , "vruntime" is assigned the value.</div>
<div> in brief ===> </div><div> se.vruntime = cfs_rq->min_vruntime - sysctl_sched_latency ( equation 1 )</div><div><br></div><div> So the process which wants to get inserted in CFS QUEUE , </div><div>
will have a KEY ==> "se->vruntime - cfs_rq->min_vruntime" ( equation 2 )</div><div> If we take merge equation 1 and equation 2 .. then KEY is equal to "-sysctl_sched_latency".</div><div>
<br></div><div> So when the Process will be added to RB TREE , then this new Task will always be the leftmost entry, as its KEY is in negative value.</div><div><br></div><div>I thought if we add the value of "sysctl_sched_latency" in equation "1" , then it would have been right as the New task will be waiting minimum "sysctl_sched_latency" nano seconds before getting schedule ( if run queue is heavily loaded ).</div>
<div><br></div><div><br></div><div><span style="background-color:rgb(255,0,0)">Can somebody help me in understanding why we are Subtracting "sysctl_sched_latency" instead of Adding</span></div><div><br></div><div>
Help will be greatly appreciated.</div><div><br></div><div>below i have added the code for "place_entity" and "entity_key"</div><div>regards</div><div>Anirban Roy</div><div><br></div><div>static void</div>
<div>place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>u64 vruntime;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vruntime = cfs_rq->min_vruntime;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (sched_feat(USE_TREE_AVG)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>struct sched_entity *last = __pick_last_entity(cfs_rq);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if (last) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>vruntime += last->vruntime;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>vruntime >>= 1;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>} else if (sched_feat(APPROX_AVG) && cfs_rq->nr_running)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vruntime += __sched_vslice(cfs_rq->nr_running)/2;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (initial && sched_feat(START_DEBIT))</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vruntime += __sched_vslice(cfs_rq->nr_running + 1);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!initial) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (sched_feat(NEW_FAIR_SLEEPERS))</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>vruntime -= sysctl_sched_latency;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vruntime = max_t(s64, vruntime, se->vruntime);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>se->vruntime = vruntime;</div><div><br></div><div>} </div><div><br></div><div><div>static inline s64</div><div>entity_key(struct cfs_rq *cfs_rq, struct sched_entity *se)</div>
<div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return se->vruntime - cfs_rq->min_vruntime;</div><div>}</div></div>