DragonFly BSD
DragonFly kernel List (threaded) for 2010-09
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: kernel - MPSAFE kern_mpipe.c


From: Venkatesh Srinivas <me@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Sep 2010 07:33:34 -0400

A patch to convert to a per-pipe token; it hasn't exploded my vkernel yet... :D

diff --git a/sys/kern/kern_mpipe.c b/sys/kern/kern_mpipe.c
index 8a8559a..5b4a667 100644
--- a/sys/kern/kern_mpipe.c
+++ b/sys/kern/kern_mpipe.c
@@ -53,8 +53,6 @@
 
 static MALLOC_DEFINE(M_MPIPEARY, "MPipe Array", "Auxillary MPIPE structure");
 
-static struct lwkt_token mpipe_token = LWKT_TOKEN_MP_INITIALIZER(mpipe_token);
-
 /*
  * Initialize a malloc pipeline for the specified malloc type and allocation
  * size.  Create an array to cache up to nom_count buffers and preallocate
@@ -93,6 +91,8 @@ mpipe_init(malloc_pipe_t mpipe, malloc_type_t type, int bytes,
  ++mpipe->free_count;
  ++mpipe->total_count;
     }
+
+   lwkt_token_init(&mpipe->token, 1, "malloc pipeline token");
 }
 
 /*
@@ -121,6 +121,8 @@ mpipe_done(malloc_pipe_t mpipe)
  kfree(mpipe->array, M_MPIPEARY);
  mpipe->array = NULL;
     }
+
+    lwkt_token_uninit(&mpipe->token);
 }
 
 /*
@@ -135,7 +137,7 @@ mpipe_alloc_nowait(malloc_pipe_t mpipe)
     void *buf;
     int n;
 
-    lwkt_gettoken(&mpipe_token);
+    lwkt_gettoken(&mpipe->token);
     if ((n = mpipe->free_count) != 0) {
  /*
  * Use a free entry if it exists.
@@ -157,7 +159,7 @@ mpipe_alloc_nowait(malloc_pipe_t mpipe)
  if (buf)
     ++mpipe->total_count;
     }
-    lwkt_reltoken(&mpipe_token);
+    lwkt_reltoken(&mpipe->token);
     return(buf);
 }
 
@@ -172,7 +174,7 @@ mpipe_alloc_waitok(malloc_pipe_t mpipe)
     int n;
     int mfailed;
 
-    lwkt_gettoken(&mpipe_token);
+    lwkt_gettoken(&mpipe->token);
     mfailed = 0;
     for (;;) {
  if ((n = mpipe->free_count) != 0) {
@@ -204,7 +206,7 @@ mpipe_alloc_waitok(malloc_pipe_t mpipe)
  }
  mfailed = 1;
     }
-    lwkt_reltoken(&mpipe_token);
+    lwkt_reltoken(&mpipe->token);
     return(buf);
 }
 
@@ -219,7 +221,7 @@ mpipe_free(malloc_pipe_t mpipe, void *buf)
     if (buf == NULL)
  return;
 
-    lwkt_gettoken(&mpipe_token);
+    lwkt_gettoken(&mpipe->token);
     if ((n = mpipe->free_count) < mpipe->ary_count) {
  /*
  * Free slot available in free array (LIFO)
@@ -228,7 +230,7 @@ mpipe_free(malloc_pipe_t mpipe, void *buf)
  ++mpipe->free_count;
  if ((mpipe->mpflags & (MPF_CACHEDATA|MPF_NOZERO)) == 0) 
     bzero(buf, mpipe->bytes);
- lwkt_reltoken(&mpipe_token);
+ lwkt_reltoken(&mpipe->token);
 
  /*
  * Wakeup anyone blocked in mpipe_alloc_*().
@@ -245,7 +247,7 @@ mpipe_free(malloc_pipe_t mpipe, void *buf)
  KKASSERT(mpipe->total_count >= mpipe->free_count);
  if (mpipe->deconstruct)
     mpipe->deconstruct(mpipe, buf);
- lwkt_reltoken(&mpipe_token);
+ lwkt_reltoken(&mpipe->token);
  kfree(buf, mpipe->type);
     }
 }
diff --git a/sys/sys/mpipe.h b/sys/sys/mpipe.h
index 832b518..b54959e 100644
--- a/sys/sys/mpipe.h
+++ b/sys/sys/mpipe.h
@@ -83,6 +83,7 @@ struct malloc_pipe {
     int total_count; /* total outstanding allocations incl free */
     int ary_count; /* guarenteed allocation count */
     int max_count; /* maximum count (M_NOWAIT used beyond nom) */
+    lwkt_token token;
     void **array; /* array[ary_count] */
     void (*deconstruct)(struct malloc_pipe *, void *buf);
 };

-- vs


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]