public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
@ 2016-03-30 12:48 H.J. Lu
  2016-04-02 16:26 ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2016-03-30 12:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: triegel

Since GTM::gtm_thread has

gtm_thread *next_thread __attribute__((__aligned__(HW_CACHELINE_SIZE)));

GTM::gtm_thread::operator new should allocate aligned memory.

Tested on Linux/x86-64.  OK for trunk.


H.J.
----

	PR libitm/70456
	* beginend.cc (GTM::gtm_thread::operator new): Use posix_memalign
	to allocate aligned memory.
---
 libitm/beginend.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libitm/beginend.cc b/libitm/beginend.cc
index 20b5547..e2a8327 100644
--- a/libitm/beginend.cc
+++ b/libitm/beginend.cc
@@ -63,7 +63,14 @@ GTM::gtm_thread::operator new (size_t s)
 
   assert(s == sizeof(gtm_thread));
 
+#ifdef HAVE_POSIX_MEMALIGN
+  if (posix_memalign (&tx, __alignof__ (gtm_thread), sizeof (gtm_thread)))
+    GTM_fatal ("Out of memory allocating %lu bytes aligned at %lu bytes",
+	       (unsigned long) sizeof (gtm_thread),
+	       (unsigned long) __alignof__ (gtm_thread));
+#else
   tx = xmalloc (sizeof (gtm_thread), true);
+#endif
   memset (tx, 0, sizeof (gtm_thread));
 
   return tx;
-- 
2.5.5

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

* Re: [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
  2016-03-30 12:48 [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new H.J. Lu
@ 2016-04-02 16:26 ` H.J. Lu
  2016-04-19 15:04   ` H.J. Lu
  2016-04-19 16:41   ` Torvald Riegel
  0 siblings, 2 replies; 4+ messages in thread
From: H.J. Lu @ 2016-04-02 16:26 UTC (permalink / raw)
  To: GCC Patches; +Cc: Torvald Riegel

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

On Wed, Mar 30, 2016 at 5:34 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Since GTM::gtm_thread has
>
> gtm_thread *next_thread __attribute__((__aligned__(HW_CACHELINE_SIZE)));
>
> GTM::gtm_thread::operator new should allocate aligned memory.
>
> Tested on Linux/x86-64.  OK for trunk.
>
>

This patch is better.  Tested on Linux/x86-64.  OK for trunk?


-- 
H.J.

[-- Attachment #2: 0001-Allocate-memory-on-cache-line-if-requested.patch --]
[-- Type: text/x-patch, Size: 1571 bytes --]

From 461ada452acc2fc6decb281f136ab1136fe46ab2 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 2 Apr 2016 07:18:05 -0700
Subject: [PATCH] Allocate memory on cache line if requested

Since GTM::gtm_thread has

gtm_thread *next_thread __attribute__((__aligned__(HW_CACHELINE_SIZE)));

GTM::gtm_thread::operator new () calls xmalloc with separate_cl == true.
xmalloc must return memory on cache line in this case.

	PR libitm/70456
	* util.cc (xmalloc): Use posix_memalign to allocate memory on
	on cache line if requested.
---
 libitm/util.cc | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/libitm/util.cc b/libitm/util.cc
index 16e5d03..f89b2e5 100644
--- a/libitm/util.cc
+++ b/libitm/util.cc
@@ -61,12 +61,22 @@ GTM_fatal (const char *fmt, ...)
 void *
 xmalloc (size_t size, bool separate_cl)
 {
-  // TODO Use posix_memalign if separate_cl is true, or some other allocation
-  // method that will avoid sharing cache lines with data used by other
-  // threads.
-  void *r = malloc (size);
-  if (r == 0)
-    GTM_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
+  void *r;
+#ifdef HAVE_POSIX_MEMALIGN
+  if (separate_cl)
+    {
+      if (posix_memalign (&r, HW_CACHELINE_SIZE, size))
+	GTM_fatal ("Out of memory allocating %lu bytes aligned on cache line",
+		   (unsigned long) size);
+    }
+  else
+#endif
+    {
+      r = malloc (size);
+      if (r == 0)
+	GTM_fatal ("Out of memory allocating %lu bytes",
+		   (unsigned long) size);
+    }
   return r;
 }
 
-- 
2.5.5


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

* Re: [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
  2016-04-02 16:26 ` H.J. Lu
@ 2016-04-19 15:04   ` H.J. Lu
  2016-04-19 16:41   ` Torvald Riegel
  1 sibling, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2016-04-19 15:04 UTC (permalink / raw)
  To: GCC Patches; +Cc: Torvald Riegel, Richard Henderson

On Sat, Apr 2, 2016 at 9:25 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Mar 30, 2016 at 5:34 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>> Since GTM::gtm_thread has
>>
>> gtm_thread *next_thread __attribute__((__aligned__(HW_CACHELINE_SIZE)));
>>
>> GTM::gtm_thread::operator new should allocate aligned memory.
>>
>> Tested on Linux/x86-64.  OK for trunk.
>>
>>
>
> This patch is better.  Tested on Linux/x86-64.  OK for trunk?
>

Hi Richard,

Is this patch:

https://gcc.gnu.org/ml/gcc-patches/2016-04/msg00119.html

OK for trunk?

-- 
H.J.

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

* Re: [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
  2016-04-02 16:26 ` H.J. Lu
  2016-04-19 15:04   ` H.J. Lu
@ 2016-04-19 16:41   ` Torvald Riegel
  1 sibling, 0 replies; 4+ messages in thread
From: Torvald Riegel @ 2016-04-19 16:41 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

On Sat, 2016-04-02 at 09:25 -0700, H.J. Lu wrote:
> On Wed, Mar 30, 2016 at 5:34 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> > Since GTM::gtm_thread has
> >
> > gtm_thread *next_thread __attribute__((__aligned__(HW_CACHELINE_SIZE)));
> >
> > GTM::gtm_thread::operator new should allocate aligned memory.
> >
> > Tested on Linux/x86-64.  OK for trunk.
> >
> >
> 
> This patch is better.  Tested on Linux/x86-64.  OK for trunk?

OK.

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

end of thread, other threads:[~2016-04-19 16:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-30 12:48 [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new H.J. Lu
2016-04-02 16:26 ` H.J. Lu
2016-04-19 15:04   ` H.J. Lu
2016-04-19 16:41   ` Torvald Riegel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).