Source-Changes-HG archive

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

[src/trunk]: src - pool_cache_invalidate(): broadcast a cross-call to drain t...



details:   https://anonhg.NetBSD.org/src/rev/5c1955ecbf28
branches:  trunk
changeset: 748189:5c1955ecbf28
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Oct 15 20:50:12 2009 +0000

description:
- pool_cache_invalidate(): broadcast a cross-call to drain the per-CPU
  caches before draining the global cache.
- pool_cache_invalidate_local(): remove.

diffstat:

 share/man/man9/pool_cache.9 |  29 +++++++----------------------
 sys/kern/subr_pool.c        |  40 ++++++++++++++++++++++++----------------
 sys/sys/pool.h              |   3 +--
 3 files changed, 32 insertions(+), 40 deletions(-)

diffs (154 lines):

diff -r 1a7125a93788 -r 5c1955ecbf28 share/man/man9/pool_cache.9
--- a/share/man/man9/pool_cache.9       Thu Oct 15 20:35:19 2009 +0000
+++ b/share/man/man9/pool_cache.9       Thu Oct 15 20:50:12 2009 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pool_cache.9,v 1.12 2009/10/08 23:15:26 wiz Exp $
+.\"    $NetBSD: pool_cache.9,v 1.13 2009/10/15 20:50:13 thorpej Exp $
 .\"
 .\" Copyright (c)2003 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -53,7 +53,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" ------------------------------------------------------------
-.Dd October 9, 2009
+.Dd October 15, 2009
 .Dt POOL_CACHE 9
 .Os
 .\" ------------------------------------------------------------
@@ -67,7 +67,6 @@
 .Nm pool_cache_put ,
 .Nm pool_cache_destruct_object ,
 .Nm pool_cache_invalidate ,
-.Nm pool_cache_invalidate_local ,
 .Nm pool_cache_sethiwat ,
 .Nm pool_cache_setlowat
 .Nd resource-pool cache manager
@@ -108,9 +107,6 @@
 .Ft void
 .Fn pool_cache_invalidate \
 "pool_cache_t pc"
-.Ft void
-.Fn pool_cache_invalidate_local \
-"pool_cache_t pc"
 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 .Ft void
 .Fn pool_cache_sethiwat \
@@ -279,22 +275,11 @@
 .Pp
 Invalidate a pool cache
 .Fa pc .
-Destruct and release all objects in the global cache.
-Per-CPU caches will not be invalidated by this call, meaning that it
-is still possible to allocate "stale" items from the cache.
-If relevant, the user must check for this condition when allocating
-items.
-.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-.It Fn pool_cache_invalidate_local "pc"
-.Pp
-Invalidate local, current CPU pool cache
-.Fa pc .
-Destruct and release all objects in the local, current CPU cache.
-Only the Per-CPU caches associated to the current CPU calling the routine
-will be invalidated, meaning that stale items can still be allocated from
-other CPUs or the global cache.
-It is the caller's responsibility to ensure that such conditions do
-not occur.
+All objects in the cache will be destructed and freed back to the pool
+backing the cache.
+For pool caches that vend constructed objects, consumers of this API
+must take care to provide proper synchronization between the input to
+the constructor and cache invalidation.
 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 .It Fn pool_cache_sethiwat "pc" "nitems"
 .Pp
diff -r 1a7125a93788 -r 5c1955ecbf28 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Thu Oct 15 20:35:19 2009 +0000
+++ b/sys/kern/subr_pool.c      Thu Oct 15 20:50:12 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.175 2009/10/08 21:54:45 jym Exp $      */
+/*     $NetBSD: subr_pool.c,v 1.176 2009/10/15 20:50:12 thorpej Exp $  */
 
 /*-
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.175 2009/10/08 21:54:45 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.176 2009/10/15 20:50:12 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pool.h"
@@ -2289,11 +2289,33 @@
  *
  *     Invalidate a pool cache (destruct and release all of the
  *     cached objects).  Does not reclaim objects from the pool.
+ *
+ *     Note: For pool caches that provide constructed objects, there
+ *     is an assumption that another level of synchronization is occurring
+ *     between the input to the constructor and the cache invalidation.
  */
 void
 pool_cache_invalidate(pool_cache_t pc)
 {
        pcg_t *full, *empty, *part;
+       uint64_t where;
+
+       if (ncpu < 2) {
+               /*
+                * We might be called early enough in the boot process
+                * for the CPU data structures to not be fully initialized.
+                * In this case, simply gather the local CPU's cache now
+                * since it will be the only one running.
+                */
+               pool_cache_xcall(pc);
+       } else {
+               /*
+                * Gather all of the CPU-specific caches into the
+                * global cache.
+                */
+               where = xc_broadcast(0, (xcfunc_t)pool_cache_xcall, pc, NULL);
+               xc_wait(where);
+       }
 
        mutex_enter(&pc->pc_lock);
        full = pc->pc_fullgroups;
@@ -2313,20 +2335,6 @@
 }
 
 /*
- * pool_cache_invalidate_local:
- *
- *     Invalidate all local ('current CPU') cached objects in
- *     pool cache.
- *     It is caller's responsibility to ensure that no operation is
- *     taking place on this pool cache while doing the local invalidation.
- */
-void
-pool_cache_invalidate_local(pool_cache_t pc)
-{
-       pool_cache_invalidate_cpu(pc, curcpu()->ci_index);
-}
-
-/*
  * pool_cache_invalidate_cpu:
  *
  *     Invalidate all CPU-bound cached objects in pool cache, the CPU being
diff -r 1a7125a93788 -r 5c1955ecbf28 sys/sys/pool.h
--- a/sys/sys/pool.h    Thu Oct 15 20:35:19 2009 +0000
+++ b/sys/sys/pool.h    Thu Oct 15 20:50:12 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pool.h,v 1.66 2009/10/08 21:54:45 jym Exp $    */
+/*     $NetBSD: pool.h,v 1.67 2009/10/15 20:50:12 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2000, 2007 The NetBSD Foundation, Inc.
@@ -321,7 +321,6 @@
 void           pool_cache_put_paddr(pool_cache_t, void *, paddr_t);
 void           pool_cache_destruct_object(pool_cache_t, void *);
 void           pool_cache_invalidate(pool_cache_t);
-void           pool_cache_invalidate_local(pool_cache_t);
 bool           pool_cache_reclaim(pool_cache_t);
 void           pool_cache_set_drain_hook(pool_cache_t,
                    void (*)(void *, int), void *);



Home | Main Index | Thread Index | Old Index