Author: blueswirl Date: Wed Sep 29 22:30:51 2010 New Revision: 872 URL: http://tracker.coreboot.org/trac/openbios/changeset/872
Log: Avoid a lot of malloc/free traffic
Each console write caused temporary buffer allocation.
Avoid allocations by changing console_draw_str() to use Forth string parameters, which are usually readily available.
Signed-off-by: Blue Swirl blauwirbel@gmail.com
Modified: trunk/openbios-devel/arch/ppc/mol/methods.c trunk/openbios-devel/arch/ppc/mol/mol.h trunk/openbios-devel/arch/ppc/pearpc/methods.c trunk/openbios-devel/arch/ppc/pearpc/pearpc.h trunk/openbios-devel/arch/sparc32/console.c trunk/openbios-devel/arch/x86/xbox/methods.c trunk/openbios-devel/include/libopenbios/console.h trunk/openbios-devel/libopenbios/console_common.c trunk/openbios-devel/packages/video.c
Modified: trunk/openbios-devel/arch/ppc/mol/methods.c ============================================================================== --- trunk/openbios-devel/arch/ppc/mol/methods.c Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/arch/ppc/mol/methods.c Wed Sep 29 22:30:51 2010 (r872) @@ -85,14 +85,9 @@ { int len = POP(); char *addr = (char*)POP(); - char *s = malloc( len + 1 ); - - strncpy_nopad( s, addr, len ); - s[len]=0;
/* printk( "%s", s ); */ - console_draw_str( s ); - free( s ); + console_draw_fstr(addr, len);
PUSH( len ); }
Modified: trunk/openbios-devel/arch/ppc/mol/mol.h ============================================================================== --- trunk/openbios-devel/arch/ppc/mol/mol.h Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/arch/ppc/mol/mol.h Wed Sep 29 22:30:51 2010 (r872) @@ -24,7 +24,7 @@ extern void set_color( int index, unsigned long color );
/* console.c */ -extern int console_draw_str( const char *str ); +extern int console_draw_fstr(const char *str, int len); extern void console_close( void );
/* pseudodisk.c */
Modified: trunk/openbios-devel/arch/ppc/pearpc/methods.c ============================================================================== --- trunk/openbios-devel/arch/ppc/pearpc/methods.c Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/arch/ppc/pearpc/methods.c Wed Sep 29 22:30:51 2010 (r872) @@ -70,16 +70,10 @@ { int len = POP(); char *addr = (char*)POP(); - char *s = malloc( len + 1 ); - - strncpy_nopad( s, addr, len ); - s[len]=0;
printk( "%s", s ); //vfd_draw_str( s ); - console_draw_str( s ); - - free( s ); + console_draw_fstr(addr, len);
PUSH( len ); }
Modified: trunk/openbios-devel/arch/ppc/pearpc/pearpc.h ============================================================================== --- trunk/openbios-devel/arch/ppc/pearpc/pearpc.h Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/arch/ppc/pearpc/pearpc.h Wed Sep 29 22:30:51 2010 (r872) @@ -19,7 +19,7 @@ extern int vfd_draw_str( const char *str ); extern void vfd_close( void );
-extern int console_draw_str( const char *str ); +extern int console_draw_fstr(const char *str, int len);
#include "kernel.h"
Modified: trunk/openbios-devel/arch/sparc32/console.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/console.c Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/arch/sparc32/console.c Wed Sep 29 22:30:51 2010 (r872) @@ -32,12 +32,11 @@
static void video_putchar(int c) { - char buf[2]; + char buf;
- buf[0] = c & 0xff; - buf[1] = 0; + buf = c & 0xff;
- console_draw_str(buf); + console_draw_fstr(&buf, 1); }
static void video_cls(void)
Modified: trunk/openbios-devel/arch/x86/xbox/methods.c ============================================================================== --- trunk/openbios-devel/arch/x86/xbox/methods.c Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/arch/x86/xbox/methods.c Wed Sep 29 22:30:51 2010 (r872) @@ -35,16 +35,10 @@ { int len = POP(); char *addr = (char*)POP(); - char *s = malloc( len + 1 ); - - strncpy_nopad( s, addr, len ); - s[len]=0;
printk( "%s", s ); //vfd_draw_str( s ); - console_draw_str( s ); - - free( s ); + console_draw_fstr(addr, len);
PUSH( len ); }
Modified: trunk/openbios-devel/include/libopenbios/console.h ============================================================================== --- trunk/openbios-devel/include/libopenbios/console.h Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/include/libopenbios/console.h Wed Sep 29 22:30:51 2010 (r872) @@ -2,7 +2,7 @@ #define VIDEO_CONSOLE_H
/* libopenbios/console_common.c */ -int console_draw_str(const char *str); +int console_draw_fstr(const char *str, int len); int console_init(void); void console_close(void);
Modified: trunk/openbios-devel/libopenbios/console_common.c ============================================================================== --- trunk/openbios-devel/libopenbios/console_common.c Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/libopenbios/console_common.c Wed Sep 29 22:30:51 2010 (r872) @@ -382,12 +382,12 @@ }
int -console_draw_str( const char *str ) +console_draw_fstr(const char *str, int len) { unsigned int y, x; unsigned char ch;
- if (!str) { + if (!str || len <= 0) { return 0; }
@@ -395,7 +395,7 @@ return -1;
show_cursor(0); - while( (ch=*str++) ) { + while((ch = *str++) && len--) { do_con_trol(ch);
if( cons.x >= cons.w ) {
Modified: trunk/openbios-devel/packages/video.c ============================================================================== --- trunk/openbios-devel/packages/video.c Wed Sep 29 20:34:41 2010 (r871) +++ trunk/openbios-devel/packages/video.c Wed Sep 29 22:30:51 2010 (r872) @@ -288,11 +288,10 @@ char *addr; int len;
- len = GETTOS(); - addr = pop_fstr_copy(); + len = POP(); + addr = (char *)POP();
- console_draw_str(addr); - free(addr); + console_draw_fstr(addr, len); PUSH(len); }