[Click] [PATCH] Fix a problem of the click_chatter on smp linuxmodule.

Joonwoo Park joonwpark81 at gmail.com
Sat Sep 29 13:33:24 EDT 2007


Hi,
This patch fixes a problem of the click_chatter on smp linuxmodule.

-
 Signed-off-by: Joonwoo Park <joonwpark81 at gmail.com>

 linuxmodule/module.cc     |   24 ++++++++++++------------
 linuxmodule/modulepriv.hh |   20 +++++++++++++++-----
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/linuxmodule/module.cc b/linuxmodule/module.cc
index 2b181fb..e507496 100644
--- a/linuxmodule/module.cc
+++ b/linuxmodule/module.cc
@@ -143,22 +143,22 @@ KernelErrorHandler::log_line(const char *begin,
const char *end)
     begin += 9;

   // manipulate log buffer to prevent memory overflow
-  if (_pos + end - begin > LOGBUF_SIZ - 1 && _pos >= LOGBUF_SAVESIZ) {
-    memcpy(&_logbuf[0], &_logbuf[LOGBUF_SAVESIZ], _pos - LOGBUF_SAVESIZ);
-    _pos -= LOGBUF_SAVESIZ;
-    _generation++;
+  if (_pos[my_cpu] + end - begin > LOGBUF_SIZ - 1 && _pos[my_cpu] >=
LOGBUF_SAVESIZ) {
+    memcpy(&_logbuf[my_cpu][0], &_logbuf[my_cpu][LOGBUF_SAVESIZ],
_pos[my_cpu] - LOGBUF_SAVESIZ);
+    _pos[my_cpu] -= LOGBUF_SAVESIZ;
+    _generation[my_cpu]++;
   }
-  if (_pos + end - begin > LOGBUF_SIZ - 1) {
-    _pos = 0;
-    _generation += 2;
+  if (_pos[my_cpu] + end - begin > LOGBUF_SIZ - 1) {
+    _pos[my_cpu] = 0;
+    _generation[my_cpu] += 2;
   }
-  if (_pos + end - begin > LOGBUF_SIZ - 1)
+  if (_pos[my_cpu] + end - begin > LOGBUF_SIZ - 1)
     begin = end - (LOGBUF_SIZ - 1);

   // log line
-  memcpy(&_logbuf[_pos], begin, end - begin);
-  _pos += end - begin;
-  _logbuf[_pos++] = '\n';
+  memcpy(&_logbuf[my_cpu][_pos[my_cpu]], begin, end - begin);
+  _pos[my_cpu] += end - begin;
+  _logbuf[my_cpu][_pos[my_cpu]++] = '\n';
 }

 void
@@ -182,7 +182,7 @@ KernelErrorHandler::handle_text(Seriousness
seriousness, const String &message)
 inline String
 KernelErrorHandler::stable_string() const
 {
-  return String::stable_string(&_logbuf[0], &_logbuf[_pos]);
+  return String::stable_string(&_logbuf[my_cpu][0],
&_logbuf[my_cpu][_pos[my_cpu]]);
 }

 static String
diff --git a/linuxmodule/modulepriv.hh b/linuxmodule/modulepriv.hh
index ad79ffe..4fb9b98 100644
--- a/linuxmodule/modulepriv.hh
+++ b/linuxmodule/modulepriv.hh
@@ -33,17 +33,27 @@ CLICK_CXX_UNPROTECT

 class KernelErrorHandler : public BaseErrorHandler { public:

-  KernelErrorHandler()			: _pos(0), _generation(0) { }
+  KernelErrorHandler()
+  {
+    memset(&_pos, 0, sizeof(_pos));
+    memset(&_generation, 0, sizeof(_generation));
+  }
   void handle_text(Seriousness, const String &);
-  void clear_log()			{ _pos = 0; _generation += 2; }
+  void clear_log()
+  {
+    for (int i = 0; i < NR_CPUS; i++) {
+      _pos[i] = 0;
+      _generation[i] += 2;
+    }
+  }
   inline String stable_string() const;

  private:

   enum { LOGBUF_SIZ = 4096, LOGBUF_SAVESIZ = 2048 };
-  char _logbuf[LOGBUF_SIZ];
-  int _pos;
-  unsigned _generation;
+  char _logbuf[NR_CPUS][LOGBUF_SIZ];
+  int _pos[NR_CPUS];
+  unsigned _generation[NR_CPUS];
   void log_line(const char *begin, const char *end);

 };
-

Thanks.

Joonwoo Park (Jason Park)


More information about the click mailing list