kernel - Third time's the charm - move lwp_ucred to td_ucred
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 15 Dec 2009 08:24:00 +0000 (00:24 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 15 Dec 2009 08:24:00 +0000 (00:24 -0800)
* Easier access to the cached ucred via the thread structure instead of
  the lwp.

sys/kern/kern_exit.c
sys/platform/pc32/i386/trap.c
sys/platform/pc64/x86_64/trap.c
sys/platform/vkernel/i386/trap.c
sys/sys/proc.h
sys/sys/thread.h

index f1497cc..07930a7 100644 (file)
@@ -551,7 +551,8 @@ exit1(int rv)
 void
 lwp_exit(int masterexit)
 {
-       struct lwp *lp = curthread->td_lwp;
+       struct thread *td = curthread;
+       struct lwp *lp = td->td_lwp;
        struct proc *p = lp->lwp_proc;
 
        /*
@@ -569,9 +570,9 @@ lwp_exit(int masterexit)
        /*
         * Clean up any syscall-cached ucred
         */
-       if (lp->lwp_ucred) {
-               crfree(lp->lwp_ucred);
-               lp->lwp_ucred = NULL;
+       if (td->td_ucred) {
+               crfree(td->td_ucred);
+               td->td_ucred = NULL;
        }
 
        /*
index 144e3ff..8b1d36b 100644 (file)
@@ -201,24 +201,23 @@ extern int max_sysmsg;
  * priority from a user priority to a kernel priority, reducing
  * syscall and trap overhead for the case where no switch occurs.
  *
- * Synchronizes lwp_ucred with p_ucred.  This is used by system calls,
+ * Synchronizes td_ucred with p_ucred.  This is used by system calls,
  * signal handling, faults, AST traps, and anything else that enters the
  * kernel from userland and provides the kernel with a stable read-only
  * copy of the process ucred.
  */
 static __inline void
-userenter(struct thread *curtd, struct lwp *curlp)
+userenter(struct thread *curtd, struct proc *curp)
 {
-       struct proc *p = curlp->lwp_proc;
        struct ucred *ocred;
        struct ucred *ncred;
 
        curtd->td_release = lwkt_passive_release;
 
-       if (curlp->lwp_ucred != p->p_ucred) {
-               ncred = crhold(p->p_ucred);
-               ocred = curlp->lwp_ucred;
-               curlp->lwp_ucred = ncred;
+       if (curtd->td_ucred != curp->p_ucred) {
+               ncred = crhold(curp->p_ucred);
+               ocred = curtd->td_ucred;
+               curtd->td_ucred = ncred;
                if (ocred)
                        crfree(ocred);
        }
@@ -517,7 +516,7 @@ restart:
                KTR_LOG(kernentry_trap, p->p_pid, lp->lwp_tid,
                        frame->tf_trapno, eva);
 
-               userenter(td, lp);
+               userenter(td, p);
 
                sticks = (int)td->td_sticks;
                lp->lwp_md.md_regs = frame;
@@ -1232,7 +1231,7 @@ syscall2(struct trapframe *frame)
        if (syscall_mpsafe == 0)
                MAKEMPSAFE(have_mplock);
 #endif
-       userenter(td, lp);      /* lazy raise our priority */
+       userenter(td, p);       /* lazy raise our priority */
 
        /*
         * Misc
@@ -1461,7 +1460,7 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame)
         * released when the thread goes to sleep.
         */
        lwkt_setpri_self(TDPRI_USER_NORM);
-       userenter(lp->lwp_thread, lp);
+       userenter(lp->lwp_thread, p);
        userret(lp, frame, 0);
 #ifdef KTRACE
        if (KTRPOINT(lp->lwp_thread, KTR_SYSRET))
index 68a5ddc..9a23474 100644 (file)
@@ -168,24 +168,23 @@ TUNABLE_INT("kern.trap_mpsafe", &trap_mpsafe);
  * the thread priority from a user priority to a kernel priority, reducing
  * syscall and trap overhead for the case where no switch occurs.
  *
- * Synchronizes lwp_ucred with p_ucred.  This is used by system calls,
+ * Synchronizes td_ucred with p_ucred.  This is used by system calls,
  * signal handling, faults, AST traps, and anything else that enters the
  * kernel from userland and provides the kernel with a stable read-only
  * copy of the process ucred.
  */
 static __inline void
-userenter(struct thread *curtd, struct lwp *curlp)
+userenter(struct thread *curtd, struct proc *curp)
 {
-       struct proc *p = curlp->lwp_proc;
        struct ucred *ocred;
        struct ucred *ncred;
 
        curtd->td_release = lwkt_passive_release;
 
-       if (curlp->lwp_ucred != p->p_ucred) {
-               ncred = crhold(p->p_ucred);
-               ocred = curlp->lwp_ucred;
-               curlp->lwp_ucred = ncred;
+       if (curtd->td_ucred != curp->p_ucred) {
+               ncred = crhold(curp->p_ucred);
+               ocred = curtd->td_ucred;
+               curtd->td_ucred = ncred;
                if (ocred)
                        crfree(ocred);
        }
@@ -446,7 +445,7 @@ trap(struct trapframe *frame)
                KTR_LOG(kernentry_trap, p->p_pid, lp->lwp_tid,
                        frame->tf_trapno, eva);
 
-               userenter(td, lp);
+               userenter(td, p);
 
                sticks = (int)td->td_sticks;
                lp->lwp_md.md_regs = frame;
@@ -1056,7 +1055,7 @@ syscall2(struct trapframe *frame)
        if (syscall_mpsafe == 0)
                MAKEMPSAFE(have_mplock);
 #endif
-       userenter(td, lp);      /* lazy raise our priority */
+       userenter(td, p);       /* lazy raise our priority */
 
        reg = 0;
        regcnt = 6;
@@ -1295,7 +1294,7 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame)
         * released when the thread goes to sleep.
         */
        lwkt_setpri_self(TDPRI_USER_NORM);
-       userenter(lp->lwp_thread, lp);
+       userenter(lp->lwp_thread, p);
        userret(lp, frame, 0);
 #ifdef KTRACE
        if (KTRPOINT(lp->lwp_thread, KTR_SYSRET))
index 0418a51..1102960 100644 (file)
@@ -187,24 +187,23 @@ extern int max_sysmsg;
  * the thread priority from a user priority to a kernel priority, reducing
  * syscall and trap overhead for the case where no switch occurs.
  *
- * Synchronizes lwp_ucred with p_ucred.  This is used by system calls,
+ * Synchronizes td_ucred with p_ucred.  This is used by system calls,
  * signal handling, faults, AST traps, and anything else that enters the
  * kernel from userland and provides the kernel with a stable read-only
  * copy of the process ucred.
  */
 static __inline void
-userenter(struct thread *curtd, struct lwp *curlp)
+userenter(struct thread *curtd, struct proc *curp)
 {
-       struct proc *p = curlp->lwp_proc;
        struct ucred *ocred;
        struct ucred *ncred;
 
        curtd->td_release = lwkt_passive_release;
 
-       if (curlp->lwp_ucred != p->p_ucred) {
-               ncred = crhold(p->p_ucred);
-               ocred = curlp->lwp_ucred;
-               curlp->lwp_ucred = ncred;
+       if (curtd->td_ucred != curp->p_ucred) {
+               ncred = crhold(curp->p_ucred);
+               ocred = curtd->td_ucred;
+               curtd->td_ucred = ncred;
                if (ocred)
                        crfree(ocred);
        }
@@ -440,7 +439,7 @@ restart:
        type = frame->tf_trapno;
        code = frame->tf_err;
 
-       userenter(td, lp);
+       userenter(td, p);
 
        sticks = (int)td->td_sticks;
        lp->lwp_md.md_regs = frame;
@@ -1148,7 +1147,7 @@ syscall2(struct trapframe *frame)
        if (syscall_mpsafe == 0)
                MAKEMPSAFE(have_mplock);
 #endif
-       userenter(td, lp);      /* lazy raise our priority */
+       userenter(td, p);       /* lazy raise our priority */
 
        /*
         * Misc
@@ -1381,7 +1380,7 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame)
         * released when the thread goes to sleep.
         */
        lwkt_setpri_self(TDPRI_USER_NORM);
-       userenter(lp->lwp_thread, lp);
+       userenter(lp->lwp_thread, p);
        userret(lp, frame, 0);
 #ifdef KTRACE
        if (KTRPOINT(lp->lwp_thread, KTR_SYSRET))
index 51926c9..9d1d42a 100644 (file)
@@ -216,7 +216,6 @@ struct lwp {
 
        struct thread   *lwp_thread;    /* backpointer to proc's thread */
        struct upcall   *lwp_upcall;    /* REGISTERED USERLAND POINTER! */
-       struct ucred    *lwp_ucred;     /* synchronized from p_ucred */
 };
 
 struct proc {
index 5c26a1c..5c29a89 100644 (file)
@@ -253,6 +253,7 @@ struct thread {
     struct timeval td_start;   /* start time for a thread/process */
     char       td_comm[MAXCOMLEN+1]; /* typ 16+1 bytes */
     struct thread *td_preempted; /* we preempted this thread */
+    struct ucred *td_ucred;            /* synchronized from p_ucred */
     struct caps_kinfo *td_caps;        /* list of client and server registrations */
     lwkt_tokref_t td_toks;     /* tokens beneficially held */
 #ifdef DEBUG_CRIT_SECTIONS