Update sched instrumentation to Linux 3.13
[lttng-modules.git] / instrumentation / events / lttng-module / sched.h
index 4d30fe3e1acbb2eb74bff3e2f9c64db1a31fa788..9e490cfe411a2ac03f6268e278939c9d0109e665 100644 (file)
@@ -8,11 +8,31 @@
 #include <linux/tracepoint.h>
 #include <linux/binfmts.h>
 #include <linux/version.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
+#include <linux/sched/rt.h>
+#endif
 
 #ifndef _TRACE_SCHED_DEF_
 #define _TRACE_SCHED_DEF_
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
+
+static inline long __trace_sched_switch_state(struct task_struct *p)
+{
+       long state = p->state;
+
+#ifdef CONFIG_PREEMPT
+       /*
+        * For all intents and purposes a preempted task is a running task.
+        */
+       if (task_preempt_count(p) & PREEMPT_ACTIVE)
+               state = TASK_RUNNING | TASK_STATE_MAX;
+#endif
+
+       return state;
+}
+
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
 
 static inline long __trace_sched_switch_state(struct task_struct *p)
 {
@@ -23,11 +43,24 @@ static inline long __trace_sched_switch_state(struct task_struct *p)
         * For all intents and purposes a preempted task is a running task.
         */
        if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
                state = TASK_RUNNING | TASK_STATE_MAX;
-#else
-               state = TASK_RUNNING;
 #endif
+
+       return state;
+}
+
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
+
+static inline long __trace_sched_switch_state(struct task_struct *p)
+{
+       long state = p->state;
+
+#ifdef CONFIG_PREEMPT
+       /*
+        * For all intents and purposes a preempted task is a running task.
+        */
+       if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
+               state = TASK_RUNNING;
 #endif
 
        return state;
@@ -327,7 +360,12 @@ TRACE_EVENT(sched_process_wait,
 )
 
 /*
- * Tracepoint for do_fork:
+ * Tracepoint for do_fork.
+ * Saving both TID and PID information, especially for the child, allows
+ * trace analyzers to distinguish between creation of a new process and
+ * creation of a new thread. Newly created processes will have child_tid
+ * == child_pid, while creation of a thread yields to child_tid !=
+ * child_pid.
  */
 TRACE_EVENT(sched_process_fork,
 
@@ -338,15 +376,19 @@ TRACE_EVENT(sched_process_fork,
        TP_STRUCT__entry(
                __array_text(   char,   parent_comm,    TASK_COMM_LEN   )
                __field(        pid_t,  parent_tid                      )
+               __field(        pid_t,  parent_pid                      )
                __array_text(   char,   child_comm,     TASK_COMM_LEN   )
                __field(        pid_t,  child_tid                       )
+               __field(        pid_t,  child_pid                       )
        ),
 
        TP_fast_assign(
                tp_memcpy(parent_comm, parent->comm, TASK_COMM_LEN)
                tp_assign(parent_tid, parent->pid)
+               tp_assign(parent_pid, parent->tgid)
                tp_memcpy(child_comm, child->comm, TASK_COMM_LEN)
                tp_assign(child_tid, child->pid)
+               tp_assign(child_pid, child->tgid)
        ),
 
        TP_printk("comm=%s tid=%d child_comm=%s child_tid=%d",
This page took 0.025155 seconds and 4 git commands to generate.