Whamcloud - gitweb
b=18498
authormaxim <maxim>
Sat, 30 May 2009 14:51:51 +0000 (14:51 +0000)
committermaxim <maxim>
Sat, 30 May 2009 14:51:51 +0000 (14:51 +0000)
i=nikita
i=shadow
Minor fix to calculate index for trace_get_tcd() and
trace_get_console_buffer() correctly.

libcfs/include/libcfs/winnt/kp30.h
libcfs/libcfs/autoMakefile.am
libcfs/libcfs/linux/linux-tracefile.c
libcfs/libcfs/linux/linux-tracefile.h [new file with mode: 0644]
libcfs/libcfs/tracefile.h
libcfs/libcfs/winnt/winnt-tracefile.c
libcfs/libcfs/winnt/winnt-tracefile.h [new file with mode: 0644]

index 940bf48..f2293ab 100644 (file)
@@ -92,6 +92,14 @@ void libcfs_unregister_panic_notifier();
 
 #define cfs_assert     _ASSERT
 
+#ifndef get_cpu
+#define cfs_get_cpu() smp_processor_id()
+#define cfs_put_cpu() do { } while (0)
+#else
+#define cfs_get_cpu() get_cpu()
+#define cfs_put_cpu() put_cpu()
+#endif
+
 #endif /* End of !__KERNEL__ */
 
 /******************************************************************************/
index 9b6e59e..92d1618 100644 (file)
@@ -87,4 +87,4 @@ EXTRA_DIST := Info.plist
 MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ linux-*.c linux/*.o darwin/*.o libcfs
 DIST_SOURCES := $(libcfs-all-objs:%.o=%.c) tracefile.h user-prim.c \
                                            user-lock.c user-tcpip.c user-bitops.c\
-                                           user-mem.c
+                                           user-mem.c linux/linux-tracefile.h
index 78d0d8a..392e972 100644 (file)
 #include <libcfs/libcfs.h>
 #include "tracefile.h"
 
-/* three types of trace_data in linux */
-enum {
-       TCD_TYPE_PROC = 0,
-       TCD_TYPE_SOFTIRQ,
-       TCD_TYPE_IRQ,
-       TCD_TYPE_MAX
-};
-
 /* percents to share the total debug memory for each type */
 static unsigned int pages_factor[TCD_TYPE_MAX] = {
        80,  /* 80% pages for TCD_TYPE_PROC */
@@ -55,7 +47,7 @@ static unsigned int pages_factor[TCD_TYPE_MAX] = {
        10   /* 10% pages for TCD_TYPE_IRQ */
 };
 
-char *trace_console_buffers[NR_CPUS][3];
+char *trace_console_buffers[NR_CPUS][TCD_TYPE_MAX];
 
 struct rw_semaphore tracefile_sem;
 
@@ -144,54 +136,15 @@ void tracefile_write_unlock()
        up_write(&tracefile_sem);
 }
 
-char *
-trace_get_console_buffer(void)
-{
-       int  cpu = cfs_get_cpu();
-       int  idx;
-
-       if (in_irq()) {
-               idx = 0;
-       } else if (in_softirq()) {
-               idx = 1;
-       } else {
-               idx = 2;
-       }
-
-       return trace_console_buffers[cpu][idx];
-}
-
-void
-trace_put_console_buffer(char *buffer)
-{
-       cfs_put_cpu();
-}
-
-struct trace_cpu_data *
-trace_get_tcd(void)
+trace_buf_type_t
+trace_buf_idx_get()
 {
-       struct trace_cpu_data *tcd;
-       int cpu;
-
-       cpu = cfs_get_cpu();
        if (in_irq())
-               tcd = &(*trace_data[TCD_TYPE_IRQ])[cpu].tcd;
+               return TCD_TYPE_IRQ;
        else if (in_softirq())
-               tcd = &(*trace_data[TCD_TYPE_SOFTIRQ])[cpu].tcd;
+               return TCD_TYPE_SOFTIRQ;
        else
-               tcd = &(*trace_data[TCD_TYPE_PROC])[cpu].tcd;
-
-       trace_lock_tcd(tcd);
-
-       return tcd;
-}
-
-void
-trace_put_tcd (struct trace_cpu_data *tcd)
-{
-       trace_unlock_tcd(tcd);
-
-       cfs_put_cpu();
+               return TCD_TYPE_PROC;
 }
 
 int trace_lock_tcd(struct trace_cpu_data *tcd)
diff --git a/libcfs/libcfs/linux/linux-tracefile.h b/libcfs/libcfs/linux/linux-tracefile.h
new file mode 100644 (file)
index 0000000..bdefc31
--- /dev/null
@@ -0,0 +1,50 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#ifndef __LIBCFS_LINUX_TRACEFILE_H__
+#define __LIBCFS_LINUX_TRACEFILE_H__
+
+/**
+ * three types of trace_data in linux
+ */
+typedef enum {
+       TCD_TYPE_PROC = 0,
+       TCD_TYPE_SOFTIRQ,
+       TCD_TYPE_IRQ,
+       TCD_TYPE_MAX
+} trace_buf_type_t;
+
+#endif
index a857fb5..6bfdaaf 100644 (file)
 
 #include <libcfs/libcfs.h>
 
+#if defined(__linux__)
+#include "linux/linux-tracefile.h"
+#elif defined(__WINNT__)
+#include "winnt/winnt-tracefile.h"
+#else
+#error Unsupported operating system.
+#endif
+
 /* trace file lock routines */
 
 #define TRACEFILE_NAME_SIZE 1024
@@ -256,12 +264,51 @@ extern void set_ptldebug_header(struct ptldebug_header *header,
 extern void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
                             int len, const char *file, const char *fn);
 
-extern struct trace_cpu_data *trace_get_tcd(void);
-extern void trace_put_tcd(struct trace_cpu_data *tcd);
 extern int trace_lock_tcd(struct trace_cpu_data *tcd);
 extern void trace_unlock_tcd(struct trace_cpu_data *tcd);
-extern char *trace_get_console_buffer(void);
-extern void trace_put_console_buffer(char *buffer);
+
+/**
+ * trace_buf_type_t, trace_buf_idx_get() and trace_console_buffers[][]
+ * are not public libcfs API; they should be defined in
+ * platform-specific tracefile include files
+ * (see, for example, linux-tracefile.h).
+ */
+
+extern char *trace_console_buffers[NR_CPUS][TCD_TYPE_MAX];
+extern trace_buf_type_t trace_buf_idx_get(void);
+
+static inline char *
+trace_get_console_buffer(void)
+{
+        return trace_console_buffers[cfs_get_cpu()][trace_buf_idx_get()];
+}
+
+static inline void
+trace_put_console_buffer(char *buffer)
+{
+        cfs_put_cpu();
+}
+
+extern union trace_data_union (*trace_data[TCD_MAX_TYPES])[NR_CPUS];
+
+static inline struct trace_cpu_data *
+trace_get_tcd(void)
+{
+       struct trace_cpu_data *tcd =
+                &(*trace_data[trace_buf_idx_get()])[cfs_get_cpu()].tcd;
+
+       trace_lock_tcd(tcd);
+
+       return tcd;
+}
+
+static inline void
+trace_put_tcd (struct trace_cpu_data *tcd)
+{
+       trace_unlock_tcd(tcd);
+
+       cfs_put_cpu();
+}
 
 int trace_refill_stock(struct trace_cpu_data *tcd, int gfp,
                       struct list_head *stock);
index 51f70a7..fb29c1d 100644 (file)
 #include <libcfs/libcfs.h>
 #include "tracefile.h"
 
-#ifndef get_cpu
-#define get_cpu() smp_processor_id()
-#define put_cpu() do { } while (0)
-#endif
-
-/* only define one trace_data type for windows */
-enum {
-        TCD_TYPE_PASSIVE = 0,
-        TCD_TYPE_DISPATCH,
-        TCD_TYPE_MAX
-};
-
 /* percents to share the total debug memory for each type */
 static unsigned int pages_factor[TCD_TYPE_MAX] = {
         90,  /* 90% pages for TCD_TYPE_PASSIVE */
@@ -147,42 +135,13 @@ void tracefile_write_unlock()
        up_write(&tracefile_sem);
 }
 
-char *
-trace_get_console_buffer(void)
+trace_buf_type_t
+trace_buf_idx_get()
 {
-        int cpu  = get_cpu();
-        int type = 0;
-        
         if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
-                type = TCD_TYPE_DISPATCH;
+                return TCD_TYPE_DISPATCH;
         else
-                type = TCD_TYPE_PASSIVE;
-       return trace_console_buffers[cpu][type];
-}
-
-void
-trace_put_console_buffer(char *buffer)
-{
-       put_cpu();
-}
-
-struct trace_cpu_data *
-trace_get_tcd(void)
-{
-        int cpu  = get_cpu();
-        int type = 0;
-        
-        if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
-                type = TCD_TYPE_DISPATCH;
-        else
-                type = TCD_TYPE_PASSIVE;
-       return &(*trace_data[type])[cpu].tcd;
-}
-
-void
-trace_put_tcd (struct trace_cpu_data *tcd)
-{
-       put_cpu();
+                return TCD_TYPE_PASSIVE;
 }
 
 int trace_lock_tcd(struct trace_cpu_data *tcd)
diff --git a/libcfs/libcfs/winnt/winnt-tracefile.h b/libcfs/libcfs/winnt/winnt-tracefile.h
new file mode 100644 (file)
index 0000000..63772ef
--- /dev/null
@@ -0,0 +1,49 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#ifndef __LIBCFS_WINNT_TRACEFILE_H__
+#define __LIBCFS_WINNT_TRACEFILE_H__
+
+/**
+ * only define one trace_data type for windows
+ */
+typedef enum {
+        TCD_TYPE_PASSIVE = 0,
+        TCD_TYPE_DISPATCH,
+        TCD_TYPE_MAX
+} trace_buf_type_t;
+
+#endif