ALSA: pcm: Fix missing check of the new non-cached buffer type
[linux-2.6-block.git] / kernel / trace / preemptirq_delay_test.c
CommitLineData
f96e8577
JFG
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Preempt / IRQ disable delay thread to test latency tracers
4 *
5 * Copyright (C) 2018 Joel Fernandes (Google) <joel@joelfernandes.org>
6 */
7
12ad0cb2 8#include <linux/trace_clock.h>
f96e8577
JFG
9#include <linux/delay.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
12#include <linux/kernel.h>
13#include <linux/kthread.h>
f96e8577
JFG
14#include <linux/module.h>
15#include <linux/printk.h>
16#include <linux/string.h>
17
18static ulong delay = 100;
19static char test_mode[10] = "irq";
20
21module_param_named(delay, delay, ulong, S_IRUGO);
22module_param_string(test_mode, test_mode, 10, S_IRUGO);
23MODULE_PARM_DESC(delay, "Period in microseconds (100 uS default)");
24MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt or irq (default irq)");
25
26static void busy_wait(ulong time)
27{
12ad0cb2
SRV
28 u64 start, end;
29 start = trace_clock_local();
f96e8577 30 do {
12ad0cb2 31 end = trace_clock_local();
f96e8577
JFG
32 if (kthread_should_stop())
33 break;
12ad0cb2 34 } while ((end - start) < (time * 1000));
f96e8577
JFG
35}
36
518eeca0 37static int preemptirq_delay_run(void *data)
f96e8577
JFG
38{
39 unsigned long flags;
40
41 if (!strcmp(test_mode, "irq")) {
42 local_irq_save(flags);
43 busy_wait(delay);
44 local_irq_restore(flags);
45 } else if (!strcmp(test_mode, "preempt")) {
46 preempt_disable();
47 busy_wait(delay);
48 preempt_enable();
49 }
50
51 return 0;
52}
53
54static int __init preemptirq_delay_init(void)
55{
56 char task_name[50];
57 struct task_struct *test_task;
58
59 snprintf(task_name, sizeof(task_name), "%s_test", test_mode);
60
61 test_task = kthread_run(preemptirq_delay_run, NULL, task_name);
62 return PTR_ERR_OR_ZERO(test_task);
63}
64
65static void __exit preemptirq_delay_exit(void)
66{
67 return;
68}
69
70module_init(preemptirq_delay_init)
71module_exit(preemptirq_delay_exit)
72MODULE_LICENSE("GPL v2");