D
digz
I saw the following code and comments in a source file, I am not able
to appreciate
what the author is trying to do in ALIGNED_ALLOC , can some one plz
help me understand why CACHE_LINE_SIZE * 2 is first added to the
parameters to malloc and then CACHE_LINE_SIZE -1 is added to the
return address and after that its bit anded with ( CACHE_LINE_SIZE
-1 ) , how is this helping alignment etc ?
/*
* Allow us to efficiently align and pad structures so that shared
fields
* don't cause contention on thread-local or read-only fields.
*/
#define CACHE_LINE_SIZE 64
#define CACHE_PAD(_n) char __pad ## _n [CACHE_LINE_SIZE]
#define ALIGNED_ALLOC(_s) \
((void *)(((unsigned long)malloc((_s)+CACHE_LINE_SIZE*2) + \
CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE-1)))
Thx
Digz
to appreciate
what the author is trying to do in ALIGNED_ALLOC , can some one plz
help me understand why CACHE_LINE_SIZE * 2 is first added to the
parameters to malloc and then CACHE_LINE_SIZE -1 is added to the
return address and after that its bit anded with ( CACHE_LINE_SIZE
-1 ) , how is this helping alignment etc ?
/*
* Allow us to efficiently align and pad structures so that shared
fields
* don't cause contention on thread-local or read-only fields.
*/
#define CACHE_LINE_SIZE 64
#define CACHE_PAD(_n) char __pad ## _n [CACHE_LINE_SIZE]
#define ALIGNED_ALLOC(_s) \
((void *)(((unsigned long)malloc((_s)+CACHE_LINE_SIZE*2) + \
CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE-1)))
Thx
Digz