]>
Commit | Line | Data |
---|---|---|
fa86ee90 MT |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* | |
3 | * cpuidle driver for haltpoll governor. | |
4 | * | |
5 | * Copyright 2019 Red Hat, Inc. and/or its affiliates. | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
8 | * the COPYING file in the top-level directory. | |
9 | * | |
10 | * Authors: Marcelo Tosatti <mtosatti@redhat.com> | |
11 | */ | |
12 | ||
13 | #include <linux/init.h> | |
14 | #include <linux/cpuidle.h> | |
15 | #include <linux/module.h> | |
16 | #include <linux/sched/idle.h> | |
17 | #include <linux/kvm_para.h> | |
18 | ||
19 | static int default_enter_idle(struct cpuidle_device *dev, | |
20 | struct cpuidle_driver *drv, int index) | |
21 | { | |
22 | if (current_clr_polling_and_test()) { | |
23 | local_irq_enable(); | |
24 | return index; | |
25 | } | |
26 | default_idle(); | |
27 | return index; | |
28 | } | |
29 | ||
30 | static struct cpuidle_driver haltpoll_driver = { | |
31 | .name = "haltpoll", | |
32 | .owner = THIS_MODULE, | |
33 | .states = { | |
34 | { /* entry 0 is for polling */ }, | |
35 | { | |
36 | .enter = default_enter_idle, | |
37 | .exit_latency = 1, | |
38 | .target_residency = 1, | |
39 | .power_usage = -1, | |
40 | .name = "haltpoll idle", | |
41 | .desc = "default architecture idle", | |
42 | }, | |
43 | }, | |
44 | .safe_state_index = 0, | |
45 | .state_count = 2, | |
46 | }; | |
47 | ||
48 | static int __init haltpoll_init(void) | |
49 | { | |
50 | struct cpuidle_driver *drv = &haltpoll_driver; | |
51 | ||
52 | cpuidle_poll_state_init(drv); | |
53 | ||
54 | if (!kvm_para_available()) | |
55 | return 0; | |
56 | ||
57 | return cpuidle_register(&haltpoll_driver, NULL); | |
58 | } | |
59 | ||
60 | static void __exit haltpoll_exit(void) | |
61 | { | |
62 | cpuidle_unregister(&haltpoll_driver); | |
63 | } | |
64 | ||
65 | module_init(haltpoll_init); | |
66 | module_exit(haltpoll_exit); | |
67 | MODULE_LICENSE("GPL"); | |
68 | MODULE_AUTHOR("Marcelo Tosatti <mtosatti@redhat.com>"); |