Skip to contentSkip to conversation

Linux Kernel Markers 0.8 for 2.6.17 (with near jump for i386)

PATCH In review Mathieu Desnoyers 3 participants 3 messages Sep 22, 2006 – Sep 25, 2006 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Linux Kernel Markers 0.8 for 2.6.17 (with near jump for i386)

Hi,

Here is a new version of the LKM. I added support for a near jump as an optimisation for i386. I guess that changing the one byte offset of the near jump instruction won't have any effect on the i386 erratas, anyone can confirm this ?

With this optimisation, the cost of this inactive marker shrinks from a memory load+far jump to a near jump.

Feel free to implement similar optimisations for other architectures.

Mathieu

---BEGIN---

arch/i386/Kconfig +2 -0
@@ -1082,6 +1082,8 @@ config KPROBES
 	  for kernel debugging, non-intrusive instrumentation and testing.
 	  If in doubt, say "N".
 
+source "kernel/Kconfig.marker"
+
 source "ltt/Kconfig"
 
 endmenu
include/asm-alpha/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-arm/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-arm26/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-cris/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-frv/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-generic/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-h8300/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-i386/marker.h new file +29 -0
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. i386 architecture optimisations.
+ *
+ * (C) Copyright 2006 Mathieu Desnoyers <[email protected]>
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
+#define ARCH_HAS_MARK_NEAR_JUMP
+
+/* Note : max 256 bytes between over_label and near_jump */
+#define MARK_DO_JUMP(name) \
+	do { \
+		__label__ near_jump_select; \
+		volatile static void *__mark_jump_select_##name \
+			asm (MARK_JUMP_SELECT_PREFIX#name) \
+			__attribute__((unused)) = &&near_jump_select; \
+		asm volatile (	".align 16;\n\t" : : ); \
+		asm volatile (	".byte 0xeb;\n\t" : : ); \
+near_jump_select: \
+		asm volatile (	".byte %0-%1;\n\t" : : \
+				"m" (*&&over_label), \
+				"m" (*&&call_label)); \
+call_label: \
+		asm volatile (	"" : : ); \
+	} while(0)
include/asm-ia64/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-m32r/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-m68k/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-m68knommu/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-mips/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-parisc/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-powerpc/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-ppc/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-ppc64/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-s390/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-sh/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-sh64/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-sparc/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-sparc64/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-um/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-v850/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-x86_64/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/asm-xtensa/marker.h new file +12 -0
@@ -0,0 +1,12 @@
+/*****************************************************************************
+ * marker.h
+ *
+ * Code markup for dynamic and static tracing. Architecture specific
+ * optimisations.
+ * 
+ * No optimisation implemented.
+ *
+ * This file is released under the GPLv2.
+ * See the file COPYING for more details.
+ */
+
include/linux/marker.h new file +132 -0

132 lines not on this page · raw message

kernel/Kconfig.marker new file +25 -0
@@ -0,0 +1,25 @@
+# Code markers configuration
+
+menu "Marker configuration"
+
+
+config MARK_SYMBOL
+	bool "Replace markers with symbols"
+	default n
+	help
+	  Put symbols in place of markers, useful for kprobe.
+
+config MARK_JUMP_CALL
+	bool "Replace markers with a jump over an inactive function call"
+	default n
+	help
+	  Put a jump over a call in place of markers.
+
+config MARK_JUMP
+	bool "Jump marker probes set/disable infrastructure"
+	select KALLSYMS
+	default n
+	help
+	  Install or remove probes from markers.
+
+endmenu

index 6844e18..1a01e5d 100644

kernel/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 obj-$(CONFIG_RELAY) += relay.o
+obj-$(CONFIG_MARK_JUMP) += marker.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/marker.c new file +161 -0

161 lines not on this page · raw message

---END---

---BEGIN---

/* probe.c
*
* Loads a function at a marker call site.
*
* (C) Copyright 2006 Mathieu Desnoyers <[email protected]> *
* This file is released under the GPLv2.
* See the file COPYING for more details.
*/

#include <linux/marker.h>
#include <linux/module.h>
#include <linux/kallsyms.h>

/* function to install */
#define DO_MARK1_FORMAT "%d"
asmlinkage void do_mark1(const char *format, int value)

{
	__mark_check_format(DO_MARK1_FORMAT, value);
	printk("value is %d\n", value);
}

#define DO_MARK2_FORMAT "%d %s"
asmlinkage void do_mark2(const char *format, int value, const char *string)

{
	__mark_check_format(DO_MARK2_FORMAT, value, string);
	printk("value is %d %s\n", value, string);
}

#define DO_MARK3_FORMAT "%d %s %s"
asmlinkage void do_mark3(const char *format, int value, const char *s1,
const char *s2)

{
	__mark_check_format(DO_MARK3_FORMAT, value, s1, s2);
	printk("value is %d %s %s\n", value, s1, s2);
}

int init_module(void)

{
	int result;
	result = marker_set_probe("subsys_mark1", DO_MARK1_FORMAT,
			(marker_probe_func*)do_mark1);
	if(result) goto end;
	result = marker_set_probe("subsys_mark2", DO_MARK2_FORMAT,
			(marker_probe_func*)do_mark2);
	if(result) goto cleanup1;
	result = marker_set_probe("subsys_mark3", DO_MARK3_FORMAT,
			(marker_probe_func*)do_mark3);
	if(result) goto cleanup2;

	return -result;

cleanup2:

	marker_disable_probe("subsys_mark2", (marker_probe_func*)do_mark2);
cleanup1:
	marker_disable_probe("subsys_mark1", (marker_probe_func*)do_mark1);
end:
	return -result;
}

void cleanup_module(void)

{
	marker_disable_probe("subsys_mark1", (marker_probe_func*)do_mark1);
	marker_disable_probe("subsys_mark2", (marker_probe_func*)do_mark2);
	marker_disable_probe("subsys_mark3", (marker_probe_func*)do_mark3);
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mathieu Desnoyers");
MODULE_DESCRIPTION("Probe");
---END---

---BEGIN---

/* test-mark.c
*
*/

#include <linux/marker.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>

volatile int x=7;

struct proc_dir_entry *pentry = NULL;

static int my_open(struct inode *inode, struct file *file)

{
	unsigned int i;

	for(i=0; i<2; i++) {
		MARK(subsys_mark1, "%d", 1);
		x=i;
		barrier();
	}
	MARK(subsys_mark2, "%d %s", 2, "blah2");
	MARK(subsys_mark3, "%d %s %s", x, "blah3", "blah5");

	return -EPERM;
}

static struct file_operations my_operations = {
.open = my_open,
};

int init_module(void)

{
	pentry = create_proc_entry("testmark", 0444, NULL);
	if (pentry)
		pentry->proc_fops = &my_operations;
	return 0;
}

void cleanup_module(void)

{
	remove_proc_entry("testmark", NULL);
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mathieu Desnoyers");
MODULE_DESCRIPTION("Marker Test");
---END---

OpenPGP public key:              http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint:     8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68 
#1 lore raw

arch/i386/Kconfig config KPROBES · line 1087

Quoted 9 lines · Mathieu Desnoyers
arch/i386/Kconfig +2 -0
@@ -1082,6 +1082,8 @@ config KPROBES
 	  for kernel debugging, non-intrusive instrumentation and testing.
 	  If in doubt, say "N".
 
+source "kernel/Kconfig.marker"
+
 source "ltt/Kconfig"

diffing against an LTT tree ...

Quoted 2 lines
include/asm-alpha/marker.h new file +0 -0

...

Quoted 2 lines
include/asm-arm/marker.h new file +0 -0

...

include/asm-arm26/marker.h

Quoted 2 lines
include/asm-arm26/marker.h new file +0 -0

...
...

Not sure about the need for asm-foo/marker.h if the file contains no code at all. If there's going to be one marker.h per arch, it might as well have a purpose. So instead of:

Quoted 2 lines
include/asm-i386/marker.h new file +0 -0

...

Quoted 1 line

+#define ARCH_HAS_MARK_NEAR_JUMP

and

Quoted 2 lines
include/linux/marker.h new file +0 -0

...

Quoted 1 line

+#ifndef ARCH_HAS_MARK_NEAR_JUMP

...

Why not just have asm-foo/marker.h either implement the optimization or point to an asm-generic/marker.h which contains the non-optimized code. No #ifndefs needed.

Quoted 2 lines
kernel/Kconfig.marker new file +0 -0

...

Quoted 1 line

+config MARK_SYMBOL

...

Quoted 1 line

+config MARK_JUMP_CALL

...

Quoted 1 line

+config MARK_JUMP

...

My understanding of Ingo's input is that he'd rather not have this multiple options. Either the markers are active or they aren't. So ...
MARK_ACTIVE ... speaks for itself, enables both the markers and the set/disable infrastructure. Markers are enabled in their optimized per-architecture implementation.

MARK_FORCE_DIRECT_CALL ... forces all markers to be non-optimized (good for embedded systems where the image is in rom/flash and can therefore not have runtime binary modifications.) Maybe this should depend on CONFIG_EMBEDDED.

Karim

Signature · 3 lines
President  / Opersys Inc.
Embedded Linux Training and Expertise
www.opersys.com  /  1.866.677.4546
#2 lore raw
Quoted 2 lines · * Karim Yaghmour ([email protected]) wrote:

diffing against an LTT tree ...

Ok, I will do the diff against a vanilla kernel, good point.

Quoted 25 lines
Quoted 2 lines
include/asm-alpha/marker.h new file +0 -0

...

Quoted 2 lines
include/asm-arm/marker.h new file +0 -0

...

include/asm-arm26/marker.h

Quoted 2 lines
include/asm-arm26/marker.h new file +0 -0

...
...

Not sure about the need for asm-foo/marker.h if the file contains no code at all. If there's going to be one marker.h per arch, it might as well have a purpose. So instead of:

Quoted 2 lines
include/asm-i386/marker.h new file +0 -0

...

Quoted 1 line

+#define ARCH_HAS_MARK_NEAR_JUMP

and

Quoted 2 lines
include/linux/marker.h new file +0 -0

...

Quoted 7 lines
Quoted 1 line

+#ifndef ARCH_HAS_MARK_NEAR_JUMP

...

Why not just have asm-foo/marker.h either implement the optimization or point to an asm-generic/marker.h which contains the non-optimized code. No #ifndefs needed.

Ok, good idea.

Quoted 17 lines
Quoted 2 lines
kernel/Kconfig.marker new file +0 -0

...

Quoted 1 line

+config MARK_SYMBOL

...

Quoted 1 line

+config MARK_JUMP_CALL

...

Quoted 1 line

+config MARK_JUMP

...

My understanding of Ingo's input is that he'd rather not have this multiple options. Either the markers are active or they aren't. So ...
MARK_ACTIVE ... speaks for itself, enables both the markers and the set/disable infrastructure. Markers are enabled in their optimized per-architecture implementation.

Quoted 6 lines

MARK_FORCE_DIRECT_CALL ... forces all markers to be non-optimized (good for embedded systems where the image is in rom/flash and can therefore not have runtime binary modifications.) Maybe this should depend on CONFIG_EMBEDDED.

Ok, now only :

CONFIG_MARKERS
and
CONFIG_MARKERS_FORCE_DIRECT_CALL (only appears is EMBEDDED is enabled)

I have rewritted almost everything else, I will post a patch soon (currently cleaning up). It now supports inline function, unrolled loops and multiple definitions of the same marker.

Supporting inline functions has proven more important than I first thought because of gcc 4.0+ optimisations where it takes a static-only function and inline it automatically in the body of the caller. It removes the symbols of the inlined function when it does that.

My new approach is a separate .markers section, everything is there.

Mathieu

OpenPGP public key:              http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint:     8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68