免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3177 | 回复: 15
打印 上一主题 下一主题

[进程管理] 请教CFS调度器问题(续) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-11-01 21:25 |只看该作者 |倒序浏览
本帖最后由 donghaitad 于 2013-11-02 20:32 编辑

本人想通过修改CFS调度器问题来阻止某一个进程的运行。

内核版本:2.6.24
通过与大家的讨论和调试,目前修改代码如下:
其基本想法是:修改从就绪队列中选择下一个进程。

static struct sched_entity *pick_next_entity(struct cfs_rq *cfs_rq)
{
        struct sched_entity *se = NULL;

        struct task_struct *tp;

        if (first_fair(cfs_rq)) {
                se = __pick_next_entity(cfs_rq);
+              tp = task_of(se);
+              if(tp->pid == target_pid)//如果目标进程被选中
+              {
+                      __dequeue_entity(cfs_rq, se);//将该进程移出就绪队列
+                      if (first_fair(cfs_rq)) {//如果就绪队列不为空
+                           se = __pick_next_entity(cfs_rq);;//重新选择进程
+                           set_next_entity(cfs_rq, se);
+                      }
+                      else{//否则选择为空
+                           prinkt("No process is selected!\n");
+                           se = NULL;
+                      }
+              }
+              else
+                       set_next_entity(cfs_rq, se);
-               set_next_entity(cfs_rq, se);
        }

        return se;
}

static struct task_struct *pick_next_task_fair(struct rq *rq)
{
        struct cfs_rq *cfs_rq = &rq->cfs;
        struct sched_entity *se;

        if (unlikely(!cfs_rq->nr_running))
                return NULL;

        do {
                se = pick_next_entity(cfs_rq);
+                if(se==NULL)
+                        return NULL;
                cfs_rq = group_cfs_rq(se);
        } while (cfs_rq);

        return task_of(se);
}

这段代码正常运行一段时间后("No process is selected!能够打印出来),系统就卡住了(但鼠标好像还可以动)。
请大家指教!!!

不好意思重新编辑了一下。

Thanks a lot!

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
2 [报告]
发表于 2013-11-02 08:14 |只看该作者
本帖最后由 firkraag 于 2013-11-02 08:15 编辑

Pointer tp is not assigned.

What does this mean?
se = set_next_entity(cfs_rq, se);//重新选择进程

prinkt("No process is selected!\n");

论坛徽章:
0
3 [报告]
发表于 2013-11-02 11:59 |只看该作者
回复 2# firkraag


不好意思,我重新编辑了一下。

tp = task_of(se);


+                      if (first_fair(cfs_rq)) {//如果就绪队列不为空
+                           se = __pick_next_entity(cfs_rq);;//重新选择进程
+                      }
+                      else{//否则选择为空
+                           prinkt("No process is selected!\n");
+                           se = NULL;
+                      }

   

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
4 [报告]
发表于 2013-11-02 12:35 |只看该作者
Should there be:
"set_next_entity(cfs_rq, se);"
after:
se = __pick_next_entity(cfs_rq);;//重新选择进程 ?

论坛徽章:
0
5 [报告]
发表于 2013-11-02 20:34 |只看该作者
回复 4# firkraag

Thank you very much for your comments, I have added "set_next_entity(cfs_rq, se);"
after:
"se = __pick_next_entity(cfs_rq);"

but it still has the problem.

   

论坛徽章:
0
6 [报告]
发表于 2013-11-02 21:18 |只看该作者
问题好像已经解决了:把 __dequeue_entity(cfs_rq, se)改成__pick_next_entity(cfs_rq)以后

好像就可以正常运行了。

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
7 [报告]
发表于 2013-11-03 10:23 |只看该作者
本帖最后由 firkraag 于 2013-11-03 16:45 编辑

Have the 'No process is selected!' ever been printed since the last modify?

Although '__dequeue_entity(cfs_rq, se)' just affects the rbtree and not modifys the data related with the rq and cfs_rq(like nr_running), it seems not a big problem.

Is there any process which can receive the input from user except the process you want to prevent from running?

论坛徽章:
0
8 [报告]
发表于 2013-11-03 17:31 |只看该作者
本帖最后由 donghaitad 于 2013-11-03 19:20 编辑

'No process is selected!' is printed.

"Is there any process which can receive the input from user except the process you want to prevent from running?"

Yes.

但在单CPU环境下还有问题,好像产生死锁了。

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
9 [报告]
发表于 2013-11-04 09:50 |只看该作者
本帖最后由 firkraag 于 2013-11-04 10:07 编辑

回复 8# donghaitad

'No process is selected!' should not been printed if you replaced '__dequeue_entity(cfs_rq, se)' with '__pick_next_entity(cfs_rq)'.

'__pick_next_entity(cfs_rq)' just returns the se of cfs_rq->rb_leftmost node of cfs_rq and does not modify the rbtree.


Has the problem 'deadlock of printk' been really sloved?

How can you get the 'target_pid'?

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
10 [报告]
发表于 2013-11-04 12:30 |只看该作者
Maybe  you can remove the printk and retry.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP