linux kernel goodness计算分析

今天早上8点过出去买了点东西,回来就赶紧打开source insight看kernel code,跟妹子聊了会天,现在开始分析:

/*
*这个函数是来确定如何描述一个进程
返回值:
-1000:从不选择这个
0:过期进程,重新计算计数值(但它仍旧可能被选中)
正值:goodness值(越大越好)
+1000:实时进程,选择这个
*/

static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm)
{
     int weight;

     /*
     * select the current process after every other
     * runnable process, but before the idle thread.
     * Also, dont trigger a counter recalculation.
     */
     weight = -1;
     if (p->policy & SCHED_YIELD) //p->policy表示进程的调度策略,SCHED_YIELD是一种策略,是为了从小分配而让出CPU,就是直接返回啦!
#define SCHED_YIELD          0x10
          goto out;

     /*
     * Non-RT process - normal case first.
     */
     //SCHED_OTHER表示分时调度策略
     if (p->policy == SCHED_OTHER) {
          /*
          * Give the process a first-approximation goodness value
          * according to the number of clock-ticks it has left.
          *
          * Don't do any other calculations if the time slice is
          * over..
          */
          weight = p->counter;
          if (!weight)
               goto out;
              
#ifdef CONFIG_SMP
          /* Give a largish advantage to the same processor...   */
          /* (this is equivalent to penalizing other processors) */
          if (p->processor == this_cpu)
               weight += PROC_CHANGE_PENALTY;
#endif

          /* .. and a slight advantage to the current MM */
          if (p->mm == this_mm || !p->mm)
               weight += 1;
          weight += 20 - p->nice;
          goto out;
     }

     /*
     * Realtime process, select the first one on the
     * runqueue (taking priorities within processes
     * into account).
     */
     weight = 1000 + p->rt_priority;
out:
     return weight;
}

这个函数比较简单吧,就是计算进程goodness值,对于分时策略,会对一些情况weight有些加成;实时进程直接就给最大了。

其实如果木有神马ATT汇编,内核源码看起来还是很爽的,只是写了一个函数,今天计划把进程调度看完,跟书同步吧,至少把书上的字看完呢!



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值