This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Torvald Riegel <triegel at redhat dot com>
- Date: Sat, 2 Apr 2016 09:25:47 -0700
- Subject: Re: [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
- Authentication-results: sourceware.org; auth=none
- References: <20160330123453 dot GA17104 at intel dot com>
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.
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