~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/cpu_pm.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /kernel/cpu_pm.c (Version linux-6.12-rc7) and /kernel/cpu_pm.c (Version linux-5.3.18)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * Copyright (C) 2011 Google, Inc.                  3  * Copyright (C) 2011 Google, Inc.
  4  *                                                  4  *
  5  * Author:                                          5  * Author:
  6  *      Colin Cross <ccross@android.com>            6  *      Colin Cross <ccross@android.com>
  7  */                                                 7  */
  8                                                     8 
  9 #include <linux/kernel.h>                           9 #include <linux/kernel.h>
 10 #include <linux/cpu_pm.h>                          10 #include <linux/cpu_pm.h>
 11 #include <linux/module.h>                          11 #include <linux/module.h>
 12 #include <linux/notifier.h>                        12 #include <linux/notifier.h>
 13 #include <linux/spinlock.h>                        13 #include <linux/spinlock.h>
 14 #include <linux/syscore_ops.h>                     14 #include <linux/syscore_ops.h>
 15                                                    15 
 16 /*                                             !!  16 static ATOMIC_NOTIFIER_HEAD(cpu_pm_notifier_chain);
 17  * atomic_notifiers use a spinlock_t, which ca << 
 18  * Notifications for cpu_pm will be issued by  << 
 19  * never block, IOW it requires using a raw_sp << 
 20  */                                            << 
 21 static struct {                                << 
 22         struct raw_notifier_head chain;        << 
 23         raw_spinlock_t lock;                   << 
 24 } cpu_pm_notifier = {                          << 
 25         .chain = RAW_NOTIFIER_INIT(cpu_pm_noti << 
 26         .lock  = __RAW_SPIN_LOCK_UNLOCKED(cpu_ << 
 27 };                                             << 
 28                                                    17 
 29 static int cpu_pm_notify(enum cpu_pm_event eve !!  18 static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls)
 30 {                                                  19 {
 31         int ret;                                   20         int ret;
 32                                                    21 
 33         rcu_read_lock();                       !!  22         /*
 34         ret = raw_notifier_call_chain(&cpu_pm_ !!  23          * __atomic_notifier_call_chain has a RCU read critical section, which
 35         rcu_read_unlock();                     !!  24          * could be disfunctional in cpu idle. Copy RCU_NONIDLE code to let
 36                                                !!  25          * RCU know this.
 37         return notifier_to_errno(ret);         !!  26          */
 38 }                                              !!  27         rcu_irq_enter_irqson();
 39                                                !!  28         ret = __atomic_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL,
 40 static int cpu_pm_notify_robust(enum cpu_pm_ev !!  29                 nr_to_call, nr_calls);
 41 {                                              !!  30         rcu_irq_exit_irqson();
 42         unsigned long flags;                   << 
 43         int ret;                               << 
 44                                                << 
 45         raw_spin_lock_irqsave(&cpu_pm_notifier << 
 46         ret = raw_notifier_call_chain_robust(& << 
 47         raw_spin_unlock_irqrestore(&cpu_pm_not << 
 48                                                    31 
 49         return notifier_to_errno(ret);             32         return notifier_to_errno(ret);
 50 }                                                  33 }
 51                                                    34 
 52 /**                                                35 /**
 53  * cpu_pm_register_notifier - register a drive     36  * cpu_pm_register_notifier - register a driver with cpu_pm
 54  * @nb: notifier block to register                 37  * @nb: notifier block to register
 55  *                                                 38  *
 56  * Add a driver to a list of drivers that are      39  * Add a driver to a list of drivers that are notified about
 57  * CPU and CPU cluster low power entry and exi     40  * CPU and CPU cluster low power entry and exit.
 58  *                                                 41  *
 59  * This function has the same return condition !!  42  * This function may sleep, and has the same return conditions as
                                                   >>  43  * raw_notifier_chain_register.
 60  */                                                44  */
 61 int cpu_pm_register_notifier(struct notifier_b     45 int cpu_pm_register_notifier(struct notifier_block *nb)
 62 {                                                  46 {
 63         unsigned long flags;                   !!  47         return atomic_notifier_chain_register(&cpu_pm_notifier_chain, nb);
 64         int ret;                               << 
 65                                                << 
 66         raw_spin_lock_irqsave(&cpu_pm_notifier << 
 67         ret = raw_notifier_chain_register(&cpu << 
 68         raw_spin_unlock_irqrestore(&cpu_pm_not << 
 69         return ret;                            << 
 70 }                                                  48 }
 71 EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);       49 EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);
 72                                                    50 
 73 /**                                                51 /**
 74  * cpu_pm_unregister_notifier - unregister a d     52  * cpu_pm_unregister_notifier - unregister a driver with cpu_pm
 75  * @nb: notifier block to be unregistered          53  * @nb: notifier block to be unregistered
 76  *                                                 54  *
 77  * Remove a driver from the CPU PM notifier li     55  * Remove a driver from the CPU PM notifier list.
 78  *                                                 56  *
 79  * This function has the same return condition !!  57  * This function may sleep, and has the same return conditions as
                                                   >>  58  * raw_notifier_chain_unregister.
 80  */                                                59  */
 81 int cpu_pm_unregister_notifier(struct notifier     60 int cpu_pm_unregister_notifier(struct notifier_block *nb)
 82 {                                                  61 {
 83         unsigned long flags;                   !!  62         return atomic_notifier_chain_unregister(&cpu_pm_notifier_chain, nb);
 84         int ret;                               << 
 85                                                << 
 86         raw_spin_lock_irqsave(&cpu_pm_notifier << 
 87         ret = raw_notifier_chain_unregister(&c << 
 88         raw_spin_unlock_irqrestore(&cpu_pm_not << 
 89         return ret;                            << 
 90 }                                                  63 }
 91 EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);     64 EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
 92                                                    65 
 93 /**                                                66 /**
 94  * cpu_pm_enter - CPU low power entry notifier     67  * cpu_pm_enter - CPU low power entry notifier
 95  *                                                 68  *
 96  * Notifies listeners that a single CPU is ent     69  * Notifies listeners that a single CPU is entering a low power state that may
 97  * cause some blocks in the same power domain      70  * cause some blocks in the same power domain as the cpu to reset.
 98  *                                                 71  *
 99  * Must be called on the affected CPU with int     72  * Must be called on the affected CPU with interrupts disabled.  Platform is
100  * responsible for ensuring that cpu_pm_enter      73  * responsible for ensuring that cpu_pm_enter is not called twice on the same
101  * CPU before cpu_pm_exit is called. Notified      74  * CPU before cpu_pm_exit is called. Notified drivers can include VFP
102  * co-processor, interrupt controller and its      75  * co-processor, interrupt controller and its PM extensions, local CPU
103  * timers context save/restore which shouldn't     76  * timers context save/restore which shouldn't be interrupted. Hence it
104  * must be called with interrupts disabled.        77  * must be called with interrupts disabled.
105  *                                                 78  *
106  * Return conditions are same as __raw_notifie     79  * Return conditions are same as __raw_notifier_call_chain.
107  */                                                80  */
108 int cpu_pm_enter(void)                             81 int cpu_pm_enter(void)
109 {                                                  82 {
110         return cpu_pm_notify_robust(CPU_PM_ENT !!  83         int nr_calls;
                                                   >>  84         int ret = 0;
                                                   >>  85 
                                                   >>  86         ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls);
                                                   >>  87         if (ret)
                                                   >>  88                 /*
                                                   >>  89                  * Inform listeners (nr_calls - 1) about failure of CPU PM
                                                   >>  90                  * PM entry who are notified earlier to prepare for it.
                                                   >>  91                  */
                                                   >>  92                 cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL);
                                                   >>  93 
                                                   >>  94         return ret;
111 }                                                  95 }
112 EXPORT_SYMBOL_GPL(cpu_pm_enter);                   96 EXPORT_SYMBOL_GPL(cpu_pm_enter);
113                                                    97 
114 /**                                                98 /**
115  * cpu_pm_exit - CPU low power exit notifier       99  * cpu_pm_exit - CPU low power exit notifier
116  *                                                100  *
117  * Notifies listeners that a single CPU is exi    101  * Notifies listeners that a single CPU is exiting a low power state that may
118  * have caused some blocks in the same power d    102  * have caused some blocks in the same power domain as the cpu to reset.
119  *                                                103  *
120  * Notified drivers can include VFP co-process    104  * Notified drivers can include VFP co-processor, interrupt controller
121  * and its PM extensions, local CPU timers con    105  * and its PM extensions, local CPU timers context save/restore which
122  * shouldn't be interrupted. Hence it must be     106  * shouldn't be interrupted. Hence it must be called with interrupts disabled.
123  *                                                107  *
124  * Return conditions are same as __raw_notifie    108  * Return conditions are same as __raw_notifier_call_chain.
125  */                                               109  */
126 int cpu_pm_exit(void)                             110 int cpu_pm_exit(void)
127 {                                                 111 {
128         return cpu_pm_notify(CPU_PM_EXIT);     !! 112         return cpu_pm_notify(CPU_PM_EXIT, -1, NULL);
129 }                                                 113 }
130 EXPORT_SYMBOL_GPL(cpu_pm_exit);                   114 EXPORT_SYMBOL_GPL(cpu_pm_exit);
131                                                   115 
132 /**                                               116 /**
133  * cpu_cluster_pm_enter - CPU cluster low powe    117  * cpu_cluster_pm_enter - CPU cluster low power entry notifier
134  *                                                118  *
135  * Notifies listeners that all cpus in a power    119  * Notifies listeners that all cpus in a power domain are entering a low power
136  * state that may cause some blocks in the sam    120  * state that may cause some blocks in the same power domain to reset.
137  *                                                121  *
138  * Must be called after cpu_pm_enter has been     122  * Must be called after cpu_pm_enter has been called on all cpus in the power
139  * domain, and before cpu_pm_exit has been cal    123  * domain, and before cpu_pm_exit has been called on any cpu in the power
140  * domain. Notified drivers can include VFP co    124  * domain. Notified drivers can include VFP co-processor, interrupt controller
141  * and its PM extensions, local CPU timers con    125  * and its PM extensions, local CPU timers context save/restore which
142  * shouldn't be interrupted. Hence it must be     126  * shouldn't be interrupted. Hence it must be called with interrupts disabled.
143  *                                                127  *
144  * Must be called with interrupts disabled.       128  * Must be called with interrupts disabled.
145  *                                                129  *
146  * Return conditions are same as __raw_notifie    130  * Return conditions are same as __raw_notifier_call_chain.
147  */                                               131  */
148 int cpu_cluster_pm_enter(void)                    132 int cpu_cluster_pm_enter(void)
149 {                                                 133 {
150         return cpu_pm_notify_robust(CPU_CLUSTE !! 134         int nr_calls;
                                                   >> 135         int ret = 0;
                                                   >> 136 
                                                   >> 137         ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls);
                                                   >> 138         if (ret)
                                                   >> 139                 /*
                                                   >> 140                  * Inform listeners (nr_calls - 1) about failure of CPU cluster
                                                   >> 141                  * PM entry who are notified earlier to prepare for it.
                                                   >> 142                  */
                                                   >> 143                 cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL);
                                                   >> 144 
                                                   >> 145         return ret;
151 }                                                 146 }
152 EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);          147 EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
153                                                   148 
154 /**                                               149 /**
155  * cpu_cluster_pm_exit - CPU cluster low power    150  * cpu_cluster_pm_exit - CPU cluster low power exit notifier
156  *                                                151  *
157  * Notifies listeners that all cpus in a power    152  * Notifies listeners that all cpus in a power domain are exiting form a
158  * low power state that may have caused some b    153  * low power state that may have caused some blocks in the same power domain
159  * to reset.                                      154  * to reset.
160  *                                                155  *
161  * Must be called after cpu_cluster_pm_enter h    156  * Must be called after cpu_cluster_pm_enter has been called for the power
162  * domain, and before cpu_pm_exit has been cal    157  * domain, and before cpu_pm_exit has been called on any cpu in the power
163  * domain. Notified drivers can include VFP co    158  * domain. Notified drivers can include VFP co-processor, interrupt controller
164  * and its PM extensions, local CPU timers con    159  * and its PM extensions, local CPU timers context save/restore which
165  * shouldn't be interrupted. Hence it must be     160  * shouldn't be interrupted. Hence it must be called with interrupts disabled.
166  *                                                161  *
167  * Return conditions are same as __raw_notifie    162  * Return conditions are same as __raw_notifier_call_chain.
168  */                                               163  */
169 int cpu_cluster_pm_exit(void)                     164 int cpu_cluster_pm_exit(void)
170 {                                                 165 {
171         return cpu_pm_notify(CPU_CLUSTER_PM_EX !! 166         return cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL);
172 }                                                 167 }
173 EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);           168 EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);
174                                                   169 
175 #ifdef CONFIG_PM                                  170 #ifdef CONFIG_PM
176 static int cpu_pm_suspend(void)                   171 static int cpu_pm_suspend(void)
177 {                                                 172 {
178         int ret;                                  173         int ret;
179                                                   174 
180         ret = cpu_pm_enter();                     175         ret = cpu_pm_enter();
181         if (ret)                                  176         if (ret)
182                 return ret;                       177                 return ret;
183                                                   178 
184         ret = cpu_cluster_pm_enter();             179         ret = cpu_cluster_pm_enter();
185         return ret;                               180         return ret;
186 }                                                 181 }
187                                                   182 
188 static void cpu_pm_resume(void)                   183 static void cpu_pm_resume(void)
189 {                                                 184 {
190         cpu_cluster_pm_exit();                    185         cpu_cluster_pm_exit();
191         cpu_pm_exit();                            186         cpu_pm_exit();
192 }                                                 187 }
193                                                   188 
194 static struct syscore_ops cpu_pm_syscore_ops =    189 static struct syscore_ops cpu_pm_syscore_ops = {
195         .suspend = cpu_pm_suspend,                190         .suspend = cpu_pm_suspend,
196         .resume = cpu_pm_resume,                  191         .resume = cpu_pm_resume,
197 };                                                192 };
198                                                   193 
199 static int cpu_pm_init(void)                      194 static int cpu_pm_init(void)
200 {                                                 195 {
201         register_syscore_ops(&cpu_pm_syscore_o    196         register_syscore_ops(&cpu_pm_syscore_ops);
202         return 0;                                 197         return 0;
203 }                                                 198 }
204 core_initcall(cpu_pm_init);                       199 core_initcall(cpu_pm_init);
205 #endif                                            200 #endif
206                                                   201 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php