b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

fork 优先级_github fork_fork(2)

电脑杂谈  发布时间:2017-04-10 15:06:12  来源:网络整理

下面以linux kernel watchdog 进程作为例子,kernel/watchdog.c

为每个cpu 创建 watchdog/N 进程,watchdog 进程的循环体在 watchdog()函数。

static int watchdog_enable(int cpu)
{
	struct task_struct *p = per_cpu(softlockup_watchdog, cpu);
	int err = 0;

	/* enable the perf event */
	err = watchdog_nmi_enable(cpu);

	/* Regardless of err above, fall through and start softlockup */

	/* create the watchdog thread */
	if (!p) {
		struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
		p = kthread_create_on_node(watchdog, NULL, cpu_to_node(cpu), "watchdog/%d", cpu);
设置 watchdog/N 进程的调度策略和进程优先级,sched policy 很明确SCHED_FIFO,为RT 实时进程。
.sched_priority 被设置成了MAX_RT_PRIO-1 也就是99了,这是个什么优先级的进程呢? 别急,且看代码且分析。
		//struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
		sched_setscheduler(p, SCHED_FIFO, m);

sched_setscheduler()

-> __sched_setscheduler()

-> __setscheduler()

在__sched_setscheduler() 函数中有这么一段代码,向我们描述了一个很重要的事实,想用sched_setscheduler()设置进程优先级,

必须满足: 实时进程有效优先级为1..99,非实时进程的优先级为0。 这里你可能觉得我是在开玩笑,非实时进程的有效优先级怎么可能为0 ?

请注意,这里指的是内核通过sched_setscheduler() 接口设置的优先级,在后面你就会看到非实时进程的优先级我们有个初始(fork/init),

你只能通过内核提供的nice 设置函数,间接修改非实时进程的优先级。

	/*
	 * Valid priorities for SCHED_FIFO and SCHED_RR are
	 * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL,
	 * SCHED_BATCH and SCHED_IDLE is 0.
	 */
	if (param->sched_priority < 0 ||
	    (p->mm && param->sched_priority > MAX_USER_RT_PRIO-1) ||
	    (!p->mm && param->sched_priority > MAX_RT_PRIO-1))
		return -EINVAL;
	if (rt_policy(policy) != (param->sched_priority != 0))
		return -EINVAL;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-40531-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    每日福利
    热点图片
    拼命载入中...