Module Name: src
Committed By: riastradh
Date: Tue Jan 26 01:05:17 UTC 2016
Modified Files:
src/share/man/man9: pserialize.9
Log Message:
Suggest the cacheline-aligned global struct idiom.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/share/man/man9/pserialize.9
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/share/man/man9/pserialize.9
diff -u src/share/man/man9/pserialize.9:1.10 src/share/man/man9/pserialize.9:1.11
--- src/share/man/man9/pserialize.9:1.10 Mon Mar 9 01:55:09 2015
+++ src/share/man/man9/pserialize.9 Tue Jan 26 01:05:17 2016
@@ -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 @@ Given a global database of frotz records
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 @@ Create a frotz and publish it, as a writ
/* 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 @@ Find a frotz, as a reader:
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 @@ readers:
.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 @@ readers:
* 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);