vx_serial runtime API

This commit is contained in:
Blaise Tine
2021-06-28 05:43:36 -04:00
parent 342c07f8d6
commit 47d317f17a
6 changed files with 163 additions and 46 deletions

View File

@@ -1,4 +1,5 @@
#include <vx_print.h>
#include <vx_spawn.h>
#include <vx_intrinsics.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -8,45 +9,32 @@
extern "C" {
#endif
int __attribute__((noinline)) __vprintf(int index, int tid, const char* format, va_list va) {
__if (index == tid) {
return vprintf(format, va);
}__endif
return 0;
struct printf_arg_t {
const char* format;
va_list va;
int ret;
};
static void __printf_callback(int task_id, void* arg) {
struct printf_arg_t* p_arg = (struct printf_arg_t*)(arg);
p_arg->ret = vprintf(p_arg->format, p_arg->va);
}
int vx_vprintf(const char* format, va_list va) {
int ret = 0;
// need to execute single-threaded due to potential thread-data dependency
// use manual goto loop to disable compiler optimizations affceting split/join placement
volatile int nt = vx_num_threads();
int tid = vx_thread_id();
for (int i = 0; i < nt; ++i) {
ret |= __vprintf(i, tid, format, va);
}
return ret;
// need to execute 'vprintf' single-threaded due to potential thread-data dependency
struct printf_arg_t arg;
arg.format = format;
arg.va = va;
vx_serial(__printf_callback, &arg);
return arg.ret;
}
int vx_printf(const char * format, ...) {
int ret = 0;
// need to execute single-threaded due to potential thread-data dependency
// use manual goto loop to disable compiler optimizations affceting split/join placement
volatile int nt = vx_num_threads();
int tid = vx_thread_id();
int ret;
va_list va;
va_start(va, format);
for (int i = 0; i < nt; ++i) {
ret |= __vprintf(i, tid, format, va);
}
va_end(va);
ret = vx_vprintf(format, va);
va_end(va);
return ret;
}