kernel - Add p_ppid
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 19 Oct 2017 19:09:56 +0000 (12:09 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 20 Oct 2017 06:33:54 +0000 (23:33 -0700)
* We have proc->p_pptr, but still needed a shared p->p_token to access
  the ppid.  Buckle under and add proc->p_ppid as well so getppid() can
  run lockless.

* Adjust the vmtotal proc scan to use a shared proc->p_token instead
  of an exclusive one.

sys/kern/kern_exit.c
sys/kern/kern_fork.c
sys/kern/kern_proc.c
sys/kern/kern_prot.c
sys/sys/proc.h
sys/vm/vm_meter.c

index 215f891..69703f3 100644 (file)
@@ -551,6 +551,7 @@ exit1(int rv)
                        LIST_REMOVE(q, p_sibling);
                        LIST_INSERT_HEAD(&reproc->p_children, q, p_sibling);
                        q->p_pptr = reproc;
+                       q->p_ppid = reproc->p_pid;
                        q->p_sigparent = SIGCHLD;
 
                        /*
@@ -1253,6 +1254,7 @@ proc_reparent(struct proc *child, struct proc *parent)
                LIST_REMOVE(child, p_sibling);
                LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
                child->p_pptr = parent;
+               child->p_ppid = parent->p_pid;
                lwkt_reltoken(&parent->p_token);
                lwkt_reltoken(&child->p_token);
                lwkt_reltoken(&opp->p_token);
index 059e066..ad66d2e 100644 (file)
@@ -625,6 +625,7 @@ fork1(struct lwp *lp1, int flags, struct proc **procp)
                pptr = p1;
        }
        p2->p_pptr = pptr;
+       p2->p_ppid = pptr->p_pid;
        LIST_INIT(&p2->p_children);
 
        lwkt_gettoken(&pptr->p_token);
index c43d234..e7c0b4b 100644 (file)
@@ -1164,6 +1164,7 @@ proc_remove_zombie(struct proc *p)
        LIST_REMOVE(p, p_list);         /* from remove master list */
        LIST_REMOVE(p, p_sibling);      /* and from sibling list */
        p->p_pptr = NULL;
+       p->p_ppid = 0;
        if (pid_doms[p->p_pid % PIDSEL_DOMAINS] != (uint8_t)time_second)
                pid_doms[p->p_pid % PIDSEL_DOMAINS] = (uint8_t)time_second;
        lwkt_reltoken(&prg->proc_token);
index 945a46a..2e3a6f4 100644 (file)
@@ -73,9 +73,7 @@ sys_getppid(struct getppid_args *uap)
 {
        struct proc *p = curproc;
 
-       lwkt_gettoken_shared(&p->p_token);
-       uap->sysmsg_result = p->p_pptr->p_pid;
-       lwkt_reltoken(&p->p_token);
+       uap->sysmsg_result = p->p_ppid;
 
        return (0);
 }
index b79918d..810a09a 100644 (file)
@@ -253,6 +253,7 @@ struct      proc {
        char            p_pad1[3];
 
        pid_t           p_pid;          /* Process identifier. */
+       pid_t           p_ppid;         /* Current parent pid */
        LIST_ENTRY(proc) p_pglist;      /* List of processes in pgrp. */
        struct proc     *p_pptr;        /* Pointer to parent process. */
        LIST_ENTRY(proc) p_sibling;     /* List of sibling processes. */
index 3f496b6..e4670b9 100644 (file)
@@ -154,7 +154,7 @@ do_vmtotal_callback(struct proc *p, void *data)
        if (p->p_flags & P_SYSTEM)
                return(0);
 
-       lwkt_gettoken(&p->p_token);
+       lwkt_gettoken_shared(&p->p_token);
 
        FOREACH_LWP_IN_PROC(lp, p) {
                switch (lp->lwp_stat) {