summaryrefslogtreecommitdiff
path: root/libitm
diff options
context:
space:
mode:
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-19 17:01:11 +0000
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-19 17:01:11 +0000
commit901cf1e23d8ebd0ec65e4091153717b0699bc78c (patch)
tree3273b0d938e451bbc5bab2642961a56fc6ba064b /libitm
parent46c5738f20730ad786046890ac4186ee23fb3a80 (diff)
downloadgcc-901cf1e23d8ebd0ec65e4091153717b0699bc78c.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235211 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libitm')
-rw-r--r--libitm/ChangeLog6
-rw-r--r--libitm/util.cc22
2 files changed, 22 insertions, 6 deletions
diff --git a/libitm/ChangeLog b/libitm/ChangeLog
index 42b47762b9f..68b5069806b 100644
--- a/libitm/ChangeLog
+++ b/libitm/ChangeLog
@@ -1,3 +1,9 @@
+2016-04-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR libitm/70456
+ * util.cc (xmalloc): Use posix_memalign to allocate memory on
+ on cache line if requested.
+
2016-03-03 Dominik Vogt <vogt@linux.vnet.ibm.com>
* config/s390/target.h (TARGET_BEGIN_TRANSACTION_ATTRIBUTE): Define
diff --git a/libitm/util.cc b/libitm/util.cc
index 16e5d034359..f89b2e5cccd 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;
}