进程创建时sched_fork

 

/*  * 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 */ }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值