Commit 79c7b9a8 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/fix-alignment-tpool' into integration_2023_w32

parents ee8269ea f3c2c12f
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#define THREAD_POOL_H #define THREAD_POOL_H
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <malloc.h>
#include <stdalign.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
...@@ -64,7 +66,10 @@ typedef struct notifiedFIFO_elt_s { ...@@ -64,7 +66,10 @@ typedef struct notifiedFIFO_elt_s {
oai_cputime_t startProcessingTime; oai_cputime_t startProcessingTime;
oai_cputime_t endProcessingTime; oai_cputime_t endProcessingTime;
oai_cputime_t returnTime; oai_cputime_t returnTime;
void *msgData; // use alignas(32) to align msgData to 32b
// user data behind it will be aligned to 32b as well
// important! this needs to be the last member in the struct
alignas(32) void *msgData;
} notifiedFIFO_elt_t; } notifiedFIFO_elt_t;
typedef struct notifiedFIFO_s { typedef struct notifiedFIFO_s {
...@@ -80,14 +85,15 @@ static inline notifiedFIFO_elt_t *newNotifiedFIFO_elt(int size, ...@@ -80,14 +85,15 @@ static inline notifiedFIFO_elt_t *newNotifiedFIFO_elt(int size,
uint64_t key, uint64_t key,
notifiedFIFO_t *reponseFifo, notifiedFIFO_t *reponseFifo,
void (*processingFunc)(void *)) { void (*processingFunc)(void *)) {
notifiedFIFO_elt_t *ret; notifiedFIFO_elt_t *ret = (notifiedFIFO_elt_t *)memalign(32, sizeof(notifiedFIFO_elt_t) + size);
AssertFatal( NULL != (ret=(notifiedFIFO_elt_t *) calloc(1, sizeof(notifiedFIFO_elt_t)+size+32)), ""); AssertFatal(NULL != ret, "out of memory\n");
ret->next=NULL; ret->next=NULL;
ret->key=key; ret->key=key;
ret->reponseFifo=reponseFifo; ret->reponseFifo=reponseFifo;
ret->processingFunc=processingFunc; ret->processingFunc=processingFunc;
// We set user data piece aligend 32 bytes to be able to process it with SIMD // We set user data piece aligend 32 bytes to be able to process it with SIMD
ret->msgData=(void *)((uint8_t*)ret+(sizeof(notifiedFIFO_elt_t)/32+1)*32); // msgData is aligned to 32bytes, so everything after will be as well
ret->msgData = ((uint8_t *)ret) + sizeof(notifiedFIFO_elt_t);
ret->malloced=true; ret->malloced=true;
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment