2008-05-12 21:20:42 +02:00
|
|
|
/*
|
|
|
|
|
* trace context switch
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
#include <linux/ftrace.h>
|
2009-04-14 19:39:12 -04:00
|
|
|
#include <trace/events/sched.h>
|
2008-05-12 21:20:42 +02:00
|
|
|
|
|
|
|
|
#include "trace.h"
|
|
|
|
|
|
2008-10-31 13:28:58 +01:00
|
|
|
static int sched_ref;
|
|
|
|
|
static DEFINE_MUTEX(sched_register_mutex);
|
2009-07-29 18:00:29 +02:00
|
|
|
|
2008-05-12 21:20:51 +02:00
|
|
|
static void
|
2010-04-20 17:04:50 -04:00
|
|
|
probe_sched_switch(void *ignore, struct task_struct *prev, struct task_struct *next)
|
2008-05-12 21:20:42 +02:00
|
|
|
{
|
2009-03-31 15:26:14 +08:00
|
|
|
if (unlikely(!sched_ref))
|
2008-07-18 12:16:17 -04:00
|
|
|
return;
|
|
|
|
|
|
2008-05-22 11:49:22 -04:00
|
|
|
tracing_record_cmdline(prev);
|
|
|
|
|
tracing_record_cmdline(next);
|
2008-05-12 21:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
2008-05-12 21:20:52 +02:00
|
|
|
static void
|
2010-04-20 17:04:50 -04:00
|
|
|
probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success)
|
2008-05-12 21:20:51 +02:00
|
|
|
{
|
2009-03-31 15:26:14 +08:00
|
|
|
if (unlikely(!sched_ref))
|
2008-05-12 21:20:51 +02:00
|
|
|
return;
|
|
|
|
|
|
2008-07-18 12:16:17 -04:00
|
|
|
tracing_record_cmdline(current);
|
2008-05-12 21:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
2008-05-12 21:21:10 +02:00
|
|
|
static int tracing_sched_register(void)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
2010-04-20 17:04:50 -04:00
|
|
|
ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
|
2008-05-12 21:21:10 +02:00
|
|
|
if (ret) {
|
2008-07-18 12:16:17 -04:00
|
|
|
pr_info("wakeup trace: Couldn't activate tracepoint"
|
2008-05-12 21:21:10 +02:00
|
|
|
" probe to kernel_sched_wakeup\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:04:50 -04:00
|
|
|
ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
|
2008-05-12 21:21:10 +02:00
|
|
|
if (ret) {
|
2008-07-18 12:16:17 -04:00
|
|
|
pr_info("wakeup trace: Couldn't activate tracepoint"
|
2008-05-12 21:21:10 +02:00
|
|
|
" probe to kernel_sched_wakeup_new\n");
|
|
|
|
|
goto fail_deprobe;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:04:50 -04:00
|
|
|
ret = register_trace_sched_switch(probe_sched_switch, NULL);
|
2008-05-12 21:21:10 +02:00
|
|
|
if (ret) {
|
2008-07-18 12:16:17 -04:00
|
|
|
pr_info("sched trace: Couldn't activate tracepoint"
|
2009-02-17 01:10:02 -05:00
|
|
|
" probe to kernel_sched_switch\n");
|
2008-05-12 21:21:10 +02:00
|
|
|
goto fail_deprobe_wake_new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
fail_deprobe_wake_new:
|
2010-04-20 17:04:50 -04:00
|
|
|
unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
|
2008-05-12 21:21:10 +02:00
|
|
|
fail_deprobe:
|
2010-04-20 17:04:50 -04:00
|
|
|
unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
|
2008-05-12 21:21:10 +02:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracing_sched_unregister(void)
|
|
|
|
|
{
|
2010-04-20 17:04:50 -04:00
|
|
|
unregister_trace_sched_switch(probe_sched_switch, NULL);
|
|
|
|
|
unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
|
|
|
|
|
unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
|
2008-05-12 21:21:10 +02:00
|
|
|
}
|
|
|
|
|
|
2008-05-22 10:37:48 +02:00
|
|
|
static void tracing_start_sched_switch(void)
|
2008-05-12 21:21:10 +02:00
|
|
|
{
|
2008-10-31 13:28:58 +01:00
|
|
|
mutex_lock(&sched_register_mutex);
|
2008-11-07 22:36:02 -05:00
|
|
|
if (!(sched_ref++))
|
2008-05-12 21:21:10 +02:00
|
|
|
tracing_sched_register();
|
2008-10-31 13:28:58 +01:00
|
|
|
mutex_unlock(&sched_register_mutex);
|
2008-05-12 21:21:10 +02:00
|
|
|
}
|
|
|
|
|
|
2008-05-22 10:37:48 +02:00
|
|
|
static void tracing_stop_sched_switch(void)
|
2008-05-12 21:21:10 +02:00
|
|
|
{
|
2008-10-31 13:28:58 +01:00
|
|
|
mutex_lock(&sched_register_mutex);
|
2008-11-07 22:36:02 -05:00
|
|
|
if (!(--sched_ref))
|
2008-05-12 21:21:10 +02:00
|
|
|
tracing_sched_unregister();
|
2008-10-31 13:28:58 +01:00
|
|
|
mutex_unlock(&sched_register_mutex);
|
2008-05-12 21:21:10 +02:00
|
|
|
}
|
|
|
|
|
|
2008-05-22 11:49:22 -04:00
|
|
|
void tracing_start_cmdline_record(void)
|
|
|
|
|
{
|
|
|
|
|
tracing_start_sched_switch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tracing_stop_cmdline_record(void)
|
|
|
|
|
{
|
|
|
|
|
tracing_stop_sched_switch();
|
|
|
|
|
}
|