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.

From-SVN: r235211
This commit is contained in:
H.J. Lu 2016-04-19 17:01:11 +00:00 committed by H.J. Lu
parent d855ad89cb
commit 831698b8f7
2 changed files with 22 additions and 6 deletions

View File

@ -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> 2016-03-03 Dominik Vogt <vogt@linux.vnet.ibm.com>
* config/s390/target.h (TARGET_BEGIN_TRANSACTION_ATTRIBUTE): Define * config/s390/target.h (TARGET_BEGIN_TRANSACTION_ATTRIBUTE): Define

View File

@ -61,12 +61,22 @@ GTM_fatal (const char *fmt, ...)
void * void *
xmalloc (size_t size, bool separate_cl) xmalloc (size_t size, bool separate_cl)
{ {
// TODO Use posix_memalign if separate_cl is true, or some other allocation void *r;
// method that will avoid sharing cache lines with data used by other #ifdef HAVE_POSIX_MEMALIGN
// threads. if (separate_cl)
void *r = malloc (size); {
if (r == 0) if (posix_memalign (&r, HW_CACHELINE_SIZE, size))
GTM_fatal ("Out of memory allocating %lu bytes", (unsigned long) 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; return r;
} }