Date: Sat, 16 Feb 2002 16:49:45 -0800 (PST) From: Julian Elischer <julian@elischer.org> To: Matthew Dillon <dillon@apollo.backplane.com> Cc: Alfred Perlstein <bright@mu.org>, Poul-Henning Kamp <phk@critter.freebsd.dk>, arch@FreeBSD.ORG, jhb@FreeBSD.ORG, peter@wemm.org, jake@locore.ca Subject: Re: gettimeofday() and crhold()/crfree() (was Re: gettimeofday() and copyout(). Is copyout() MPSAFE on non-i386 archs? ) Message-ID: <Pine.BSF.4.21.0202161647070.39539-200000@InterJet.elischer.org> In-Reply-To: <200202162200.g1GM04F39752@apollo.backplane.com>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
the whole point is moot..
you don't need to get or drop the creds at all..
see the attached patch I'm about to commit a version of..
On Sat, 16 Feb 2002, Matthew Dillon wrote:
>
> :Go ahead with using mutex pools for creds, I thought I'd done it
> :already but it looks like I only got to struct file and struct
> :uidinfo. :)
> :
> :I do sort of think that keeping your own cred freelist is probably
> :a bad idea especially with what Jeff R has coming down the pipe for
> :us. But we can take that out later if something better comes along.
> :
> :-Alfred
>
> Well, I dunno... I'm warming to the idea if it in fact eases the job
> of pushing Giant down. It seems so easy to do for the ucred, though
> of course I am not trying to proactively trim down the size of the
> freelist (yet)... but even that would be fairly simple to do in the
> allocation code by adding a count of the number of items in the freelist.
>
> It would be another ten lines of code relative to the patch
> I just posted. int cr_free_count; .. in allocation code do
> while (cr_free_count > HYSTERESIS) { ... free ... }
>
> -Matt
> Matthew Dillon
> <dillon@backplane.com>
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-arch" in the body of the message
>
[-- Attachment #2 --]
? i386/conf/LINT
? modules/netgraph/ksocket/ng_ksocket.kld
? modules/netgraph/ksocket/ng_ksocket.ko
Index: i386/i386/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/trap.c,v
retrieving revision 1.211
diff -u -r1.211 trap.c
--- i386/i386/trap.c 10 Jan 2002 11:49:54 -0000 1.211
+++ i386/i386/trap.c 13 Feb 2002 01:07:07 -0000
@@ -256,9 +256,8 @@
sticks = td->td_kse->ke_sticks;
td->td_frame = &frame;
KASSERT(td->td_ucred == NULL, ("already have a ucred"));
- PROC_LOCK(p);
- td->td_ucred = crhold(p->p_ucred);
- PROC_UNLOCK(p);
+ if (td->td_ucred != p->p_ucred)
+ aquire_ucred(td, p);
switch (type) {
case T_PRIVINFLT: /* privileged instruction fault */
@@ -644,10 +643,12 @@
userret(td, &frame, sticks);
mtx_assert(&Giant, MA_NOTOWNED);
userout:
+#ifdef INVARIANTS
mtx_lock(&Giant);
crfree(td->td_ucred);
mtx_unlock(&Giant);
td->td_ucred = NULL;
+#endif
out:
return;
}
@@ -954,9 +955,8 @@
sticks = td->td_kse->ke_sticks;
td->td_frame = &frame;
KASSERT(td->td_ucred == NULL, ("already have a ucred"));
- PROC_LOCK(p);
- td->td_ucred = crhold(p->p_ucred);
- PROC_UNLOCK(p);
+ if (td->td_ucred != p->p_ucred)
+ aquire_ucred(td, p);
params = (caddr_t)frame.tf_esp + sizeof(int);
code = frame.tf_eax;
orig_tf_eflags = frame.tf_eflags;
@@ -1099,10 +1099,12 @@
*/
STOPEVENT(p, S_SCX, code);
+#ifdef INVARIANTS
mtx_lock(&Giant);
crfree(td->td_ucred);
mtx_unlock(&Giant);
td->td_ucred = NULL;
+#endif
#ifdef WITNESS
if (witness_list(td)) {
panic("system call %s returning with mutex(s) held\n",
Index: kern/kern_fork.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.130
diff -u -r1.130 kern_fork.c
--- kern/kern_fork.c 7 Feb 2002 23:06:26 -0000 1.130
+++ kern/kern_fork.c 13 Feb 2002 01:07:11 -0000
@@ -799,10 +799,12 @@
kthread_exit(0);
}
PROC_UNLOCK(p);
+#ifdef INVARIANTS
mtx_lock(&Giant);
crfree(td->td_ucred);
mtx_unlock(&Giant);
td->td_ucred = NULL;
+#endif
mtx_assert(&Giant, MA_NOTOWNED);
}
Index: kern/subr_trap.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_trap.c,v
retrieving revision 1.207
diff -u -r1.207 subr_trap.c
--- kern/subr_trap.c 11 Feb 2002 20:37:53 -0000 1.207
+++ kern/subr_trap.c 13 Feb 2002 01:07:12 -0000
@@ -56,6 +56,24 @@
#include <machine/pcb.h>
/*
+ * small routine to swap a thread's current ucred for the correct one
+ * taken from the process
+ */
+void
+aquire_ucred(struct thread *td, struct proc *p)
+{
+ if (td->td_ucred != NULL) {
+ mtx_lock(&Giant);
+ crfree(td->td_ucred);
+ mtx_unlock(&Giant);
+ td->td_ucred = NULL;
+ }
+ PROC_LOCK(p);
+ td->td_ucred = crhold(p->p_ucred);
+ PROC_UNLOCK(p);
+}
+
+/*
* Define the code needed before returning to user mode, for
* trap and syscall.
*
@@ -161,9 +179,8 @@
p->p_stats->p_prof.pr_ticks = 0;
}
mtx_unlock_spin(&sched_lock);
- PROC_LOCK(p);
- td->td_ucred = crhold(p->p_ucred);
- PROC_UNLOCK(p);
+ if (td->td_ucred != p->p_ucred)
+ aquire_ucred(td, p);
if (flags & KEF_OWEUPC && sflag & PS_PROFIL)
addupc_task(ke, p->p_stats->p_prof.pr_addr, prticks);
if (sflag & PS_ALRMPEND) {
@@ -188,10 +205,12 @@
}
userret(td, framep, sticks);
+#ifdef INVARIANTS
mtx_lock(&Giant);
crfree(td->td_ucred);
mtx_unlock(&Giant);
td->td_ucred = NULL;
+#endif
s = cpu_critical_enter();
}
mtx_assert(&Giant, MA_NOTOWNED);
Index: sys/ucred.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/ucred.h,v
retrieving revision 1.26
diff -u -r1.26 ucred.h
--- sys/ucred.h 11 Oct 2001 23:38:17 -0000 1.26
+++ sys/ucred.h 13 Feb 2002 01:07:22 -0000
@@ -83,19 +83,20 @@
#ifdef _KERNEL
-void change_egid __P((struct ucred *newcred, gid_t egid));
-void change_euid __P((struct ucred *newcred, uid_t euid));
-void change_rgid __P((struct ucred *newcred, gid_t rgid));
-void change_ruid __P((struct ucred *newcred, uid_t ruid));
-void change_svgid __P((struct ucred *newcred, gid_t svgid));
-void change_svuid __P((struct ucred *newcred, uid_t svuid));
-void crcopy __P((struct ucred *dest, struct ucred *src));
-struct ucred *crdup __P((struct ucred *cr));
-void crfree __P((struct ucred *cr));
-struct ucred *crget __P((void));
-struct ucred *crhold __P((struct ucred *cr));
-int crshared __P((struct ucred *cr));
-int groupmember __P((gid_t gid, struct ucred *cred));
+void aquire_ucred(struct thread *td, struct proc *p);
+void change_egid (struct ucred *newcred, gid_t egid);
+void change_euid (struct ucred *newcred, uid_t euid);
+void change_rgid (struct ucred *newcred, gid_t rgid);
+void change_ruid (struct ucred *newcred, uid_t ruid);
+void change_svgid (struct ucred *newcred, gid_t svgid);
+void change_svuid (struct ucred *newcred, uid_t svuid);
+void crcopy (struct ucred *dest, struct ucred *src);
+struct ucred *crdup (struct ucred *cr);
+void crfree (struct ucred *cr);
+struct ucred *crget (void);
+struct ucred *crhold (struct ucred *cr);
+int crshared (struct ucred *cr);
+int groupmember (gid_t gid, struct ucred *cred);
#endif /* _KERNEL */
#endif /* !_SYS_UCRED_H_ */
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0202161647070.39539-200000>
