diff options
author | Chris Johns <chrisj@rtems.org> | 2016-05-20 18:39:50 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2016-05-25 15:47:34 +1000 |
commit | 24d0ee57a4d95f99be6e7e60bd162a30daf0638d (patch) | |
tree | 94239c8cc6b21813ca44b6ca89da73f9038914cc /cpukit | |
parent | psxtests/psxmsgq01: Fix typo (diff) | |
download | rtems-24d0ee57a4d95f99be6e7e60bd162a30daf0638d.tar.bz2 |
cpukit, testsuite: Add rtems_printf and rtems_printer support.
This change adds rtems_printf and related functions and wraps the
RTEMS print plugin support into a user API. All references to the
plugin are removed and replaced with the rtems_printer interface.
Printk and related functions are made to return a valid number of
characters formatted and output.
The function attribute to check printf functions has been added
to rtems_printf and printk. No changes to remove warrnings are part
of this patch set.
The testsuite has been moved over to the rtems_printer. The testsuite
has a mix of rtems_printer access and direct print control via the
tmacros.h header file. The support for begink/endk has been removed
as it served no purpose and only confused the code base. The testsuite
has not been refactored to use rtems_printf. This is future work.
Diffstat (limited to 'cpukit')
36 files changed, 565 insertions, 402 deletions
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index c84ccc3073..aa1111e99b 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -97,6 +97,7 @@ include_rtems_rtl_HEADERS += libdl/rap.h libdl/rap-shell.h endif include_rtems_HEADERS += include/rtems/bspIo.h +include_rtems_HEADERS += include/rtems/print.h include_rtems_HEADERS += include/rtems/userenv.h include_rtems_HEADERS += include/rtems/fs.h if !LIBPCI diff --git a/cpukit/include/rtems/bspIo.h b/cpukit/include/rtems/bspIo.h index dde8d942e8..403b857e43 100644 --- a/cpukit/include/rtems/bspIo.h +++ b/cpukit/include/rtems/bspIo.h @@ -37,6 +37,15 @@ extern "C" { */ /** + * Print format function attribute for warning checks. Can be defined if + * checking needs to be disabled. + */ +#ifndef RTEMS_PRINTF_ATTRIBUTE +#define RTEMS_PRINTF_ATTRIBUTE(_format_pos, _ap_pos) \ + __attribute__((format(__printf__, _format_pos, _ap_pos))) +#endif + +/** * This type defines the prototype for the BSP provided method to * print a single character. It is assumed to be polled. */ @@ -84,8 +93,10 @@ extern int getchark(void); * * @param[in] fmt is a printf()-style format string * @param[in] ap is a va_list pointer to arguments + * + * @return The number of characters output. */ -extern void vprintk(const char *fmt, va_list ap); +extern int vprintk(const char *fmt, va_list ap); /** * @brief Kernel Print @@ -93,8 +104,10 @@ extern void vprintk(const char *fmt, va_list ap); * This method allows the user to perform a debug printk(). * * @param[in] fmt is a printf()-style format string + * + * @return The number of characters output. */ -extern void printk(const char *fmt, ...); +extern int printk(const char *fmt, ...) RTEMS_PRINTF_ATTRIBUTE(1, 2); /** * @brief Kernel Put String @@ -102,8 +115,10 @@ extern void printk(const char *fmt, ...); * This method allows the user to perform a debug puts(). * * @param[in] s is the string to print + * + * @return The number of characters output. */ -extern void putk(const char *s); +extern int putk(const char *s); /** * @brief Kernel Put Character @@ -118,15 +133,13 @@ extern void rtems_putc(char c); * Type definition for function which can be plugged in to * certain reporting routines to redirect the output. * - * Methods following this prototype may be passed into RTEMS reporting - * functions that allow their output to be redirected. In particular, - * the cpu usage, period usage, and stack usage reporting - * functions use this. + * Use the RTEMS Print interface to call these functions. Do not + * directly use them. * * If the user provides their own "printf plugin", then they may * redirect those reports as they see fit. */ -typedef int (*rtems_printk_plugin_t)(void *, const char *format, ...); +typedef int (*rtems_print_plugin_t)(void *, const char *format, va_list ap); /** * @brief Reporting Methods printk() Plugin @@ -136,7 +149,7 @@ typedef int (*rtems_printk_plugin_t)(void *, const char *format, ...); * * @return The number of characters printed. */ -extern int printk_plugin(void *context, const char *fmt, ...); +extern int printk_plugin(void *context, const char *fmt, va_list ap); /** * @brief Reporting Methods printf() Plugin @@ -149,7 +162,7 @@ extern int printk_plugin(void *context, const char *fmt, ...); * * @return The number of characters printed. */ -extern int rtems_printf_plugin(void *context, const char *fmt, ...); +extern int rtems_printf_plugin(void *context, const char *fmt, va_list ap); /**@}*/ diff --git a/cpukit/include/rtems/print.h b/cpukit/include/rtems/print.h new file mode 100644 index 0000000000..5268e8c744 --- /dev/null +++ b/cpukit/include/rtems/print.h @@ -0,0 +1,134 @@ +/** + * @file rtems/print.h + * + * @brief User print interface to the bspIO print plug in. + * + * This include file defines the user interface to kernel print methods. + */ + +/* + * Copyright (c) 2016 Chris Johns <chrisj@rtems.org> + * All rights reserved. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef _RTEMS_PRINT_H +#define _RTEMS_PRINT_H + +#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> + +#include <rtems/bspIo.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup RTEMS Print Support + * + * This module contains all methods and support related to providing the user + * with an interface to the kernel level print support. + */ + +/** + * Type definition for the printer structure used to access the kernel print + * support. + */ +typedef struct { + void *context; + rtems_print_plugin_t printer; +}rtems_printer; + +/** + * @brief check if the printer is valid. + * + * @param[in] printer Pointer to the printer structure. + * + * @return true The printer is valid else false is returned. + */ +static inline bool rtems_print_printer_valid(const rtems_printer *printer) +{ + return printer != NULL && printer->printer != NULL; +} + +/** + * @brief Print to the kernel plugin handler. This has to be a macro because + * there is no vprint version of the plug in handlers. + * + * @param[in] printer Pointer to the printer structure. + * @param[in] fmt Print format string. + * @param[in] ... Print variable argument list. + * + * @return int Number of characters printed. + */ +extern int rtems_printf(const rtems_printer *printer, + const char *format, + ...) RTEMS_PRINTF_ATTRIBUTE(2, 3); + +/** + * @brief Print to the kernel plugin handler. This has to be a macro because + * there is no vprint version of the plug in handlers. + * + * @param[in] printer Pointer to the printer structure. + * @param[in] fmt Print format string. + * @param[in] ap Print variable argument list pointer. + * + * @return int Number of characters printed. + */ +extern int rtems_vprintf(const rtems_printer *printer, + const char *format, + va_list ap); + +/** + * @brief Intiialise the rtems_printer struct to empty. + * + * An empty printer prints nothing. You can use this to implement an enable and + * disable type print implementation. + * + * @param[in] printer Pointer to the printer structure. + */ +static inline void rtems_print_printer_empty(rtems_printer *printer) +{ + printer->context = NULL; + printer->printer = NULL; +} + +/** + * @brief Intiialise the rtems_printer struct to printk + * + * The printer will output to the kernel printk support. + * + * @param[in] printer Pointer to the printer structure. + */ +void rtems_print_printer_printk(rtems_printer *printer); + +/** + * @brief Intiialise the rtems_printer struct to printf + * + * The printer will output to the libc printf support. + * + * @param[in] printer Pointer to the printer structure. + */ +extern void rtems_print_printer_printf(rtems_printer *printer); + +/** + * @brief Intiialise the rtems_printer struct to a fprintf device. + * + * The printer will output to the libc fprintf file provided. + * + * @param[in] printer Pointer to the printer structure. + */ +extern void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cpukit/libblock/include/rtems/blkdev.h b/cpukit/libblock/include/rtems/blkdev.h index 81e2dfa0da..99f857379b 100644 --- a/cpukit/libblock/include/rtems/blkdev.h +++ b/cpukit/libblock/include/rtems/blkdev.h @@ -16,7 +16,7 @@ #include <rtems.h> #include <rtems/diskdevs.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> #include <sys/ioctl.h> #include <stdio.h> @@ -348,15 +348,14 @@ void rtems_blkdev_print_stats( uint32_t media_block_size, uint32_t media_block_count, uint32_t block_size, - rtems_printk_plugin_t print, - void *print_arg + const rtems_printer* printer ); /** * @brief Block device statistics command. */ void rtems_blkstats( - FILE *output, + const rtems_printer *printer, const char *device, bool reset ); diff --git a/cpukit/libblock/src/blkdev-blkstats.c b/cpukit/libblock/src/blkdev-blkstats.c index 1e773cf8c2..ca1e0e4b9c 100644 --- a/cpukit/libblock/src/blkdev-blkstats.c +++ b/cpukit/libblock/src/blkdev-blkstats.c @@ -31,7 +31,7 @@ #include <errno.h> #include <string.h> -void rtems_blkstats(FILE *output, const char *device, bool reset) +void rtems_blkstats(const rtems_printer* printer, const char *device, bool reset) { int fd = open(device, O_RDONLY); @@ -45,7 +45,7 @@ void rtems_blkstats(FILE *output, const char *device, bool reset) if (reset) { rv = rtems_disk_fd_reset_device_stats(fd); if (rv != 0) { - fprintf(output, "error: reset stats: %s\n", strerror(errno)); + rtems_printf(printer, "error: reset stats: %s\n", strerror(errno)); } } else { uint32_t media_block_size = 0; @@ -64,25 +64,24 @@ void rtems_blkstats(FILE *output, const char *device, bool reset) media_block_size, media_block_count, block_size, - (rtems_printk_plugin_t) fprintf, - output + printer ); } else { - fprintf(output, "error: get stats: %s\n", strerror(errno)); + rtems_printf(printer, "error: get stats: %s\n", strerror(errno)); } } } else { - fprintf(output, "error: not a block device\n"); + rtems_printf(printer, "error: not a block device\n"); } } else { - fprintf(output, "error: get file stats: %s\n", strerror(errno)); + rtems_printf(printer, "error: get file stats: %s\n", strerror(errno)); } rv = close(fd); if (rv != 0) { - fprintf(output, "error: close device: %s\n", strerror(errno)); + rtems_printf(printer, "error: close device: %s\n", strerror(errno)); } } else { - fprintf(output, "error: open device: %s\n", strerror(errno)); + rtems_printf(printer, "error: open device: %s\n", strerror(errno)); } } diff --git a/cpukit/libblock/src/blkdev-print-stats.c b/cpukit/libblock/src/blkdev-print-stats.c index edeee906fa..aba2173b42 100644 --- a/cpukit/libblock/src/blkdev-print-stats.c +++ b/cpukit/libblock/src/blkdev-print-stats.c @@ -32,12 +32,11 @@ void rtems_blkdev_print_stats( uint32_t media_block_size, uint32_t media_block_count, uint32_t block_size, - rtems_printk_plugin_t print, - void *print_arg + const rtems_printer* printer ) { - (*print)( - print_arg, + rtems_printf( + printer, "-------------------------------------------------------------------------------\n" " DEVICE STATISTICS\n" "----------------------+--------------------------------------------------------\n" diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index b3ad3db4e1..f047cfc40f 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -112,6 +112,8 @@ BSD_LIBC_C_FILES = src/strlcpy.c src/strlcat.c src/issetugid.c libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \ src/printk_plugin.c src/putk.c src/vprintk.c \ src/rtems_putc.c \ + src/print_fprintf.c \ + src/print_printf.c \ src/printf_plugin.c \ src/sup_fs_location.c \ src/sup_fs_eval_path.c \ diff --git a/cpukit/libcsupport/src/print_fprintf.c b/cpukit/libcsupport/src/print_fprintf.c new file mode 100644 index 0000000000..5e46d1c959 --- /dev/null +++ b/cpukit/libcsupport/src/print_fprintf.c @@ -0,0 +1,29 @@ +/** + * @file + * + * @brief RTEMS Print Support + * @ingroup libcsupport + */ + +/* + * Copyright (c) 2016 Chris Johns <chrisj@rtems.org> + * All rights reserved. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include <rtems/print.h> + +#include <stdio.h> + +void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file) +{ + printer->context = file; + printer->printer = (rtems_print_plugin_t) fprintf; +} diff --git a/cpukit/libcsupport/src/print_printf.c b/cpukit/libcsupport/src/print_printf.c new file mode 100644 index 0000000000..c8695234c0 --- /dev/null +++ b/cpukit/libcsupport/src/print_printf.c @@ -0,0 +1,52 @@ +/** + * @file + * + * @brief RTEMS Print Support + * @ingroup libcsupport + */ + +/* + * Copyright (c) 2016 Chris Johns <chrisj@rtems.org> + * All rights reserved. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include <rtems/print.h> + +#include <stdio.h> + +int rtems_vprintf( + const rtems_printer *printer, + const char *format, + va_list ap +) +{ + int len = 0; + if ( rtems_print_printer_valid( printer ) ) { + len = printer->printer( printer->context, format, ap ); + } + return len; +} + +int rtems_printf( + const rtems_printer *printer, + const char *format, + ... +) +{ + int len = 0; + if ( rtems_print_printer_valid( printer ) ) { + va_list ap; + va_start( ap, format ); + len = printer->printer( printer->context, format, ap ); + va_end( ap ); + } + return len; +} diff --git a/cpukit/libcsupport/src/printf_plugin.c b/cpukit/libcsupport/src/printf_plugin.c index ab4f4a44a2..097e4126b5 100644 --- a/cpukit/libcsupport/src/printf_plugin.c +++ b/cpukit/libcsupport/src/printf_plugin.c @@ -23,18 +23,18 @@ #include "config.h" #endif -#include <rtems/bspIo.h> +#include <rtems/print.h> #include <stdio.h> -int rtems_printf_plugin(void *context, const char *format, ...) +void rtems_print_printer_printf(rtems_printer *printer) { - int rv; - va_list ap; - - va_start(ap, format); - rv = vprintf(format, ap); - va_end(ap); + printer->context = NULL; + printer->printer = rtems_printf_plugin; +} - return rv; +int rtems_printf_plugin(void *context, const char *format, va_list ap) +{ + (void) context; + return vprintf(format, ap); } diff --git a/cpukit/libcsupport/src/printk.c b/cpukit/libcsupport/src/printk.c index badbd0d591..88cd22aab0 100644 --- a/cpukit/libcsupport/src/printk.c +++ b/cpukit/libcsupport/src/printk.c @@ -32,11 +32,12 @@ /** * Kernel printf function requiring minimal infrastructure. */ -void printk(const char *fmt, ...) +int printk(const char *fmt, ...) { - va_list ap; /* points to each unnamed argument in turn */ - + va_list ap; /* points to each unnamed argument in turn */ + int len; va_start(ap, fmt); /* make ap point to 1st unnamed arg */ - vprintk(fmt, ap); + len = vprintk(fmt, ap); va_end(ap); /* clean up when done */ + return len; } diff --git a/cpukit/libcsupport/src/printk_plugin.c b/cpukit/libcsupport/src/printk_plugin.c index b600378d0a..3ecacb8a28 100644 --- a/cpukit/libcsupport/src/printk_plugin.c +++ b/cpukit/libcsupport/src/printk_plugin.c @@ -19,23 +19,23 @@ #endif #include <stdarg.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> + +void rtems_print_printer_printk( + rtems_printer *printer +) +{ + printer->context = NULL; + printer->printer = printk_plugin; +} int printk_plugin( void *ignored, const char *format, - ... + va_list ap ) { - va_list arg_pointer; - (void) ignored; - - va_start (arg_pointer, format); - - vprintk( format, arg_pointer ); - - va_end(arg_pointer); /* clean up when done */ - + vprintk( format, ap ); return 0; } diff --git a/cpukit/libcsupport/src/putk.c b/cpukit/libcsupport/src/putk.c index 2532a64500..76fa8b0040 100644 --- a/cpukit/libcsupport/src/putk.c +++ b/cpukit/libcsupport/src/putk.c @@ -1,7 +1,7 @@ /** * @file * - * @brief Write Character to Stream + * @brief Write Character to Stream * @ingroup libcsupport */ @@ -23,11 +23,13 @@ /** * Kernel putk (e.g. puts) function requiring minimal infrastrure. */ -void putk(const char *s) +int putk(const char *s) { const char *p; + int len_out = 0; - for (p=s ; *p ; p++ ) + for (p=s ; *p ; p++, len_out++ ) BSP_output_char(*p); BSP_output_char('\n'); + return len_out + 1; } diff --git a/cpukit/libcsupport/src/vprintk.c b/cpukit/libcsupport/src/vprintk.c index 51e4947e43..a254934a0d 100644 --- a/cpukit/libcsupport/src/vprintk.c +++ b/cpukit/libcsupport/src/vprintk.c @@ -30,7 +30,7 @@ #include <stdbool.h> #include <rtems/bspIo.h> -static void printNum( +static int printNum( long long num, unsigned base, bool sign, @@ -45,11 +45,12 @@ static void printNum( * Arguments: * as in printf: fmt - format string, ... - unnamed arguments. */ -void vprintk( +int vprintk( const char *fmt, va_list ap ) { + int len_out = 0; for (; *fmt != '\0'; fmt++) { unsigned base = 0; unsigned width = 0; @@ -66,6 +67,7 @@ void vprintk( if (c != '%') { rtems_putc(c); + ++len_out; continue; } @@ -101,6 +103,7 @@ void vprintk( /* need a cast here since va_arg() only takes fully promoted types */ char chr = (char) va_arg(ap, int); rtems_putc(chr); + ++len_out; continue; } @@ -120,7 +123,7 @@ void vprintk( /* leading spaces */ if ( !minus ) - for ( i=len ; i<width ; i++ ) + for ( i=len ; i<width ; i++, len_out++ ) rtems_putc(' '); /* no width option */ @@ -129,12 +132,12 @@ void vprintk( } /* output the string */ - for ( i=0 ; i<width && *str ; str++ ) + for ( i=0 ; i<width && *str ; str++, len_out++ ) rtems_putc(*str); /* trailing spaces */ if ( minus ) - for ( i=len ; i<width ; i++ ) + for ( i=len ; i<width ; i++, len_out++ ) rtems_putc(' '); continue; @@ -154,6 +157,7 @@ void vprintk( base = 16; sign = false; lflag = LFLAG_LONG; } else { rtems_putc(c); + ++len_out; continue; } @@ -172,8 +176,10 @@ void vprintk( break; } - printNum(num, base, sign, width, lead); + len_out += printNum(num, base, sign, width, lead); } + + return len_out; } /** @@ -181,7 +187,7 @@ void vprintk( * @param[in] num is the number to print * @param[in] base is the base used to print the number */ -static void printNum( +static int printNum( long long num, unsigned base, bool sign, @@ -194,9 +200,11 @@ static void printNum( unsigned count; #define UINT64_MAX_IN_OCTAL_FORMAT "1777777777777777777777" char toPrint[sizeof(UINT64_MAX_IN_OCTAL_FORMAT)]; + int len_out = 0; if ( sign && (num < 0) ) { rtems_putc('-'); + ++len_out; unsigned_num = (unsigned long long) -num; if (maxwidth) maxwidth--; } else { @@ -210,10 +218,12 @@ static void printNum( } toPrint[count++] = (char) unsigned_num; - for (n=maxwidth ; n > count; n-- ) + for (n=maxwidth ; n > count; n--, len_out++ ) rtems_putc(lead); - for (n = 0; n < count; n++) { + for (n = 0; n < count; n++, len_out++) { rtems_putc("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]); } + + return len_out; } diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c index 95d06480d6..5200352f96 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereport.c +++ b/cpukit/libmisc/cpuuse/cpuusagereport.c @@ -34,8 +34,7 @@ * rtems_cpu_usage_report */ void rtems_cpu_usage_report_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ) { uint32_t i; @@ -44,11 +43,8 @@ void rtems_cpu_usage_report_with_plugin( Objects_Information *information; char name[13]; uint32_t ival, fval; - Timestamp_Control uptime, total, used, uptime_at_last_reset; - uint32_t seconds, nanoseconds; - - if ( !print ) - return; + Timestamp_Control uptime, total, used, uptime_at_last_reset; + uint32_t seconds, nanoseconds; /* * When not using nanosecond CPU usage resolution, we have to count @@ -58,8 +54,8 @@ void rtems_cpu_usage_report_with_plugin( _Timestamp_Set_to_zero( &total ); uptime_at_last_reset = CPU_usage_Uptime_at_last_reset; - (*print)( - context, + rtems_printf( + printer, "-------------------------------------------------------------------------------\n" " CPU USAGE BY THREAD\n" "------------+----------------------------------------+---------------+---------\n" @@ -83,8 +79,8 @@ void rtems_cpu_usage_report_with_plugin( rtems_object_get_name( the_thread->Object.id, sizeof(name), name ); - (*print)( - context, + rtems_printf( + printer, " 0x%08" PRIx32 " | %-38s |", the_thread->Object.id, name @@ -102,7 +98,7 @@ void rtems_cpu_usage_report_with_plugin( seconds = _Timestamp_Get_seconds( &used ); nanoseconds = _Timestamp_Get_nanoseconds( &used ) / TOD_NANOSECONDS_PER_MICROSECOND; - (*print)( context, + rtems_printf( printer, "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n", seconds, nanoseconds, ival, fval @@ -114,8 +110,8 @@ void rtems_cpu_usage_report_with_plugin( seconds = _Timestamp_Get_seconds( &total ); nanoseconds = _Timestamp_Get_nanoseconds( &total ) / TOD_NANOSECONDS_PER_MICROSECOND; - (*print)( - context, + rtems_printf( + printer, "------------+----------------------------------------+---------------+---------\n" " TIME SINCE LAST CPU USAGE RESET IN SECONDS: %7" PRIu32 ".%06" PRIu32 "\n" "-------------------------------------------------------------------------------\n", @@ -125,5 +121,7 @@ void rtems_cpu_usage_report_with_plugin( void rtems_cpu_usage_report( void ) { - rtems_cpu_usage_report_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk( &printer ); + rtems_cpu_usage_report_with_plugin( &printer ); } diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c index cf896e3782..2f48eb8f63 100644 --- a/cpukit/libmisc/cpuuse/cpuusagetop.c +++ b/cpukit/libmisc/cpuuse/cpuusagetop.c @@ -41,15 +41,6 @@ #include <rtems/score/wkspace.h> /* - * Common variable to sync the load monitor task. - */ -typedef struct -{ - void* context; - rtems_printk_plugin_t print; -} rtems_cpu_usage_plugin; - -/* * Use a struct for all data to allow more than one top and to support the * thread iterator. */ @@ -61,7 +52,7 @@ typedef struct volatile uint32_t sort_order; volatile uint32_t poll_rate_usecs; volatile uint32_t show; - rtems_cpu_usage_plugin plugin; + const rtems_printer* printer; Timestamp_Control zero; Timestamp_Control uptime; Timestamp_Control last_uptime; @@ -144,27 +135,19 @@ static inline bool less_than_uint32_t( uint32_t * lhs, uint32_t * rhs ) return false; } -#define CPU_usage_Equal_to( _lhs, _rhs ) \ - _Timestamp_Equal_to( _lhs, _rhs ) - -#define CPU_usage_Set_to_zero( _time ) \ - _Timestamp_Set_to_zero( _time ) - -#define CPU_usage_Less_than( _lhs, _rhs ) \ - _Timestamp_Less_than( _lhs, _rhs ) +#define CPU_usage_Equal_to( _lhs, _rhs ) _Timestamp_Equal_to( _lhs, _rhs ) +#define CPU_usage_Set_to_zero( _time ) _Timestamp_Set_to_zero( _time ) +#define CPU_usage_Less_than( _lhs, _rhs ) _Timestamp_Less_than( _lhs, _rhs ) static void print_memsize(rtems_cpu_usage_data* data, const uint32_t size, const char* label) { if (size > (1024 * 1024)) - (*data->plugin.print)(data->plugin.context, "%4" PRIu32 "M %s", - size / (1024 * 1024), label); + rtems_printf(data->printer, "%4" PRIu32 "M %s", size / (1024 * 1024), label); else if (size > 1024) - (*data->plugin.print)(data->plugin.context, "%4" PRIu32 "K %s", - size / 1024, label); + rtems_printf(data->printer, "%4" PRIu32 "K %s", size / 1024, label); else - (*data->plugin.print)(data->plugin.context, "%4" PRIu32 " %s", - size, label); + rtems_printf(data->printer, "%4" PRIu32 " %s", size, label); } static int @@ -184,19 +167,19 @@ print_time(rtems_cpu_usage_data* data, uint32_t hours = mins / 60; if (hours > 24) { - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 "d", hours / 24); + len += rtems_printf(data->printer, "%" PRIu32 "d", hours / 24); hours %= 24; } - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 "hr", hours); + len += rtems_printf(data->printer, "%" PRIu32 "hr", hours); mins %= 60; } - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 "m", mins); + len += rtems_printf(data->printer, "%" PRIu32 "m", mins); secs %= 60; } - len += (*data->plugin.print)(data->plugin.context, "%" PRIu32 ".%06" PRIu32, secs, usecs); + len += rtems_printf(data->printer, "%" PRIu32 ".%06" PRIu32, secs, usecs); if (len < length) - (*data->plugin.print)(data->plugin.context, "%*c", length - len, ' '); + rtems_printf(data->printer, "%*c", length - len, ' '); return len; } @@ -344,7 +327,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) data->current_usage = realloc(data->current_usage, usage_size); if ((data->tasks == NULL) || (data->usage == NULL) || (data->current_usage == NULL)) { - (*data->plugin.print)(data->plugin.context, "top worker: error: no memory\n"); + rtems_printf(data->printer, "top worker: error: no memory\n"); data->thread_run = false; break; } @@ -371,7 +354,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) data->last_usage = realloc(data->last_usage, usage_size); if ((data->last_tasks == NULL) || (data->last_usage == NULL)) { - (*data->plugin.print)(data->plugin.context, "top worker: error: no memory\n"); + rtems_printf(data->printer, "top worker: error: no memory\n"); data->thread_run = false; break; } @@ -396,43 +379,43 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) _Protected_heap_Get_information(&_Workspace_Area, &wksp); if (data->single_page) - (*data->plugin.print)(data->plugin.context, - "\x1b[H\x1b[J" - " ENTER:Exit SPACE:Refresh" - " S:Scroll A:All <>:Order +/-:Lines\n"); - (*data->plugin.print)(data->plugin.context,"\n"); + rtems_printf(data->printer, + "\x1b[H\x1b[J" + " ENTER:Exit SPACE:Refresh" + " S:Scroll A:All <>:Order +/-:Lines\n"); + rtems_printf(data->printer, "\n"); /* * Uptime and period of this sample. */ - (*data->plugin.print)(data->plugin.context, "Uptime: "); + rtems_printf(data->printer, "Uptime: "); print_time(data, &data->uptime, 20); - (*data->plugin.print)(data->plugin.context, " Period: "); + rtems_printf(data->printer, " Period: "); print_time(data, &data->period, 20); /* * Task count, load and idle levels. */ - (*data->plugin.print)(data->plugin.context, "\nTasks: %4i ", data->task_count); + rtems_printf(data->printer, "\nTasks: %4i ", data->task_count); _Timestamp_Subtract(&data->idle, &data->total, &load); _Timestamp_Divide(&load, &data->uptime, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - "Load Average: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); + rtems_printf(data->printer, + "Load Average: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); _Timestamp_Subtract(&data->current_idle, &data->current, &load); _Timestamp_Divide(&load, &data->period, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " Load: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); + rtems_printf(data->printer, + " Load: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); _Timestamp_Divide(&data->current_idle, &data->period, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " Idle: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); + rtems_printf(data->printer, + " Idle: %4" PRIu32 ".%03" PRIu32 "%%", ival, fval); /* * Memory usage. */ if (rtems_configuration_get_unified_work_area()) { - (*data->plugin.print)(data->plugin.context, "\nMem: "); + rtems_printf(data->printer, "\nMem: "); print_memsize(data, wksp.Free.total, "free"); print_memsize(data, wksp.Used.total, "used"); } @@ -440,7 +423,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) { region_information_block libc_heap; malloc_info(&libc_heap); - (*data->plugin.print)(data->plugin.context, "\nMem: Wksp: "); + rtems_printf(data->printer, "\nMem: Wksp: "); print_memsize(data, wksp.Free.total, "free"); print_memsize(data, wksp.Used.total, "used Heap: "); print_memsize(data, libc_heap.Free.total, "free"); @@ -449,7 +432,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) print_memsize(data, data->stack_size, "stack\n"); - (*data->plugin.print)(data->plugin.context, + rtems_printf(data->printer, "\n" " ID | NAME | RPRI | CPRI | TIME | TOTAL | CURRENT\n" "-%s---------+---------------------+-%s-----%s-----+---------------------+-%s------+--%s----\n", @@ -487,12 +470,12 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) if (name[0] == '\0') snprintf(name, sizeof(name) - 1, "(%p)", thread->Start.Entry.Kinds.Numeric.entry); - (*data->plugin.print)(data->plugin.context, - " 0x%08" PRIx32 " | %-19s | %3" PRId32 " | %3" PRId32 " | ", - thread->Object.id, - name, - thread->real_priority, - thread->current_priority); + rtems_printf(data->printer, + " 0x%08" PRIx32 " | %-19s | %3" PRId32 " | %3" PRId32 " | ", + thread->Object.id, + name, + thread->real_priority, + thread->current_priority); usage = data->usage[i]; current_usage = data->current_usage[i]; @@ -502,11 +485,11 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) */ print_time(data, &usage, 19); _Timestamp_Divide(&usage, &data->total, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " |%4" PRIu32 ".%03" PRIu32, ival, fval); + rtems_printf(data->printer, + " |%4" PRIu32 ".%03" PRIu32, ival, fval); _Timestamp_Divide(¤t_usage, &data->period, &ival, &fval); - (*data->plugin.print)(data->plugin.context, - " |%4" PRIu32 ".%03" PRIu32 "\n", ival, fval); + rtems_printf(data->printer, + " |%4" PRIu32 ".%03" PRIu32 "\n", ival, fval); } if (data->single_page && (data->show != 0) && (task_count < data->show)) @@ -514,7 +497,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) i = data->show - task_count; while (i > 0) { - (*data->plugin.print)(data->plugin.context, "\x1b[K\n"); + rtems_printf(data->printer, "\x1b[K\n"); i--; } } @@ -525,8 +508,8 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) &out); if ((sc != RTEMS_SUCCESSFUL) && (sc != RTEMS_TIMEOUT)) { - (*data->plugin.print)(data->plugin.context, - "error: event receive: %s\n", rtems_status_text(sc)); + rtems_printf(data->printer, + "error: event receive: %s\n", rtems_status_text(sc)); break; } } @@ -542,8 +525,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg) } void rtems_cpu_usage_top_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ) { rtems_status_code sc; @@ -553,9 +535,6 @@ void rtems_cpu_usage_top_with_plugin( rtems_cpu_usage_data data; int show_lines = 25; - if ( !print ) - return; - memset(&data, 0, sizeof(data)); data.thread_run = true; @@ -563,18 +542,14 @@ void rtems_cpu_usage_top_with_plugin( data.sort_order = RTEMS_TOP_SORT_CURRENT; data.poll_rate_usecs = 3000; data.show = show_lines; - data.plugin.context = context; - data.plugin.print = print; + data.printer = printer; sc = rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority); if (sc != RTEMS_SUCCESSFUL) { - (*print)( - context, - "error: cannot obtain the current priority: %s\n", - rtems_status_text (sc) - ); + rtems_printf (printer, + "error: cannot obtain the current priority: %s\n", rtems_status_text (sc)); return; } @@ -587,24 +562,16 @@ void rtems_cpu_usage_top_with_plugin( if (sc != RTEMS_SUCCESSFUL) { - (*print)( - context, - "error: cannot create helper thread: %s\n", - rtems_status_text (sc) - ); + rtems_printf (printer, + "error: cannot create helper thread: %s\n", rtems_status_text (sc)); return; } - sc = rtems_task_start ( - id, rtems_cpuusage_top_thread, (rtems_task_argument) &data - ); + sc = rtems_task_start (id, rtems_cpuusage_top_thread, (rtems_task_argument) &data); if (sc != RTEMS_SUCCESSFUL) { - (*print)( - context, - "error: cannot start helper thread: %s\n", - rtems_status_text (sc) - ); + rtems_printf (printer, + "error: cannot start helper thread: %s\n", rtems_status_text (sc)); rtems_task_delete (id); return; } @@ -624,7 +591,7 @@ void rtems_cpu_usage_top_with_plugin( while (loops && data.thread_active) rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (100000)); - (*print)(context, "load monitoring stopped.\n"); + rtems_printf (printer, "load monitoring stopped.\n"); return; } else if (c == '<') @@ -676,7 +643,9 @@ void rtems_cpu_usage_top_with_plugin( } } -void rtems_cpu_usage_top( void ) +void rtems_cpu_usage_top (void) { - rtems_cpu_usage_top_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk (&printer); + rtems_cpu_usage_top_with_plugin (&printer); } diff --git a/cpukit/libmisc/cpuuse/cpuuse.h b/cpukit/libmisc/cpuuse/cpuuse.h index 1e26019cd6..1a3d2a7f3e 100644 --- a/cpukit/libmisc/cpuuse/cpuuse.h +++ b/cpukit/libmisc/cpuuse/cpuuse.h @@ -1,6 +1,6 @@ /** * @file rtems/cpuuse.h - * + * * @defgroup libmisc_cpuuse CPU Usage * * @ingroup libmisc @@ -23,7 +23,7 @@ #define __RTEMS_CPUUSE_h #include <rtems.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> #include <rtems/score/timestamp.h> @@ -43,10 +43,7 @@ extern Timestamp_Control CPU_usage_Uptime_at_last_reset; * rtems_cpu_usage_report_with_handler */ -void rtems_cpu_usage_report_with_plugin( - void *context, - rtems_printk_plugin_t handler -); +void rtems_cpu_usage_report_with_plugin( const rtems_printer *printer ); /** * @brief Report CPU usage. @@ -62,10 +59,7 @@ void rtems_cpu_usage_report( void ); * Report CPU Usage in top format to * to a print plugin. */ -void rtems_cpu_usage_top_with_plugin( - void *context, - rtems_printk_plugin_t print -); +void rtems_cpu_usage_top_with_plugin( const rtems_printer *printer ); /** * @brief CPU usage top. diff --git a/cpukit/libmisc/fb/mw_print.c b/cpukit/libmisc/fb/mw_print.c index 8f4e465da2..25a3456c80 100644 --- a/cpukit/libmisc/fb/mw_print.c +++ b/cpukit/libmisc/fb/mw_print.c @@ -43,12 +43,13 @@ void uid_print_message( struct MW_UID_MESSAGE *uid ) { - uid_print_message_with_plugin( NULL, printk_plugin, uid ); + rtems_printer printer; + rtems_print_printer_printk(&printer); + uid_print_message_with_plugin( &printer, uid ); } void uid_print_message_with_plugin( - void *context, - rtems_printk_plugin_t handler, + const rtems_printer *printer, struct MW_UID_MESSAGE *uid ) { @@ -56,11 +57,11 @@ void uid_print_message_with_plugin( switch (uid->type) { case MV_UID_INVALID: - (*handler)( context, "MV_UID_INVALID\n" ); + rtems_printf( printer, "MV_UID_INVALID\n" ); break; case MV_UID_REL_POS: - (*handler)( - context, + rtems_printf( + printer, "MV_UID_REL_POS - %s x=%d y=%d z=%d\n", uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)), uid->m.pos.x, /* x location */ @@ -69,8 +70,8 @@ void uid_print_message_with_plugin( ); break; case MV_UID_ABS_POS: - (*handler)( - context, + rtems_printf( + printer, "MV_UID_ABS_POS - %s x=%d y=%d z=%d\n", uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)), uid->m.pos.x, /* x location */ @@ -79,7 +80,7 @@ void uid_print_message_with_plugin( ); break; case MV_UID_KBD: - (*handler)( context, + rtems_printf( printer, "MV_UID_KBD - code=0x%04x modifiers=0x%02x mode=0x%02x\n", uid->m.kbd.code, /* keycode or scancode */ uid->m.kbd.modifiers, /* key modifiers */ @@ -87,10 +88,10 @@ void uid_print_message_with_plugin( ); break; case MV_UID_TIMER: - (*handler)( context, "MV_UID_TIMER\n" ); + rtems_printf( printer, "MV_UID_TIMER\n" ); break; default: - (*handler)( context, "Invalid device type\n" ); + rtems_printf( printer, "Invalid device type\n" ); break; } diff --git a/cpukit/libmisc/fb/mw_uid.h b/cpukit/libmisc/fb/mw_uid.h index 8a10a8f38c..aa88392d26 100644 --- a/cpukit/libmisc/fb/mw_uid.h +++ b/cpukit/libmisc/fb/mw_uid.h @@ -18,7 +18,7 @@ #define _MW_UID_H #include <sys/types.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> /** * @defgroup libmisc_fb_mw Input Devices for MicroWindows @@ -179,14 +179,11 @@ void uid_print_message( * This methods prints the specified UID message using your fprintf * style method of choice. * - * @param[in] context is a pointer to a data area which may be - * used by some print handlers - * @param[in] handler is the fprintf style method to invoke + * @param[in] RTEMS printer * @param[in] uid points to the message to print */ void uid_print_message_with_plugin( - void *context, - rtems_printk_plugin_t handler, + const rtems_printer *printer, struct MW_UID_MESSAGE *uid ); diff --git a/cpukit/libmisc/shell/main_blkstats.c b/cpukit/libmisc/shell/main_blkstats.c index 50d783d76c..d814df673c 100644 --- a/cpukit/libmisc/shell/main_blkstats.c +++ b/cpukit/libmisc/shell/main_blkstats.c @@ -31,6 +31,7 @@ static int rtems_shell_main_blkstats(int argc, char **argv) bool ok = false; bool reset = false; const char *device; + rtems_printer printer; if (argc == 2) { ok = true; @@ -41,10 +42,12 @@ static int rtems_shell_main_blkstats(int argc, char **argv) device = argv [2]; } + rtems_print_printer_printf(&printer); + if (ok) { - rtems_blkstats(stdout, device, reset); + rtems_blkstats(&printer, device, reset); } else { - fprintf(stdout, "usage: %s\n", rtems_shell_BLKSTATS_Command.usage); + rtems_printf(&printer, "usage: %s\n", rtems_shell_BLKSTATS_Command.usage); } return 0; diff --git a/cpukit/libmisc/shell/main_cpuuse.c b/cpukit/libmisc/shell/main_cpuuse.c index c1f991a390..190fd039ff 100644 --- a/cpukit/libmisc/shell/main_cpuuse.c +++ b/cpukit/libmisc/shell/main_cpuuse.c @@ -30,7 +30,9 @@ static int rtems_shell_main_cpuuse( * When invoked with no arguments, print the report. */ if ( argc == 1 ) { - rtems_cpu_usage_report_with_plugin(stdout, (rtems_printk_plugin_t)fprintf); + rtems_printer printer; + rtems_print_printer_fprintf(&printer, stdout); + rtems_cpu_usage_report_with_plugin(&printer); return 0; } diff --git a/cpukit/libmisc/shell/main_perioduse.c b/cpukit/libmisc/shell/main_perioduse.c index 9b33a75446..023e154cbc 100644 --- a/cpukit/libmisc/shell/main_perioduse.c +++ b/cpukit/libmisc/shell/main_perioduse.c @@ -29,9 +29,10 @@ static int rtems_shell_main_perioduse( * When invoked with no arguments, print the report. */ if ( argc == 1 ) { + rtems_printer printer; + rtems_print_printer_printf(&printer); rtems_rate_monotonic_report_statistics_with_plugin( - stdout, - (rtems_printk_plugin_t)fprintf + &printer ); return 0; } diff --git a/cpukit/libmisc/shell/main_profreport.c b/cpukit/libmisc/shell/main_profreport.c index d6e4c5a843..a98b8ba9aa 100644 --- a/cpukit/libmisc/shell/main_profreport.c +++ b/cpukit/libmisc/shell/main_profreport.c @@ -24,10 +24,11 @@ static int rtems_shell_main_profreport(int argc, char **argv) { + rtems_printer printer; + rtems_print_printer_printf(&printer); rtems_profiling_report_xml( "Shell", - (rtems_profiling_printf) fprintf, - stdout, + &printer, 0, " " ); diff --git a/cpukit/libmisc/shell/main_stackuse.c b/cpukit/libmisc/shell/main_stackuse.c index 74d47e16b0..40fc711f49 100644 --- a/cpukit/libmisc/shell/main_stackuse.c +++ b/cpukit/libmisc/shell/main_stackuse.c @@ -25,10 +25,9 @@ static int rtems_shell_main_stackuse( char *argv[] RTEMS_UNUSED ) { - rtems_stack_checker_report_usage_with_plugin( - stdout, - (rtems_printk_plugin_t)fprintf - ); + rtems_printer printer; + rtems_print_printer_printf(&printer); + rtems_stack_checker_report_usage_with_plugin( &printer ); return 0; } diff --git a/cpukit/libmisc/shell/main_top.c b/cpukit/libmisc/shell/main_top.c index ad6223a560..aea50d80fb 100644 --- a/cpukit/libmisc/shell/main_top.c +++ b/cpukit/libmisc/shell/main_top.c @@ -30,7 +30,9 @@ static int rtems_shell_main_top( * When invoked with no arguments, print the report. */ if ( argc == 1 ) { - rtems_cpu_usage_top_with_plugin(stdout, (rtems_printk_plugin_t)fprintf); + rtems_printer printer; + rtems_print_printer_fprintf(&printer, stdout); + rtems_cpu_usage_top_with_plugin(&printer); return 0; } diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c index 9c6932e290..93d45de77c 100644 --- a/cpukit/libmisc/stackchk/check.c +++ b/cpukit/libmisc/stackchk/check.c @@ -387,8 +387,7 @@ static inline void *Stack_check_find_high_water_mark( * * Try to print out how much stack was actually used by the task. */ -static void *print_context; -static rtems_printk_plugin_t print_handler; +static const rtems_printer* printer; static void Stack_check_Dump_threads_usage( Thread_Control *the_thread @@ -438,8 +437,8 @@ static void Stack_check_Dump_threads_usage( if ( the_thread ) #endif { - (*print_handler)( - print_context, + rtems_printf( + printer, "0x%08" PRIx32 " %4s", the_thread->Object.id, rtems_object_get_name( the_thread->Object.id, sizeof(name), name ) @@ -447,12 +446,12 @@ static void Stack_check_Dump_threads_usage( } #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) else { - (*print_handler)( print_context, "0x%08" PRIx32 " INTR", ~0 ); + rtems_printf( printer, "0x%08" PRIx32 " INTR", ~0 ); } #endif - (*print_handler)( - print_context, + rtems_printf( + printer, " %010p - %010p %010p %8" PRId32 " ", stack->area, stack->area + stack->size - 1, @@ -461,9 +460,9 @@ static void Stack_check_Dump_threads_usage( ); if (Stack_check_Initialized == 0) { - (*print_handler)( print_context, "Unavailable\n" ); + rtems_printf( printer, "Unavailable\n" ); } else { - (*print_handler)( print_context, "%8" PRId32 "\n", used ); + rtems_printf( printer, "%8" PRId32 "\n", used ); } @@ -489,18 +488,16 @@ static void Stack_check_Dump_threads_usage( */ void rtems_stack_checker_report_usage_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer* printer_ ) { - if ( !print ) + if ( printer != NULL || ! rtems_print_printer_valid ( printer_ ) ) return; - print_context = context; - print_handler = print; + printer = printer_; - (*print)( context, "Stack usage by thread\n"); - (*print)( context, + rtems_printf( printer, "Stack usage by thread\n"); + rtems_printf( printer, " ID NAME LOW HIGH CURRENT AVAILABLE USED\n" ); @@ -512,11 +509,12 @@ void rtems_stack_checker_report_usage_with_plugin( Stack_check_Dump_threads_usage((Thread_Control *) -1); #endif - print_context = NULL; - print_handler = NULL; + printer = NULL; } void rtems_stack_checker_report_usage( void ) { - rtems_stack_checker_report_usage_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk(&printer); + rtems_stack_checker_report_usage_with_plugin( &printer ); } diff --git a/cpukit/libmisc/stackchk/stackchk.h b/cpukit/libmisc/stackchk/stackchk.h index b824057f59..f7f75b63e2 100644 --- a/cpukit/libmisc/stackchk/stackchk.h +++ b/cpukit/libmisc/stackchk/stackchk.h @@ -25,7 +25,7 @@ #include <stdbool.h> /* bool */ #include <rtems/score/thread.h> /* Thread_Control */ -#include <rtems/bspIo.h> +#include <rtems/print.h> /** * @defgroup libmisc_stackchk Stack Checker Mechanism @@ -71,8 +71,7 @@ void rtems_stack_checker_report_usage( void ); * @note It uses the caller's routine to print the report. */ void rtems_stack_checker_report_usage_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ); /************************************************************* diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h index 497c4b679b..980ab666a6 100644 --- a/cpukit/libmisc/testsupport/test.h +++ b/cpukit/libmisc/testsupport/test.h @@ -16,7 +16,7 @@ #define _RTEMS_TEST_H #include <rtems.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> #include <rtems/score/atomic.h> #include <rtems/score/smpbarrier.h> @@ -38,6 +38,11 @@ extern "C" { extern const char rtems_test_name[]; /** + * @brief Each test must define a printer. + */ +extern rtems_printer rtems_test_printer; + +/** * @brief Fatal extension for tests. */ void rtems_test_fatal_extension( @@ -53,70 +58,35 @@ void rtems_test_fatal_extension( { NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension } /** - * @brief Prints a begin of test message. - * - * @param[in] printf_func The formatted output function. - * @param[in, out] printf_arg The formatted output function argument. - * - * @returns As specified by printf(). - */ -int rtems_test_begin_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg -); - -/** - * @brief Prints a begin of test message using printf(). - * - * @returns As specified by printf(). + * @brief Begin of test message format string. */ -static inline int rtems_test_begin(void) -{ - return rtems_test_begin_with_plugin(rtems_printf_plugin, NULL); -} +#define TEST_BEGIN_STRING "\n\n*** BEGIN OF TEST %s ***\n", rtems_test_name /** - * @brief Prints a begin of test message using printk(). - * - * @returns As specified by printf(). + * @brief End of test message format string. */ -static inline int rtems_test_begink(void) -{ - return rtems_test_begin_with_plugin(printk_plugin, NULL); -} +#define TEST_END_STRING "*** END OF TEST %s ***\n", rtems_test_name /** - * @brief Prints an end of test message. - * - * @param[in] printf_func The formatted output function. - * @param[in, out] printf_arg The formatted output function argument. + * @brief Prints a begin of test message using printf(). * * @returns As specified by printf(). */ -int rtems_test_end_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg -); +int rtems_test_begin(void); /** * @brief Prints an end of test message using printf(). * * @returns As specified by printf(). */ -static inline int rtems_test_end(void) -{ - return rtems_test_end_with_plugin(rtems_printf_plugin, NULL); -} +int rtems_test_end(void); /** - * @brief Prints an end of test message using printk(). + * @brief Prints via the RTEMS printer. * * @returns As specified by printf(). */ -static inline int rtems_test_endk(void) -{ - return rtems_test_end_with_plugin(printk_plugin, NULL); -} +int rtems_test_print(const char* format, ...) RTEMS_PRINTF_ATTRIBUTE(1, 2); /** * @brief Internal context for parallel job execution. diff --git a/cpukit/libmisc/testsupport/testbeginend.c b/cpukit/libmisc/testsupport/testbeginend.c index 6383b33a78..6bfc400e1e 100644 --- a/cpukit/libmisc/testsupport/testbeginend.c +++ b/cpukit/libmisc/testsupport/testbeginend.c @@ -18,26 +18,35 @@ #include <rtems/test.h> -int rtems_test_begin_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg -) +int rtems_test_begin(void) +{ + return rtems_printf( + &rtems_test_printer, + TEST_BEGIN_STRING + ); +} + +int rtems_test_end(void) { - return (*printf_func)( - printf_arg, - "\n\n*** BEGIN OF TEST %s ***\n", - rtems_test_name + return rtems_printf( + &rtems_test_printer, + TEST_END_STRING ); } -int rtems_test_end_with_plugin( - rtems_printk_plugin_t printf_func, - void *printf_arg +int rtems_test_print( + const char* format, + ... ) { - return (*printf_func)( - printf_arg, - "*** END OF TEST %s ***\n", - rtems_test_name + va_list ap; + int len; + va_start(ap, format); + len = rtems_vprintf( + &rtems_test_printer, + format, + ap ); + va_end(ap); + return len; } diff --git a/cpukit/libmisc/testsupport/testextension.c b/cpukit/libmisc/testsupport/testextension.c index a689e66792..43f79bc114 100644 --- a/cpukit/libmisc/testsupport/testextension.c +++ b/cpukit/libmisc/testsupport/testextension.c @@ -33,6 +33,9 @@ void rtems_test_fatal_extension( { #if defined(RTEMS_PROFILING) rtems_interrupt_lock_context lock_context; + rtems_printer printer; + + rtems_print_printer_printk( &printer ); /* * Ensures to report only once on SMP machines and ensures that the report is @@ -50,8 +53,7 @@ void rtems_test_fatal_extension( rtems_profiling_report_xml( rtems_test_name, - printk_plugin, - NULL, + &printer, 1, " " ); diff --git a/cpukit/preinstall.am b/cpukit/preinstall.am index c8f2cd3fcb..fdf2016ec5 100644 --- a/cpukit/preinstall.am +++ b/cpukit/preinstall.am @@ -224,6 +224,10 @@ $(PROJECT_INCLUDE)/rtems/bspIo.h: include/rtems/bspIo.h $(PROJECT_INCLUDE)/rtems $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bspIo.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bspIo.h +$(PROJECT_INCLUDE)/rtems/print.h: include/rtems/print.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/print.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/print.h + $(PROJECT_INCLUDE)/rtems/userenv.h: include/rtems/userenv.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/userenv.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/userenv.h diff --git a/cpukit/rtems/include/rtems/rtems/ratemon.h b/cpukit/rtems/include/rtems/rtems/ratemon.h index 87bd064c98..6e8fab64d5 100644 --- a/cpukit/rtems/include/rtems/rtems/ratemon.h +++ b/cpukit/rtems/include/rtems/rtems/ratemon.h @@ -35,7 +35,7 @@ #include <rtems/rtems/status.h> #include <rtems/score/thread.h> #include <rtems/score/watchdog.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> #ifdef __cplusplus extern "C" { @@ -356,14 +356,13 @@ void rtems_rate_monotonic_reset_all_statistics( void ); * @brief RTEMS Report Rate Monotonic Statistics * * This routine allows a thread to print the statistics information - * on ALL period instances which have non-zero counts using printk. - * The implementation of this directive straddles the fence between - * inside and outside of RTEMS. It is presented as part of the Manager - * but actually uses other services of the Manager. + * on ALL period instances which have non-zero counts using the RTEMS + * printer. The implementation of this directive straddles the fence + * between inside and outside of RTEMS. It is presented as part of + * the Manager but actually uses other services of the Manager. */ void rtems_rate_monotonic_report_statistics_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ); /** diff --git a/cpukit/rtems/src/ratemonreportstatistics.c b/cpukit/rtems/src/ratemonreportstatistics.c index 856d431bdc..3f264df487 100644 --- a/cpukit/rtems/src/ratemonreportstatistics.c +++ b/cpukit/rtems/src/ratemonreportstatistics.c @@ -20,6 +20,7 @@ #include <rtems/rtems/ratemonimpl.h> #include <rtems/rtems/object.h> +#include <rtems/print.h> #include <inttypes.h> @@ -29,8 +30,7 @@ #define NANOSECONDS_FMT "%06" PRId32 void rtems_rate_monotonic_report_statistics_with_plugin( - void *context, - rtems_printk_plugin_t print + const rtems_printer *printer ) { rtems_status_code status; @@ -39,12 +39,9 @@ void rtems_rate_monotonic_report_statistics_with_plugin( rtems_rate_monotonic_period_status the_status; char name[5]; - if ( !print ) - return; - - (*print)( context, "Period information by period\n" ); - (*print)( context, "--- CPU times are in seconds ---\n" ); - (*print)( context, "--- Wall times are in seconds ---\n" ); + rtems_printf( printer, "Period information by period\n" ); + rtems_printf( printer, "--- CPU times are in seconds ---\n" ); + rtems_printf( printer, "--- Wall times are in seconds ---\n" ); /* Layout by columns -- in memory of Hollerith :) @@ -58,7 +55,7 @@ ididididid NNNN ccccc mmmmmm X 1234567890123456789012345678901234567890123456789012345678901234567890123456789\ \n"); */ - (*print)( context, + rtems_printf( printer, " ID OWNER COUNT MISSED " " CPU TIME WALL TIME\n" " " @@ -90,7 +87,7 @@ ididididid NNNN ccccc mmmmmm X /* * Print part of report line that is not dependent on granularity */ - (*print)( context, + rtems_printf( printer, "0x%08" PRIx32 " %4s %5" PRId32 " %6" PRId32 " ", id, name, the_stats.count, the_stats.missed_count @@ -100,7 +97,7 @@ ididididid NNNN ccccc mmmmmm X * If the count is zero, don't print statistics */ if (the_stats.count == 0) { - (*print)( context, "\n" ); + rtems_printf( printer, "\n" ); continue; } @@ -114,7 +111,7 @@ ididididid NNNN ccccc mmmmmm X struct timespec *total_cpu = &the_stats.total_cpu_time; _Timespec_Divide_by_integer( total_cpu, the_stats.count, &cpu_average ); - (*print)( context, + rtems_printf( printer, "%" PRId32 "." NANOSECONDS_FMT "/" /* min cpu time */ "%" PRId32 "." NANOSECONDS_FMT "/" /* max cpu time */ "%" PRId32 "." NANOSECONDS_FMT " ", /* avg cpu time */ @@ -137,7 +134,7 @@ ididididid NNNN ccccc mmmmmm X struct timespec *total_wall = &the_stats.total_wall_time; _Timespec_Divide_by_integer(total_wall, the_stats.count, &wall_average); - (*print)( context, + rtems_printf( printer, "%" PRId32 "." NANOSECONDS_FMT "/" /* min wall time */ "%" PRId32 "." NANOSECONDS_FMT "/" /* max wall time */ "%" PRId32 "." NANOSECONDS_FMT "\n", /* avg wall time */ @@ -154,5 +151,7 @@ ididididid NNNN ccccc mmmmmm X void rtems_rate_monotonic_report_statistics( void ) { - rtems_rate_monotonic_report_statistics_with_plugin( NULL, printk_plugin ); + rtems_printer printer; + rtems_print_printer_printk( &printer ); + rtems_rate_monotonic_report_statistics_with_plugin( &printer ); } diff --git a/cpukit/sapi/include/rtems/profiling.h b/cpukit/sapi/include/rtems/profiling.h index 836e6d890e..9e434b2a3c 100644 --- a/cpukit/sapi/include/rtems/profiling.h +++ b/cpukit/sapi/include/rtems/profiling.h @@ -25,6 +25,8 @@ #include <stdint.h> +#include <rtems/print.h> + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -306,24 +308,10 @@ void rtems_profiling_iterate( ); /** - * @brief Function for formatted output. - * - * @param[in, out] arg Some argument. - * @param[in] format The output format as specified by printf(). - * @param[in] ... More parameters according to format. - * - * @returns As specified by printf(). - * - * @see rtems_profiling_report_xml(). - */ -typedef int (*rtems_profiling_printf)(void *arg, const char *format, ...); - -/** * @brief Reports profiling data as XML. * * @param[in] name The name of the profiling report. - * @param[in] printf_func The formatted output function. - * @param[in, out] printf_arg The formatted output function argument. + * @param[in] printer The RTEMS printer to send the output too. * @param[in] indentation_level The current indentation level. * @param[in] indentation The string used for indentation. * @@ -331,8 +319,7 @@ typedef int (*rtems_profiling_printf)(void *arg, const char *format, ...); */ int rtems_profiling_report_xml( const char *name, - rtems_profiling_printf printf_func, - void *printf_arg, + const rtems_printer *printer, uint32_t indentation_level, const char *indentation ); diff --git a/cpukit/sapi/src/profilingreportxml.c b/cpukit/sapi/src/profilingreportxml.c index 777d1f1d52..e64314695f 100644 --- a/cpukit/sapi/src/profilingreportxml.c +++ b/cpukit/sapi/src/profilingreportxml.c @@ -23,8 +23,7 @@ #include <inttypes.h> typedef struct { - rtems_profiling_printf printf_func; - void *printf_arg; + const rtems_printer *printer; uint32_t indentation_level; const char *indentation; int retval; @@ -43,7 +42,7 @@ static void indent(context *ctx, uint32_t indentation_level) uint32_t i; for (i = 0; i < n; ++i) { - int rv = (*ctx->printf_func)(ctx->printf_arg, "%s", ctx->indentation); + int rv = rtems_printf(ctx->printer, "%s", ctx->indentation); update_retval(ctx, rv); } @@ -56,21 +55,19 @@ static uint64_t arithmetic_mean(uint64_t total, uint64_t count) static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) { - rtems_profiling_printf printf_func = ctx->printf_func; - void *printf_arg = ctx->printf_arg; int rv; indent(ctx, 1); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<PerCPUProfilingReport processorIndex=\"%" PRIu32 "\">\n", per_cpu->processor_index ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MaxThreadDispatchDisabledTime unit=\"ns\">%" PRIu32 "</MaxThreadDispatchDisabledTime>\n", per_cpu->max_thread_dispatch_disabled_time @@ -78,8 +75,8 @@ static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MeanThreadDispatchDisabledTime unit=\"ns\">%" PRIu64 "</MeanThreadDispatchDisabledTime>\n", arithmetic_mean( @@ -90,8 +87,8 @@ static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<TotalThreadDispatchDisabledTime unit=\"ns\">%" PRIu64 "</TotalThreadDispatchDisabledTime>\n", per_cpu->total_thread_dispatch_disabled_time @@ -99,24 +96,24 @@ static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<ThreadDispatchDisabledCount>%" PRIu64 "</ThreadDispatchDisabledCount>\n", per_cpu->thread_dispatch_disabled_count ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MaxInterruptDelay unit=\"ns\">%" PRIu32 "</MaxInterruptDelay>\n", per_cpu->max_interrupt_delay ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MaxInterruptTime unit=\"ns\">%" PRIu32 "</MaxInterruptTime>\n", per_cpu->max_interrupt_time @@ -124,8 +121,8 @@ static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MeanInterruptTime unit=\"ns\">%" PRIu64 "</MeanInterruptTime>\n", arithmetic_mean( @@ -136,24 +133,24 @@ static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<TotalInterruptTime unit=\"ns\">%" PRIu64 "</TotalInterruptTime>\n", per_cpu->total_interrupt_time ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<InterruptCount>%" PRIu64 "</InterruptCount>\n", per_cpu->interrupt_count ); update_retval(ctx, rv); indent(ctx, 1); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "</PerCPUProfilingReport>\n" ); update_retval(ctx, rv); @@ -161,38 +158,36 @@ static void report_per_cpu(context *ctx, const rtems_profiling_per_cpu *per_cpu) static void report_smp_lock(context *ctx, const rtems_profiling_smp_lock *smp_lock) { - rtems_profiling_printf printf_func = ctx->printf_func; - void *printf_arg = ctx->printf_arg; int rv; uint32_t i; indent(ctx, 1); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<SMPLockProfilingReport name=\"%s\">\n", smp_lock->name ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MaxAcquireTime unit=\"ns\">%" PRIu32 "</MaxAcquireTime>\n", smp_lock->max_acquire_time ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MaxSectionTime unit=\"ns\">%" PRIu32 "</MaxSectionTime>\n", smp_lock->max_section_time ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MeanAcquireTime unit=\"ns\">%" PRIu64 "</MeanAcquireTime>\n", arithmetic_mean( @@ -203,8 +198,8 @@ static void report_smp_lock(context *ctx, const rtems_profiling_smp_lock *smp_lo update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<MeanSectionTime unit=\"ns\">%" PRIu64 "</MeanSectionTime>\n", arithmetic_mean( @@ -215,24 +210,24 @@ static void report_smp_lock(context *ctx, const rtems_profiling_smp_lock *smp_lo update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<TotalAcquireTime unit=\"ns\">%" PRIu64 "</TotalAcquireTime>\n", smp_lock->total_acquire_time ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<TotalSectionTime unit=\"ns\">%" PRIu64 "</TotalSectionTime>\n", smp_lock->total_section_time ); update_retval(ctx, rv); indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<UsageCount>%" PRIu64 "</UsageCount>\n", smp_lock->usage_count ); @@ -240,8 +235,8 @@ static void report_smp_lock(context *ctx, const rtems_profiling_smp_lock *smp_lo for (i = 0; i < RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS; ++i) { indent(ctx, 2); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "<ContentionCount initialQueueLength=\"%" PRIu32 "\">%" PRIu64 "</ContentionCount>\n", i, @@ -251,8 +246,8 @@ static void report_smp_lock(context *ctx, const rtems_profiling_smp_lock *smp_lo } indent(ctx, 1); - rv = (*printf_func)( - printf_arg, + rv = rtems_printf( + ctx->printer, "</SMPLockProfilingReport>\n" ); update_retval(ctx, rv); @@ -276,16 +271,14 @@ static void report(void *arg, const rtems_profiling_data *data) int rtems_profiling_report_xml( const char *name, - rtems_profiling_printf printf_func, - void *printf_arg, + const rtems_printer *printer, uint32_t indentation_level, const char *indentation ) { #ifdef RTEMS_PROFILING context ctx_instance = { - .printf_func = printf_func, - .printf_arg = printf_arg, + .printer = printer, .indentation_level = indentation_level, .indentation = indentation, .retval = 0 @@ -294,20 +287,19 @@ int rtems_profiling_report_xml( int rv; indent(ctx, 0); - rv = (*printf_func)(printf_arg, "<ProfilingReport name=\"%s\">\n", name); + rv = rtems_printf(printer, "<ProfilingReport name=\"%s\">\n", name); update_retval(ctx, rv); rtems_profiling_iterate(report, ctx); indent(ctx, 0); - rv = (*printf_func)(printf_arg, "</ProfilingReport>\n"); + rv = rtems_printf(printer, "</ProfilingReport>\n"); update_retval(ctx, rv); return ctx->retval; #else /* RTEMS_PROFILING */ (void) name; - (void) printf_func; - (void) printf_arg; + (void) printer; (void) indentation_level; (void) indentation; diff --git a/cpukit/score/src/cpusetprintsupport.c b/cpukit/score/src/cpusetprintsupport.c index 76851d3043..83345d985c 100644 --- a/cpukit/score/src/cpusetprintsupport.c +++ b/cpukit/score/src/cpusetprintsupport.c @@ -23,16 +23,15 @@ #include <stdio.h> #include <ctype.h> #include <inttypes.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> #include <rtems/score/cpusetimpl.h> #ifdef __RTEMS_HAVE_SYS_CPUSET_H__ void _CPU_set_Show_with_plugin( - void *context, - rtems_printk_plugin_t print, - const char *description, - const cpu_set_t *cpuset + const rtems_printer *printer, + const char *description, + const cpu_set_t *cpuset ); /* @@ -42,21 +41,16 @@ * print plugin . */ void _CPU_set_Show_with_plugin( - void *context, - rtems_printk_plugin_t print, - const char *description, - const cpu_set_t *cpuset + const rtems_printer *printer, + const char *description, + const cpu_set_t *cpuset ) { int i; - - if ( !print ) - return; - - (*print)(context ,"%s: ", description); + rtems_printf(printer ,"%s: ", description); for(i=0; i<_NCPUWORDS; i++) - (*print)(context ,"%x", cpuset->__bits[i]); - (*print)(context ,"\n"); + rtems_printf(printer ,"%x", cpuset->__bits[i]); + rtems_printf(printer ,"\n"); } /* @@ -67,7 +61,9 @@ */ void _CPU_set_Show( const char *description, const cpu_set_t *cpuset) { - _CPU_set_Show_with_plugin( NULL, printk_plugin, description, cpuset ); + rtems_printer printer; + rtems_print_printer_printk( &printer ); + _CPU_set_Show_with_plugin( &printer, description, cpuset ); } /* |