Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 May 2007 22:53:14 GMT
From:      Matt Jacob <mjacob@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 120130 for review
Message-ID:  <200705202253.l4KMrEnp069168@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=120130

Change 120130 by mjacob@mjexp-obrien on 2007/05/20 22:52:30

	IFC

Affected files ...

.. //depot/projects/mjexp/sys/amd64/amd64/pmap.c#12 integrate
.. //depot/projects/mjexp/sys/compat/ndis/kern_windrv.c#2 integrate
.. //depot/projects/mjexp/sys/i386/i386/machdep.c#12 integrate
.. //depot/projects/mjexp/sys/i386/i386/mp_machdep.c#9 integrate
.. //depot/projects/mjexp/sys/i386/i386/pmap.c#13 integrate
.. //depot/projects/mjexp/sys/i386/i386/sys_machdep.c#5 integrate
.. //depot/projects/mjexp/sys/i386/i386/vm_machdep.c#5 integrate
.. //depot/projects/mjexp/sys/i386/include/proc.h#2 integrate
.. //depot/projects/mjexp/sys/kern/kern_clock.c#6 integrate
.. //depot/projects/mjexp/sys/kern/subr_prof.c#3 integrate
.. //depot/projects/mjexp/sys/kern/subr_witness.c#11 integrate
.. //depot/projects/mjexp/sys/sparc64/sparc64/pmap.c#4 integrate
.. //depot/projects/mjexp/sys/sun4v/sun4v/pmap.c#9 integrate
.. //depot/projects/mjexp/sys/sun4v/sun4v/tsb.c#6 integrate
.. //depot/projects/mjexp/sys/sun4v/sun4v/tte_hash.c#6 integrate
.. //depot/projects/mjexp/sys/sys/systm.h#13 integrate
.. //depot/projects/mjexp/sys/sys/vmmeter.h#4 integrate
.. //depot/projects/mjexp/sys/vm/vm_page.c#11 integrate

Differences ...

==== //depot/projects/mjexp/sys/amd64/amd64/pmap.c#12 (text+ko) ====

@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/amd64/amd64/pmap.c,v 1.585 2007/05/18 07:10:43 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/amd64/amd64/pmap.c,v 1.586 2007/05/20 22:33:41 jeff Exp $");
 
 /*
  *	Manages physical address maps.
@@ -1149,7 +1149,7 @@
 	 */
 	m->right = *free;
 	*free = m;
-	VMCNT_DEC(wire_count, 1);
+	VMCNT_SUB(wire_count, 1);
 	return 1;
 }
 
@@ -1459,7 +1459,7 @@
 	pmap->pm_pml4[PML4PML4I] = 0;	/* Recursive Mapping */
 
 	m->wire_count--;
-	VMCNT_DEC(wire_count, 1);
+	VMCNT_SUB(wire_count, 1);
 	vm_page_free_zero(m);
 	PMAP_LOCK_DESTROY(pmap);
 }

==== //depot/projects/mjexp/sys/compat/ndis/kern_windrv.c#2 (text+ko) ====

@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/compat/ndis/kern_windrv.c,v 1.13 2005/11/02 18:01:04 wpaul Exp $");
+__FBSDID("$FreeBSD: src/sys/compat/ndis/kern_windrv.c,v 1.14 2007/05/20 22:03:57 jeff Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -883,9 +883,9 @@
 	struct gdt		gtable;
 	uint16_t		ltable;
 
-	mtx_lock_spin(&sched_lock);
+	t = curthread;
 
-	t = curthread;
+	mtx_lock_spin(&dt_lock);
 
 	/* Grab location of existing GDT. */
 
@@ -904,7 +904,7 @@
 
 	x86_setldt(&gtable, ltable);
 
-	mtx_unlock_spin(&sched_lock);
+	mtx_unlock_spin(&dt_lock);
 
 	return;
 }
@@ -918,9 +918,9 @@
 	struct x86desc		*l;
 	struct thread		*t;
 
-	mtx_lock_spin(&sched_lock);
+	t = curthread;
 
-	t = curthread;
+	mtx_lock_spin(&dt_lock);
 
 	/* Grab location of existing GDT. */
 
@@ -952,7 +952,7 @@
 
 	x86_setldt(&gtable, ltable);
 
-	mtx_unlock_spin(&sched_lock);
+	mtx_unlock_spin(&dt_lock);
 
 	/* Whew. */
 

==== //depot/projects/mjexp/sys/i386/i386/machdep.c#12 (text+ko) ====

@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/machdep.c,v 1.651 2007/05/18 07:10:44 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/machdep.c,v 1.652 2007/05/20 22:03:57 jeff Exp $");
 
 #include "opt_apic.h"
 #include "opt_atalk.h"
@@ -1171,8 +1171,10 @@
 	pcb->pcb_gs = _udatasel;
 	load_gs(_udatasel);
 
+	mtx_lock_spin(&dt_lock);
 	if (td->td_proc->p_md.md_ldt)
 		user_ldt_free(td);
+	mtx_unlock_spin(&dt_lock);
   
 	bzero((char *)regs, sizeof(struct trapframe));
 	regs->tf_eip = entry;
@@ -1278,6 +1280,7 @@
 struct gate_descriptor *idt = &idt0[0];	/* interrupt descriptor table */
 union descriptor ldt[NLDT];		/* local descriptor table */
 struct region_descriptor r_gdt, r_idt;	/* table descriptors */
+struct mtx dt_lock;			/* lock for GDT and LDT */
 
 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
 extern int has_f00f_bug;
@@ -2101,6 +2104,7 @@
 
 	r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
 	r_gdt.rd_base =  (int) gdt;
+	mtx_init(&dt_lock, "descriptor tables", NULL, MTX_SPIN);
 	lgdt(&r_gdt);
 
 	pcpu_init(pc, 0, sizeof(struct pcpu));

==== //depot/projects/mjexp/sys/i386/i386/mp_machdep.c#9 (text+ko) ====

@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/mp_machdep.c,v 1.278 2007/05/08 22:01:03 jhb Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/mp_machdep.c,v 1.279 2007/05/20 22:03:57 jeff Exp $");
 
 #include "opt_apic.h"
 #include "opt_cpu.h"
@@ -1388,11 +1388,9 @@
 
 	if (mp_ncpus == 1) 
 		return;
-	mtx_lock_spin(&sched_lock);
 	atomic_store_rel_int(&aps_ready, 1);
 	while (smp_started == 0)
 		ia32_pause();
-	mtx_unlock_spin(&sched_lock);
 }
 SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
 

==== //depot/projects/mjexp/sys/i386/i386/pmap.c#13 (text+ko) ====

@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/pmap.c,v 1.590 2007/05/18 07:10:44 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/pmap.c,v 1.591 2007/05/20 22:33:42 jeff Exp $");
 
 /*
  *	Manages physical address maps.
@@ -1168,7 +1168,7 @@
 	pmap->pm_pdir[m->pindex] = 0;
 	--pmap->pm_stats.resident_count;
 
-	VMCNT_DEC(wire_count, 1);
+	VMCNT_SUB(wire_count, 1);
 
 	/*
 	 * Do an invltlb to make the invalidated mapping
@@ -1536,7 +1536,7 @@
 		    ("pmap_release: got wrong ptd page"));
 #endif
 		m->wire_count--;
-		VMCNT_DEC(wire_count, 1);
+		VMCNT_SUB(wire_count, 1);
 		vm_page_free_zero(m);
 	}
 	PMAP_LOCK_DESTROY(pmap);

==== //depot/projects/mjexp/sys/i386/i386/sys_machdep.c#5 (text+ko) ====

@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/sys_machdep.c,v 1.108 2007/04/22 15:31:21 rwatson Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/sys_machdep.c,v 1.109 2007/05/20 22:03:57 jeff Exp $");
 
 #include "opt_kstack_pages.h"
 #include "opt_mac.h"
@@ -42,6 +42,7 @@
 #include <sys/mutex.h>
 #include <sys/priv.h>
 #include <sys/proc.h>
+#include <sys/refcount.h>
 #include <sys/smp.h>
 #include <sys/sysproto.h>
 
@@ -115,7 +116,6 @@
 		break;
 	}
 
-	mtx_lock(&Giant);
 	switch(uap->op) {
 	case I386_GET_LDT:
 		error = i386_get_ldt(td, &kargs.largs);
@@ -215,7 +215,6 @@
 		error = EINVAL;
 		break;
 	}
-	mtx_unlock(&Giant);
 	return (error);
 }
 
@@ -351,16 +350,19 @@
 
 /*
  * Update the GDT entry pointing to the LDT to point to the LDT of the
- * current process.
- *
- * This must be called with sched_lock held.  Unfortunately, we can't use a
- * mtx_assert() here because cpu_switch() calls this function after changing
- * curproc but before sched_lock's owner is updated in mi_switch().
+ * current process. Manage dt_lock holding/unholding autonomously.
  */   
 void
 set_user_ldt(struct mdproc *mdp)
 {
 	struct proc_ldt *pldt;
+	int dtlocked;
+
+	dtlocked = 0;
+	if (!mtx_owned(&dt_lock)) {
+		mtx_lock_spin(&dt_lock);
+		dtlocked = 1;
+	}
 
 	pldt = mdp->md_ldt;
 #ifdef SMP
@@ -370,6 +372,8 @@
 #endif
 	lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
 	PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL));
+	if (dtlocked)
+		mtx_unlock_spin(&dt_lock);
 }
 
 #ifdef SMP
@@ -385,17 +389,15 @@
 #endif
 
 /*
- * Must be called with either sched_lock free or held but not recursed.
- * If it does not return NULL, it will return with it owned.
+ * dt_lock must be held. Returns with dt_lock held.
  */
 struct proc_ldt *
 user_ldt_alloc(struct mdproc *mdp, int len)
 {
 	struct proc_ldt *pldt, *new_ldt;
 
-	if (mtx_owned(&sched_lock))
-		mtx_unlock_spin(&sched_lock);
-	mtx_assert(&sched_lock, MA_NOTOWNED);
+	mtx_assert(&dt_lock, MA_OWNED);
+	mtx_unlock_spin(&dt_lock);
 	MALLOC(new_ldt, struct proc_ldt *, sizeof(struct proc_ldt),
 		M_SUBPROC, M_WAITOK);
 
@@ -406,54 +408,49 @@
 		FREE(new_ldt, M_SUBPROC);
 		return NULL;
 	}
-	new_ldt->ldt_refcnt = 1;
+	refcount_init(&new_ldt->ldt_refcnt, 1);
 	new_ldt->ldt_active = 0;
 
-	mtx_lock_spin(&sched_lock);
+	mtx_lock_spin(&dt_lock);
 	gdt_segs[GUSERLDT_SEL].ssd_base = (unsigned)new_ldt->ldt_base;
 	gdt_segs[GUSERLDT_SEL].ssd_limit = len * sizeof(union descriptor) - 1;
 	ssdtosd(&gdt_segs[GUSERLDT_SEL], &new_ldt->ldt_sd);
 
-	if ((pldt = mdp->md_ldt)) {
+	if ((pldt = mdp->md_ldt) != NULL) {
 		if (len > pldt->ldt_len)
 			len = pldt->ldt_len;
 		bcopy(pldt->ldt_base, new_ldt->ldt_base,
 		    len * sizeof(union descriptor));
-	} else {
+	} else
 		bcopy(ldt, new_ldt->ldt_base, sizeof(ldt));
-	}
-	return new_ldt;
+	
+	return (new_ldt);
 }
 
 /*
- * Must be called either with sched_lock free or held but not recursed.
- * If md_ldt is not NULL, it will return with sched_lock released.
+ * Must be called with dt_lock held.
  */
 void
 user_ldt_free(struct thread *td)
 {
 	struct mdproc *mdp = &td->td_proc->p_md;
-	struct proc_ldt *pldt = mdp->md_ldt;
+	struct proc_ldt *pldt;
 
-	if (pldt == NULL)
+	mtx_assert(&dt_lock, MA_OWNED);
+	if ((pldt = mdp->md_ldt) == NULL)
 		return;
 
-	if (!mtx_owned(&sched_lock))
-		mtx_lock_spin(&sched_lock);
-	mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED);
 	if (td == PCPU_GET(curthread)) {
 		lldt(_default_ldt);
 		PCPU_SET(currentldt, _default_ldt);
 	}
 
 	mdp->md_ldt = NULL;
-	if (--pldt->ldt_refcnt == 0) {
-		mtx_unlock_spin(&sched_lock);
+	if (refcount_release(&pldt->ldt_refcnt)) {
 		kmem_free(kernel_map, (vm_offset_t)pldt->ldt_base,
 			pldt->ldt_len * sizeof(union descriptor));
 		FREE(pldt, M_SUBPROC);
-	} else
-		mtx_unlock_spin(&sched_lock);
+	}
 }
 
 /*
@@ -468,7 +465,7 @@
 	struct i386_ldt_args *uap;
 {
 	int error = 0;
-	struct proc_ldt *pldt = td->td_proc->p_md.md_ldt;
+	struct proc_ldt *pldt;
 	int nldt, num;
 	union descriptor *lp;
 
@@ -477,11 +474,14 @@
 	    uap->start, uap->num, (void *)uap->descs);
 #endif
 
-	if (pldt) {
+	mtx_lock_spin(&dt_lock);
+	if ((pldt = td->td_proc->p_md.md_ldt) != NULL) {
 		nldt = pldt->ldt_len;
+		lp = &((union descriptor *)(pldt->ldt_base))[uap->start];
+		mtx_unlock_spin(&dt_lock);
 		num = min(uap->num, nldt);
-		lp = &((union descriptor *)(pldt->ldt_base))[uap->start];
 	} else {
+		mtx_unlock_spin(&dt_lock);
 		nldt = sizeof(ldt)/sizeof(ldt[0]);
 		num = min(uap->num, nldt);
 		lp = &ldt[uap->start];
@@ -531,10 +531,10 @@
 		}
 		if (uap->num <= 0)
 			return (EINVAL);
-		mtx_lock_spin(&sched_lock);
-		pldt = mdp->md_ldt;
-		if (pldt == NULL || uap->start >= pldt->ldt_len) {
-			mtx_unlock_spin(&sched_lock);
+		mtx_lock_spin(&dt_lock);
+		if ((pldt = mdp->md_ldt) == NULL ||
+		    uap->start >= pldt->ldt_len) {
+			mtx_unlock_spin(&dt_lock);
 			return (0);
 		}
 		largest_ld = uap->start + uap->num;
@@ -543,7 +543,7 @@
 		i = largest_ld - uap->start;
 		bzero(&((union descriptor *)(pldt->ldt_base))[uap->start],
 		    sizeof(union descriptor) * i);
-		mtx_unlock_spin(&sched_lock);
+		mtx_unlock_spin(&dt_lock);
 		return (0);
 	}
 
@@ -626,15 +626,15 @@
 
 	if (uap->start == LDT_AUTO_ALLOC && uap->num == 1) {
 		/* Allocate a free slot */
-		pldt = mdp->md_ldt;
-		if (pldt == NULL) {
-			error = i386_ldt_grow(td, NLDT + 1);
-			if (error)
+		mtx_lock_spin(&dt_lock);
+		if ((pldt = mdp->md_ldt) == NULL) {
+			if ((error = i386_ldt_grow(td, NLDT + 1))) {
+				mtx_unlock_spin(&dt_lock);
 				return (error);
+			}
 			pldt = mdp->md_ldt;
 		}
 again:
-		mtx_lock_spin(&sched_lock);
 		/*
 		 * start scanning a bit up to leave room for NVidia and
 		 * Wine, which still user the "Blat" method of allocation.
@@ -646,24 +646,23 @@
 			dp++;
 		}
 		if (i >= pldt->ldt_len) {
-			mtx_unlock_spin(&sched_lock);
-			error = i386_ldt_grow(td, pldt->ldt_len+1);
-			if (error)
+			if ((error = i386_ldt_grow(td, pldt->ldt_len+1))) {
+				mtx_unlock_spin(&dt_lock);
 				return (error);
+			}
 			goto again;
 		}
 		uap->start = i;
 		error = i386_set_ldt_data(td, i, 1, descs);
-		mtx_unlock_spin(&sched_lock);
+		mtx_unlock_spin(&dt_lock);
 	} else {
 		largest_ld = uap->start + uap->num;
-		error = i386_ldt_grow(td, largest_ld);
-		if (error == 0) {
-			mtx_lock_spin(&sched_lock);
+		mtx_lock_spin(&dt_lock);
+		if (!(error = i386_ldt_grow(td, largest_ld))) {
 			error = i386_set_ldt_data(td, uap->start, uap->num,
 			    descs);
-			mtx_unlock_spin(&sched_lock);
 		}
+		mtx_unlock_spin(&dt_lock);
 	}
 	if (error == 0)
 		td->td_retval[0] = uap->start;
@@ -677,7 +676,7 @@
 	struct mdproc *mdp = &td->td_proc->p_md;
 	struct proc_ldt *pldt = mdp->md_ldt;
 
-	mtx_assert(&sched_lock, MA_OWNED);
+	mtx_assert(&dt_lock, MA_OWNED);
 
 	/* Fill in range */
 	bcopy(descs,
@@ -694,14 +693,15 @@
 	caddr_t old_ldt_base;
 	int old_ldt_len;
 
+	mtx_assert(&dt_lock, MA_OWNED);
+
 	if (len > MAX_LD)
 		return (ENOMEM);
 	if (len < NLDT + 1)
 		len = NLDT + 1;
 
 	/* Allocate a user ldt. */
-	pldt = mdp->md_ldt;
-	if (!pldt || len > pldt->ldt_len) {
+	if ((pldt = mdp->md_ldt) != NULL || len > pldt->ldt_len) {
 		struct proc_ldt *new_ldt;
 
 		new_ldt = user_ldt_alloc(mdp, len);
@@ -709,42 +709,35 @@
 			return (ENOMEM);
 		pldt = mdp->md_ldt;
 
-		/* sched_lock was acquired by user_ldt_alloc. */
-		if (pldt) {
+		if (pldt != NULL) {
 			if (new_ldt->ldt_len > pldt->ldt_len) {
 				old_ldt_base = pldt->ldt_base;
 				old_ldt_len = pldt->ldt_len;
 				pldt->ldt_sd = new_ldt->ldt_sd;
 				pldt->ldt_base = new_ldt->ldt_base;
 				pldt->ldt_len = new_ldt->ldt_len;
-				mtx_unlock_spin(&sched_lock);
 				kmem_free(kernel_map, (vm_offset_t)old_ldt_base,
 					old_ldt_len * sizeof(union descriptor));
 				FREE(new_ldt, M_SUBPROC);
-				mtx_lock_spin(&sched_lock);
 			} else {
 				/*
 				 * If other threads already did the work,
 				 * do nothing.
 				 */
-				mtx_unlock_spin(&sched_lock);
 				kmem_free(kernel_map,
 				   (vm_offset_t)new_ldt->ldt_base,
 				   new_ldt->ldt_len * sizeof(union descriptor));
 				FREE(new_ldt, M_SUBPROC);
 				return (0);
 			}
-		} else {
+		} else
 			mdp->md_ldt = pldt = new_ldt;
-		}
 #ifdef SMP
-		mtx_unlock_spin(&sched_lock);
 		/* signal other cpus to reload ldt */
 		smp_rendezvous(NULL, (void (*)(void *))set_user_ldt_rv,
 		    NULL, td);
 #else
 		set_user_ldt(mdp);
-		mtx_unlock_spin(&sched_lock);
 #endif
 	}
 	return (0);

==== //depot/projects/mjexp/sys/i386/i386/vm_machdep.c#5 (text+ko) ====

@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.279 2007/04/24 21:17:45 jhb Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.280 2007/05/20 22:03:57 jeff Exp $");
 
 #include "opt_isa.h"
 #include "opt_npx.h"
@@ -62,6 +62,7 @@
 #include <sys/mutex.h>
 #include <sys/pioctl.h>
 #include <sys/proc.h>
+#include <sys/refcount.h>
 #include <sys/sf_buf.h>
 #include <sys/smp.h>
 #include <sys/sched.h>
@@ -158,8 +159,9 @@
 			struct mdproc *mdp1 = &p1->p_md;
 			struct proc_ldt *pldt;
 
-			pldt = mdp1->md_ldt;
-			if (pldt && pldt->ldt_refcnt > 1) {
+			mtx_lock_spin(&dt_lock);
+			if ((pldt = mdp1->md_ldt) != NULL &&
+			    pldt->ldt_refcnt > 1) {
 				pldt = user_ldt_alloc(mdp1, pldt->ldt_len);
 				if (pldt == NULL)
 					panic("could not copy LDT");
@@ -167,6 +169,7 @@
 				set_user_ldt(mdp1);
 				user_ldt_free(td1);
 			}
+			mtx_unlock_spin(&dt_lock);
 		}
 		return;
 	}
@@ -248,10 +251,10 @@
 	pcb2->pcb_ext = 0;
 
 	/* Copy the LDT, if necessary. */
-	mtx_lock_spin(&sched_lock);
+	mtx_lock_spin(&dt_lock);
 	if (mdp2->md_ldt != NULL) {
 		if (flags & RFMEM) {
-			mdp2->md_ldt->ldt_refcnt++;
+			refcount_acquire(&mdp2->md_ldt->ldt_refcnt);
 		} else {
 			mdp2->md_ldt = user_ldt_alloc(mdp2,
 			    mdp2->md_ldt->ldt_len);
@@ -259,7 +262,7 @@
 				panic("could not copy LDT");
 		}
 	}
-	mtx_unlock_spin(&sched_lock);
+	mtx_unlock_spin(&dt_lock);
 
 	/* Setup to release sched_lock in fork_exit(). */
 	td2->td_md.md_spinlock_count = 1;
@@ -304,11 +307,13 @@
 	 * If this process has a custom LDT, release it.  Reset pc->pcb_gs
 	 * and %gs before we free it in case they refer to an LDT entry.
 	 */
+	mtx_lock_spin(&dt_lock);
 	if (td->td_proc->p_md.md_ldt) {
 		td->td_pcb->pcb_gs = _udatasel;
 		load_gs(_udatasel);
 		user_ldt_free(td);
 	}
+	mtx_unlock_spin(&dt_lock);
 }
 
 void

==== //depot/projects/mjexp/sys/i386/include/proc.h#2 (text+ko) ====

@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)proc.h	7.1 (Berkeley) 5/15/91
- * $FreeBSD: src/sys/i386/include/proc.h,v 1.25 2005/04/04 21:53:54 jhb Exp $
+ * $FreeBSD: src/sys/i386/include/proc.h,v 1.26 2007/05/20 22:03:57 jeff Exp $
  */
 
 #ifndef _MACHINE_PROC_H_
@@ -45,6 +45,8 @@
 
 /*
  * Machine-dependent part of the proc structure for i386.
+ * Table of MD locks:
+ *       t - Descriptor tables lock
  */
 struct mdthread {
 	int	md_spinlock_count;	/* (k) */
@@ -52,7 +54,7 @@
 };
 
 struct mdproc {
-	struct proc_ldt *md_ldt;	/* (j) per-process ldt */
+	struct proc_ldt *md_ldt;	/* (t) per-process ldt */
 };
 
 #ifdef	_KERNEL
@@ -61,6 +63,8 @@
 struct 	proc_ldt *user_ldt_alloc(struct mdproc *, int);
 void 	user_ldt_free(struct thread *);
 
+extern struct mtx dt_lock;
+
 #endif	/* _KERNEL */
 
 #endif /* !_MACHINE_PROC_H_ */

==== //depot/projects/mjexp/sys/kern/kern_clock.c#6 (text+ko) ====

@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/kern_clock.c,v 1.194 2007/03/08 06:44:33 julian Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/kern_clock.c,v 1.195 2007/05/20 22:11:49 jeff Exp $");
 
 #include "opt_device_polling.h"
 #include "opt_hwpmc_hooks.h"
@@ -83,6 +83,9 @@
 /* Some of these don't belong here, but it's easiest to concentrate them. */
 long cp_time[CPUSTATES];
 
+/* Spin-lock protecting profiling statistics. */
+struct mtx time_lock;
+
 static int
 sysctl_kern_cp_time(SYSCTL_HANDLER_ARGS)
 {
@@ -172,6 +175,7 @@
 	 * code do its bit.
 	 */
 	cpu_initclocks();
+	mtx_init(&time_lock, "time lock", NULL, MTX_SPIN);
 
 	/*
 	 * Compute profhz/stathz, and fix profhz if needed.
@@ -349,20 +353,15 @@
 	register struct proc *p;
 {
 
-	/*
-	 * XXX; Right now sched_lock protects statclock(), but perhaps
-	 * it should be protected later on by a time_lock, which would
-	 * cover psdiv, etc. as well.
-	 */
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	if (p->p_flag & P_STOPPROF)
 		return;
 	if ((p->p_flag & P_PROFIL) == 0) {
-		mtx_lock_spin(&sched_lock);
 		p->p_flag |= P_PROFIL;
+		mtx_lock_spin(&time_lock);
 		if (++profprocs == 1)
 			cpu_startprofclock();
-		mtx_unlock_spin(&sched_lock);
+		mtx_unlock_spin(&time_lock);
 	}
 }
 
@@ -385,11 +384,11 @@
 		}
 		if ((p->p_flag & P_PROFIL) == 0)
 			return;
-		mtx_lock_spin(&sched_lock);
 		p->p_flag &= ~P_PROFIL;
+		mtx_lock_spin(&time_lock);
 		if (--profprocs == 0)
 			cpu_stopprofclock();
-		mtx_unlock_spin(&sched_lock);
+		mtx_unlock_spin(&time_lock);
 	}
 }
 
@@ -412,7 +411,6 @@
 	td = curthread;
 	p = td->td_proc;
 
-	mtx_lock_spin_flags(&sched_lock, MTX_QUIET);
 	if (usermode) {
 		/*
 		 * Charge the time as appropriate.
@@ -422,6 +420,7 @@
 			thread_statclock(1);
 #endif
 		td->td_uticks++;
+		mtx_lock_spin_flags(&time_lock, MTX_QUIET);
 		if (p->p_nice > NZERO)
 			cp_time[CP_NICE]++;
 		else
@@ -442,6 +441,7 @@
 		if ((td->td_pflags & TDP_ITHREAD) ||
 		    td->td_intr_nesting_level >= 2) {
 			td->td_iticks++;
+			mtx_lock_spin_flags(&time_lock, MTX_QUIET);
 			cp_time[CP_INTR]++;
 		} else {
 #ifdef KSE
@@ -450,15 +450,18 @@
 #endif
 			td->td_pticks++;
 			td->td_sticks++;
+			mtx_lock_spin_flags(&time_lock, MTX_QUIET);
 			if (!TD_IS_IDLETHREAD(td))
 				cp_time[CP_SYS]++;
 			else
 				cp_time[CP_IDLE]++;
 		}
 	}
+	mtx_unlock_spin_flags(&time_lock, MTX_QUIET);
 	CTR4(KTR_SCHED, "statclock: %p(%s) prio %d stathz %d",
 	    td, td->td_proc->p_comm, td->td_priority, (stathz)?stathz:hz);
 
+	mtx_lock_spin_flags(&sched_lock, MTX_QUIET);
 	sched_clock(td);
 
 	/* Update resource usage integrals and maximums. */

==== //depot/projects/mjexp/sys/kern/subr_prof.c#3 (text+ko) ====

@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/subr_prof.c,v 1.77 2007/03/04 22:36:46 rwatson Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/subr_prof.c,v 1.78 2007/05/20 22:11:49 jeff Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -423,12 +423,12 @@
 	}
 	PROC_LOCK(p);
 	upp = &td->td_proc->p_stats->p_prof;
-	mtx_lock_spin(&sched_lock);
+	mtx_lock_spin(&time_lock);
 	upp->pr_off = uap->offset;
 	upp->pr_scale = uap->scale;
 	upp->pr_base = uap->samples;
 	upp->pr_size = uap->size;
-	mtx_unlock_spin(&sched_lock);
+	mtx_unlock_spin(&time_lock);
 	startprofclock(p);
 	PROC_UNLOCK(p);
 
@@ -468,15 +468,15 @@
 	if (ticks == 0)
 		return;
 	prof = &td->td_proc->p_stats->p_prof;
-	mtx_lock_spin(&sched_lock);
+	mtx_lock_spin(&time_lock);
 	if (pc < prof->pr_off ||
 	    (i = PC_TO_INDEX(pc, prof)) >= prof->pr_size) {
-		mtx_unlock_spin(&sched_lock);		
+		mtx_unlock_spin(&time_lock);		
 		return;			/* out of range; ignore */
 	}
 
 	addr = prof->pr_base + i;
-	mtx_unlock_spin(&sched_lock);
+	mtx_unlock_spin(&time_lock);
 	if ((v = fuswintr(addr)) == -1 || suswintr(addr, v + ticks) == -1) {
 		td->td_profil_addr = pc;
 		td->td_profil_ticks = ticks;

==== //depot/projects/mjexp/sys/kern/subr_witness.c#11 (text+ko) ====

@@ -82,7 +82,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/subr_witness.c,v 1.230 2007/04/19 08:02:51 jkoshy Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/subr_witness.c,v 1.231 2007/05/20 22:11:49 jeff Exp $");
 
 #include "opt_ddb.h"
 #include "opt_hwpmc_hooks.h"
@@ -410,6 +410,7 @@
 	{ "callout", &lock_class_mtx_spin },
 	{ "entropy harvest mutex", &lock_class_mtx_spin },
 	{ "syscons video lock", &lock_class_mtx_spin },
+	{ "time lock", &lock_class_mtx_spin },
 	/*
 	 * leaf locks
 	 */

==== //depot/projects/mjexp/sys/sparc64/sparc64/pmap.c#4 (text+ko) ====

@@ -39,7 +39,7 @@
  * SUCH DAMAGE.
  *
  *      from:   @(#)pmap.c      7.7 (Berkeley)  5/12/91
- * $FreeBSD: src/sys/sparc64/sparc64/pmap.c,v 1.161 2007/05/18 07:10:47 jeff Exp $
+ * $FreeBSD: src/sys/sparc64/sparc64/pmap.c,v 1.162 2007/05/20 22:33:42 jeff Exp $
  */
 
 /*
@@ -1088,7 +1088,7 @@
 		    ("pmap_release: freeing held tsb page"));
 		m->md.pmap = NULL;
 		m->wire_count--;
-		VMCNT_DEC(wire_count, 1);
+		VMCNT_SUB(wire_count, 1);
 		vm_page_free_zero(m);
 		vm_page_unlock_queues();
 	}

==== //depot/projects/mjexp/sys/sun4v/sun4v/pmap.c#9 (text+ko) ====

@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/sun4v/sun4v/pmap.c,v 1.35 2007/05/20 13:06:45 marius Exp $");
+__FBSDID("$FreeBSD: src/sys/sun4v/sun4v/pmap.c,v 1.36 2007/05/20 22:33:42 jeff Exp $");
 
 #include "opt_kstack_pages.h"
 #include "opt_msgbuf.h"
@@ -1312,7 +1312,7 @@
 	m = PHYS_TO_VM_PAGE(TLB_DIRECT_TO_PHYS((vm_offset_t)ptr));
 	for (i = 0; i < npages; i++, m++) {
 		m->wire_count--;
-		VMCNT_DEC(wire_count, 1);
+		VMCNT_SUB(wire_count, 1);
 		vm_page_free(m);
 	}
 }

==== //depot/projects/mjexp/sys/sun4v/sun4v/tsb.c#6 (text+ko) ====

@@ -25,7 +25,7 @@
  *
  */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/sun4v/sun4v/tsb.c,v 1.8 2007/05/18 07:10:48 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/sun4v/sun4v/tsb.c,v 1.9 2007/05/20 22:33:42 jeff Exp $");
 
 
 #include "opt_ddb.h"
@@ -104,7 +104,7 @@
 	m = PHYS_TO_VM_PAGE((vm_paddr_t)hvtsb->hti_ra);
 	for (i = 0, tm = m; i < TSB_SIZE; i++, m++) {
 		tm->wire_count--;
-		VMCNT_DEC(wire_count, 1);
+		VMCNT_SUB(wire_count, 1);
 		vm_page_free(tm);
 	}
 }

==== //depot/projects/mjexp/sys/sun4v/sun4v/tte_hash.c#6 (text+ko) ====

@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/sun4v/sun4v/tte_hash.c,v 1.11 2007/05/20 09:21:29 marius Exp $");
+__FBSDID("$FreeBSD: src/sys/sun4v/sun4v/tte_hash.c,v 1.12 2007/05/20 22:33:42 jeff Exp $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -231,7 +231,7 @@
         for (fh = ptr; fh != NULL; fh = fh->thf_head.fh_next) {
                 m = PHYS_TO_VM_PAGE(TLB_DIRECT_TO_PHYS((vm_offset_t)fh));
                 m->wire_count--;
-		VMCNT_DEC(wire_count, 1);
+		VMCNT_SUB(wire_count, 1);
                 vm_page_free(m);
         }
 }

==== //depot/projects/mjexp/sys/sys/systm.h#13 (text+ko) ====

@@ -32,7 +32,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)systm.h	8.7 (Berkeley) 3/29/95
- * $FreeBSD: src/sys/sys/systm.h,v 1.255 2007/04/08 23:54:01 pjd Exp $
+ * $FreeBSD: src/sys/sys/systm.h,v 1.256 2007/05/20 22:11:50 jeff Exp $
  */
 
 #ifndef _SYS_SYSTM_H_
@@ -71,6 +71,8 @@
 
 extern int maxusers;		/* system tune hint */
 
+extern struct mtx time_lock;	/* time lock for profiling */
+
 #ifdef	INVARIANTS		/* The option is always available */
 #define	KASSERT(exp,msg) do {						\
 	if (__predict_false(!(exp)))					\

==== //depot/projects/mjexp/sys/sys/vmmeter.h#4 (text+ko) ====

@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)vmmeter.h	8.2 (Berkeley) 7/10/94
- * $FreeBSD: src/sys/sys/vmmeter.h,v 1.29 2007/05/18 07:10:48 jeff Exp $
+ * $FreeBSD: src/sys/sys/vmmeter.h,v 1.30 2007/05/20 22:33:42 jeff Exp $
  */
 
 #ifndef _SYS_VMMETER_H_
@@ -109,7 +109,7 @@
 	atomic_store_rel_int(__CONCAT(&cnt.v_, member), val)
 #define	VMCNT_ADD(member, val)						\
 	atomic_add_int(__CONCAT(&cnt.v_, member), val)
-#define	VMCNT_DEC(member, val)						\
+#define	VMCNT_SUB(member, val)						\
 	atomic_subtract_int(__CONCAT(&cnt.v_, member), val)
 #define	VMCNT_GET(member)	(__CONCAT(cnt.v_, member))
 #define	VMCNT_PTR(member)						\

==== //depot/projects/mjexp/sys/vm/vm_page.c#11 (text+ko) ====

@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/vm/vm_page.c,v 1.343 2007/05/18 07:10:49 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/vm/vm_page.c,v 1.344 2007/05/20 22:33:42 jeff Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1249,7 +1249,7 @@
 	if (m->wire_count > 0) {
 		m->wire_count--;
 		if (m->wire_count == 0) {
-			VMCNT_DEC(wire_count, 1);
+			VMCNT_SUB(wire_count, 1);
 			if (m->flags & PG_UNMANAGED) {
 				;
 			} else if (activate)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705202253.l4KMrEnp069168>