diff --git a/Framework/Core/src/CommonServices.cxx b/Framework/Core/src/CommonServices.cxx index 9192cbd0c965d..ecfdf983ed573 100644 --- a/Framework/Core/src/CommonServices.cxx +++ b/Framework/Core/src/CommonServices.cxx @@ -715,16 +715,16 @@ o2::framework::ServiceSpec O2_SIGNPOST_EVENT_EMIT(data_processor_context, cid, "oldest_possible_timeslice", "Queueing oldest possible timeslice %" PRIu64 " propagation for execution.", (uint64_t)oldestPossibleOutput.timeslice.value); AsyncQueueHelpers::post( - queue, AsyncTask{ .timeslice = TimesliceId{oldestPossibleTimeslice}, - .id = decongestion.oldestPossibleTimesliceTask, - .debounce = -1, .callback = decongestionCallback} - .user(DecongestionContext{.ref = services, .oldestPossibleOutput = oldestPossibleOutput})); + queue, AsyncTask{.timeslice = TimesliceId{oldestPossibleTimeslice}, + .id = decongestion.oldestPossibleTimesliceTask, + .debounce = -1, + .callback = decongestionCallback} + .user(DecongestionContext{.ref = services, .oldestPossibleOutput = oldestPossibleOutput})); if (decongestion.orderedCompletionPolicyActive) { AsyncQueueHelpers::post( - queue, AsyncTask{.timeslice = TimesliceId{oldestPossibleOutput.timeslice.value},.id = decongestion.oldestPossibleTimesliceTask, .debounce = -1, - .callback = decongestionCallbackOrdered} - .user({.ref = services, .oldestPossibleOutput = oldestPossibleOutput})); + queue, AsyncTask{.timeslice = TimesliceId{oldestPossibleOutput.timeslice.value}, .id = decongestion.oldestPossibleTimesliceTask, .debounce = -1, .callback = decongestionCallbackOrdered} + .user({.ref = services, .oldestPossibleOutput = oldestPossibleOutput})); } }, .kind = ServiceKind::Serial}; } diff --git a/Framework/Foundation/3rdparty/x9/examples/x9_example_1.c b/Framework/Foundation/3rdparty/x9/examples/x9_example_1.c index 6498ac2a76da7..aa79d95d038cb 100644 --- a/Framework/Foundation/3rdparty/x9/examples/x9_example_1.c +++ b/Framework/Foundation/3rdparty/x9/examples/x9_example_1.c @@ -47,17 +47,20 @@ typedef struct { int sum; } msg; -static int random_int(int const min, int const max) { +static int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static inline void fill_msg_1(msg* const msg) { - msg->a = random_int(0, 10); - msg->b = random_int(0, 10); +static inline void fill_msg_1(msg* const msg) +{ + msg->a = random_int(0, 10); + msg->b = random_int(0, 10); msg->sum = msg->a + msg->b; } -static void* producer_fn(void* args) { +static void* producer_fn(void* args) +{ th_struct* data = (th_struct*)args; msg m = {0}; @@ -68,7 +71,8 @@ static void* producer_fn(void* args) { return 0; } -static void* consumer_fn(void* args) { +static void* consumer_fn(void* args) +{ th_struct* data = (th_struct*)args; msg m = {0}; @@ -79,7 +83,8 @@ static void* consumer_fn(void* args) { return 0; } -int main(void) { +int main(void) +{ /* Seed random generator */ srand((uint32_t)time(0)); @@ -90,11 +95,11 @@ int main(void) { assert(x9_inbox_is_valid(inbox)); /* Producer */ - pthread_t producer_th = {0}; + pthread_t producer_th = {0}; th_struct producer_struct = {.inbox = inbox}; /* Consumer */ - pthread_t consumer_th = {0}; + pthread_t consumer_th = {0}; th_struct consumer_struct = {.inbox = inbox}; /* Launch threads */ diff --git a/Framework/Foundation/3rdparty/x9/examples/x9_example_2.c b/Framework/Foundation/3rdparty/x9/examples/x9_example_2.c index 411c7c8128779..a9fd67acf7b0a 100644 --- a/Framework/Foundation/3rdparty/x9/examples/x9_example_2.c +++ b/Framework/Foundation/3rdparty/x9/examples/x9_example_2.c @@ -67,25 +67,29 @@ typedef struct { int product; } msg_type_2; -static inline int random_int(int const min, int const max) { +static inline int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static inline void fill_msg_type_1(msg_type_1 msg[const static 1]) { - msg->a = random_int(0, 10); - msg->b = random_int(0, 10); +static inline void fill_msg_type_1(msg_type_1 msg[const static 1]) +{ + msg->a = random_int(0, 10); + msg->b = random_int(0, 10); msg->sum = msg->a + msg->b; } -static inline void fill_msg_type_2(msg_type_2 to[const static 1], - msg_type_1 const from[const static 1]) { - to->x = from->a; - to->y = from->b; - to->sum = from->sum; +static inline void fill_msg_type_2(msg_type_2 to[const static 1], + msg_type_1 const from[const static 1]) +{ + to->x = from->a; + to->y = from->b; + to->sum = from->sum; to->product = (from->a * from->b); } -static void* producer_fn(void* args) { +static void* producer_fn(void* args) +{ th_struct* data = (th_struct*)args; x9_inbox* const destination = x9_select_inbox_from_node(data->node, "ibx_1"); @@ -99,7 +103,8 @@ static void* producer_fn(void* args) { return 0; } -static void* producer_consumer_fn(void* args) { +static void* producer_consumer_fn(void* args) +{ th_struct* data = (th_struct*)args; x9_inbox* const inbox = x9_select_inbox_from_node(data->node, "ibx_1"); @@ -122,7 +127,8 @@ static void* producer_consumer_fn(void* args) { return 0; } -static void* consumer_fn(void* args) { +static void* consumer_fn(void* args) +{ th_struct* data = (th_struct*)args; x9_inbox* const inbox = x9_select_inbox_from_node(data->node, "ibx_2"); @@ -139,16 +145,17 @@ static void* consumer_fn(void* args) { return 0; } -int main(void) { +int main(void) +{ /* Seed random generator */ srand((uint32_t)time(0)); /* Create inboxes */ x9_inbox* const inbox_msg_type_1 = - x9_create_inbox(4, "ibx_1", sizeof(msg_type_1)); + x9_create_inbox(4, "ibx_1", sizeof(msg_type_1)); x9_inbox* const inbox_msg_type_2 = - x9_create_inbox(4, "ibx_2", sizeof(msg_type_2)); + x9_create_inbox(4, "ibx_2", sizeof(msg_type_2)); /* Using asserts to simplify code for presentation purpose. */ assert(x9_inbox_is_valid(inbox_msg_type_1)); @@ -156,24 +163,24 @@ int main(void) { /* Create node */ x9_node* const node = - x9_create_node("my_node", 2, inbox_msg_type_1, inbox_msg_type_2); + x9_create_node("my_node", 2, inbox_msg_type_1, inbox_msg_type_2); /* Assert - Same reason as above. */ assert(x9_node_is_valid(node)); /* Producers */ - pthread_t producer_th_1 = {0}; + pthread_t producer_th_1 = {0}; th_struct producer_1_struct = {.node = node}; - pthread_t producer_th_2 = {0}; + pthread_t producer_th_2 = {0}; th_struct producer_2_struct = {.node = node}; /* Producer/Consumer */ pthread_t producer_consumer_th = {0}; - th_struct prod_cons_struct = {.node = node}; + th_struct prod_cons_struct = {.node = node}; /* Consumer */ - pthread_t consumer_th = {0}; + pthread_t consumer_th = {0}; th_struct consumer_struct = {.node = node}; /* Launch threads */ diff --git a/Framework/Foundation/3rdparty/x9/examples/x9_example_3.c b/Framework/Foundation/3rdparty/x9/examples/x9_example_3.c index c10824e208c3c..19a31146ac426 100644 --- a/Framework/Foundation/3rdparty/x9/examples/x9_example_3.c +++ b/Framework/Foundation/3rdparty/x9/examples/x9_example_3.c @@ -62,27 +62,32 @@ typedef struct { double product; } msg_type_2; -static inline int random_int(int const min, int const max) { +static inline int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static inline double random_double(int const min, int const max) { +static inline double random_double(int const min, int const max) +{ return ((double)(random_int(min, max) * 1.0)); } -static inline void fill_msg_type_1(msg_type_1* const msg) { - msg->a = random_int(0, 10); - msg->b = random_int(0, 10); +static inline void fill_msg_type_1(msg_type_1* const msg) +{ + msg->a = random_int(0, 10); + msg->b = random_int(0, 10); msg->sum = msg->a + msg->b; } -static inline void fill_msg_type_2(msg_type_2* const msg) { - msg->x = random_double(0, 10); - msg->y = random_double(0, 10); +static inline void fill_msg_type_2(msg_type_2* const msg) +{ + msg->x = random_double(0, 10); + msg->y = random_double(0, 10); msg->product = msg->x * msg->y; } -static void* producer_1_fn(void* args) { +static void* producer_1_fn(void* args) +{ th_struct* data = (th_struct*)args; x9_inbox* const write_inbox = x9_select_inbox_from_node(data->node, "ibx_1"); @@ -122,7 +127,8 @@ static void* producer_1_fn(void* args) { return 0; } -static void* producer_2_fn(void* args) { +static void* producer_2_fn(void* args) +{ th_struct* data = (th_struct*)args; x9_inbox* const write_inbox = x9_select_inbox_from_node(data->node, "ibx_2"); @@ -161,16 +167,17 @@ static void* producer_2_fn(void* args) { return 0; } -int main(void) { +int main(void) +{ /* Seed random generator */ srand((uint32_t)time(0)); /* Create inboxes */ x9_inbox* const inbox_msg_type_1 = - x9_create_inbox(4, "ibx_1", sizeof(msg_type_1)); + x9_create_inbox(4, "ibx_1", sizeof(msg_type_1)); x9_inbox* const inbox_msg_type_2 = - x9_create_inbox(4, "ibx_2", sizeof(msg_type_2)); + x9_create_inbox(4, "ibx_2", sizeof(msg_type_2)); /* Using asserts to simplify code for presentation purpose. */ assert(x9_inbox_is_valid(inbox_msg_type_1)); @@ -178,17 +185,17 @@ int main(void) { /* Create node */ x9_node* const node = - x9_create_node("my_node", 2, inbox_msg_type_1, inbox_msg_type_2); + x9_create_node("my_node", 2, inbox_msg_type_1, inbox_msg_type_2); /* Asserts - Same reason as above.*/ assert(x9_node_is_valid(node)); /* Producer 1 (left on diagram) */ - pthread_t producer_1_th = {0}; + pthread_t producer_1_th = {0}; th_struct producer_1_struct = {.node = node}; /* Producer 2 (right on diagram) */ - pthread_t producer_2_th = {0}; + pthread_t producer_2_th = {0}; th_struct producer_2_struct = {.node = node}; /* Launch threads */ diff --git a/Framework/Foundation/3rdparty/x9/examples/x9_example_4.c b/Framework/Foundation/3rdparty/x9/examples/x9_example_4.c index a4a096bebce94..5719d1eeffdda 100644 --- a/Framework/Foundation/3rdparty/x9/examples/x9_example_4.c +++ b/Framework/Foundation/3rdparty/x9/examples/x9_example_4.c @@ -53,7 +53,7 @@ typedef struct { x9_node* node; - char* inbox_to_consume_from; + char* inbox_to_consume_from; } th_struct; typedef struct { @@ -62,17 +62,20 @@ typedef struct { int sum; } msg; -static inline int random_int(int const min, int const max) { +static inline int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static inline void fill_msg_type(msg* const m) { - m->a = random_int(0, 10); - m->b = random_int(0, 10); +static inline void fill_msg_type(msg* const m) +{ + m->a = random_int(0, 10); + m->b = random_int(0, 10); m->sum = m->a + m->b; } -static void* producer_fn(void* args) { +static void* producer_fn(void* args) +{ th_struct* data = (th_struct*)args; msg m = {0}; @@ -83,11 +86,12 @@ static void* producer_fn(void* args) { return 0; } -static void* consumer_fn(void* args) { +static void* consumer_fn(void* args) +{ th_struct* data = (th_struct*)args; x9_inbox* const inbox = - x9_select_inbox_from_node(data->node, data->inbox_to_consume_from); + x9_select_inbox_from_node(data->node, data->inbox_to_consume_from); assert(x9_inbox_is_valid(inbox)); msg m = {0}; @@ -99,7 +103,8 @@ static void* consumer_fn(void* args) { return 0; } -int main(void) { +int main(void) +{ /* Seed random generator */ srand((uint32_t)time(0)); @@ -121,21 +126,21 @@ int main(void) { assert(x9_node_is_valid(node)); /* Producer */ - pthread_t producer_th = {0}; + pthread_t producer_th = {0}; th_struct producer_struct = {.node = node}; /* Consumer 1 */ - pthread_t consumer_1_th = {0}; - th_struct consumer_1_struct = {.node = node, + pthread_t consumer_1_th = {0}; + th_struct consumer_1_struct = {.node = node, .inbox_to_consume_from = "ibx_1"}; /* Consumer 2 */ - pthread_t consumer_2_th = {0}; - th_struct consumer_2_struct = {.node = node, + pthread_t consumer_2_th = {0}; + th_struct consumer_2_struct = {.node = node, .inbox_to_consume_from = "ibx_2"}; /* Consumer 3 */ - pthread_t consumer_3_th = {0}; - th_struct consumer_3_struct = {.node = node, + pthread_t consumer_3_th = {0}; + th_struct consumer_3_struct = {.node = node, .inbox_to_consume_from = "ibx_3"}; /* Launch threads */ diff --git a/Framework/Foundation/3rdparty/x9/examples/x9_example_5.c b/Framework/Foundation/3rdparty/x9/examples/x9_example_5.c index 9f310feed6b90..ce003b60cba72 100644 --- a/Framework/Foundation/3rdparty/x9/examples/x9_example_5.c +++ b/Framework/Foundation/3rdparty/x9/examples/x9_example_5.c @@ -33,12 +33,12 @@ * - Each consumer processes at least one message. */ -#include /* assert */ -#include /* pthread_t, pthread functions */ -#include /* bool */ -#include /* uint64_t */ -#include /* printf */ -#include /* rand, RAND_MAX */ +#include /* assert */ +#include /* pthread_t, pthread functions */ +#include /* bool */ +#include /* uint64_t */ +#include /* printf */ +#include /* rand, RAND_MAX */ #include "../x9.h" @@ -50,40 +50,46 @@ typedef struct { x9_inbox* inbox; - uint64_t msgs_read; + uint64_t msgs_read; } th_struct; typedef struct { - int a; - int b; - int sum; + int a; + int b; + int sum; bool last_message; char pad[3]; } msg; -static inline int random_int(int const min, int const max) { +static inline int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static inline void fill_msg_type(msg* const m) { - m->a = random_int(0, 10); - m->b = random_int(0, 10); +static inline void fill_msg_type(msg* const m) +{ + m->a = random_int(0, 10); + m->b = random_int(0, 10); m->sum = m->a + m->b; } -static void* producer_fn(void* args) { +static void* producer_fn(void* args) +{ th_struct* data = (th_struct*)args; msg m = {0}; for (uint_fast64_t k = 0; k != NUMBER_OF_MESSAGES; ++k) { fill_msg_type(&m); - if (k == (NUMBER_OF_MESSAGES - 1)) { m.last_message = true; } + if (k == (NUMBER_OF_MESSAGES - 1)) { + m.last_message = true; + } x9_write_to_inbox_spin(data->inbox, sizeof(msg), &m); } return 0; } -static void* consumer_fn(void* args) { +static void* consumer_fn(void* args) +{ th_struct* data = (th_struct*)args; msg m = {0}; @@ -91,12 +97,15 @@ static void* consumer_fn(void* args) { if (x9_read_from_shared_inbox(data->inbox, sizeof(msg), &m)) { assert(m.sum == (m.a + m.b)); ++data->msgs_read; - if (m.last_message) { return 0; } + if (m.last_message) { + return 0; + } } } } -int main(void) { +int main(void) +{ /* Seed random generator */ srand((uint32_t)time(0)); @@ -107,23 +116,23 @@ int main(void) { assert(x9_inbox_is_valid(inbox)); /* Producers */ - pthread_t producer_1_th = {0}; + pthread_t producer_1_th = {0}; th_struct producer_1_struct = {.inbox = inbox}; - pthread_t producer_2_th = {0}; + pthread_t producer_2_th = {0}; th_struct producer_2_struct = {.inbox = inbox}; - pthread_t producer_3_th = {0}; + pthread_t producer_3_th = {0}; th_struct producer_3_struct = {.inbox = inbox}; /* Consumers */ - pthread_t consumer_1_th = {0}; + pthread_t consumer_1_th = {0}; th_struct consumer_1_struct = {.inbox = inbox}; - pthread_t consumer_2_th = {0}; + pthread_t consumer_2_th = {0}; th_struct consumer_2_struct = {.inbox = inbox}; - pthread_t consumer_3_th = {0}; + pthread_t consumer_3_th = {0}; th_struct consumer_3_struct = {.inbox = inbox}; /* Launch threads */ diff --git a/Framework/Foundation/3rdparty/x9/examples/x9_example_6.c b/Framework/Foundation/3rdparty/x9/examples/x9_example_6.c index 1faad026e1feb..7049fd93c8425 100644 --- a/Framework/Foundation/3rdparty/x9/examples/x9_example_6.c +++ b/Framework/Foundation/3rdparty/x9/examples/x9_example_6.c @@ -47,42 +47,48 @@ typedef struct { x9_inbox* inbox; - uint64_t msgs_read; + uint64_t msgs_read; } th_struct; typedef struct { - int a; - int b; - int sum; + int a; + int b; + int sum; bool last_message; char pad[3]; } msg; -static inline int random_int(int const min, int const max) { +static inline int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static inline void fill_msg_type(msg* const m) { - m->a = random_int(0, 10); - m->b = random_int(0, 10); +static inline void fill_msg_type(msg* const m) +{ + m->a = random_int(0, 10); + m->b = random_int(0, 10); m->sum = m->a + m->b; } -static void* producer_fn(void* args) { +static void* producer_fn(void* args) +{ th_struct* data = (th_struct*)args; msg m = {0}; for (uint_fast64_t k = 0; k != (NUMBER_OF_MESSAGES); ++k) { fill_msg_type(&m); - if (k == (NUMBER_OF_MESSAGES - 1)) { m.last_message = true; } + if (k == (NUMBER_OF_MESSAGES - 1)) { + m.last_message = true; + } x9_write_to_inbox_spin(data->inbox, sizeof(msg), &m); } return 0; } -static void* consumer_fn(void* args) { +static void* consumer_fn(void* args) +{ th_struct* data = (th_struct*)args; - msg m = {0}; + msg m = {0}; for (;;) { x9_read_from_shared_inbox_spin(data->inbox, sizeof(msg), &m); assert(m.sum == (m.a + m.b)); @@ -107,7 +113,8 @@ static void* consumer_fn(void* args) { } } -int main(void) { +int main(void) +{ /* Seed random generator */ srand((uint32_t)time(0)); @@ -118,14 +125,14 @@ int main(void) { assert(x9_inbox_is_valid(inbox)); /* Producer */ - pthread_t producer_th = {0}; + pthread_t producer_th = {0}; th_struct producer_struct = {.inbox = inbox}; /* Consumers */ - pthread_t consumer_1_th = {0}; + pthread_t consumer_1_th = {0}; th_struct consumer_1_struct = {.inbox = inbox}; - pthread_t consumer_2_th = {0}; + pthread_t consumer_2_th = {0}; th_struct consumer_2_struct = {.inbox = inbox}; /* Launch threads */ @@ -145,9 +152,9 @@ int main(void) { /* Assert that the total number of messages read == NUMBER_OF_MESSAGES or * NUMBER_OF_MESSAGES + 1 */ assert((NUMBER_OF_MESSAGES + 1) == - (consumer_1_struct.msgs_read + consumer_2_struct.msgs_read) || + (consumer_1_struct.msgs_read + consumer_2_struct.msgs_read) || (NUMBER_OF_MESSAGES) == - (consumer_1_struct.msgs_read + consumer_2_struct.msgs_read) + (consumer_1_struct.msgs_read + consumer_2_struct.msgs_read) ); diff --git a/Framework/Foundation/3rdparty/x9/profiling/x9_profiler.c b/Framework/Foundation/3rdparty/x9/profiling/x9_profiler.c index d596dd816791d..1d84fefcb1823 100644 --- a/Framework/Foundation/3rdparty/x9/profiling/x9_profiler.c +++ b/Framework/Foundation/3rdparty/x9/profiling/x9_profiler.c @@ -27,7 +27,8 @@ #include "../x9.h" -typedef enum { HEADER = 1, SEPARATOR } stdout_output; +typedef enum { HEADER = 1, + SEPARATOR } stdout_output; #define ARG(arg_name) (!strcmp(long_options[option_idx].name, arg_name)) @@ -54,54 +55,70 @@ typedef struct { typedef struct { x9_inbox* inbox; - uint64_t msg_sz; - uint64_t n_msgs; - double writer_hit_ratio; - double reader_hit_ratio; + uint64_t msg_sz; + uint64_t n_msgs; + double writer_hit_ratio; + double reader_hit_ratio; } th_struct; typedef struct { uint8_t* a; } msg; -__attribute__((noreturn)) static void abort_test(char const* const msg) { +__attribute__((noreturn)) static void abort_test(char const* const msg) +{ printf("%s\n", msg); abort(); } -static vector* vector_init(uint64_t const sz) { - if ((sz % 2)) { abort_test("ERROR: vector sz must be % 2 == 0"); } +static vector* vector_init(uint64_t const sz) +{ + if ((sz % 2)) { + abort_test("ERROR: vector sz must be % 2 == 0"); + } vector* const v = calloc(1, sizeof(vector)); - if (NULL == v) { abort_test("ERROR: failed to allocate vector."); } + if (NULL == v) { + abort_test("ERROR: failed to allocate vector."); + } v->data = calloc(1, sz * sizeof(*v->data)); - if (NULL == v->data) { abort_test("ERROR: failed to allocate v->data."); } + if (NULL == v->data) { + abort_test("ERROR: failed to allocate v->data."); + } v->size = sz; return v; } -static void vector_insert(vector* const v, int64_t value) { +static void vector_insert(vector* const v, int64_t value) +{ if (v->used == v->size) { v->size *= 2; v->data = realloc(v->data, v->size * sizeof(*v->data)); - if (NULL == v->data) { abort_test("ERROR: realloc failed."); } + if (NULL == v->data) { + abort_test("ERROR: realloc failed."); + } } v->data[v->used++] = value; } -static void vector_free(vector* const v) { +static void vector_free(vector* const v) +{ free(v->data); free(v); } -static int random_int(int const min, int const max) { +static int random_int(int const min, int const max) +{ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } -static void* producer_fn_test_1(void* args) { +static void* producer_fn_test_1(void* args) +{ th_struct* data = (th_struct*)args; msg m = {.a = calloc(data->msg_sz, sizeof(uint8_t))}; - if (NULL == m.a) { abort_test("ERROR: failed to allocate msg buffer"); } + if (NULL == m.a) { + abort_test("ERROR: failed to allocate msg buffer"); + } for (uint64_t k = 0; k != data->n_msgs; ++k) { int32_t const random_val = random_int(1, 9); @@ -112,11 +129,14 @@ static void* producer_fn_test_1(void* args) { return 0; } -static void* consumer_fn_test_1(void* args) { +static void* consumer_fn_test_1(void* args) +{ th_struct* data = (th_struct*)args; msg m = {.a = calloc(data->msg_sz, sizeof(uint8_t))}; - if (NULL == m.a) { abort_test("ERROR: failed to allocate msg buffer"); } + if (NULL == m.a) { + abort_test("ERROR: failed to allocate msg buffer"); + } for (uint64_t k = 0; k != data->n_msgs; ++k) { x9_read_from_inbox_spin(data->inbox, data->msg_sz, m.a); @@ -126,20 +146,27 @@ static void* consumer_fn_test_1(void* args) { return 0; } -static void* producer_fn_test_2(void* args) { +static void* producer_fn_test_2(void* args) +{ th_struct* data = (th_struct*)args; msg m = {.a = calloc(data->msg_sz, sizeof(uint8_t))}; - if (NULL == m.a) { abort_test("ERROR: failed to allocate msg buffer"); } + if (NULL == m.a) { + abort_test("ERROR: failed to allocate msg buffer"); + } uint64_t write_attempts = 0; - uint64_t msgs_written = 0; + uint64_t msgs_written = 0; for (;;) { - if (msgs_written == data->n_msgs) { break; } + if (msgs_written == data->n_msgs) { + break; + } int32_t const random_val = random_int(1, 9); memset(m.a, random_val, data->msg_sz); - if (x9_write_to_inbox(data->inbox, data->msg_sz, m.a)) { ++msgs_written; } + if (x9_write_to_inbox(data->inbox, data->msg_sz, m.a)) { + ++msgs_written; + } ++write_attempts; } @@ -148,17 +175,22 @@ static void* producer_fn_test_2(void* args) { return 0; } -static void* consumer_fn_test_2(void* args) { +static void* consumer_fn_test_2(void* args) +{ th_struct* data = (th_struct*)args; msg m = {.a = calloc(data->msg_sz, sizeof(uint8_t))}; - if (NULL == m.a) { abort_test("ERROR: failed to allocate msg buffer"); } + if (NULL == m.a) { + abort_test("ERROR: failed to allocate msg buffer"); + } uint64_t read_attempts = 0; - uint64_t msgs_read = 0; + uint64_t msgs_read = 0; for (;;) { - if (msgs_read == data->n_msgs) { break; } + if (msgs_read == data->n_msgs) { + break; + } if (x9_read_from_inbox(data->inbox, data->msg_sz, m.a)) { ++msgs_read; assert(m.a[(data->msg_sz - 1)] == (m.a[0])); @@ -178,7 +210,8 @@ static perf_results run_test(uint64_t const ibx_sz, uint64_t const second_core, uint64_t const test -) { +) +{ /* Create inbox */ x9_inbox* const inbox = x9_create_inbox(ibx_sz, "ibx_1", msg_sz); @@ -188,18 +221,18 @@ static perf_results run_test(uint64_t const ibx_sz, } /* Producer */ - pthread_t producer_th = {0}; + pthread_t producer_th = {0}; pthread_attr_t producer_attr = {0}; pthread_attr_init(&producer_attr); th_struct producer_struct = { - .inbox = inbox, .msg_sz = msg_sz, .n_msgs = n_msgs}; + .inbox = inbox, .msg_sz = msg_sz, .n_msgs = n_msgs}; /* Consumer */ - pthread_t consumer_th = {0}; + pthread_t consumer_th = {0}; pthread_attr_t consumer_attr = {0}; pthread_attr_init(&consumer_attr); th_struct consumer_struct = { - .inbox = inbox, .msg_sz = msg_sz, .n_msgs = n_msgs}; + .inbox = inbox, .msg_sz = msg_sz, .n_msgs = n_msgs}; /* Set affinity */ cpu_set_t f_core = {0}; @@ -240,58 +273,64 @@ static perf_results run_test(uint64_t const ibx_sz, clock_gettime(CLOCK_MONOTONIC, &toc); uint64_t const before = - ((uint64_t)tic.tv_sec * 1000000000UL) + (uint64_t)tic.tv_nsec; + ((uint64_t)tic.tv_sec * 1000000000UL) + (uint64_t)tic.tv_nsec; uint64_t const after = - ((uint64_t)toc.tv_sec * 1000000000UL) + (uint64_t)toc.tv_nsec; + ((uint64_t)toc.tv_sec * 1000000000UL) + (uint64_t)toc.tv_nsec; /* Cleanup */ pthread_attr_destroy(&producer_attr); pthread_attr_destroy(&consumer_attr); x9_free_inbox(inbox); - return (perf_results){.time_secs = (double)(after - before) / 1e9, + return (perf_results){.time_secs = (double)(after - before) / 1e9, .writer_hit_ratio = producer_struct.writer_hit_ratio, .reader_hit_ratio = consumer_struct.reader_hit_ratio}; } static void parse_array_arguments(char* restrict const args, - vector* const write_to) { - char* args_start = args; - char const* const args_end = args + strlen(args); + vector* const write_to) +{ + char* args_start = args; + char const* const args_end = args + strlen(args); for (; args_start < args_end;) { char* begin = args_start; - char* end = args_start; + char* end = args_start; for (; end != args_end; ++end) { - if (',' == *end) { break; } + if (',' == *end) { + break; + } } - args_start = end + 1; + args_start = end + 1; int64_t const n = strtoll(begin, &end, 10); vector_insert(write_to, n); } } -static perf_config* parse_command_line_args(int argc, char** argv) { +static perf_config* parse_command_line_args(int argc, char** argv) +{ perf_config* config = calloc(1, sizeof(perf_config)); if (NULL == config) { abort_test("ERROR: failed to allocate 'perf_config'"); } for (;;) { - int option_idx = 0; + int option_idx = 0; static struct option long_options[] = { - {"inboxes_szs", required_argument, 0, 0}, - {"msgs_szs", required_argument, 0, 0}, - {"n_msgs", required_argument, 0, 0}, - {"n_its", required_argument, 0, 0}, - {"run_in_cores", required_argument, 0, 0}, - {"test", required_argument, 0, 0}, - {0, 0, 0, 0} + {"inboxes_szs", required_argument, 0, 0}, + {"msgs_szs", required_argument, 0, 0}, + {"n_msgs", required_argument, 0, 0}, + {"n_its", required_argument, 0, 0}, + {"run_in_cores", required_argument, 0, 0}, + {"test", required_argument, 0, 0}, + {0, 0, 0, 0} }; int const c = getopt_long(argc, argv, "", long_options, &option_idx); - if (-1 == c) { break; } + if (-1 == c) { + break; + } switch (c) { case 0: @@ -302,16 +341,16 @@ static perf_config* parse_command_line_args(int argc, char** argv) { if (!config->inboxes_sizes->data[0]) { abort_test( - "ERROR: test requires at least one value for " - "'--inboxes_sizes'"); + "ERROR: test requires at least one value for " + "'--inboxes_sizes'"); } for (uint64_t k = 0; k != config->inboxes_sizes->used; ++k) { int64_t const n = config->inboxes_sizes->data[k]; if (!((n > 0) && ((n % 2) == 0))) { abort_test( - "ERROR: '--inboxes_sizes' values must be > 0 and % 2 == " - "0"); + "ERROR: '--inboxes_sizes' values must be > 0 and % 2 == " + "0"); } } } @@ -321,8 +360,8 @@ static perf_config* parse_command_line_args(int argc, char** argv) { if (!config->msgs_sizes->data[0]) { abort_test( - "ERROR: test requires at least one value for " - "'--msgs_sizes'"); + "ERROR: test requires at least one value for " + "'--msgs_sizes'"); } for (uint64_t k = 0; k != config->msgs_sizes->used; ++k) { @@ -358,13 +397,17 @@ static perf_config* parse_command_line_args(int argc, char** argv) { if (ARG("n_msgs")) { int64_t const n = atoll(optarg); - if (!(n > 0)) { abort_test("ERROR: '--n_msgs' value must be > 0"); } + if (!(n > 0)) { + abort_test("ERROR: '--n_msgs' value must be > 0"); + } config->n_messages = n; } if (ARG("n_its")) { int64_t const n = atoll(optarg); - if (!(n > 0)) { abort_test("ERROR: '--n_its' value must be > 0"); } + if (!(n > 0)) { + abort_test("ERROR: '--n_its' value must be > 0"); + } config->n_iterations = n; } @@ -386,14 +429,15 @@ static perf_config* parse_command_line_args(int argc, char** argv) { if (1 == config->test) { if (config->run_in_cores->data[0] == config->run_in_cores->data[1]) { abort_test( - "ERROR: for '--test 1' the values of '--run_in_cores' can not be " - "equal because there's no sched_yield())'"); + "ERROR: for '--test 1' the values of '--run_in_cores' can not be " + "equal because there's no sched_yield())'"); } } return config; } -static void free_perf_config(perf_config* config) { +static void free_perf_config(perf_config* config) +{ vector_free(config->inboxes_sizes); vector_free(config->msgs_sizes); vector_free(config->run_in_cores); @@ -401,12 +445,13 @@ static void free_perf_config(perf_config* config) { } static void print_to_stdout(perf_config const* const config, - stdout_output const what_to_print) { - char const* const i_sz = "Inbox size"; - char const* const sep = " | "; - char const* const m_sz = "Msg size"; - char const* const time = "Time (secs)"; - char const* const m_sec = "Msgs/second"; + stdout_output const what_to_print) +{ + char const* const i_sz = "Inbox size"; + char const* const sep = " | "; + char const* const m_sz = "Msg size"; + char const* const time = "Time (secs)"; + char const* const m_sec = "Msgs/second"; char const* const prod_hit = "Writer hit ratio"; char const* const cons_hit = "Reader hit ratio"; @@ -427,25 +472,32 @@ static void print_to_stdout(perf_config const* const config, } } if (1 == config->test) { - for (uint64_t k = 0; k != test_1_sep_len; ++k) { fputs("-", stdout); } + for (uint64_t k = 0; k != test_1_sep_len; ++k) { + fputs("-", stdout); + } } else { - for (uint64_t k = 0; k != test_2_sep_len; ++k) { fputs("-", stdout); } + for (uint64_t k = 0; k != test_2_sep_len; ++k) { + fputs("-", stdout); + } } puts(""); } -static int cmp(const void* a, const void* b) { +static int cmp(const void* a, const void* b) +{ return (*(const double*)a > *(const double*)b) ? 1 : (*(const double*)a < *(const double*)b) ? -1 : 0; } -static double calculate_median(uint64_t const sz, double* const arr) { +static double calculate_median(uint64_t const sz, double* const arr) +{ qsort(arr, sz, sizeof(double), cmp); return ((sz % 2) == 0) ? ((arr[sz / 2 - 1] + arr[sz / 2]) / 2) : arr[sz / 2]; } -int main(int argc, char** argv) { +int main(int argc, char** argv) +{ /* Seed random generator */ srand((uint32_t)time(0)); @@ -459,13 +511,13 @@ int main(int argc, char** argv) { } double* writer_hit_ratio = - calloc((uint64_t)config->n_iterations, sizeof(double)); + calloc((uint64_t)config->n_iterations, sizeof(double)); if (NULL == writer_hit_ratio) { abort_test("ERROR: failed to allocate 'writer_hit_ratio'"); } double* reader_hit_ratio = - calloc((uint64_t)config->n_iterations, sizeof(double)); + calloc((uint64_t)config->n_iterations, sizeof(double)); if (NULL == reader_hit_ratio) { abort_test("ERROR: failed to allocate 'reader_hit_ratio'"); } @@ -476,20 +528,20 @@ int main(int argc, char** argv) { if (config->msgs_sizes->data[j]) { for (uint64_t it = 0; it != (uint64_t)config->n_iterations; ++it) { perf_results results = - run_test((uint64_t)config->inboxes_sizes->data[k], - (uint64_t)config->msgs_sizes->data[j], - (uint64_t)config->n_messages, - (uint64_t)config->run_in_cores->data[0], - (uint64_t)config->run_in_cores->data[1], - (uint64_t)config->test); - - time_secs[it] = results.time_secs; + run_test((uint64_t)config->inboxes_sizes->data[k], + (uint64_t)config->msgs_sizes->data[j], + (uint64_t)config->n_messages, + (uint64_t)config->run_in_cores->data[0], + (uint64_t)config->run_in_cores->data[1], + (uint64_t)config->test); + + time_secs[it] = results.time_secs; writer_hit_ratio[it] = results.writer_hit_ratio; reader_hit_ratio[it] = results.reader_hit_ratio; } double const median_secs = - calculate_median((uint64_t)config->n_iterations, time_secs); + calculate_median((uint64_t)config->n_iterations, time_secs); printf("%10ld | ", config->inboxes_sizes->data[k]); printf("%8ld | ", config->msgs_sizes->data[j]); @@ -500,10 +552,10 @@ int main(int argc, char** argv) { if (2 == config->test) { double const median_writer_hit = calculate_median( - (uint64_t)config->n_iterations, writer_hit_ratio); + (uint64_t)config->n_iterations, writer_hit_ratio); double const median_reader_hit = calculate_median( - (uint64_t)config->n_iterations, reader_hit_ratio); + (uint64_t)config->n_iterations, reader_hit_ratio); printf(" |%*.2f%% | ", 16, median_writer_hit * 100); printf("%*.2f%%", 15, median_reader_hit * 100); diff --git a/Framework/Foundation/3rdparty/x9/x9.c b/Framework/Foundation/3rdparty/x9/x9.c index 2ca4bb80237b3..46e1462df13a5 100644 --- a/Framework/Foundation/3rdparty/x9/x9.c +++ b/Framework/Foundation/3rdparty/x9/x9.c @@ -34,7 +34,7 @@ #include "x9.h" -#include /* assert */ +#include /* assert */ #if defined(__x86_64__) || defined(__i386__) #include /* _mm_pause */ #elif defined(__aarch64__) @@ -50,11 +50,12 @@ #include /* memcpy */ /* CPU cache line size */ -#define X9_CL_SIZE 64 +#define X9_CL_SIZE 64 #define X9_ALIGN_TO_CL() __attribute__((__aligned__(X9_CL_SIZE))) #ifdef X9_DEBUG -static void x9_print_error_msg(char const* const error_msg) { +static void x9_print_error_msg(char const* const error_msg) +{ printf("X9_ERROR: %s\n", error_msg); fflush(stdout); return; @@ -67,52 +68,55 @@ typedef struct { _Atomic(bool) slot_has_data; _Atomic(bool) msg_written; _Atomic(bool) shared; - char const pad[5]; + char const pad[5]; } x9_msg_header; typedef struct x9_inbox_internal { - _Atomic(uint64_t) read_idx X9_ALIGN_TO_CL(); + _Atomic(uint64_t) read_idx X9_ALIGN_TO_CL(); _Atomic(uint64_t) write_idx X9_ALIGN_TO_CL(); - uint64_t sz X9_ALIGN_TO_CL(); - uint64_t msg_sz; - uint64_t constant; - void* msgs; - char* name; - char pad[24]; + uint64_t sz X9_ALIGN_TO_CL(); + uint64_t msg_sz; + uint64_t constant; + void* msgs; + char* name; + char pad[24]; } x9_inbox; typedef struct x9_node_internal { x9_inbox** inboxes; - uint64_t n_inboxes; - char* name; + uint64_t n_inboxes; + char* name; } x9_node; /* --- Internal functions --- */ static inline uint64_t x9_load_idx(x9_inbox* const inbox, - bool const read_idx) { + bool const read_idx) +{ /* From paper: Faster Remainder by Direct Computation, Lemire et al */ register uint64_t const low_bits = - inbox->constant * - (read_idx ? atomic_load_explicit(&inbox->read_idx, __ATOMIC_RELAXED) - : atomic_load_explicit(&inbox->write_idx, __ATOMIC_RELAXED)); + inbox->constant * + (read_idx ? atomic_load_explicit(&inbox->read_idx, __ATOMIC_RELAXED) + : atomic_load_explicit(&inbox->write_idx, __ATOMIC_RELAXED)); return ((__uint128_t)low_bits * inbox->sz) >> 64; } static inline uint64_t x9_increment_idx(x9_inbox* const inbox, - bool const read_idx) { + bool const read_idx) +{ /* From paper: Faster Remainder by Direct Computation, Lemire et al */ register uint64_t const low_bits = - inbox->constant * - (read_idx - ? atomic_fetch_add_explicit(&inbox->read_idx, 1, __ATOMIC_RELAXED) - : atomic_fetch_add_explicit(&inbox->write_idx, 1, - __ATOMIC_RELAXED)); + inbox->constant * + (read_idx + ? atomic_fetch_add_explicit(&inbox->read_idx, 1, __ATOMIC_RELAXED) + : atomic_fetch_add_explicit(&inbox->write_idx, 1, + __ATOMIC_RELAXED)); return ((__uint128_t)low_bits * inbox->sz) >> 64; } static inline void* x9_header_ptr(x9_inbox const* const inbox, - uint64_t const idx) { + uint64_t const idx) +{ return &((char*)inbox->msgs)[idx * (inbox->msg_sz + sizeof(x9_msg_header))]; } @@ -120,26 +124,35 @@ static inline void* x9_header_ptr(x9_inbox const* const inbox, x9_inbox* x9_create_inbox(uint64_t const sz, char const* restrict const name, - uint64_t const msg_sz) { - if (!((sz > 0) && !(sz % 2))) { goto inbox_incorrect_size; } + uint64_t const msg_sz) +{ + if (!((sz > 0) && !(sz % 2))) { + goto inbox_incorrect_size; + } x9_inbox* inbox = aligned_alloc(X9_CL_SIZE, sizeof(x9_inbox)); - if (NULL == inbox) { goto inbox_allocation_failed; } + if (NULL == inbox) { + goto inbox_allocation_failed; + } memset(inbox, 0, sizeof(x9_inbox)); uint64_t const name_len = strlen(name); - char* ibx_name = calloc(name_len + 1, sizeof(char)); - if (NULL == ibx_name) { goto inbox_name_allocation_failed; } + char* ibx_name = calloc(name_len + 1, sizeof(char)); + if (NULL == ibx_name) { + goto inbox_name_allocation_failed; + } memcpy(ibx_name, name, name_len); void* msgs = calloc(sz, msg_sz + sizeof(x9_msg_header)); - if (NULL == msgs) { goto inbox_msgs_allocation_failed; } + if (NULL == msgs) { + goto inbox_msgs_allocation_failed; + } inbox->constant = UINT64_C(0xFFFFFFFFFFFFFFFF) / sz + 1; - inbox->name = ibx_name; - inbox->msgs = msgs; - inbox->sz = sz; - inbox->msg_sz = msg_sz; + inbox->name = ibx_name; + inbox->msgs = msgs; + inbox->sz = sz; + inbox->msg_sz = msg_sz; return inbox; inbox_incorrect_size: @@ -170,25 +183,31 @@ x9_inbox* x9_create_inbox(uint64_t const sz, return NULL; } -bool x9_inbox_is_valid(x9_inbox const* const inbox) { +bool x9_inbox_is_valid(x9_inbox const* const inbox) +{ return !(NULL == inbox); } bool x9_inbox_name_is(x9_inbox const* const inbox, - char const* restrict const cmp) { + char const* restrict const cmp) +{ return !strcmp(inbox->name, cmp) ? true : false; } -void x9_free_inbox(x9_inbox* const inbox) { +void x9_free_inbox(x9_inbox* const inbox) +{ free(inbox->msgs); free(inbox->name); free(inbox); } x9_inbox* x9_select_inbox_from_node(x9_node const* const node, - char const* restrict const name) { + char const* restrict const name) +{ for (uint64_t k = 0; k != node->n_inboxes; ++k) { - if (x9_inbox_name_is(node->inboxes[k], name)) { return node->inboxes[k]; } + if (x9_inbox_name_is(node->inboxes[k], name)) { + return node->inboxes[k]; + } } #ifdef X9_DEBUG x9_print_error_msg("NODE_DOES_NOT_CONTAIN_INBOX"); @@ -198,15 +217,22 @@ x9_inbox* x9_select_inbox_from_node(x9_node const* const node, x9_node* x9_create_node(char* restrict const name, uint64_t const n_inboxes, - ...) { - if (!(n_inboxes > 0)) { goto node_incorrect_definition; } + ...) +{ + if (!(n_inboxes > 0)) { + goto node_incorrect_definition; + } x9_node* node = calloc(1, sizeof(x9_node)); - if (NULL == node) { goto node_allocation_failed; } + if (NULL == node) { + goto node_allocation_failed; + } - uint64_t const name_len = strlen(name); - char* node_name = calloc(name_len + 1, sizeof(char)); - if (NULL == node_name) { goto node_name_allocation_failed; } + uint64_t const name_len = strlen(name); + char* node_name = calloc(name_len + 1, sizeof(char)); + if (NULL == node_name) { + goto node_name_allocation_failed; + } memcpy(node_name, name, name_len); node->name = node_name; @@ -214,8 +240,10 @@ x9_node* x9_create_node(char* restrict const name, va_start(argp, n_inboxes); x9_inbox** inboxes = calloc(n_inboxes, sizeof(x9_inbox)); - if (NULL == inboxes) { goto node_inboxes_allocation_failed; } - node->inboxes = inboxes; + if (NULL == inboxes) { + goto node_inboxes_allocation_failed; + } + node->inboxes = inboxes; node->n_inboxes = n_inboxes; for (uint64_t k = 0; k != n_inboxes; ++k) { @@ -278,17 +306,20 @@ x9_node* x9_create_node(char* restrict const name, bool x9_node_is_valid(x9_node const* const node) { return !(NULL == node); } bool x9_node_name_is(x9_node const* const node, - char const* restrict const cmp) { + char const* restrict const cmp) +{ return !strcmp(node->name, cmp) ? true : false; } -void x9_free_node(x9_node* const node) { +void x9_free_node(x9_node* const node) +{ free(node->name); free(node->inboxes); free(node); } -void x9_free_node_and_attached_inboxes(x9_node* const node) { +void x9_free_node_and_attached_inboxes(x9_node* const node) +{ for (uint64_t k = 0; k != node->n_inboxes; ++k) { if (NULL != node->inboxes[k]) { x9_free_inbox(node->inboxes[k]); @@ -299,10 +330,11 @@ void x9_free_node_and_attached_inboxes(x9_node* const node) { } bool x9_write_to_inbox(x9_inbox* const inbox, - uint64_t const msg_sz, - void const* restrict const msg) { - bool f = false; - register uint64_t const idx = x9_load_idx(inbox, false); + uint64_t const msg_sz, + void const* restrict const msg) +{ + bool f = false; + register uint64_t const idx = x9_load_idx(inbox, false); register x9_msg_header* const header = x9_header_ptr(inbox, idx); if (atomic_compare_exchange_strong_explicit(&header->slot_has_data, &f, true, @@ -317,11 +349,12 @@ bool x9_write_to_inbox(x9_inbox* const inbox, } void x9_write_to_inbox_spin(x9_inbox* const inbox, - uint64_t const msg_sz, - void const* restrict const msg) { + uint64_t const msg_sz, + void const* restrict const msg) +{ for (;;) { - bool f = false; - register uint64_t const idx = x9_increment_idx(inbox, false); + bool f = false; + register uint64_t const idx = x9_increment_idx(inbox, false); register x9_msg_header* const header = x9_header_ptr(inbox, idx); if (atomic_compare_exchange_weak_explicit(&header->slot_has_data, &f, true, __ATOMIC_ACQUIRE, @@ -334,17 +367,19 @@ void x9_write_to_inbox_spin(x9_inbox* const inbox, } void x9_broadcast_msg_to_all_node_inboxes(x9_node const* const node, - uint64_t const msg_sz, - void const* restrict const msg) { + uint64_t const msg_sz, + void const* restrict const msg) +{ for (uint64_t k = 0; k != node->n_inboxes; ++k) { x9_write_to_inbox_spin(node->inboxes[k], msg_sz, msg); } } bool x9_read_from_inbox(x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam) { - register uint64_t const idx = x9_load_idx(inbox, true); + uint64_t const msg_sz, + void* restrict const outparam) +{ + register uint64_t const idx = x9_load_idx(inbox, true); register x9_msg_header* const header = x9_header_ptr(inbox, idx); if (atomic_load_explicit(&header->slot_has_data, __ATOMIC_RELAXED)) { @@ -360,16 +395,17 @@ bool x9_read_from_inbox(x9_inbox* const inbox, } void x9_read_from_inbox_spin(x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam) { - register uint64_t const idx = x9_increment_idx(inbox, true); + uint64_t const msg_sz, + void* restrict const outparam) +{ + register uint64_t const idx = x9_increment_idx(inbox, true); register x9_msg_header* const header = x9_header_ptr(inbox, idx); for (;;) { #if defined(__x86_64__) || defined(__i386__) _mm_pause(); #elif defined(__aarch64__) - __asm__ __volatile__ ("yield"); + __asm__ __volatile__("yield"); #else #error Not supported architecture #endif @@ -385,14 +421,15 @@ void x9_read_from_inbox_spin(x9_inbox* const inbox, } bool x9_read_from_shared_inbox(x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam) { - bool f = false; - register uint64_t const idx = x9_load_idx(inbox, true); + uint64_t const msg_sz, + void* restrict const outparam) +{ + bool f = false; + register uint64_t const idx = x9_load_idx(inbox, true); register x9_msg_header* const header = x9_header_ptr(inbox, idx); if (atomic_compare_exchange_strong_explicit( - &header->shared, &f, true, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + &header->shared, &f, true, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { if (atomic_load_explicit(&header->slot_has_data, __ATOMIC_RELAXED)) { if (atomic_load_explicit(&header->msg_written, __ATOMIC_ACQUIRE)) { memcpy(outparam, (char*)header + sizeof(x9_msg_header), msg_sz); @@ -409,15 +446,16 @@ bool x9_read_from_shared_inbox(x9_inbox* const inbox, } void x9_read_from_shared_inbox_spin(x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam) { + uint64_t const msg_sz, + void* restrict const outparam) +{ for (;;) { - bool f = false; - register uint64_t const idx = x9_increment_idx(inbox, true); + bool f = false; + register uint64_t const idx = x9_increment_idx(inbox, true); register x9_msg_header* const header = x9_header_ptr(inbox, idx); if (atomic_compare_exchange_strong_explicit( - &header->shared, &f, true, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + &header->shared, &f, true, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { if (atomic_load_explicit(&header->slot_has_data, __ATOMIC_RELAXED)) { if (atomic_load_explicit(&header->msg_written, __ATOMIC_ACQUIRE)) { memcpy(outparam, (char*)header + sizeof(x9_msg_header), msg_sz); @@ -432,4 +470,3 @@ void x9_read_from_shared_inbox_spin(x9_inbox* const inbox, } } } - diff --git a/Framework/Foundation/3rdparty/x9/x9.h b/Framework/Foundation/3rdparty/x9/x9.h index 229d7adf7dba0..ce37e5a6b60cf 100644 --- a/Framework/Foundation/3rdparty/x9/x9.h +++ b/Framework/Foundation/3rdparty/x9/x9.h @@ -42,7 +42,7 @@ extern "C" { /* --- Opaque types --- */ -typedef struct x9_node_internal x9_node; +typedef struct x9_node_internal x9_node; typedef struct x9_inbox_internal x9_inbox; /* --- Public API --- */ @@ -56,7 +56,7 @@ typedef struct x9_inbox_internal x9_inbox; * Example: * x9_inbox* inbox = x9_create_inbox(512, "ibx", sizeof());*/ __attribute__((nonnull)) x9_inbox* x9_create_inbox( - uint64_t const sz, char const* restrict const name, uint64_t const msg_sz); + uint64_t const sz, char const* restrict const name, uint64_t const msg_sz); /* Variadic function that creates a 'x9_node', which is an abstraction that * unifies x9_inbox(es). @@ -88,7 +88,7 @@ bool x9_node_is_valid(x9_node const* const node); /* Selects a x9_inbox from a 'node' by its 'name'. * Returns NULL if the 'node' does not contain an x9_inbox with such 'name'.*/ __attribute__((nonnull)) x9_inbox* x9_select_inbox_from_node( - x9_node const* const node, char const* restrict const name); + x9_node const* const node, char const* restrict const name); /* Returns 'true' if the 'inbox' name == 'cmp', 'false' otherwise.*/ __attribute__((nonnull)) bool x9_inbox_name_is(x9_inbox const* const inbox, @@ -108,66 +108,66 @@ __attribute__((nonnull)) void x9_free_node(x9_node* const node); * IMPORTANT: should only be used when the attached x9_inbox(es) are not shared * with other nodes.*/ __attribute__((nonnull)) void x9_free_node_and_attached_inboxes( - x9_node* const node); + x9_node* const node); /* Returns 'true' if a message was read, 'false' otherwise. * If 'true', the message will be written to 'outparam'. * IMPORTANT: Can only be used to read from inboxes where the thread calling * this function is the only thread reading from said 'inbox'.*/ __attribute__((nonnull)) bool x9_read_from_inbox( - x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam); + x9_inbox* const inbox, + uint64_t const msg_sz, + void* restrict const outparam); /* Reads the next unread message in the 'inbox' to 'outparam'. * Uses spinning, that is, it wil not return until it has read a message, and * it will keep checking if a message was written and try to read it. */ __attribute__((nonnull)) void x9_read_from_inbox_spin( - x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam); + x9_inbox* const inbox, + uint64_t const msg_sz, + void* restrict const outparam); /* Returns 'true' if a message was read, 'false' otherwise. * If 'true', the msg contents will be written to the 'outparam'. * Use this function when multiple threads read from the same inbox. */ __attribute__((nonnull)) bool x9_read_from_shared_inbox( - x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam); + x9_inbox* const inbox, + uint64_t const msg_sz, + void* restrict const outparam); /* Reads the next unread message in the 'inbox' to 'outparam'. * Use this function when multiple threads read from the same inbox. * Uses spinning, that is, it wil not return until it has read a message, and * it will keep checking if a message was written and try to read it. */ __attribute__((nonnull)) void x9_read_from_shared_inbox_spin( - x9_inbox* const inbox, - uint64_t const msg_sz, - void* restrict const outparam); + x9_inbox* const inbox, + uint64_t const msg_sz, + void* restrict const outparam); /* Returns 'true' if the message was written to the 'inbox', 'false' * otherwise. */ __attribute__((nonnull)) bool x9_write_to_inbox( - x9_inbox* const inbox, - uint64_t const msg_sz, - void const* restrict const msg); + x9_inbox* const inbox, + uint64_t const msg_sz, + void const* restrict const msg); /* Writes the 'msg' to the 'inbox'. * Uses spinning, that is, it wil not not return until it has written the * 'msg', and it will keep checking if the destination inbox has a free * slot that it can write the 'msg' to. */ __attribute__((nonnull)) void x9_write_to_inbox_spin( - x9_inbox* const inbox, - uint64_t const msg_sz, - void const* restrict const msg); + x9_inbox* const inbox, + uint64_t const msg_sz, + void const* restrict const msg); /* Writes the same 'msg' to all 'node' inboxes. * Calls 'x9_write_to_inbox_spin' in the background. * Users must guarantee that all 'node' inboxes accept messages of the * same type (or at least of the same 'msg_sz') */ __attribute__((nonnull)) void x9_broadcast_msg_to_all_node_inboxes( - x9_node const* const node, - uint64_t const msg_sz, - void const* restrict const msg); + x9_node const* const node, + uint64_t const msg_sz, + void const* restrict const msg); #ifdef __cplusplus }