lttng-dev Archive on lore.kernel.org
 help / color / Atom feed
* Userspace RCU data alignment
@ 2020-06-03 12:36 Dmitry Antipov via lttng-dev
  2020-06-03 12:36 ` [lttng-dev] " Dmitry Antipov via lttng-dev
  2020-06-05 16:09 ` Mathieu Desnoyers via lttng-dev
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Antipov via lttng-dev @ 2020-06-03 12:36 UTC (permalink / raw)
  To: lttng-dev


[-- Attachment #1: Type: text/plain, Size: 1922 bytes --]

I've compiled userspace-rcu with:

CC=gcc CFLAGS='-O0 -g3 -fsanitize=undefined' LIBS='-lubsan' ./configure [xxx]

and see a lot of 'misaligned address' runtime errors like:

  ./doc/examples/urcu-flavors/bp ==>

../include/urcu/static/urcu-bp.h:185:6: runtime error: member access within misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which requires 128 byte alignment
0x7fcac376a020: note: pointer points here
  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
               ^
     #0 0x7fcac372a880 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:185
     #1 0x7fcac372b0d9 in urcu_bp_read_unlock /home/antipov/userspace-rcu/src/urcu-bp.c:363
     #2 0x4017d5 in main /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
     #4 0x40111d in _start (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)

../include/urcu/static/urcu-bp.h:189:2: runtime error: member access within misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which requires 128 byte alignment
0x7fcac376a020: note: pointer points here
  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
               ^
     #0 0x7fcac372a8c1 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:189
     #1 0x7fcac372b0d9 in urcu_bp_read_unlock /home/antipov/userspace-rcu/src/urcu-bp.c:363
     #2 0x4017d5 in main /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
     #4 0x40111d in _start (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)

Is it critical for correctness, or speed, or whatever else?

To whom it may be interesting, some of (probably not all) alignment issues may be fixed
with attached patch.

Dmitry

[-- Attachment #2: urcu_bp_reader_alignment.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]

diff --git a/include/urcu/list.h b/include/urcu/list.h
index 4aaf869..d5f28fe 100644
--- a/include/urcu/list.h
+++ b/include/urcu/list.h
@@ -40,6 +40,11 @@ struct cds_list_head {
 #define CDS_LIST_HEAD(name) \
 	struct cds_list_head name = { &(name), &(name) }
 
+/* Likewise but aligned to ALIGN bytes. */
+#define CDS_LIST_HEAD_ALIGNED(name, align) \
+	struct cds_list_head name __attribute__((aligned (align))) \
+	= { &(name), &(name) }
+
 /* Initialize a new list head. */
 #define CDS_INIT_LIST_HEAD(ptr) \
 	(ptr)->next = (ptr)->prev = (ptr)
diff --git a/src/urcu-bp.c b/src/urcu-bp.c
index 05efd97..4e31147 100644
--- a/src/urcu-bp.c
+++ b/src/urcu-bp.c
@@ -154,12 +154,15 @@ URCU_ATTR_ALIAS("urcu_bp_gp") extern struct urcu_bp_gp rcu_gp_bp;
 DEFINE_URCU_TLS(struct urcu_bp_reader *, urcu_bp_reader);
 DEFINE_URCU_TLS_ALIAS(struct urcu_bp_reader *, urcu_bp_reader, rcu_reader_bp);
 
-static CDS_LIST_HEAD(registry);
+static CDS_LIST_HEAD_ALIGNED(registry, CAA_CACHE_LINE_SIZE);
 
 struct registry_chunk {
 	size_t data_len;		/* data length */
 	size_t used;			/* amount of data used */
 	struct cds_list_head node;	/* chunk_list node */
+	char pad[CAA_CACHE_LINE_SIZE -  /* pad to ensure expected alignment */
+		 sizeof(size_t) * 2 -
+		 sizeof(struct cds_list_head)];
 	char data[];
 };
 
@@ -270,8 +273,8 @@ static void wait_for_readers(struct cds_list_head *input_readers,
 
 void urcu_bp_synchronize_rcu(void)
 {
-	CDS_LIST_HEAD(cur_snap_readers);
-	CDS_LIST_HEAD(qsreaders);
+	CDS_LIST_HEAD_ALIGNED(cur_snap_readers, CAA_CACHE_LINE_SIZE);
+	CDS_LIST_HEAD_ALIGNED(qsreaders, CAA_CACHE_LINE_SIZE);
 	sigset_t newmask, oldmask;
 	int ret;
 

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [lttng-dev] Userspace RCU data alignment
  2020-06-03 12:36 Userspace RCU data alignment Dmitry Antipov via lttng-dev
@ 2020-06-03 12:36 ` Dmitry Antipov via lttng-dev
  2020-06-05 16:09 ` Mathieu Desnoyers via lttng-dev
  1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Antipov via lttng-dev @ 2020-06-03 12:36 UTC (permalink / raw)
  To: lttng-dev


[-- Attachment #1: Type: text/plain, Size: 1922 bytes --]

I've compiled userspace-rcu with:

CC=gcc CFLAGS='-O0 -g3 -fsanitize=undefined' LIBS='-lubsan' ./configure [xxx]

and see a lot of 'misaligned address' runtime errors like:

  ./doc/examples/urcu-flavors/bp ==>

../include/urcu/static/urcu-bp.h:185:6: runtime error: member access within misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which requires 128 byte alignment
0x7fcac376a020: note: pointer points here
  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
               ^
     #0 0x7fcac372a880 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:185
     #1 0x7fcac372b0d9 in urcu_bp_read_unlock /home/antipov/userspace-rcu/src/urcu-bp.c:363
     #2 0x4017d5 in main /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
     #4 0x40111d in _start (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)

../include/urcu/static/urcu-bp.h:189:2: runtime error: member access within misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which requires 128 byte alignment
0x7fcac376a020: note: pointer points here
  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
               ^
     #0 0x7fcac372a8c1 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:189
     #1 0x7fcac372b0d9 in urcu_bp_read_unlock /home/antipov/userspace-rcu/src/urcu-bp.c:363
     #2 0x4017d5 in main /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
     #4 0x40111d in _start (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)

Is it critical for correctness, or speed, or whatever else?

To whom it may be interesting, some of (probably not all) alignment issues may be fixed
with attached patch.

Dmitry

[-- Attachment #2: urcu_bp_reader_alignment.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]

diff --git a/include/urcu/list.h b/include/urcu/list.h
index 4aaf869..d5f28fe 100644
--- a/include/urcu/list.h
+++ b/include/urcu/list.h
@@ -40,6 +40,11 @@ struct cds_list_head {
 #define CDS_LIST_HEAD(name) \
 	struct cds_list_head name = { &(name), &(name) }
 
+/* Likewise but aligned to ALIGN bytes. */
+#define CDS_LIST_HEAD_ALIGNED(name, align) \
+	struct cds_list_head name __attribute__((aligned (align))) \
+	= { &(name), &(name) }
+
 /* Initialize a new list head. */
 #define CDS_INIT_LIST_HEAD(ptr) \
 	(ptr)->next = (ptr)->prev = (ptr)
diff --git a/src/urcu-bp.c b/src/urcu-bp.c
index 05efd97..4e31147 100644
--- a/src/urcu-bp.c
+++ b/src/urcu-bp.c
@@ -154,12 +154,15 @@ URCU_ATTR_ALIAS("urcu_bp_gp") extern struct urcu_bp_gp rcu_gp_bp;
 DEFINE_URCU_TLS(struct urcu_bp_reader *, urcu_bp_reader);
 DEFINE_URCU_TLS_ALIAS(struct urcu_bp_reader *, urcu_bp_reader, rcu_reader_bp);
 
-static CDS_LIST_HEAD(registry);
+static CDS_LIST_HEAD_ALIGNED(registry, CAA_CACHE_LINE_SIZE);
 
 struct registry_chunk {
 	size_t data_len;		/* data length */
 	size_t used;			/* amount of data used */
 	struct cds_list_head node;	/* chunk_list node */
+	char pad[CAA_CACHE_LINE_SIZE -  /* pad to ensure expected alignment */
+		 sizeof(size_t) * 2 -
+		 sizeof(struct cds_list_head)];
 	char data[];
 };
 
@@ -270,8 +273,8 @@ static void wait_for_readers(struct cds_list_head *input_readers,
 
 void urcu_bp_synchronize_rcu(void)
 {
-	CDS_LIST_HEAD(cur_snap_readers);
-	CDS_LIST_HEAD(qsreaders);
+	CDS_LIST_HEAD_ALIGNED(cur_snap_readers, CAA_CACHE_LINE_SIZE);
+	CDS_LIST_HEAD_ALIGNED(qsreaders, CAA_CACHE_LINE_SIZE);
 	sigset_t newmask, oldmask;
 	int ret;
 

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Userspace RCU data alignment
  2020-06-03 12:36 Userspace RCU data alignment Dmitry Antipov via lttng-dev
  2020-06-03 12:36 ` [lttng-dev] " Dmitry Antipov via lttng-dev
@ 2020-06-05 16:09 ` Mathieu Desnoyers via lttng-dev
  2020-06-05 16:09   ` [lttng-dev] " Mathieu Desnoyers via lttng-dev
  1 sibling, 1 reply; 4+ messages in thread
From: Mathieu Desnoyers via lttng-dev @ 2020-06-05 16:09 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: lttng-dev

----- On Jun 3, 2020, at 8:36 AM, lttng-dev lttng-dev@lists.lttng.org wrote:

> I've compiled userspace-rcu with:
> 
> CC=gcc CFLAGS='-O0 -g3 -fsanitize=undefined' LIBS='-lubsan' ./configure [xxx]
> 
> and see a lot of 'misaligned address' runtime errors like:
> 
>  ./doc/examples/urcu-flavors/bp ==>
> 
> ../include/urcu/static/urcu-bp.h:185:6: runtime error: member access within
> misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which
> requires 128 byte alignment
> 0x7fcac376a020: note: pointer points here
>  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
>  00 00  00 00 00 00
>               ^
>     #0 0x7fcac372a880 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:185
>     #1 0x7fcac372b0d9 in urcu_bp_read_unlock
>     /home/antipov/userspace-rcu/src/urcu-bp.c:363
>     #2 0x4017d5 in main
>     /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
>     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
>     #4 0x40111d in _start
>     (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)
> 
> ../include/urcu/static/urcu-bp.h:189:2: runtime error: member access within
> misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which
> requires 128 byte alignment
> 0x7fcac376a020: note: pointer points here
>  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
>  00 00  00 00 00 00
>               ^
>     #0 0x7fcac372a8c1 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:189
>     #1 0x7fcac372b0d9 in urcu_bp_read_unlock
>     /home/antipov/userspace-rcu/src/urcu-bp.c:363
>     #2 0x4017d5 in main
>     /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
>     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
>     #4 0x40111d in _start
>     (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)
> 
> Is it critical for correctness, or speed, or whatever else?

As I remember this is mainly for speed, so it's not a show-stopper.

> To whom it may be interesting, some of (probably not all) alignment issues may
> be fixed
> with attached patch.

I agree on fixing this, but I recommend a different approach:

Change:

struct registry_chunk {
        size_t data_len;                /* data length */
        size_t used;                    /* amount of data used */
        struct cds_list_head node;      /* chunk_list node */
        char data[];
};

for:

struct registry_chunk {
        size_t nr_readers;              /* number of readers */
        size_t used;                    /* amount of data used */
        struct cds_list_head node;      /* chunk_list node */
        struct urcu_bp_reader readers[];
};

And adapt all the readers allocation scheme within urcu-bp to work on
"readers" elements rather than bytes.

By doing so, struct registry_chunk will adapt to have the proper alignment.

Thanks,

Mathieu

> 
> Dmitry
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] Userspace RCU data alignment
  2020-06-05 16:09 ` Mathieu Desnoyers via lttng-dev
@ 2020-06-05 16:09   ` Mathieu Desnoyers via lttng-dev
  0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Desnoyers via lttng-dev @ 2020-06-05 16:09 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: lttng-dev

----- On Jun 3, 2020, at 8:36 AM, lttng-dev lttng-dev@lists.lttng.org wrote:

> I've compiled userspace-rcu with:
> 
> CC=gcc CFLAGS='-O0 -g3 -fsanitize=undefined' LIBS='-lubsan' ./configure [xxx]
> 
> and see a lot of 'misaligned address' runtime errors like:
> 
>  ./doc/examples/urcu-flavors/bp ==>
> 
> ../include/urcu/static/urcu-bp.h:185:6: runtime error: member access within
> misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which
> requires 128 byte alignment
> 0x7fcac376a020: note: pointer points here
>  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
>  00 00  00 00 00 00
>               ^
>     #0 0x7fcac372a880 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:185
>     #1 0x7fcac372b0d9 in urcu_bp_read_unlock
>     /home/antipov/userspace-rcu/src/urcu-bp.c:363
>     #2 0x4017d5 in main
>     /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
>     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
>     #4 0x40111d in _start
>     (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)
> 
> ../include/urcu/static/urcu-bp.h:189:2: runtime error: member access within
> misaligned address 0x7fcac376a020 for type 'struct urcu_bp_reader', which
> requires 128 byte alignment
> 0x7fcac376a020: note: pointer points here
>  ca 7f 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
>  00 00  00 00 00 00
>               ^
>     #0 0x7fcac372a8c1 in _urcu_bp_read_unlock ../include/urcu/static/urcu-bp.h:189
>     #1 0x7fcac372b0d9 in urcu_bp_read_unlock
>     /home/antipov/userspace-rcu/src/urcu-bp.c:363
>     #2 0x4017d5 in main
>     /home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp.c:92
>     #3 0x7fcac2bc2041 in __libc_start_main ../csu/libc-start.c:308
>     #4 0x40111d in _start
>     (/home/antipov/userspace-rcu/doc/examples/urcu-flavors/bp+0x40111d)
> 
> Is it critical for correctness, or speed, or whatever else?

As I remember this is mainly for speed, so it's not a show-stopper.

> To whom it may be interesting, some of (probably not all) alignment issues may
> be fixed
> with attached patch.

I agree on fixing this, but I recommend a different approach:

Change:

struct registry_chunk {
        size_t data_len;                /* data length */
        size_t used;                    /* amount of data used */
        struct cds_list_head node;      /* chunk_list node */
        char data[];
};

for:

struct registry_chunk {
        size_t nr_readers;              /* number of readers */
        size_t used;                    /* amount of data used */
        struct cds_list_head node;      /* chunk_list node */
        struct urcu_bp_reader readers[];
};

And adapt all the readers allocation scheme within urcu-bp to work on
"readers" elements rather than bytes.

By doing so, struct registry_chunk will adapt to have the proper alignment.

Thanks,

Mathieu

> 
> Dmitry
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03 12:36 Userspace RCU data alignment Dmitry Antipov via lttng-dev
2020-06-03 12:36 ` [lttng-dev] " Dmitry Antipov via lttng-dev
2020-06-05 16:09 ` Mathieu Desnoyers via lttng-dev
2020-06-05 16:09   ` [lttng-dev] " Mathieu Desnoyers via lttng-dev

lttng-dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lttng-dev/0 lttng-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lttng-dev lttng-dev/ https://lore.kernel.org/lttng-dev \
		lttng-dev@lists.lttng.org
	public-inbox-index lttng-dev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.lttng.lists.lttng-dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git