summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2007-01-30 19:18:06 +0000
committerhunt <hunt>2007-01-30 19:18:06 +0000
commiteaa5bbf4b8703e3794943f27d3fb9c1265dfd418 (patch)
tree354d34ca2b46ddd86f0f5de26345ce4fc753d6a9
parentd21d36c05265b136246ae2c4ee9b5a38af46f45c (diff)
downloadsystemtap-steved-eaa5bbf4b8703e3794943f27d3fb9c1265dfd418.tar.gz
systemtap-steved-eaa5bbf4b8703e3794943f27d3fb9c1265dfd418.tar.xz
systemtap-steved-eaa5bbf4b8703e3794943f27d3fb9c1265dfd418.zip
2007-01-30 Martin Hunt <hunt@redhat.com>
* io.c (_stp_vlog): Use dynamic percpu allocations instead of very wasteful static allocations. * print.c (_stp_print_init): Do percpu allocations for io.c. (_stp_print_cleanup): Free percpu allocations. * string.c (_stp_sprintf): Overflow check needed to be >= instead of >.
-rw-r--r--runtime/ChangeLog11
-rw-r--r--runtime/io.c22
-rw-r--r--runtime/print.c17
-rw-r--r--runtime/string.c2
4 files changed, 37 insertions, 15 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog
index 30acf19a..a4e8a7b4 100644
--- a/runtime/ChangeLog
+++ b/runtime/ChangeLog
@@ -1,4 +1,15 @@
2007-01-30 Martin Hunt <hunt@redhat.com>
+
+ * io.c (_stp_vlog): Use dynamic percpu allocations
+ instead of very wasteful static allocations.
+ * print.c (_stp_print_init): Do percpu allocations
+ for io.c.
+ (_stp_print_cleanup): Free percpu allocations.
+
+ * string.c (_stp_sprintf): Overflow check needed
+ to be >= instead of >.
+
+2007-01-30 Martin Hunt <hunt@redhat.com>
* alloc.c (_stp_alloc_percpu): Don't implement
our own; just call __alloc_percpu with appropriate args
diff --git a/runtime/io.c b/runtime/io.c
index 5ef88957..1483acfd 100644
--- a/runtime/io.c
+++ b/runtime/io.c
@@ -1,6 +1,6 @@
/* -*- linux-c -*-
* I/O for printing warnings, errors and debug messages
- * Copyright (C) 2005, 2006 Red Hat Inc.
+ * Copyright (C) 2005, 2006, 2007 Red Hat Inc.
*
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
@@ -23,23 +23,24 @@ void _stp_string_cat_cstr (String str1, const char *str2);
* @{
*/
-/** private buffer for _stp_log() */
-#define STP_LOG_BUF_LEN 2047
#define WARN_STRING "WARNING: "
#define ERR_STRING "ERROR: "
+enum code { INFO=0, WARN, ERROR, DBUG };
-static char _stp_lbuf[NR_CPUS][STP_LOG_BUF_LEN + 1];
+/** private buffer for _stp_log() */
+#define STP_LOG_BUF_LEN 256
-enum code { INFO=0, WARN, ERROR, DBUG };
+typedef char _stp_lbuf[STP_LOG_BUF_LEN];
+void *Stp_lbuf = NULL;
static void _stp_vlog (enum code type, const char *func, int line, const char *fmt, va_list args)
{
int num;
- char *buf = &_stp_lbuf[get_cpu()][0];
+ char *buf = per_cpu_ptr(Stp_lbuf, smp_processor_id());
int start = 0;
if (type == DBUG) {
- start = scnprintf(buf, STP_LOG_BUF_LEN, "\033[36m%s:%d:\033[0m ", func, line);
+ start = _stp_snprintf(buf, STP_LOG_BUF_LEN, "\033[36m%s:%d:\033[0m ", func, line);
} else if (type == WARN) {
strcpy (buf, WARN_STRING);
start = sizeof(WARN_STRING) - 1;
@@ -48,14 +49,14 @@ static void _stp_vlog (enum code type, const char *func, int line, const char *f
start = sizeof(ERR_STRING) - 1;
}
- num = vscnprintf (buf + start, STP_LOG_BUF_LEN - start, fmt, args);
+ num = _stp_vscnprintf (buf + start, STP_LOG_BUF_LEN - start - 1, fmt, args);
if (num + start) {
if (buf[num + start - 1] != '\n') {
buf[num + start] = '\n';
num++;
+ buf[num + start] = '\0';
}
- buf[num + start] = '\0';
-
+
if (type != DBUG)
_stp_write(STP_OOB_DATA, buf, start + num + 1);
else {
@@ -63,7 +64,6 @@ static void _stp_vlog (enum code type, const char *func, int line, const char *f
_stp_print_flush();
}
}
- put_cpu();
}
/** Logs Data.
diff --git a/runtime/print.c b/runtime/print.c
index d305dee8..8ddafab8 100644
--- a/runtime/print.c
+++ b/runtime/print.c
@@ -1,6 +1,6 @@
/* -*- linux-c -*-
* Print Functions
- * Copyright (C) 2005, 2006 Red Hat Inc.
+ * Copyright (C) 2005, 2006, 2007 Red Hat Inc.
*
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
@@ -12,8 +12,9 @@
#define _PRINT_C_
#include "string.h"
-#include "io.c"
#include "vsprintf.c"
+#include "io.c"
+
/** @file print.c
* Printing Functions.
@@ -50,12 +51,20 @@ typedef struct __stp_pbuf {
void *Stp_pbuf = NULL;
+/* create percpu print and io buffers */
int _stp_print_init (void)
{
Stp_pbuf = alloc_percpu(_stp_pbuf);
if (unlikely(Stp_pbuf == 0))
return -1;
- _stp_allocated_memory += sizeof(_stp_pbuf) * num_online_cpus();
+
+ /* now initialize IO buffer used in io.c */
+ Stp_lbuf = alloc_percpu(_stp_lbuf);
+ if (unlikely(Stp_lbuf == 0)) {
+ free_percpu(Stp_pbuf);
+ return -1;
+ }
+ _stp_allocated_memory += (sizeof(_stp_pbuf)+sizeof(_stp_lbuf)) * num_online_cpus();
return 0;
}
@@ -63,6 +72,8 @@ void _stp_print_cleanup (void)
{
if (Stp_pbuf)
free_percpu(Stp_pbuf);
+ if (Stp_lbuf)
+ free_percpu(Stp_lbuf);
}
/** Send the print buffer to the transport now.
diff --git a/runtime/string.c b/runtime/string.c
index 6615d741..b740c064 100644
--- a/runtime/string.c
+++ b/runtime/string.c
@@ -64,7 +64,7 @@ void _stp_sprintf (String str, const char *fmt, ...)
va_start(args, fmt);
num = _stp_vsnprintf(buf, size, fmt, args);
va_end(args);
- if (unlikely(num > size)) {
+ if (unlikely(num >= size)) {
/* overflowed the buffer */
if (pb->len == 0) {
/* A single print request exceeded the buffer size. */