博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
进程创建时sched_fork
阅读量:4156 次
发布时间:2019-05-25

本文共 3568 字,大约阅读时间需要 11 分钟。

 
/* * fork()/clone()-time setup: */int sched_fork(unsigned long clone_flags, struct task_struct *p){ unsigned long flags; int cpu = get_cpu();  __sched_fork(clone_flags, p); /*  * We mark the process as NEW here. This guarantees that  * nobody will actually run it, and a signal or other external  * event cannot wake it up and insert it on the runqueue either.  */ p->state = TASK_NEW;  /*  * Make sure we do not leak PI boosting priority to the child.  */ p->prio = current->normal_prio;  /*  * Revert to default priority/policy on fork if requested.  */ if (unlikely(p->sched_reset_on_fork)) {  if (task_has_dl_policy(p) || task_has_rt_policy(p)) {   p->policy = SCHED_NORMAL;   p->static_prio = NICE_TO_PRIO(0);   p->rt_priority = 0;  } else if (PRIO_TO_NICE(p->static_prio) < 0)   p->static_prio = NICE_TO_PRIO(0);   p->prio = p->normal_prio = __normal_prio(p);  set_load_weight(p);   /*   * We don't need the reset flag anymore after the fork. It has   * fulfilled its duty:   */  p->sched_reset_on_fork = 0; }  if (dl_prio(p->prio)) {  put_cpu();  return -EAGAIN; } else if (rt_prio(p->prio)) {  p->sched_class = &rt_sched_class; } else {  p->sched_class = &fair_sched_class; }  init_entity_runnable_average(&p->se);  /*  * The child is not yet in the pid-hash so no cgroup attach races,  * and the cgroup is pinned to this child due to cgroup_fork()  * is ran before sched_fork().  *  * Silence PROVE_RCU.  */ raw_spin_lock_irqsave(&p->pi_lock, flags); /*  * We're setting the cpu for the first time, we don't migrate,  * so use __set_task_cpu().  */ __set_task_cpu(p, cpu); if (p->sched_class->task_fork)  p->sched_class->task_fork(p); raw_spin_unlock_irqrestore(&p->pi_lock, flags); #ifdef CONFIG_SCHED_INFO if (likely(sched_info_on()))  memset(&p->sched_info, 0, sizeof(p->sched_info));#endif#if defined(CONFIG_SMP) p->on_cpu = 0;#endif init_task_preempt_count(p);#ifdef CONFIG_SMP plist_node_init(&p->pushable_tasks, MAX_PRIO); RB_CLEAR_NODE(&p->pushable_dl_tasks);#endif  put_cpu(); return 0;}
/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. * * __sched_fork() is basic setup used by init_idle() too: */static void __sched_fork(unsigned long clone_flags, struct task_struct *p){ p->on_rq   = 0;  p->se.on_rq   = 0; p->se.exec_start  = 0; p->se.sum_exec_runtime  = 0; p->se.prev_sum_exec_runtime = 0; p->se.nr_migrations  = 0; p->se.vruntime   = 0; INIT_LIST_HEAD(&p->se.group_node); #ifdef CONFIG_FAIR_GROUP_SCHED p->se.cfs_rq   = NULL;#endif #ifdef CONFIG_SCHEDSTATS /* Even if schedstat is disabled, there should not be garbage */ memset(&p->se.statistics, 0, sizeof(p->se.statistics));#endif  RB_CLEAR_NODE(&p->dl.rb_node); init_dl_task_timer(&p->dl); __dl_clear_params(p);  INIT_LIST_HEAD(&p->rt.run_list); p->rt.timeout  = 0; p->rt.time_slice = sched_rr_timeslice; p->rt.on_rq  = 0; p->rt.on_list  = 0; #ifdef CONFIG_PREEMPT_NOTIFIERS INIT_HLIST_HEAD(&p->preempt_notifiers);#endif #ifdef CONFIG_NUMA_BALANCING if (p->mm && atomic_read(&p->mm->mm_users) == 1) {  p->mm->numa_next_scan = jiffies + msecs_to_jiffies(sysctl_numa_balancing_scan_delay);  p->mm->numa_scan_seq = 0; }  if (clone_flags & CLONE_VM)  p->numa_preferred_nid = current->numa_preferred_nid; else  p->numa_preferred_nid = -1;  p->node_stamp = 0ULL; p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq : 0; p->numa_scan_period = sysctl_numa_balancing_scan_delay; p->numa_work.next = &p->numa_work; p->numa_faults = NULL; p->last_task_numa_placement = 0; p->last_sum_exec_runtime = 0;  p->numa_group = NULL;#endif /* CONFIG_NUMA_BALANCING */}

转载地址:http://azhti.baihongyu.com/

你可能感兴趣的文章
最新ubuntu搭建公网个人邮件服务器(基于postfix,dovecot,mysql)
查看>>
Codeforces Round #174 (Div. 1 + Div. 2)
查看>>
dd命令的使用
查看>>
EF执行SQL语句
查看>>
如何设置IIS 6的应用程序池(4G内存)【转】
查看>>
随机数不随机
查看>>
UVA 10560 - Minimum Weight(数论)
查看>>
同余及逆元
查看>>
使用Dragablz快速构建Chrome样式的可拖拽分离的Tab页程序
查看>>
mongodb- 副本集(Ha方案)
查看>>
知识点干货--讲一讲final、finally、finalize的区别
查看>>
机器学习基础算法__python实现(基于numpy等基础库)
查看>>
[php] in_array 判断问题(坑)
查看>>
ios 把数组对象转成json字符串存起来
查看>>
udev规则以及编写
查看>>
ASP.NET DataList 分页之PagedDataSource
查看>>
《linux就该这么学》第十节课:第8章iptables和firewalld
查看>>
《linux就该这么学》第十三节课:第11章和第12章,vsftpd服务与samba和nfs服务
查看>>
[转]mysql日常工作手记
查看>>
火车购票
查看>>