nohz_tests: Initial version

Let's say, Nohz tests 0.0.1 ?

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..98cae6a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+all:
+	gcc user_loop.c -o user_loop
diff --git a/README b/README
new file mode 100644
index 0000000..f471bdc
--- /dev/null
+++ b/README
@@ -0,0 +1,14 @@
+Make sure CPU 1 is full dynticks (it must be in the "nohz_full=" boot parameter
+cpu mask).
+
+To run:
+	$ make
+	# ./run
+
+Look at the resulting trace in trace.1
+hrtimer events should report you the tick events (unless you haven't
+CONFIG_HRTIMER=y) and tick_stop events tell you what's going on with full dynticks
+behaviour.
+
+trace.1.example shows an example of a successful full dynticks behaviour. The
+tick got mostly stopped during the execution of the user loop.
diff --git a/run b/run
new file mode 100755
index 0000000..b461fc8
--- /dev/null
+++ b/run
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+NR_CPUS=$(getconf  _NPROCESSORS_ONLN)
+
+# Migrate nocb tasks to CPU 0
+# Beware, this assume that there is no online CPU > NR_CPUS
+for CPU in $(seq $(($NR_CPUS-1)))
+do
+	PIDS=$(ps -o pid= -C rcuob/$CPU,rcuos/$CPU,rcuop/$CPU)
+	for PID in $PIDS
+	do
+		taskset -cp 0 $PID
+	done
+
+done
+
+# Migrate irqs to CPU 0
+for D in $(ls /proc/irq)
+do
+	if [[ -x "/proc/irq/$D" && $D != "0" ]]
+	then
+		echo $D
+		echo 1 > /proc/irq/$D/smp_affinity
+	fi
+done
+
+# Delay the annoying vmstat timer far away
+sysctl vm.stat_interval=120
+
+# Shutdown nmi watchdog as it uses perf events
+sysctl -w kernel.watchdog=0
+
+DIR=/sys/kernel/debug/tracing
+echo > $DIR/trace
+echo 0 > $DIR/tracing_on
+# Uncomment the below for more details on what disturbs the CPU
+#echo 0 > $DIR/events/irq/enable
+#echo 1 > $DIR/events/sched/sched_switch/enable
+#echo 1 > $DIR/events/workqueue/workqueue_queue_work/enable
+echo 1 > $DIR/events/workqueue/workqueue_execute_start/enable
+echo 1 > $DIR/events/timer/hrtimer_expire_entry/enable
+echo 1 > $DIR/events/timer/tick_stop/enable
+echo nop > $DIR/current_tracer
+echo 1 > $DIR/tracing_on
+
+# Run a 10 secs user loop on CPU 1
+taskset -c 1 ./user_loop &
+sleep 10
+killall user_loop
+
+# Checkout the trace in trace.1
+cat /sys/kernel/debug/tracing/per_cpu/cpu1/trace > trace.1
diff --git a/trace.1.example b/trace.1.example
new file mode 100644
index 0000000..5159dea
--- /dev/null
+++ b/trace.1.example
@@ -0,0 +1,25 @@
+# tracer: nop
+#
+# entries-in-buffer/entries-written: 1128/1128   #P:4
+#
+#                              _-----=> irqs-off
+#                             / _----=> need-resched
+#                            | / _---=> hardirq/softirq
+#                            || / _--=> preempt-depth
+#                            ||| /     delay
+#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
+#              | |       |   ||||       |         |
+       user_loop-1176  [001] d.h1   148.052583: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=147800006870
+       user_loop-1176  [001] d..1   148.052604: tick_stop: success=yes msg= 
+       user_loop-1176  [001] d.h1   149.051973: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=148800001673
+       user_loop-1176  [001] d.h1   149.751554: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=149500003663
+       user_loop-1176  [001] d.h1   150.750949: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=150500001115
+       user_loop-1176  [001] d.h1   151.750347: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=151500001116
+       user_loop-1176  [001] d.h1   152.749745: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=152500001109
+       user_loop-1176  [001] d.h1   153.749143: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=153500001188
+       user_loop-1176  [001] d.h1   154.748540: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=154500001048
+       user_loop-1176  [001] d.h1   155.747938: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=155500001120
+       user_loop-1176  [001] d.h1   156.747336: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=156500001196
+       user_loop-1176  [001] d.h1   157.746734: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=157500001219
+           <...>-1179  [001] d.h1   158.076540: hrtimer_expire_entry: hrtimer=ffff880107c8d500 function=tick_sched_timer now=157830004100
+           <...>-1179  [001] d..1   158.076560: tick_stop: success=yes msg= 
diff --git a/user_loop.c b/user_loop.c
new file mode 100644
index 0000000..3cdc4f3
--- /dev/null
+++ b/user_loop.c
@@ -0,0 +1,7 @@
+int main(void)
+{
+	while (1);
+
+
+	return 0;
+}