Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 Dec 2008 23:44:35 +0000 (UTC)
From:      Kip Macy <kmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r186663 - in user/kmacy/HEAD_fast_net/sys: kern sys
Message-ID:  <200812312344.mBVNiZGb038362@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kmacy
Date: Wed Dec 31 23:44:34 2008
New Revision: 186663
URL: http://svn.freebsd.org/changeset/base/186663

Log:
  avoid runtime switching of kqueue locking by adding knote_locked and KNOTE_ACTIVATE_LOCKED

Modified:
  user/kmacy/HEAD_fast_net/sys/kern/kern_event.c
  user/kmacy/HEAD_fast_net/sys/sys/event.h

Modified: user/kmacy/HEAD_fast_net/sys/kern/kern_event.c
==============================================================================
--- user/kmacy/HEAD_fast_net/sys/kern/kern_event.c	Wed Dec 31 23:22:45 2008	(r186662)
+++ user/kmacy/HEAD_fast_net/sys/kern/kern_event.c	Wed Dec 31 23:44:34 2008	(r186663)
@@ -163,16 +163,16 @@ SYSCTL_INT(_kern, OID_AUTO, kq_calloutma
     &kq_calloutmax, 0, "Maximum number of callouts allocated for kqueue");
 
 /* XXX - ensure not KN_INFLUX?? */
-#define KNOTE_ACTIVATE(kn, islock) do { 				\
-	if ((islock))							\
-		mtx_assert(&(kn)->kn_kq->kq_lock, MA_OWNED);		\
-	else								\
-		KQ_LOCK((kn)->kn_kq);					\
+#define KNOTE_ACTIVATE_LOCKED(kn) do {	 				\
+	mtx_assert(&(kn)->kn_kq->kq_lock, MA_OWNED);			\
 	(kn)->kn_status |= KN_ACTIVE;					\
 	if (((kn)->kn_status & (KN_QUEUED | KN_DISABLED)) == 0)		\
 		knote_enqueue((kn));					\
-	if (!(islock))							\
-		KQ_UNLOCK((kn)->kn_kq);					\
+} while(0)
+#define KNOTE_ACTIVATE(kn) do {		 				\
+	KQ_LOCK((kn)->kn_kq);						\
+	KNOTE_ACTIVATE_LOCKED(kn);					\
+	KQ_UNLOCK((kn)->kn_kq);						\
 } while(0)
 #define KQ_LOCK(kq) do {						\
 	mtx_lock(&(kq)->kq_lock);					\
@@ -357,7 +357,7 @@ filt_procattach(struct knote *kn)
 	 * process, e.g. a child, dies before the kevent is registered.
 	 */
 	if (immediate && filt_proc(kn, NOTE_EXIT))
-		KNOTE_ACTIVATE(kn, 0);
+		KNOTE_ACTIVATE(kn);
 
 	PROC_UNLOCK(p);
 
@@ -456,7 +456,7 @@ knote_fork(struct knlist *list, int pid)
 		if ((kn->kn_sfflags & NOTE_TRACK) == 0) {
 			kn->kn_status |= KN_HASKQLOCK;
 			if (kn->kn_fop->f_event(kn, NOTE_FORK | pid))
-				KNOTE_ACTIVATE(kn, 1);
+				KNOTE_ACTIVATE_LOCKED(kn);
 			kn->kn_status &= ~KN_HASKQLOCK;
 			KQ_UNLOCK(kq);
 			continue;
@@ -484,7 +484,7 @@ knote_fork(struct knlist *list, int pid)
 		kev.udata = kn->kn_kevent.udata;/* preserve udata */
 		error = kqueue_register(kq, &kev, NULL, 0);
 		if (kn->kn_fop->f_event(kn, NOTE_FORK | pid))
-			KNOTE_ACTIVATE(kn, 0);
+			KNOTE_ACTIVATE(kn);
 		if (error)
 			kn->kn_fflags |= NOTE_TRACKERR;
 		KQ_LOCK(kq);
@@ -519,7 +519,7 @@ filt_timerexpire(void *knx)
 	struct callout *calloutp;
 
 	kn->kn_data++;
-	KNOTE_ACTIVATE(kn, 0);	/* XXX - handle locking */
+	KNOTE_ACTIVATE(kn);	/* XXX - handle locking */
 
 	if ((kn->kn_flags & EV_ONESHOT) != EV_ONESHOT) {
 		calloutp = (struct callout *)kn->kn_hook;
@@ -1011,7 +1011,7 @@ findkn:
 		event = kn->kn_fop->f_event(kn, 0);
 		KQ_LOCK(kq);
 		if (event)
-			KNOTE_ACTIVATE(kn, 1);
+			KNOTE_ACTIVATE_LOCKED(kn);
 		kn->kn_status &= ~KN_INFLUX;
 		KN_LIST_UNLOCK(kn);
 	} else if (kev->flags & EV_DELETE) {
@@ -1625,23 +1625,15 @@ kqueue_wakeup(struct kqueue *kq)
  * first.
  */
 void
-knote(struct knlist *list, long hint, int islocked)
+knote_locked(struct knlist *list, long hint)
 {
+
 	struct kqueue *kq;
 	struct knote *kn;
 
 	if (list == NULL)
 		return;
-
-	KNL_ASSERT_LOCK(list, islocked);
-
-	if (!islocked){
-		if (list->kl_lock != knlist_mtx_lock)
-			list->kl_lock(list->kl_lockarg);
-		else
-			mtx_lock((struct mtx *)list->kl_lockarg);
-	}
-
+	
 	/*
 	 * If we unlock the list lock (and set KN_INFLUX), we can eliminate
 	 * the kqueue scheduling, but this will introduce four
@@ -1657,17 +1649,30 @@ knote(struct knlist *list, long hint, in
 			if ((kn->kn_status & KN_INFLUX) != KN_INFLUX) {
 				kn->kn_status |= KN_HASKQLOCK;
 				if (kn->kn_fop->f_event(kn, hint))
-					KNOTE_ACTIVATE(kn, 1);
+					KNOTE_ACTIVATE_LOCKED(kn);
 				kn->kn_status &= ~KN_HASKQLOCK;
 			}
 			KQ_UNLOCK(kq);
 		}
 		kq = NULL;
 	}
-	if (!islocked)
-		list->kl_unlock(list->kl_lockarg); 
 }
 
+void
+knote(struct knlist *list, long hint)
+{
+	if (list == NULL)
+		return;
+
+	if (list->kl_lock != knlist_mtx_lock)
+		list->kl_lock(list->kl_lockarg);
+	else
+		mtx_lock((struct mtx *)list->kl_lockarg);
+	knote_locked(list, hint);
+	list->kl_unlock(list->kl_lockarg); 
+}
+
+
 /*
  * add a knote to a knlist
  */

Modified: user/kmacy/HEAD_fast_net/sys/sys/event.h
==============================================================================
--- user/kmacy/HEAD_fast_net/sys/sys/event.h	Wed Dec 31 23:22:45 2008	(r186662)
+++ user/kmacy/HEAD_fast_net/sys/sys/event.h	Wed Dec 31 23:44:34 2008	(r186663)
@@ -135,9 +135,15 @@ struct knlist {
 MALLOC_DECLARE(M_KQUEUE);
 #endif
 
-#define KNOTE(list, hist, lock)		knote(list, hist, lock)
-#define KNOTE_LOCKED(list, hint)	knote(list, hint, 1)
-#define KNOTE_UNLOCKED(list, hint)	knote(list, hint, 0)
+#define KNOTE(list, hist, lock) do {			\
+	if (lock)					\
+		knote_locked(list, hist);		\
+	else						\
+		knote(list, hist);			\
+} while (0)
+
+#define KNOTE_LOCKED(list, hint)	knote_locked(list, hint)
+#define KNOTE_UNLOCKED(list, hint)	knote(list, hint)
 
 #define	KNLIST_EMPTY(list)		SLIST_EMPTY(&(list)->kl_list)
 
@@ -204,7 +210,8 @@ struct thread;
 struct proc;
 struct knlist;
 
-extern void	knote(struct knlist *list, long hint, int islocked);
+extern void	knote(struct knlist *list, long hint);
+extern void	knote_locked(struct knlist *list, long hint);
 extern void	knote_fork(struct knlist *list, int pid);
 extern void	knlist_add(struct knlist *knl, struct knote *kn, int islocked);
 extern void	knlist_remove(struct knlist *knl, struct knote *kn, int islocked);



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