Source-Changes-HG archive

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

[src/trunk]: src/share/man/man9 Suggest the cacheline-aligned global struct i...



details:   https://anonhg.NetBSD.org/src/rev/3a1bbdfb8197
branches:  trunk
changeset: 813379:3a1bbdfb8197
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Jan 26 01:05:17 2016 +0000

description:
Suggest the cacheline-aligned global struct idiom.

diffstat:

 share/man/man9/pserialize.9 |  32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diffs (86 lines):

diff -r 0999fdb75830 -r 3a1bbdfb8197 share/man/man9/pserialize.9
--- a/share/man/man9/pserialize.9       Mon Jan 25 21:58:02 2016 +0000
+++ b/share/man/man9/pserialize.9       Tue Jan 26 01:05:17 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pserialize.9,v 1.10 2015/03/09 01:55:09 riastradh Exp $
+.\"    $NetBSD: pserialize.9,v 1.11 2016/01/26 01:05:17 riastradh Exp $
 .\"
 .\" Copyright (c) 2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 21, 2014
+.Dd January 26, 2016
 .Dt PSERIALIZE 9
 .Os
 .Sh NAME
@@ -81,9 +81,11 @@
                struct frotz    *f_next;
        };
 
-       kmutex_t frobbotzim_lock;
-       struct frotz *frobbotzim;
-       pserialize_t frobbotzim_psz;
+       static struct {
+               kmutex_t        lock;
+               pserialize_t    psz;
+               struct frotz    *first;
+       } frobbotzim __cacheline_aligned;
 .Ed
 .Pp
 Create a frotz and publish it, as a writer:
@@ -93,15 +95,15 @@
        /* Initialize f.  */
        ...
 
-       mutex_enter(\*[Am]frobbotzim_lock);
-       f->f_next = frobbotzim;
+       mutex_enter(\*[Am]frobbotzim.lock);
+       f->f_next = frobbotzim.first;
        /*
         * Publish the contents of f->f_next before we publish the
-        * pointer to f in frobbotzim.
+        * pointer to f in frobbotzim.first.
         */
        membar_producer();
-       frobbotzim = f;
-       mutex_exit(\*[Am]frobbotzim_lock);
+       frobbotzim.first = f;
+       mutex_exit(\*[Am]frobbotzim.lock);
 .Ed
 .Pp
 Find a frotz, as a reader:
@@ -111,7 +113,7 @@
        int s;
 
        s = pserialize_read_enter();
-       for (f = frobbotzim; f != NULL; f = f->f_next) {
+       for (f = frobbotzim.first; f != NULL; f = f->f_next) {
                /* Fetch f before we fetch anything f points to.  */
                membar_datadep_consumer();
                if (f->f_... == key) {
@@ -130,8 +132,8 @@
 .Bd -literal
        struct frotz **fp, *f;
 
-       mutex_enter(\*[Am]frobbotzim_lock);
-       for (fp = \*[Am]frobbotzim; (f = *fp) != NULL; fp = &f->f_next) {
+       mutex_enter(\*[Am]frobbotzim.lock);
+       for (fp = \*[Am]frobbotzim.first; (f = *fp) != NULL; fp = &f->f_next) {
                if (f->f_... == key) {
                        /*
                         * Unhook it from the list.  Readers may still
@@ -147,9 +149,9 @@
         * Wait for all existing readers to complete.  New readers will
         * not see f because the list no longer points to it.
         */
-       pserialize_perform(frobbotzim_psz);
+       pserialize_perform(frobbotzim.psz);
        /* Now nobody else can be touching f, so it is safe to free.  */
-       mutex_exit(\*[Am]frobbotzim_lock);
+       mutex_exit(\*[Am]frobbotzim.lock);
 
        if (f != NULL)
                pool_put(\*[Am]frotz_pool, f);



Home | Main Index | Thread Index | Old Index