Clean up using global_dirty_limit wrapper for writeback probe
authorAndrew Gabbasov <andrew_gabbasov@mentor.com>
Tue, 2 Apr 2013 13:25:37 +0000 (09:25 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Apr 2013 13:25:37 +0000 (09:25 -0400)
Move the wrapper around reading of global_dirty_limit to /wrapper/
directory.  Introduce a new kallsyms_lookup_dataptr function for
obtaining the address unchanged and use it in global_dirty_limit
wrapper.  Since the data address is available only if
CONFIG_KALLSYMS_ALL is set, omit the whole probe from building if this
config is missing.

[ Edit by Mathieu Desnoyers: small coding style fixes ]

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
probes/Makefile
probes/lttng-probe-writeback.c
wrapper/kallsyms.h
wrapper/writeback.h [new file with mode: 0644]

index 088cd5f107c6403a697e2b918fd68013ba4f82d0..08adad5b125612ddf70185aa568f44b49b7b4d78 100644 (file)
@@ -189,10 +189,12 @@ endif
 
 obj-m += lttng-probe-workqueue.o
 
+ifneq ($(CONFIG_KALLSYMS_ALL),)
 obj-m +=  $(shell \
        if [ $(VERSION) -ge 3 \
                -o \( $(VERSION) -eq 2 -a $(PATCHLEVEL) -ge 6 -a $(SUBLEVEL) -ge 36 \) ] ; then \
                echo "lttng-probe-writeback.o" ; fi;)
+endif
 
 
 ifneq ($(CONFIG_KPROBES),)
index 0a5c0221de8ddfe7e49916e438783f77de211671..5e421e59f93d374aab483d8d6b977341bec7de4c 100644 (file)
 #include <trace/events/writeback.h>
 
 #include "../lttng-kernel-version.h"
+#include "../wrapper/writeback.h"
 
 /* #if <check version number if global_dirty_limit will be exported> */
-#ifdef CONFIG_KALLSYMS
-#include "../wrapper/kallsyms.h"
 
-static unsigned long *wrapper_global_dirty_limit_sym = 0;
-static inline
-unsigned long wrapper_global_dirty_limit(void)
-{
-       if (!wrapper_global_dirty_limit_sym)
-               wrapper_global_dirty_limit_sym =
-                       (void *)kallsyms_lookup_funcptr("global_dirty_limit");
-       if (wrapper_global_dirty_limit_sym)
-               return *wrapper_global_dirty_limit_sym;
-       else {
-               printk(KERN_WARNING "LTTng: global_dirty_limit symbol lookup failed.\n");
-               return 0;
-       }
-}
 #define global_dirty_limit wrapper_global_dirty_limit()
-#endif
+
 /* #endif <check version number> */
 
 /*
index f07788a04913ae2219a30edfb5102ac29f12e9ab..ad9e1f282060f9efa2f50969ad37fff0d6049a54 100644 (file)
@@ -42,4 +42,10 @@ unsigned long kallsyms_lookup_funcptr(const char *name)
 #endif
        return addr;
 }
+
+static inline
+unsigned long kallsyms_lookup_dataptr(const char *name)
+{
+       return kallsyms_lookup_name(name);
+}
 #endif /* _LTTNG_WRAPPER_KALLSYMS_H */
diff --git a/wrapper/writeback.h b/wrapper/writeback.h
new file mode 100644 (file)
index 0000000..492cb75
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef _LTTNG_WRAPPER_WRITEBACK_H
+#define _LTTNG_WRAPPER_WRITEBACK_H
+
+/*
+ * wrapper/writeback.h
+ *
+ * wrapper around global_dirty_limit read. Using KALLSYMS with KALLSYMS_ALL
+ * to get its address when available, else we need to have a kernel that
+ * exports this variable to GPL modules.
+ *
+ * Copyright (C) 2013 Mentor Graphics Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef CONFIG_KALLSYMS_ALL
+
+#include <linux/kallsyms.h>
+#include "kallsyms.h"
+
+static unsigned long *global_dirty_limit_sym;
+
+static inline
+unsigned long wrapper_global_dirty_limit(void)
+{
+       if (!global_dirty_limit_sym)
+               global_dirty_limit_sym =
+                       (void *) kallsyms_lookup_dataptr("global_dirty_limit");
+       if (global_dirty_limit_sym) {
+               return *global_dirty_limit_sym;
+       } else {
+               printk(KERN_WARNING "LTTng: global_dirty_limit symbol lookup failed.\n");
+               return 0;
+       }
+}
+
+#else
+
+#include <linux/writeback.h>
+
+static inline
+unsigned long wrapper_global_dirty_limit(void)
+{
+       return global_dirty_limit;
+}
+
+#endif
+
+#endif /* _LTTNG_WRAPPER_WRITEBACK_H */
This page took 0.02804 seconds and 4 git commands to generate.