Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Aug 2007 18:29:14 GMT
From:      Maxim Zhuravlev <thioretic@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124964 for review
Message-ID:  <200708091829.l79ITERa082830@repoman.freebsd.org>

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

Change 124964 by thioretic@thioretic on 2007/08/09 18:29:10

	Errata, some locking.

Affected files ...

.. //depot/projects/soc2007/thioretic_gidl2/kern/subr_busio.c#2 edit
.. //depot/projects/soc2007/thioretic_gidl2/sys/uio.h#2 edit

Differences ...

==== //depot/projects/soc2007/thioretic_gidl2/kern/subr_busio.c#2 (text+ko) ====

@@ -3,6 +3,10 @@
 #include <sys/kthread.h>
 #include <sys/malloc.h>
 #include <sys/queue.h>
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/uio.h>
 
 static MALLOC_DEFINE(M_BUS_IO, "bus_io", "Bus io subsystem data structures");
 
@@ -15,8 +19,42 @@
 typedef work_kthread* work_kthread_t;
 
 typedef TAILQ_HEAD(work_kthread_list, work_kthread) work_kthread_list_t;
+static work_kthread_list_t work_kthreads = TAILQ_HEAD_INITIALIZER(work_kthreads);
+
+static struct mtx work_kthreads_list_mtx;
 
-static work_kthread_list_t work_kthreads = TAILQ_HEAD_INITIALIZER(work_kthreads);
+struct ior {
+#define OPEN	1<<0
+#define FDOPEN	1<<1
+#define CLOSE	1<<2
+#define READ	1<<3
+#define WRITE	1<<4
+#define IOCTL	1<<5
+#define POLL	1<<6
+#define MMAP	1<<7
+#define STRATEGY	1<<8
+#define DUMP	1<<9
+#define KQFILTER	1<<10
+#define PURGE	1<<11
+#define SPARE2	1<<12
+	u_int32_t type;
+	void* data;
+#define IORS_INVALIDATE	1<<0
+#define IORS_DONE	1<<1
+#define IORS_RETRY	1<<2
+	u_int32_t state;
+	u_int32_t flags;
+	ior_t parent;
+	ior_list_t children;
+	devicelink_list_t path;
+	TAILQ_ENTRY (ior) link;
+};
+typedef struct ior* ior_t;
+
+typedef TAILQ_HEAD(ior_list, ior) ior_list_t;
+static ior_list_t iors = TAILQ_HEAD_INITIALIZER(iors);
+
+static struct mtx iors_list_mtx;
 
 SYSCTL_NODE(_kern, OID_AUTO, newbus, CTLFLAG_RW, 
 			0, "Newbus tuneup family");
@@ -31,44 +69,70 @@
 			work_kthreads_set_number, "I", "Number of kernel threads"
 			"to process queued io requests");
 
+static void bus_io_process_next_irp (work_kthread_t tp);
+
 static void
 work_kthread_proc (void *arg){
-	static work_kthread_t my_pwk = *((work_kthread_t)arg);
+	static work_kthread_t my_pwk = ((work_kthread_t)arg);
+	struct thread *tp = FIRST_THREAD_IN_PROC(my_pwk->kthread);
+
+	mtx_lock_spin (&sched_lock);
+	sched_prio (tp, );		/*TODO*/
+	mtx_unlock_spin (&sched_lock);
+
+	while (TRUE){
+		if (my_pwk->flags & WKF_REMOVE){
+			mtx_lock (&work_kthreads_list_mtx);
+			TAILQ_REMOVE (&work_kthreads, my_pwk, link);
+			mtx_unlock (&work_kthreads_list_mtx);
+			free (my_pwk);
+			kthread_exit (0);
+			return ();
+		}
+		bus_io_process_next_irp (my_pwk);
+	}
 }
 
 static void 
 reset_work_kthreads (void){
 	work_kthread_t pwk;
-	u_int32_t cur_work_kthread_num;
+	u_int32_t cur_work_kthreads_num;
 
 	if (old_work_kthreads_num == work_kthreads_num)
 		return ();
 
+	if (!mtx_initialized (&work_kthreads_list_mtx))
+		mtx_init (&work_kthreads_list_mtx, 
+			"bus_io_work_threads_list_mtx",
+			NULL, MTX_DEF);
+
+	mtx_lock (&work_kthreads_list_mtx);
+
 	if (old_work_kthreads_num < work_kthreads_num){
-		cur_work_kthread_num = old_work_kthreads_num;
+		cur_work_kthreads_num = old_work_kthreads_num;
 		do{
-			id = cur_work_kthreads_num;
 			pwk = malloc (sizeof(struct work_kthread), M_BUS_IO, M_NOWAIT|M_ZERO);
-			if (!pwk || kthread_create (&work_kthread_proc, &pwk, 
-					&(pwk->kthread), 0, 0, "bus_io_work_kthread%d", id)){
+			if (!pwk || kthread_create (&work_kthread_proc, pwk, 
+					&(pwk->kthread), 0, 0, "bus_io_work_kthread%d",
+					cur_work_kthreads_num)){
 				work_kthreads_num = cur_work_kthreads_num;
 				if (pwk) free(pwk);
-				return ();
+				break;
 			}
 			TAILQ_INSERT_TAIL(&work_kthreads, pwk, link);
 		}while (work_kthreads_num < ++cur_work_kthreads_num);
 	}
 	else{
-		cur_work_kthread_num = work_kthreads_num;
+		cur_work_kthreads_num = work_kthreads_num;
 		TAILQ_FOREACH(pwk, &work_kthreads, link){
-			if(cur_work_kthreads_num){
+			if(cur_work_kthreads_num)
 				cur_work_kthreads_num--;
-			}
-			else{
+			else
 				pwk->flags |= WKF_REMOVE;
-			}
 		}
 	}
+
+	mtx_unlock (&work_kthreads_list_mtx);
 }
 
 static int
@@ -92,5 +156,12 @@
 
 void
 bus_io_init (void){
+	mtx_init (&iors_list_mtx, 
+			"bus_io_iors_list_mtx",
+			NULL, MTX_DEF);
 	reset_work_kthreads();
+}
+
+static void 
+bus_io_process_next_irp (work_kthread_t wkt){
 }
==== //depot/projects/soc2007/thioretic_gidl2/sys/uio.h#2 (text+ko) ====

@@ -68,11 +68,6 @@
 	enum	uio_seg uio_segflg;
 	enum	uio_rw uio_rw;
 	struct	thread *uio_td;
-	char* stack_path;
-#define INVALIDATE	1
-#define FULFILLED	2
-#define RETRY	4
-	int state;
 };
 
 /*



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