From: Andrew Gabbasov Date: Tue, 2 Apr 2013 13:25:37 +0000 (-0400) Subject: Clean up using global_dirty_limit wrapper for writeback probe X-Git-Tag: v2.2.0-rc2~9 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=42d9070d001d2e641a3f1c27b1d613cdaeec3d58;p=lttng-modules.git Clean up using global_dirty_limit wrapper for writeback probe 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/probes/Makefile b/probes/Makefile index 088cd5f1..08adad5b 100644 --- a/probes/Makefile +++ b/probes/Makefile @@ -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),) diff --git a/probes/lttng-probe-writeback.c b/probes/lttng-probe-writeback.c index 0a5c0221..5e421e59 100644 --- a/probes/lttng-probe-writeback.c +++ b/probes/lttng-probe-writeback.c @@ -32,27 +32,12 @@ #include #include "../lttng-kernel-version.h" +#include "../wrapper/writeback.h" /* #if */ -#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 */ /* diff --git a/wrapper/kallsyms.h b/wrapper/kallsyms.h index f07788a0..ad9e1f28 100644 --- a/wrapper/kallsyms.h +++ b/wrapper/kallsyms.h @@ -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 index 00000000..492cb75f --- /dev/null +++ b/wrapper/writeback.h @@ -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 +#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 + +static inline +unsigned long wrapper_global_dirty_limit(void) +{ + return global_dirty_limit; +} + +#endif + +#endif /* _LTTNG_WRAPPER_WRITEBACK_H */