The only raison d'etre of scheduler_fork_hook() is because `p_estcpu' is
not at the right place in "struct proc".  Diff below fixes that.  I
reordered the fields to not have implicit padding increase the size of
the structure.

ok?

Index: sys/proc.h
===================================================================
RCS file: /cvs/src/sys/sys/proc.h,v
retrieving revision 1.273
diff -u -p -r1.273 proc.h
--- sys/proc.h  2 Aug 2019 02:17:35 -0000       1.273
+++ sys/proc.h  15 Oct 2019 14:50:40 -0000
@@ -349,10 +349,7 @@ struct proc {
 #define        p_startzero     p_dupfd
        int     p_dupfd;         /* Sideways return value from filedescopen. 
XXX */
 
-       long    p_thrslpid;     /* for thrsleep syscall */
-
        /* scheduling */
-       u_int   p_estcpu;               /* [s] Time averaged val of p_cpticks */
        int     p_cpticks;       /* Ticks of cpu time. */
        const volatile void *p_wchan;   /* [s] Sleep address. */
        struct  timeout p_sleep_to;/* timeout for tsleep() */
@@ -364,6 +361,8 @@ struct proc {
        u_int   p_iticks;               /* Statclock hits processing intr. */
        struct  cpu_info * volatile p_cpu; /* [s] CPU we're running on. */
 
+       long    p_thrslpid;             /* for thrsleep syscall */
+
        struct  rusage p_ru;            /* Statistics */
        struct  tusage p_tu;            /* accumulated times. */
        struct  timespec p_rtime;       /* Real time. */
@@ -379,6 +378,7 @@ struct proc {
 
        u_char  p_priority;     /* [s] Process priority. */
        u_char  p_usrpri;       /* [s] User-prio based on p_estcpu & ps_nice. */
+       u_int   p_estcpu;               /* [s] Time averaged val of p_cpticks */
        int     p_pledge_syscall;       /* Cache of current syscall */
 
        struct  ucred *p_ucred;         /* cached credentials */
Index: sys/sched.h
===================================================================
RCS file: /cvs/src/sys/sys/sched.h,v
retrieving revision 1.55
diff -u -p -r1.55 sched.h
--- sys/sched.h 15 Oct 2019 10:05:43 -0000      1.55
+++ sys/sched.h 15 Oct 2019 14:48:45 -0000
@@ -182,11 +182,6 @@ void sched_init_runqueues(void);
 void setrunqueue(struct cpu_info *, struct proc *, uint8_t);
 void remrunqueue(struct proc *);
 
-/* Inherit the parent's scheduler history */
-#define scheduler_fork_hook(parent, child) do {                                
\
-       (child)->p_estcpu = (parent)->p_estcpu;                         \
-} while (0)
-
 /* Chargeback parents for the sins of their children.  */
 #define scheduler_wait_hook(parent, child) do {                                
\
        (parent)->p_estcpu = ESTCPULIM((parent)->p_estcpu + (child)->p_estcpu);\
Index: kern/kern_fork.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.214
diff -u -p -r1.214 kern_fork.c
--- kern/kern_fork.c    15 Oct 2019 10:05:43 -0000      1.214
+++ kern/kern_fork.c    15 Oct 2019 14:48:37 -0000
@@ -170,13 +170,6 @@ thread_new(struct proc *parent, vaddr_t 
         */
        timeout_set(&p->p_sleep_to, endtsleep, p);
 
-       /*
-        * set priority of child to be that of parent
-        * XXX should move p_estcpu into the region of struct proc which gets
-        * copied.
-        */
-       scheduler_fork_hook(parent, p);
-
 #ifdef WITNESS
        p->p_sleeplocks = NULL;
 #endif

Reply via email to