PERFORCE change 99733 for review

Kip Macy kmacy at FreeBSD.org
Wed Jun 21 08:10:12 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=99733

Change 99733 by kmacy at kmacy_storage:sun4v_work on 2006/06/21 08:09:40

	socket and filedesc pushdown

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_descrip.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_umtx.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/sys_pipe.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/filedesc.h#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/lock.h#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/socket.h#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/unpcb.h#3 edit

Differences ...

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_descrip.c#6 (text+ko) ====

@@ -359,25 +359,8 @@
 	struct vnode *vp;
 	u_int newmin;
 	int error, flg, tmp;
-	int giant_locked;
+	int giant_locked = 0;
 
-	/*
-	 * XXXRW: Some fcntl() calls require Giant -- others don't.  Try to
-	 * avoid grabbing Giant for calls we know don't need it.
-	 */
-	switch (cmd) {
-	case F_DUPFD:
-	case F_GETFD:
-	case F_SETFD:
-	case F_GETFL:
-		giant_locked = 0;
-		break;
-
-	default:
-		giant_locked = 1;
-		mtx_lock(&Giant);
-	}
-
 	error = 0;
 	flg = F_POSIX;
 	p = td->td_proc;
@@ -391,9 +374,12 @@
 	}
 	pop = &fdp->fd_ofileflags[fd];
 
+	if ((fp->f_ops->fo_flags & DFLAG_MPSAFE) == 0) {
+		mtx_lock(&Giant);
+		giant_locked = 1;
+	} 
 	switch (cmd) {
 	case F_DUPFD:
-		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		FILEDESC_UNLOCK(fdp);
 		newmin = arg;
 		PROC_LOCK(p);
@@ -408,20 +394,17 @@
 		break;
 
 	case F_GETFD:
-		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		td->td_retval[0] = (*pop & UF_EXCLOSE) ? FD_CLOEXEC : 0;
 		FILEDESC_UNLOCK(fdp);
 		break;
 
 	case F_SETFD:
-		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		*pop = (*pop &~ UF_EXCLOSE) |
 		    (arg & FD_CLOEXEC ? UF_EXCLOSE : 0);
 		FILEDESC_UNLOCK(fdp);
 		break;
 
 	case F_GETFL:
-		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		FILE_LOCK(fp);
 		td->td_retval[0] = OFLAGS(fp->f_flag);
 		FILE_UNLOCK(fp);
@@ -429,7 +412,6 @@
 		break;
 
 	case F_SETFL:
-		mtx_assert(&Giant, MA_OWNED);
 		FILE_LOCK(fp);
 		fhold_locked(fp);
 		fp->f_flag &= ~FCNTLFLAGS;
@@ -457,7 +439,6 @@
 		break;
 
 	case F_GETOWN:
-		mtx_assert(&Giant, MA_OWNED);
 		fhold(fp);
 		FILEDESC_UNLOCK(fdp);
 		error = fo_ioctl(fp, FIOGETOWN, &tmp, td->td_ucred, td);
@@ -467,7 +448,6 @@
 		break;
 
 	case F_SETOWN:
-		mtx_assert(&Giant, MA_OWNED);
 		fhold(fp);
 		FILEDESC_UNLOCK(fdp);
 		tmp = arg;
@@ -476,12 +456,10 @@
 		break;
 
 	case F_SETLKW:
-		mtx_assert(&Giant, MA_OWNED);
 		flg |= F_WAIT;
 		/* FALLTHROUGH F_SETLK */
 
 	case F_SETLK:
-		mtx_assert(&Giant, MA_OWNED);
 		if (fp->f_type != DTYPE_VNODE) {
 			FILEDESC_UNLOCK(fdp);
 			error = EBADF;
@@ -555,7 +533,6 @@
 		break;
 
 	case F_GETLK:
-		mtx_assert(&Giant, MA_OWNED);
 		if (fp->f_type != DTYPE_VNODE) {
 			FILEDESC_UNLOCK(fdp);
 			error = EBADF;

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_umtx.c#6 (text+ko) ====

@@ -97,7 +97,6 @@
 static void umtxq_init_chains(void *);
 static int umtxq_hash(struct umtx_key *key);
 static struct mtx *umtxq_mtx(int chain);
-static void umtxq_lock(struct umtx_key *key);
 static void umtxq_unlock(struct umtx_key *key);
 static void umtxq_busy(struct umtx_key *key);
 static void umtxq_unbusy(struct umtx_key *key);
@@ -188,12 +187,20 @@
 		wakeup_one(&umtxq_chains[chain]);
 }
 
+#define umtxq_lock(key) \
+do { \
+    int chain = umtxq_hash(key); \
+    mtx_lock(umtxq_mtx(chain)); \
+} while (0)
+
+#if 0
 static inline void
 umtxq_lock(struct umtx_key *key)
 {
 	int chain = umtxq_hash(key);
-	mtx_lock(umtxq_mtx(chain));
+	mtx_lock(umtxq_mtx(chain)); 
 }
+#endif 
 
 static inline void
 umtxq_unlock(struct umtx_key *key)

==== //depot/projects/kmacy_sun4v/src/sys/kern/sys_pipe.c#3 (text+ko) ====

@@ -153,7 +153,7 @@
 	.fo_kqfilter = pipe_kqfilter,
 	.fo_stat = pipe_stat,
 	.fo_close = pipe_close,
-	.fo_flags = DFLAG_PASSABLE
+	.fo_flags = DFLAG_PASSABLE | DFLAG_MPSAFE
 };
 
 static void	filt_pipedetach(struct knote *kn);

==== //depot/projects/kmacy_sun4v/src/sys/sys/filedesc.h#4 (text+ko) ====

@@ -114,7 +114,7 @@
 		    ("fdesc locking mistake %d should be %d", (fd)->fd_locked, 2));	\
 		(fd)->fd_locked = 0;							\
 		if ((fd)->fd_wanted)							\
-			wakeup(&(fd)->fd_locked);					\
+			wakeup_one(&(fd)->fd_locked);					\
 		mtx_unlock(&(fd)->fd_mtx);						\
 	} while (0)
 
@@ -134,7 +134,7 @@
 		    ("fdesc locking mistake %d should be %d", (fd)->fd_locked, 1));	\
 		(fd)->fd_locked = 0;							\
 		if ((fd)->fd_wanted)							\
-			wakeup(&(fd)->fd_locked);					\
+			wakeup_one(&(fd)->fd_locked);					\
 		mtx_unlock(&(fd)->fd_mtx);						\
 	} while (0)
 

==== //depot/projects/kmacy_sun4v/src/sys/sys/lock.h#5 (text+ko) ====

@@ -72,7 +72,7 @@
 #define	LO_PROFILE	0x10000000	/* Enable per-lock profiling */
 
 /*
- * Lock classes are statically assigned an index into the gobal lock_classes
+ * Lock classes are statically assigned an index into the global lock_classes
  * array.  Debugging code looks up the lock class for a given lock object
  * by indexing the array.
  */

==== //depot/projects/kmacy_sun4v/src/sys/sys/socket.h#3 (text+ko) ====

@@ -208,7 +208,8 @@
 #define	AF_SCLUSTER	34		/* Sitara cluster protocol */
 #define	AF_ARP		35
 #define	AF_BLUETOOTH	36		/* Bluetooth sockets */
-#define	AF_MAX		37
+#define	AF_STUB		37		/* Stub sample protocol */
+#define	AF_MAX		38
 #endif
 
 /*
@@ -293,6 +294,7 @@
 #define PF_SCLUSTER	AF_SCLUSTER
 #define	PF_ARP		AF_ARP
 #define	PF_BLUETOOTH	AF_BLUETOOTH
+#define	PF_STUB		AF_STUB
 
 #define	PF_MAX		AF_MAX
 

==== //depot/projects/kmacy_sun4v/src/sys/sys/unpcb.h#3 (text+ko) ====

@@ -78,6 +78,7 @@
 	unp_gen_t unp_gencnt;		/* generation count of this instance */
 	int	unp_flags;		/* flags */
 	struct	xucred unp_peercred;	/* peer credentials, if applicable */
+	struct	mtx unp_mtx;		/* mutex */
 };
 
 /*
@@ -98,6 +99,14 @@
 #define	UNP_WANTCRED			0x004	/* credentials wanted */
 #define	UNP_CONNWAIT			0x008	/* connect blocks until accepted */
 
+/*
+ * These flags are used to handle non-atomicity in connect() and bind()
+ * operations on a socket: in particular, to avoid races between multiple
+ * threads or processes operating simultaneously on the same socket.
+ */
+#define	UNP_CONNECTING			0x010	/* Currently connecting. */
+#define	UNP_BINDING			0x020	/* Currently binding. */
+
 #define	sotounpcb(so)	((struct unpcb *)((so)->so_pcb))
 
 /* Hack alert -- this structure depends on <sys/socketvar.h>. */


More information about the p4-projects mailing list