- Move sched_fork() later in fork() after the various sections of the new

thread and proc have been copied and zeroed from the old thread and
  proc.  Otherwise attempts to modify thread or process data in sched_fork()
  could be undone.
- Don't copy td_{base,}_user_pri from the old thread to the new thread in
  sched_fork_thread() in ULE.  This is already done courtesy the bcopy()
  of the thread copy region.
- Always initialize the real priority (td_priority) of new threads to the
  new thread's base priority (td_base_pri) to avoid bogusly inheriting a
  borrowed priority from the parent thread.

MFC after:	2 weeks
This commit is contained in:
John Baldwin 2011-01-06 22:24:00 +00:00
parent 177499ebcc
commit 22d19207e9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=217078
3 changed files with 13 additions and 9 deletions

View File

@ -360,12 +360,6 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
p2->p_state = PRS_NEW; /* protect against others */
p2->p_pid = trypid;
/*
* Allow the scheduler to initialize the child.
*/
thread_lock(td);
sched_fork(td, td2);
thread_unlock(td);
AUDIT_ARG_PID(p2->p_pid);
LIST_INSERT_HEAD(&allproc, p2, p_list);
LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
@ -456,6 +450,13 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
td2->td_vnet_lpush = NULL;
#endif
/*
* Allow the scheduler to initialize the child.
*/
thread_lock(td);
sched_fork(td, td2);
thread_unlock(td);
/*
* Duplicate sub-structures as needed.
* Increase reference counts on shared objects.

View File

@ -759,6 +759,7 @@ sched_fork_thread(struct thread *td, struct thread *childtd)
childtd->td_estcpu = td->td_estcpu;
childtd->td_lock = &sched_lock;
childtd->td_cpuset = cpuset_ref(td->td_cpuset);
childtd->td_priority = childtd->td_base_pri;
ts = childtd->td_sched;
bzero(ts, sizeof(*ts));
ts->ts_flags |= (td->td_sched->ts_flags & TSF_AFFINITY);

View File

@ -1961,14 +1961,16 @@ sched_fork_thread(struct thread *td, struct thread *child)
ts2->ts_cpu = ts->ts_cpu;
ts2->ts_flags = 0;
/*
* Grab our parents cpu estimation information and priority.
* Grab our parents cpu estimation information.
*/
ts2->ts_ticks = ts->ts_ticks;
ts2->ts_ltick = ts->ts_ltick;
ts2->ts_incrtick = ts->ts_incrtick;
ts2->ts_ftick = ts->ts_ftick;
child->td_user_pri = td->td_user_pri;
child->td_base_user_pri = td->td_base_user_pri;
/*
* Do not inherit any borrowed priority from the parent.
*/
child->td_priority = child->td_base_pri;
/*
* And update interactivity score.
*/