From b9448c069a6458d7c1f4dca12ebbad7e176f7654 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 14 Feb 2016 23:12:39 +0000 Subject: [PATCH] Make rtio_log() accept variable number of arguments. --- artiq/runtime/ksupport.c | 1 + artiq/runtime/rtio.c | 28 ++++++++++++++++++++-------- artiq/runtime/rtio.h | 4 +++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/artiq/runtime/ksupport.c b/artiq/runtime/ksupport.c index 55adda177..eb2c4fa1c 100644 --- a/artiq/runtime/ksupport.c +++ b/artiq/runtime/ksupport.c @@ -103,6 +103,7 @@ static const struct symbol runtime_exports[] = { {"watchdog_clear", &watchdog_clear}, {"core_log", &core_log}, + {"rtio_log", &rtio_log}, {"send_rpc", &send_rpc}, {"recv_rpc", &recv_rpc}, diff --git a/artiq/runtime/rtio.c b/artiq/runtime/rtio.c index 2e619a984..76514d19a 100644 --- a/artiq/runtime/rtio.c +++ b/artiq/runtime/rtio.c @@ -39,25 +39,28 @@ void rtio_process_exceptional_status(int status, long long int timestamp, int ch } } -void rtio_log(long long int timestamp, char *message) +void rtio_log_va(long long int timestamp, const char *fmt, va_list args) { - unsigned int word; - int i; + // This executes on the kernel CPU's stack, which is specifically designed + // for allocation of this kind of massive buffers. + int len = vsnprintf(NULL, 0, fmt, args); + char *buf = __builtin_alloca(len + 1); + vsnprintf(buf, len + 1, fmt, args); rtio_chan_sel_write(CONFIG_RTIO_LOG_CHANNEL); rtio_o_timestamp_write(timestamp); - i = 0; - word = 0; + int i = 0; + unsigned int word = 0; while(1) { word <<= 8; - word |= *message & 0xff; - if(*message == 0) { + word |= *buf & 0xff; + if(*buf == 0) { rtio_o_data_write(word); rtio_o_we_write(1); break; } - message++; + buf++; i++; if(i == 4) { rtio_o_data_write(word); @@ -67,3 +70,12 @@ void rtio_log(long long int timestamp, char *message) } } } + +void rtio_log(long long int timestamp, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + rtio_log_va(timestamp, fmt, args); + va_end(args); +} diff --git a/artiq/runtime/rtio.h b/artiq/runtime/rtio.h index d8273f3f2..87d8a9f37 100644 --- a/artiq/runtime/rtio.h +++ b/artiq/runtime/rtio.h @@ -1,6 +1,7 @@ #ifndef __RTIO_H #define __RTIO_H +#include #include #include "artiq_personality.h" @@ -14,7 +15,8 @@ void rtio_init(void); long long int rtio_get_counter(void); void rtio_process_exceptional_status(int status, long long int timestamp, int channel); -void rtio_log(long long int timestamp, char *message); +void rtio_log(long long int timestamp, const char *format, ...); +void rtio_log_va(long long int timestamp, const char *format, va_list args); static inline void rtio_write_and_process_status(long long int timestamp, int channel) {