Fix: update sched prev_state instrumentation for upstream kernel
[lttng-modules.git] / instrumentation / events / lttng-module / sched.h
index e5066afe3b55049a422afc7b944c601cdc61f9d6..95bf13cc72b44726049cf11a6299e35bcb12aa8b 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM sched
 
 #ifndef _TRACE_SCHED_DEF_
 #define _TRACE_SCHED_DEF_
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
+
+static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
+{
+        unsigned int state;
+
+#ifdef CONFIG_SCHED_DEBUG
+        BUG_ON(p != current);
+#endif /* CONFIG_SCHED_DEBUG */
+
+        /*
+         * Preemption ignores task state, therefore preempted tasks are always
+         * RUNNING (we will not have dequeued if state != RUNNING).
+         */
+        if (preempt)
+                return TASK_REPORT_MAX;
+
+        /*
+         * task_state_index() uses fls() and returns a value from 0-8 range.
+         * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
+         * it for left shift operation to get the correct task->state
+         * mapping.
+         */
+        state = task_state_index(p);
+
+        return state ? (1 << (state - 1)) : state;
+}
+
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0))
+
+static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
+{
+        unsigned int state;
+
+#ifdef CONFIG_SCHED_DEBUG
+        BUG_ON(p != current);
+#endif /* CONFIG_SCHED_DEBUG */
+
+        /*
+         * Preemption ignores task state, therefore preempted tasks are always
+         * RUNNING (we will not have dequeued if state != RUNNING).
+         */
+        if (preempt)
+                return TASK_REPORT_MAX;
+
+        /*
+         * __get_task_state() uses fls() and returns a value from 0-8 range.
+         * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
+         * it for left shift operation to get the correct task->state
+         * mapping.
+         */
+        state = __get_task_state(p);
+
+        return state ? (1 << (state - 1)) : state;
+}
+
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
 
 static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
 {
@@ -146,7 +203,13 @@ LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret,
  * Tracepoint for waking up a task:
  */
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
-       LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0))
+       LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template,
 
        TP_PROTO(struct task_struct *p),
@@ -186,7 +249,13 @@ LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template,
 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
-       LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0))
+       LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
 
 /*
  * Tracepoint called when waking a task; this tracepoint is guaranteed to be
@@ -540,7 +609,27 @@ LTTNG_TRACEPOINT_EVENT(sched_stat_runtime,
 )
 #endif
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) || \
+       LTTNG_RT_KERNEL_RANGE(4,9,27,18, 4,10,0,0) || \
+       LTTNG_RT_KERNEL_RANGE(4,11,5,1, 4,12,0,0))
+/*
+ * Tracepoint for showing priority inheritance modifying a tasks
+ * priority.
+ */
+LTTNG_TRACEPOINT_EVENT(sched_pi_setprio,
+
+       TP_PROTO(struct task_struct *tsk, struct task_struct *pi_task),
+
+       TP_ARGS(tsk, pi_task),
+
+       TP_FIELDS(
+               ctf_array_text(char, comm, tsk->comm, TASK_COMM_LEN)
+               ctf_integer(pid_t, tid, tsk->pid)
+               ctf_integer(int, oldprio, tsk->prio - MAX_RT_PRIO)
+               ctf_integer(int, newprio, pi_task ? pi_task->prio - MAX_RT_PRIO : tsk->prio - MAX_RT_PRIO)
+       )
+)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
 /*
  * Tracepoint for showing priority inheritance modifying a tasks
  * priority.
This page took 0.02382 seconds and 4 git commands to generate.