2017-11-01 15:07:57 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
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"
|
|
|
|
|
|
2017-06-26 19:01:55 -07:00
|
|
|
#define RECORD_CMDLINE 1
|
|
|
|
|
#define RECORD_TGID 2
|
|
|
|
|
|
|
|
|
|
static int sched_cmdline_ref;
|
|
|
|
|
static int sched_tgid_ref;
|
2008-10-31 13:28:58 +01:00
|
|
|
static DEFINE_MUTEX(sched_register_mutex);
|
2009-07-29 18:00:29 +02:00
|
|
|
|
2008-05-12 21:20:51 +02:00
|
|
|
static void
|
2015-09-28 18:06:56 +02:00
|
|
|
probe_sched_switch(void *ignore, bool preempt,
|
|
|
|
|
struct task_struct *prev, struct task_struct *next)
|
2008-05-12 21:20:42 +02:00
|
|
|
{
|
2017-06-26 19:01:55 -07:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
|
|
flags = (RECORD_TGID * !!sched_tgid_ref) +
|
|
|
|
|
(RECORD_CMDLINE * !!sched_cmdline_ref);
|
2008-07-18 12:16:17 -04:00
|
|
|
|
2017-06-26 19:01:55 -07:00
|
|
|
if (!flags)
|
|
|
|
|
return;
|
|
|
|
|
tracing_record_taskinfo_sched_switch(prev, next, flags);
|
2008-05-12 21:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
2008-05-12 21:20:52 +02:00
|
|
|
static void
|
2015-06-09 11:13:36 +02:00
|
|
|
probe_sched_wakeup(void *ignore, struct task_struct *wakee)
|
2008-05-12 21:20:51 +02:00
|
|
|
{
|
2017-06-26 19:01:55 -07:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
|
|
flags = (RECORD_TGID * !!sched_tgid_ref) +
|
|
|
|
|
(RECORD_CMDLINE * !!sched_cmdline_ref);
|
2008-05-12 21:20:51 +02:00
|
|
|
|
2017-06-26 19:01:55 -07:00
|
|
|
if (!flags)
|
|
|
|
|
return;
|
|
|
|
|
tracing_record_taskinfo(current, flags);
|
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
|
|
|
}
|
|
|
|
|
|
2017-06-26 19:01:55 -07:00
|
|
|
static void tracing_start_sched_switch(int ops)
|
2008-05-12 21:21:10 +02:00
|
|
|
{
|
2017-06-26 19:01:55 -07:00
|
|
|
bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref);
|
2008-10-31 13:28:58 +01:00
|
|
|
mutex_lock(&sched_register_mutex);
|
2017-06-26 19:01:55 -07:00
|
|
|
|
|
|
|
|
switch (ops) {
|
|
|
|
|
case RECORD_CMDLINE:
|
|
|
|
|
sched_cmdline_ref++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECORD_TGID:
|
|
|
|
|
sched_tgid_ref++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sched_register && (sched_cmdline_ref || sched_tgid_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
|
|
|
}
|
|
|
|
|
|
2017-06-26 19:01:55 -07:00
|
|
|
static void tracing_stop_sched_switch(int ops)
|
2008-05-12 21:21:10 +02:00
|
|
|
{
|
2008-10-31 13:28:58 +01:00
|
|
|
mutex_lock(&sched_register_mutex);
|
2017-06-26 19:01:55 -07:00
|
|
|
|
|
|
|
|
switch (ops) {
|
|
|
|
|
case RECORD_CMDLINE:
|
|
|
|
|
sched_cmdline_ref--;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECORD_TGID:
|
|
|
|
|
sched_tgid_ref--;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sched_cmdline_ref && !sched_tgid_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)
|
|
|
|
|
{
|
2017-06-26 19:01:55 -07:00
|
|
|
tracing_start_sched_switch(RECORD_CMDLINE);
|
2008-05-22 11:49:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tracing_stop_cmdline_record(void)
|
|
|
|
|
{
|
2017-06-26 19:01:55 -07:00
|
|
|
tracing_stop_sched_switch(RECORD_CMDLINE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tracing_start_tgid_record(void)
|
|
|
|
|
{
|
|
|
|
|
tracing_start_sched_switch(RECORD_TGID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tracing_stop_tgid_record(void)
|
|
|
|
|
{
|
|
|
|
|
tracing_stop_sched_switch(RECORD_TGID);
|
2008-05-22 11:49:22 -04:00
|
|
|
}
|