]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/cpuidle/cpuidle-haltpoll.c
add cpuidle-haltpoll driver
[mirror_ubuntu-jammy-kernel.git] / drivers / cpuidle / cpuidle-haltpoll.c
CommitLineData
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
19static 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
30static 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
48static 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
60static void __exit haltpoll_exit(void)
61{
62 cpuidle_unregister(&haltpoll_driver);
63}
64
65module_init(haltpoll_init);
66module_exit(haltpoll_exit);
67MODULE_LICENSE("GPL");
68MODULE_AUTHOR("Marcelo Tosatti <mtosatti@redhat.com>");