@@ -116,8 +116,6 @@ static void __dtpm_sub_power(struct dtpm *dtpm)
116
116
parent -> power_limit -= dtpm -> power_limit ;
117
117
parent = parent -> parent ;
118
118
}
119
-
120
- __dtpm_rebalance_weight (root );
121
119
}
122
120
123
121
static void __dtpm_add_power (struct dtpm * dtpm )
@@ -130,45 +128,45 @@ static void __dtpm_add_power(struct dtpm *dtpm)
130
128
parent -> power_limit += dtpm -> power_limit ;
131
129
parent = parent -> parent ;
132
130
}
131
+ }
132
+
133
+ static int __dtpm_update_power (struct dtpm * dtpm )
134
+ {
135
+ int ret ;
136
+
137
+ __dtpm_sub_power (dtpm );
138
+
139
+ ret = dtpm -> ops -> update_power_uw (dtpm );
140
+ if (ret )
141
+ pr_err ("Failed to update power for '%s': %d\n" ,
142
+ dtpm -> zone .name , ret );
133
143
134
- __dtpm_rebalance_weight (root );
144
+ if (!test_bit (DTPM_POWER_LIMIT_FLAG , & dtpm -> flags ))
145
+ dtpm -> power_limit = dtpm -> power_max ;
146
+
147
+ __dtpm_add_power (dtpm );
148
+
149
+ if (root )
150
+ __dtpm_rebalance_weight (root );
151
+
152
+ return ret ;
135
153
}
136
154
137
155
/**
138
156
* dtpm_update_power - Update the power on the dtpm
139
157
* @dtpm: a pointer to a dtpm structure to update
140
- * @power_min: a u64 representing the new power_min value
141
- * @power_max: a u64 representing the new power_max value
142
158
*
143
159
* Function to update the power values of the dtpm node specified in
144
160
* parameter. These new values will be propagated to the tree.
145
161
*
146
162
* Return: zero on success, -EINVAL if the values are inconsistent
147
163
*/
148
- int dtpm_update_power (struct dtpm * dtpm , u64 power_min , u64 power_max )
164
+ int dtpm_update_power (struct dtpm * dtpm )
149
165
{
150
- int ret = 0 ;
166
+ int ret ;
151
167
152
168
mutex_lock (& dtpm_lock );
153
-
154
- if (power_min == dtpm -> power_min && power_max == dtpm -> power_max )
155
- goto unlock ;
156
-
157
- if (power_max < power_min ) {
158
- ret = - EINVAL ;
159
- goto unlock ;
160
- }
161
-
162
- __dtpm_sub_power (dtpm );
163
-
164
- dtpm -> power_min = power_min ;
165
- dtpm -> power_max = power_max ;
166
- if (!test_bit (DTPM_POWER_LIMIT_FLAG , & dtpm -> flags ))
167
- dtpm -> power_limit = power_max ;
168
-
169
- __dtpm_add_power (dtpm );
170
-
171
- unlock :
169
+ ret = __dtpm_update_power (dtpm );
172
170
mutex_unlock (& dtpm_lock );
173
171
174
172
return ret ;
@@ -359,24 +357,18 @@ static struct powercap_zone_ops zone_ops = {
359
357
};
360
358
361
359
/**
362
- * dtpm_alloc - Allocate and initialize a dtpm struct
363
- * @name: a string specifying the name of the node
364
- *
365
- * Return: a struct dtpm pointer, NULL in case of error
360
+ * dtpm_init - Allocate and initialize a dtpm struct
361
+ * @dtpm: The dtpm struct pointer to be initialized
362
+ * @ops: The dtpm device specific ops, NULL for a virtual node
366
363
*/
367
- struct dtpm * dtpm_alloc ( struct dtpm_ops * ops )
364
+ void dtpm_init ( struct dtpm * dtpm , struct dtpm_ops * ops )
368
365
{
369
- struct dtpm * dtpm ;
370
-
371
- dtpm = kzalloc (sizeof (* dtpm ), GFP_KERNEL );
372
366
if (dtpm ) {
373
367
INIT_LIST_HEAD (& dtpm -> children );
374
368
INIT_LIST_HEAD (& dtpm -> sibling );
375
369
dtpm -> weight = 1024 ;
376
370
dtpm -> ops = ops ;
377
371
}
378
-
379
- return dtpm ;
380
372
}
381
373
382
374
/**
@@ -436,6 +428,7 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
436
428
437
429
if (dtpm -> ops && !(dtpm -> ops -> set_power_uw &&
438
430
dtpm -> ops -> get_power_uw &&
431
+ dtpm -> ops -> update_power_uw &&
439
432
dtpm -> ops -> release ))
440
433
return - EINVAL ;
441
434
@@ -455,7 +448,10 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
455
448
root = dtpm ;
456
449
}
457
450
458
- __dtpm_add_power (dtpm );
451
+ if (dtpm -> ops && !dtpm -> ops -> update_power_uw (dtpm )) {
452
+ __dtpm_add_power (dtpm );
453
+ dtpm -> power_limit = dtpm -> power_max ;
454
+ }
459
455
460
456
pr_info ("Registered dtpm node '%s' / %llu-%llu uW, \n" ,
461
457
dtpm -> zone .name , dtpm -> power_min , dtpm -> power_max );
@@ -465,9 +461,9 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
465
461
return 0 ;
466
462
}
467
463
468
- static int __init dtpm_init (void )
464
+ static int __init init_dtpm (void )
469
465
{
470
- struct dtpm_descr * * dtpm_descr ;
466
+ struct dtpm_descr * dtpm_descr ;
471
467
472
468
pct = powercap_register_control_type (NULL , "dtpm" , NULL );
473
469
if (IS_ERR (pct )) {
@@ -476,8 +472,8 @@ static int __init dtpm_init(void)
476
472
}
477
473
478
474
for_each_dtpm_table (dtpm_descr )
479
- ( * dtpm_descr ) -> init (* dtpm_descr );
475
+ dtpm_descr -> init ();
480
476
481
477
return 0 ;
482
478
}
483
- late_initcall (dtpm_init );
479
+ late_initcall (init_dtpm );
0 commit comments