Skip to content

Commit 1933f96

Browse files
jasonbuxiaoxiang781216
authored andcommitted
pm: remove pm global, make per domain isolated
After change, when CONFIG_PM_NDOMAINS > 1, the pm_register will not able to get notificaion from not PM_IDLE_DOMAIN. Should use pm_domain_register as a replacement. Isolate domains from global callbacks can decrease not necessary execution, and reduce the lock instruction requirements. Signed-off-by: buxiasen <[email protected]>
1 parent 6f50847 commit 1933f96

15 files changed

+100
-119
lines changed

drivers/power/pm/activity_governor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static void governor_update(int domain, int16_t accum)
317317

318318
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
319319
pdomstate = &g_pm_activity_governor.domain_states[domain];
320-
state = g_pmglobals.domain[domain].state;
320+
state = g_pmdomains[domain].state;
321321

322322
#if CONFIG_PM_GOVERNOR_MEMORY > 1
323323
/* We won't bother to do anything until we have accumulated
@@ -469,7 +469,7 @@ static enum pm_state_e governor_checkstate(int domain)
469469
/* Get a convenience pointer to minimize all of the indexing */
470470

471471
pdomstate = &g_pm_activity_governor.domain_states[domain];
472-
pdom = &g_pmglobals.domain[domain];
472+
pdom = &g_pmdomains[domain];
473473

474474
/* Check for the end of the current time slice. This must be performed
475475
* with interrupts disabled so that it does not conflict with the similar
@@ -563,7 +563,7 @@ static void governor_timer(int domain, enum pm_state_e newstate)
563563
TIME_SLICE_TICKS * CONFIG_PM_GOVERNOR_SLEEPENTER_COUNT
564564
};
565565

566-
pdom = &g_pmglobals.domain[domain];
566+
pdom = &g_pmdomains[domain];
567567
pdomstate = &g_pm_activity_governor.domain_states[domain];
568568

569569
if (newstate < PM_SLEEP && dq_empty(&pdom->wakelock[newstate]))

drivers/power/pm/greedy_governor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static enum pm_state_e greedy_governor_checkstate(int domain)
9494
irqstate_t flags;
9595
int state;
9696

97-
pdom = &g_pmglobals.domain[domain];
97+
pdom = &g_pmdomains[domain];
9898
state = PM_NORMAL;
9999

100100
/* We disable interrupts since pm_stay()/pm_relax() could be simultaneously

drivers/power/pm/pm.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct pm_domain_s
5353

5454
uint8_t state;
5555

56+
/* Registry is a doubly-linked list of registered power management
57+
* callback structures.
58+
*/
59+
60+
dq_queue_t registry;
61+
5662
/* The power state lock count */
5763

5864
struct dq_queue_s wakelock[PM_COUNT];
@@ -87,28 +93,6 @@ struct pm_domain_s
8793
rmutex_t lock;
8894
};
8995

90-
/* This structure encapsulates all of the global data used by the PM system */
91-
92-
struct pm_global_s
93-
{
94-
/* This rmutex manages mutually exclusive access to the power management
95-
* registry. It must be initialized to the value 1.
96-
*/
97-
98-
rmutex_t reglock;
99-
100-
/* registry is a doubly-linked list of registered power management
101-
* callback structures. To ensure mutually exclusive access, this list
102-
* must be locked by calling pm_lock() before it is accessed.
103-
*/
104-
105-
dq_queue_t registry;
106-
107-
/* The state information for each PM domain */
108-
109-
struct pm_domain_s domain[CONFIG_PM_NDOMAINS];
110-
};
111-
11296
/****************************************************************************
11397
* Public Data
11498
****************************************************************************/
@@ -124,7 +108,7 @@ extern "C"
124108

125109
/* All PM global data: */
126110

127-
EXTERN struct pm_global_s g_pmglobals;
111+
EXTERN struct pm_domain_s g_pmdomains[CONFIG_PM_NDOMAINS];
128112

129113
/****************************************************************************
130114
* Public Function Prototypes

drivers/power/pm/pm_activity.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ static void pm_waklock_cb(wdparm_t arg)
5454
#ifdef CONFIG_PM_PROCFS
5555
static void pm_wakelock_stats_rm(FAR struct pm_wakelock_s *wakelock)
5656
{
57-
FAR struct pm_domain_s *pdom = &g_pmglobals.domain[wakelock->domain];
57+
FAR struct pm_domain_s *pdom = &g_pmdomains[wakelock->domain];
5858

5959
dq_rem(&wakelock->fsnode, &pdom->wakelockall);
6060
}
6161

6262
static void pm_wakelock_stats(FAR struct pm_wakelock_s *wakelock, bool stay)
6363
{
64-
FAR struct pm_domain_s *pdom = &g_pmglobals.domain[wakelock->domain];
64+
FAR struct pm_domain_s *pdom = &g_pmdomains[wakelock->domain];
6565
struct timespec ts;
6666

6767
if (stay)
@@ -121,9 +121,9 @@ void pm_activity(int domain, int priority)
121121
{
122122
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
123123

124-
if (g_pmglobals.domain[domain].governor->activity)
124+
if (g_pmdomains[domain].governor->activity)
125125
{
126-
g_pmglobals.domain[domain].governor->activity(domain, priority);
126+
g_pmdomains[domain].governor->activity(domain, priority);
127127
}
128128

129129
pm_auto_updatestate(domain);
@@ -301,7 +301,7 @@ void pm_wakelock_uninit(FAR struct pm_wakelock_s *wakelock)
301301
/* Get a convenience pointer to minimize all of the indexing */
302302

303303
domain = wakelock->domain;
304-
pdom = &g_pmglobals.domain[domain];
304+
pdom = &g_pmdomains[domain];
305305
dq = &pdom->wakelock[wakelock->state];
306306
wdog = &wakelock->wdog;
307307

@@ -350,7 +350,7 @@ void pm_wakelock_stay(FAR struct pm_wakelock_s *wakelock)
350350
/* Get a convenience pointer to minimize all of the indexing */
351351

352352
domain = wakelock->domain;
353-
pdom = &g_pmglobals.domain[domain];
353+
pdom = &g_pmdomains[domain];
354354
dq = &pdom->wakelock[wakelock->state];
355355

356356
flags = pm_domain_lock(domain);
@@ -397,7 +397,7 @@ void pm_wakelock_relax(FAR struct pm_wakelock_s *wakelock)
397397
/* Get a convenience pointer to minimize all of the indexing */
398398

399399
domain = wakelock->domain;
400-
pdom = &g_pmglobals.domain[domain];
400+
pdom = &g_pmdomains[domain];
401401
dq = &pdom->wakelock[wakelock->state];
402402

403403
flags = pm_domain_lock(domain);
@@ -448,7 +448,7 @@ void pm_wakelock_staytimeout(FAR struct pm_wakelock_s *wakelock, int ms)
448448
/* Get a convenience pointer to minimize all of the indexing */
449449

450450
domain = wakelock->domain;
451-
pdom = &g_pmglobals.domain[domain];
451+
pdom = &g_pmdomains[domain];
452452
dq = &pdom->wakelock[wakelock->state];
453453
wdog = &wakelock->wdog;
454454

drivers/power/pm/pm_autoupdate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void pm_auto_updatestate_cb(FAR void *arg)
7373
void pm_auto_updatestate(int domain)
7474
{
7575
FAR struct pm_domain_s *pdom;
76-
pdom = &g_pmglobals.domain[domain];
76+
pdom = &g_pmdomains[domain];
7777

7878
if (pdom->auto_update)
7979
{
@@ -113,7 +113,7 @@ void pm_auto_update(int domain, bool auto_update)
113113
irqstate_t flags;
114114

115115
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
116-
pdom = &g_pmglobals.domain[domain];
116+
pdom = &g_pmdomains[domain];
117117

118118
flags = pm_domain_lock(domain);
119119
pdom->auto_update = auto_update;

drivers/power/pm/pm_changestate.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void pm_stats_preparefail(int domain,
106106
int newstate, int ret)
107107
{
108108
struct timespec ts;
109-
FAR struct pm_preparefail_s *pf = &callback->preparefail[domain];
109+
FAR struct pm_preparefail_s *pf = &callback->preparefail;
110110

111111
if (pf->state != PM_RESTORE)
112112
{
@@ -153,20 +153,23 @@ static void pm_stats_preparefail(int domain,
153153

154154
static int pm_prepall(int domain, enum pm_state_e newstate, bool restore)
155155
{
156+
FAR struct pm_domain_s *pdom;
157+
FAR struct pm_callback_s *cb;
156158
FAR dq_entry_t *entry;
157159
int ret = OK;
158160

159-
if (newstate <= g_pmglobals.domain[domain].state)
161+
pdom = &g_pmdomains[domain];
162+
if (newstate <= pdom->state)
160163
{
161164
/* Visit each registered callback structure in normal order. */
162165

163-
for (entry = dq_peek(&g_pmglobals.registry);
166+
for (entry = dq_peek(&pdom->registry);
164167
entry && ret == OK;
165168
entry = dq_next(entry))
166169
{
167170
/* Is the prepare callback supported? */
168171

169-
FAR struct pm_callback_s *cb = (FAR struct pm_callback_s *)entry;
172+
cb = (FAR struct pm_callback_s *)entry;
170173
if (cb->prepare)
171174
{
172175
/* Yes.. prepare the driver */
@@ -183,13 +186,13 @@ static int pm_prepall(int domain, enum pm_state_e newstate, bool restore)
183186
{
184187
/* Visit each registered callback structure in reverse order. */
185188

186-
for (entry = dq_tail(&g_pmglobals.registry);
189+
for (entry = dq_tail(&pdom->registry);
187190
entry && ret == OK;
188191
entry = dq_prev(entry))
189192
{
190193
/* Is the prepare callback supported? */
191194

192-
FAR struct pm_callback_s *cb = (FAR struct pm_callback_s *)entry;
195+
cb = (FAR struct pm_callback_s *)entry;
193196
if (cb->prepare)
194197
{
195198
/* Yes.. prepare the driver */
@@ -227,18 +230,21 @@ static int pm_prepall(int domain, enum pm_state_e newstate, bool restore)
227230

228231
static inline void pm_changeall(int domain, enum pm_state_e newstate)
229232
{
233+
FAR struct pm_domain_s *pdom;
234+
FAR struct pm_callback_s *cb;
230235
FAR dq_entry_t *entry;
231236

232-
if (newstate <= g_pmglobals.domain[domain].state)
237+
pdom = &g_pmdomains[domain];
238+
if (newstate <= pdom->state)
233239
{
234240
/* Visit each registered callback structure in normal order. */
235241

236-
for (entry = dq_peek(&g_pmglobals.registry);
242+
for (entry = dq_peek(&pdom->registry);
237243
entry; entry = dq_next(entry))
238244
{
239245
/* Is the notification callback supported? */
240246

241-
FAR struct pm_callback_s *cb = (FAR struct pm_callback_s *)entry;
247+
cb = (FAR struct pm_callback_s *)entry;
242248
if (cb->notify)
243249
{
244250
/* Yes.. notify the driver */
@@ -251,12 +257,12 @@ static inline void pm_changeall(int domain, enum pm_state_e newstate)
251257
{
252258
/* Visit each registered callback structure in reverse order. */
253259

254-
for (entry = dq_tail(&g_pmglobals.registry);
260+
for (entry = dq_tail(&pdom->registry);
255261
entry; entry = dq_prev(entry))
256262
{
257263
/* Is the notification callback supported? */
258264

259-
FAR struct pm_callback_s *cb = (FAR struct pm_callback_s *)entry;
265+
cb = (FAR struct pm_callback_s *)entry;
260266
if (cb->notify)
261267
{
262268
/* Yes.. notify the driver */
@@ -327,15 +333,15 @@ int pm_changestate(int domain, enum pm_state_e newstate)
327333
* Revert to the preceding state.
328334
*/
329335

330-
newstate = g_pmglobals.domain[domain].state;
336+
newstate = g_pmdomains[domain].state;
331337
pm_prepall(domain, newstate, true);
332338
}
333339
}
334340

335341
/* Statistics */
336342

337-
pm_stats(&g_pmglobals.domain[domain],
338-
g_pmglobals.domain[domain].state, newstate);
343+
pm_stats(&g_pmdomains[domain],
344+
g_pmdomains[domain].state, newstate);
339345

340346
/* All drivers have agreed to the state change (or, one or more have
341347
* disagreed and the state has been reverted). Set the new state.
@@ -345,16 +351,16 @@ int pm_changestate(int domain, enum pm_state_e newstate)
345351

346352
/* Notify governor of (possible) state change */
347353

348-
if (g_pmglobals.domain[domain].governor->statechanged)
354+
if (g_pmdomains[domain].governor->statechanged)
349355
{
350-
g_pmglobals.domain[domain].governor->statechanged(domain, newstate);
356+
g_pmdomains[domain].governor->statechanged(domain, newstate);
351357
}
352358

353359
/* Domain state update after statechanged done */
354360

355361
if (newstate != PM_RESTORE)
356362
{
357-
g_pmglobals.domain[domain].state = newstate;
363+
g_pmdomains[domain].state = newstate;
358364
}
359365

360366
/* Restore the interrupt state */
@@ -380,7 +386,7 @@ int pm_changestate(int domain, enum pm_state_e newstate)
380386
enum pm_state_e pm_querystate(int domain)
381387
{
382388
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
383-
return g_pmglobals.domain[domain].state;
389+
return g_pmdomains[domain].state;
384390
}
385391

386392
#endif /* CONFIG_PM */

drivers/power/pm/pm_checkstate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ enum pm_state_e pm_checkstate(int domain)
7373
{
7474
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
7575

76-
if (g_pmglobals.domain[domain].governor->checkstate)
76+
if (g_pmdomains[domain].governor->checkstate)
7777
{
78-
return g_pmglobals.domain[domain].governor->checkstate(domain);
78+
return g_pmdomains[domain].governor->checkstate(domain);
7979
}
8080

8181
return PM_NORMAL;

drivers/power/pm/pm_governor.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ int pm_set_governor(int domain, FAR const struct pm_governor_s *gov)
7575
return -EINVAL;
7676
}
7777

78-
if (g_pmglobals.domain[domain].governor &&
79-
g_pmglobals.domain[domain].governor->deinitialize)
78+
if (g_pmdomains[domain].governor &&
79+
g_pmdomains[domain].governor->deinitialize)
8080
{
81-
g_pmglobals.domain[domain].governor->deinitialize();
81+
g_pmdomains[domain].governor->deinitialize();
8282
}
8383

84-
g_pmglobals.domain[domain].governor = gov;
84+
g_pmdomains[domain].governor = gov;
8585

86-
if (g_pmglobals.domain[domain].governor->initialize)
86+
if (g_pmdomains[domain].governor->initialize)
8787
{
88-
g_pmglobals.domain[domain].governor->initialize();
88+
g_pmdomains[domain].governor->initialize();
8989
}
9090

9191
return 0;

drivers/power/pm/pm_initialize.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,7 @@
3838

3939
/* All PM global data: */
4040

41-
/* Initialize the registry and the PM global data structures. The PM
42-
* global data structure resides in .data which is zeroed at boot time. So
43-
* it is only required to initialize non-zero elements of the PM global
44-
* data structure here.
45-
*/
46-
47-
struct pm_global_s g_pmglobals =
48-
{
49-
NXRMUTEX_INITIALIZER
50-
};
41+
struct pm_domain_s g_pmdomains[CONFIG_PM_NDOMAINS];
5142

5243
/****************************************************************************
5344
* Public Functions
@@ -98,10 +89,10 @@ void pm_initialize(void)
9889
pm_set_governor(i, gov);
9990

10091
#if defined(CONFIG_PM_PROCFS)
101-
clock_systime_timespec(&g_pmglobals.domain[i].start);
92+
clock_systime_timespec(&g_pmdomains[i].start);
10293
#endif
10394

104-
nxrmutex_init(&g_pmglobals.domain[i].lock);
95+
nxrmutex_init(&g_pmdomains[i].lock);
10596

10697
#if CONFIG_PM_GOVERNOR_EXPLICIT_RELAX
10798
for (state = 0; state < PM_COUNT; state++)

drivers/power/pm/pm_lock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ void pm_unlock(FAR rmutex_t *lock, irqstate_t flags)
5959

6060
irqstate_t pm_domain_lock(int domain)
6161
{
62-
return pm_lock(&g_pmglobals.domain[domain].lock);
62+
return pm_lock(&g_pmdomains[domain].lock);
6363
}
6464

6565
void pm_domain_unlock(int domain, irqstate_t flags)
6666
{
67-
pm_unlock(&g_pmglobals.domain[domain].lock, flags);
67+
pm_unlock(&g_pmdomains[domain].lock, flags);
6868
}
6969

7070
#endif /* CONFIG_PM */

0 commit comments

Comments
 (0)