diff options
Diffstat (limited to 'runtime/io.c')
-rw-r--r-- | runtime/io.c | 95 |
1 files changed, 65 insertions, 30 deletions
diff --git a/runtime/io.c b/runtime/io.c index 0612f563..f5e640e9 100644 --- a/runtime/io.c +++ b/runtime/io.c @@ -1,7 +1,9 @@ -#ifndef _IO_C_ +#ifndef _IO_C_ /* -*- linux-c -*- */ #define _IO_C_ -/* -*- linux-c -*- */ +#include "relay-app.h" +#include "print.c" + /** @file io.c * @brief I/O functions */ @@ -10,6 +12,9 @@ * @{ */ +#define STP_LOG_BUF_LEN 2047 +static char _stp_lbuf[NR_CPUS][STP_LOG_BUF_LEN + 1]; + /** Logs Data. * This function is compatible with printk. In fact it currently * sends all output to vprintk, after sending "STP: ". This allows @@ -22,44 +27,74 @@ * @todo Either deprecate or redefine this as a way to log debug or * status messages, separate from the normal program output. */ -void dlog (const char *fmt, ...) + +void _stp_log (const char *fmt, ...) { - va_list args; - printk("STP: "); - va_start(args, fmt); - vprintk(fmt, args); - va_end(args); + int num; + char *buf = &_stp_lbuf[smp_processor_id()][0]; + va_list args; + va_start(args, fmt); + num = vscnprintf (buf, STP_LOG_BUF_LEN, fmt, args); + va_end(args); + buf[num] = '\0'; + + if (app.logging) + send_reply (STP_REALTIME_DATA, buf, num + 1, stpd_pid); + else + printk("STP: %s", buf); } -/** Prints to the trace buffer. - * This function uses the same formatting as printk. It currently - * writes to the system log. - * - * @param fmt A variable number of args. - * @todo Needs replaced with something much faster that does not - * use the system log. - */ +static void stpd_app_started(void) +{ + printk ("stpd has started.\n"); +} -void _stp_print (const char *fmt, ...) +static void stpd_app_stopped(void) { - va_list args; - va_start(args, fmt); - vprintk(fmt, args); - va_end(args); + printk ("stpd has stopped.\n"); } -/** Prints to the trace buffer. - * This function will write a string to the trace buffer. It currently - * writes to the system log. - * - * @param str String. - * @todo Needs replaced with something much faster that does not - * use the system log. +static void probe_exit(void); + +#include <linux/delay.h> +static int stpd_command (int type, void *data) +{ + if (type == STP_EXIT) { + printk ("STP_EXIT received\n"); + probe_exit(); +#ifndef STP_NETLINK_ONLY + relay_flush(app.chan); + ssleep(2); /* FIXME: time for data to be flushed */ +#endif + send_reply (STP_EXIT, __this_module.name, strlen(__this_module.name) + 1, stpd_pid); + return 1; + } + return 0; +} + +/* + * relay-app callbacks */ +static struct relay_app_callbacks stp_callbacks = +{ + .app_started = stpd_app_started, + .app_stopped = stpd_app_stopped, + .user_command = stpd_command +}; -void _stp_print_str (char *str) +int _stp_netlink_open(void) +{ + if (init_relay_app("stpd", "cpu", &stp_callbacks)) { + printk ("STP: couldn't init relay app\n"); + return -1; + } + return 0; +} + +void _stp_netlink_close (void) { - printk ("%s", str); + send_reply (STP_DONE, NULL, 0, stpd_pid); + close_relay_app(); } /** @} */ |