Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 141008
b: refs/heads/master
c: cf027f6
h: refs/heads/master
v: v3
  • Loading branch information
Tom Zanussi authored and Ingo Molnar committed Mar 22, 2009
1 parent 729f942 commit e2d7d9a
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 46 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0a5d649018b151cb9331c213a843ac4a3e7e44ab
refs/heads/master: cf027f645e6aee4f0ca6197a6b6a57f327fdb13f
13 changes: 6 additions & 7 deletions trunk/Documentation/tracepoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ used to export the defined tracepoints.

* Probe / tracepoint example

See the example provided in samples/tracepoints
See the example provided in samples/tracepoints/src

Compile them with your kernel. They are built during 'make' (not
'make modules') when CONFIG_SAMPLE_TRACEPOINTS=m.
Compile them with your kernel.

Run, as root :
modprobe tracepoint-sample (insmod order is not important)
modprobe tracepoint-probe-sample
cat /proc/tracepoint-sample (returns an expected error)
rmmod tracepoint-sample tracepoint-probe-sample
modprobe tracepoint-example (insmod order is not important)
modprobe tracepoint-probe-example
cat /proc/tracepoint-example (returns an expected error)
rmmod tracepoint-example tracepoint-probe-example
dmesg
14 changes: 2 additions & 12 deletions trunk/kernel/extable.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,11 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/ftrace.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/init.h>

#include <asm/sections.h>
#include <linux/ftrace.h>
#include <asm/uaccess.h>

/*
* mutex protecting text section modification (dynamic code patching).
* some users need to sleep (allocating memory...) while they hold this lock.
*
* NOT exported to modules - patching kernel text is a really delicate matter.
*/
DEFINE_MUTEX(text_mutex);
#include <asm/sections.h>

extern struct exception_table_entry __start___ex_table[];
extern struct exception_table_entry __stop___ex_table[];
Expand Down
8 changes: 4 additions & 4 deletions trunk/kernel/trace/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
extern int ring_buffer_page_too_big(void);

#ifdef CONFIG_HOTPLUG_CPU
static int rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu);
static int __cpuinit rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu);
#endif

/**
Expand Down Expand Up @@ -2784,8 +2784,8 @@ static __init int rb_init_debugfs(void)
fs_initcall(rb_init_debugfs);

#ifdef CONFIG_HOTPLUG_CPU
static int rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
static int __cpuinit rb_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
{
struct ring_buffer *buffer =
container_of(self, struct ring_buffer, cpu_notify);
Expand Down
30 changes: 21 additions & 9 deletions trunk/kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,26 @@ enum {
TRACE_EVENT_TYPE_RAW = 2,
};

struct ftrace_event_field {
struct list_head link;
char *name;
char *type;
int offset;
int size;
};

struct ftrace_event_call {
char *name;
char *system;
struct dentry *dir;
int enabled;
int (*regfunc)(void);
void (*unregfunc)(void);
int id;
int (*raw_init)(void);
int (*show_format)(struct trace_seq *s);
char *name;
char *system;
struct dentry *dir;
int enabled;
int (*regfunc)(void);
void (*unregfunc)(void);
int id;
int (*raw_init)(void);
int (*show_format)(struct trace_seq *s);
int (*define_fields)(void);
struct list_head fields;

#ifdef CONFIG_EVENT_PROFILE
atomic_t profile_count;
Expand All @@ -793,6 +803,8 @@ struct ftrace_event_call {
#endif
};

int trace_define_field(struct ftrace_event_call *call, char *type,
char *name, int offset, int size);
void event_trace_printk(unsigned long ip, const char *fmt, ...);
extern struct ftrace_event_call __start_ftrace_events[];
extern struct ftrace_event_call __stop_ftrace_events[];
Expand Down
40 changes: 39 additions & 1 deletion trunk/kernel/trace/trace_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@

static DEFINE_MUTEX(event_mutex);

int trace_define_field(struct ftrace_event_call *call, char *type,
char *name, int offset, int size)
{
struct ftrace_event_field *field;

field = kmalloc(sizeof(*field), GFP_KERNEL);
if (!field)
goto err;
field->name = kstrdup(name, GFP_KERNEL);
if (!field->name)
goto err;
field->type = kstrdup(type, GFP_KERNEL);
if (!field->type)
goto err;
field->offset = offset;
field->size = size;
list_add(&field->link, &call->fields);

return 0;
err:
if (field) {
kfree(field->name);
kfree(field->type);
}
kfree(field);
return -ENOMEM;
}

static void ftrace_clear_events(void)
{
struct ftrace_event_call *call = (void *)__start_ftrace_events;
Expand Down Expand Up @@ -343,7 +371,8 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,

#undef FIELD
#define FIELD(type, name) \
#type, #name, offsetof(typeof(field), name), sizeof(field.name)
#type, "common_" #name, offsetof(typeof(field), name), \
sizeof(field.name)

static int trace_write_header(struct trace_seq *s)
{
Expand Down Expand Up @@ -581,6 +610,15 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events)
call->name);
}

if (call->define_fields) {
ret = call->define_fields();
if (ret < 0) {
pr_warning("Could not initialize trace point"
" events/%s\n", call->name);
return ret;
}
}

/* A trace may not want to export its format */
if (!call->show_format)
return 0;
Expand Down
45 changes: 45 additions & 0 deletions trunk/kernel/trace/trace_events_stage_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,48 @@ ftrace_format_##call(struct trace_seq *s) \
}

#include <trace/trace_event_types.h>

#undef __field
#define __field(type, item) \
ret = trace_define_field(event_call, #type, #item, \
offsetof(typeof(field), item), \
sizeof(field.item)); \
if (ret) \
return ret;

#undef __array
#define __array(type, item, len) \
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
offsetof(typeof(field), item), \
sizeof(field.item)); \
if (ret) \
return ret;

#define __common_field(type, item) \
ret = trace_define_field(event_call, #type, "common_" #item, \
offsetof(typeof(field.ent), item), \
sizeof(field.ent.item)); \
if (ret) \
return ret;

#undef TRACE_EVENT
#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
int \
ftrace_define_fields_##call(void) \
{ \
struct ftrace_raw_##call field; \
struct ftrace_event_call *event_call = &event_##call; \
int ret; \
\
__common_field(unsigned char, type); \
__common_field(unsigned char, flags); \
__common_field(unsigned char, preempt_count); \
__common_field(int, pid); \
__common_field(int, tgid); \
\
tstruct; \
\
return ret; \
}

#include <trace/trace_event_types.h>
2 changes: 2 additions & 0 deletions trunk/kernel/trace/trace_events_stage_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ static int ftrace_raw_init_event_##call(void) \
if (!id) \
return -ENODEV; \
event_##call.id = id; \
INIT_LIST_HEAD(&event_##call.fields); \
return 0; \
} \
\
Expand All @@ -264,6 +265,7 @@ __attribute__((section("_ftrace_events"))) event_##call = { \
.regfunc = ftrace_raw_reg_event_##call, \
.unregfunc = ftrace_raw_unreg_event_##call, \
.show_format = ftrace_format_##call, \
.define_fields = ftrace_define_fields_##call, \
_TRACE_PROFILE_INIT(call) \
}

Expand Down
8 changes: 8 additions & 0 deletions trunk/mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ int randomize_va_space __read_mostly =
2;
#endif

/*
* mutex protecting text section modification (dynamic code patching).
* some users need to sleep (allocating memory...) while they hold this lock.
*
* NOT exported to modules - patching kernel text is a really delicate matter.
*/
DEFINE_MUTEX(text_mutex);

static int __init disable_randmaps(char *s)
{
randomize_va_space = 0;
Expand Down
24 changes: 12 additions & 12 deletions trunk/samples/tracepoints/tracepoint-sample.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* tracepoint-sample.c
*
* Executes a tracepoint when /proc/tracepoint-sample is opened.
* Executes a tracepoint when /proc/tracepoint-example is opened.
*
* (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
*
Expand All @@ -16,7 +16,7 @@
DEFINE_TRACE(subsys_event);
DEFINE_TRACE(subsys_eventb);

struct proc_dir_entry *pentry_sample;
struct proc_dir_entry *pentry_example;

static int my_open(struct inode *inode, struct file *file)
{
Expand All @@ -32,25 +32,25 @@ static struct file_operations mark_ops = {
.open = my_open,
};

static int __init sample_init(void)
static int __init example_init(void)
{
printk(KERN_ALERT "sample init\n");
pentry_sample = proc_create("tracepoint-sample", 0444, NULL,
printk(KERN_ALERT "example init\n");
pentry_example = proc_create("tracepoint-example", 0444, NULL,
&mark_ops);
if (!pentry_sample)
if (!pentry_example)
return -EPERM;
return 0;
}

static void __exit sample_exit(void)
static void __exit example_exit(void)
{
printk(KERN_ALERT "sample exit\n");
remove_proc_entry("tracepoint-sample", NULL);
printk(KERN_ALERT "example exit\n");
remove_proc_entry("tracepoint-example", NULL);
}

module_init(sample_init)
module_exit(sample_exit)
module_init(example_init)
module_exit(example_exit)

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mathieu Desnoyers");
MODULE_DESCRIPTION("Tracepoint sample");
MODULE_DESCRIPTION("Tracepoint example");

0 comments on commit e2d7d9a

Please sign in to comment.