* [linux-next:master 580/1375] drivers/powercap/dtpm.c:162 dtpm_update_power() warn: test_bit() takes a bit number
@ 2021-01-05 0:51 kernel test robot
0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2021-01-05 0:51 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 12893 bytes --]
CC: kbuild-all(a)lists.01.org
CC: Linux Memory Management List <linux-mm@kvack.org>
TO: Daniel Lezcano <daniel.lezcano@linaro.org>
CC: "Rafael J. Wysocki" <rjw@rjwysocki.net>
CC: Lukasz Luba <lukasz.luba@arm.com>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head: 766eff5a4f6c1f2a8d5030727258d622f2f750fa
commit: a20d0ef97abf486a917aff066c457bdb930425af [580/1375] powercap/drivers/dtpm: Add API for dynamic thermal power management
:::::: branch date: 21 hours ago
:::::: commit date: 13 days ago
config: ia64-randconfig-m031-20210105 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
drivers/powercap/dtpm.c:162 dtpm_update_power() warn: test_bit() takes a bit number
drivers/powercap/dtpm.c:244 __set_power_limit_uw() warn: test_bit() takes a bit number
Old smatch warnings:
drivers/powercap/dtpm.c:246 __set_power_limit_uw() warn: test_bit() takes a bit number
vim +162 drivers/powercap/dtpm.c
a20d0ef97abf486 Daniel Lezcano 2020-12-08 136
a20d0ef97abf486 Daniel Lezcano 2020-12-08 137 /**
a20d0ef97abf486 Daniel Lezcano 2020-12-08 138 * dtpm_update_power - Update the power on the dtpm
a20d0ef97abf486 Daniel Lezcano 2020-12-08 139 * @dtpm: a pointer to a dtpm structure to update
a20d0ef97abf486 Daniel Lezcano 2020-12-08 140 * @power_min: a u64 representing the new power_min value
a20d0ef97abf486 Daniel Lezcano 2020-12-08 141 * @power_max: a u64 representing the new power_max value
a20d0ef97abf486 Daniel Lezcano 2020-12-08 142 *
a20d0ef97abf486 Daniel Lezcano 2020-12-08 143 * Function to update the power values of the dtpm node specified in
a20d0ef97abf486 Daniel Lezcano 2020-12-08 144 * parameter. These new values will be propagated to the tree.
a20d0ef97abf486 Daniel Lezcano 2020-12-08 145 *
a20d0ef97abf486 Daniel Lezcano 2020-12-08 146 * Return: zero on success, -EINVAL if the values are inconsistent
a20d0ef97abf486 Daniel Lezcano 2020-12-08 147 */
a20d0ef97abf486 Daniel Lezcano 2020-12-08 148 int dtpm_update_power(struct dtpm *dtpm, u64 power_min, u64 power_max)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 149 {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 150 mutex_lock(&dtpm_lock);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 151
a20d0ef97abf486 Daniel Lezcano 2020-12-08 152 if (power_min == dtpm->power_min && power_max == dtpm->power_max)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 153 return 0;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 154
a20d0ef97abf486 Daniel Lezcano 2020-12-08 155 if (power_max < power_min)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 156 return -EINVAL;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 157
a20d0ef97abf486 Daniel Lezcano 2020-12-08 158 __dtpm_sub_power(dtpm);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 159
a20d0ef97abf486 Daniel Lezcano 2020-12-08 160 dtpm->power_min = power_min;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 161 dtpm->power_max = power_max;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 @162 if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags))
a20d0ef97abf486 Daniel Lezcano 2020-12-08 163 dtpm->power_limit = power_max;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 164
a20d0ef97abf486 Daniel Lezcano 2020-12-08 165 __dtpm_add_power(dtpm);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 166
a20d0ef97abf486 Daniel Lezcano 2020-12-08 167 mutex_unlock(&dtpm_lock);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 168
a20d0ef97abf486 Daniel Lezcano 2020-12-08 169 return 0;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 170 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 171
a20d0ef97abf486 Daniel Lezcano 2020-12-08 172 /**
a20d0ef97abf486 Daniel Lezcano 2020-12-08 173 * dtpm_release_zone - Cleanup when the node is released
a20d0ef97abf486 Daniel Lezcano 2020-12-08 174 * @pcz: a pointer to a powercap_zone structure
a20d0ef97abf486 Daniel Lezcano 2020-12-08 175 *
a20d0ef97abf486 Daniel Lezcano 2020-12-08 176 * Do some housecleaning and update the weight on the tree. The
a20d0ef97abf486 Daniel Lezcano 2020-12-08 177 * release will be denied if the node has children. This function must
a20d0ef97abf486 Daniel Lezcano 2020-12-08 178 * be called by the specific release callback of the different
a20d0ef97abf486 Daniel Lezcano 2020-12-08 179 * backends.
a20d0ef97abf486 Daniel Lezcano 2020-12-08 180 *
a20d0ef97abf486 Daniel Lezcano 2020-12-08 181 * Return: 0 on success, -EBUSY if there are children
a20d0ef97abf486 Daniel Lezcano 2020-12-08 182 */
a20d0ef97abf486 Daniel Lezcano 2020-12-08 183 int dtpm_release_zone(struct powercap_zone *pcz)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 184 {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 185 struct dtpm *dtpm = to_dtpm(pcz);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 186 struct dtpm *parent = dtpm->parent;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 187
a20d0ef97abf486 Daniel Lezcano 2020-12-08 188 mutex_lock(&dtpm_lock);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 189
a20d0ef97abf486 Daniel Lezcano 2020-12-08 190 if (!list_empty(&dtpm->children))
a20d0ef97abf486 Daniel Lezcano 2020-12-08 191 return -EBUSY;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 192
a20d0ef97abf486 Daniel Lezcano 2020-12-08 193 if (parent)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 194 list_del(&dtpm->sibling);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 195
a20d0ef97abf486 Daniel Lezcano 2020-12-08 196 __dtpm_sub_power(dtpm);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 197
a20d0ef97abf486 Daniel Lezcano 2020-12-08 198 mutex_unlock(&dtpm_lock);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 199
a20d0ef97abf486 Daniel Lezcano 2020-12-08 200 if (dtpm->ops)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 201 dtpm->ops->release(dtpm);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 202
a20d0ef97abf486 Daniel Lezcano 2020-12-08 203 kfree(dtpm);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 204
a20d0ef97abf486 Daniel Lezcano 2020-12-08 205 return 0;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 206 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 207
a20d0ef97abf486 Daniel Lezcano 2020-12-08 208 static int __get_power_limit_uw(struct dtpm *dtpm, int cid, u64 *power_limit)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 209 {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 210 *power_limit = dtpm->power_limit;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 211 return 0;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 212 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 213
a20d0ef97abf486 Daniel Lezcano 2020-12-08 214 static int get_power_limit_uw(struct powercap_zone *pcz,
a20d0ef97abf486 Daniel Lezcano 2020-12-08 215 int cid, u64 *power_limit)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 216 {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 217 struct dtpm *dtpm = to_dtpm(pcz);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 218 int ret;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 219
a20d0ef97abf486 Daniel Lezcano 2020-12-08 220 mutex_lock(&dtpm_lock);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 221 ret = __get_power_limit_uw(dtpm, cid, power_limit);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 222 mutex_unlock(&dtpm_lock);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 223
a20d0ef97abf486 Daniel Lezcano 2020-12-08 224 return ret;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 225 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 226
a20d0ef97abf486 Daniel Lezcano 2020-12-08 227 /*
a20d0ef97abf486 Daniel Lezcano 2020-12-08 228 * Set the power limit on the nodes, the power limit is distributed
a20d0ef97abf486 Daniel Lezcano 2020-12-08 229 * given the weight of the children.
a20d0ef97abf486 Daniel Lezcano 2020-12-08 230 *
a20d0ef97abf486 Daniel Lezcano 2020-12-08 231 * The dtpm node lock must be held when calling this function.
a20d0ef97abf486 Daniel Lezcano 2020-12-08 232 */
a20d0ef97abf486 Daniel Lezcano 2020-12-08 233 static int __set_power_limit_uw(struct dtpm *dtpm, int cid, u64 power_limit)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 234 {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 235 struct dtpm *child;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 236 int ret = 0;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 237 u64 power;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 238
a20d0ef97abf486 Daniel Lezcano 2020-12-08 239 /*
a20d0ef97abf486 Daniel Lezcano 2020-12-08 240 * A max power limitation means we remove the power limit,
a20d0ef97abf486 Daniel Lezcano 2020-12-08 241 * otherwise we set a constraint and flag the dtpm node.
a20d0ef97abf486 Daniel Lezcano 2020-12-08 242 */
a20d0ef97abf486 Daniel Lezcano 2020-12-08 243 if (power_limit == dtpm->power_max) {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 @244 clear_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 245 } else {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 246 set_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 247 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 248
a20d0ef97abf486 Daniel Lezcano 2020-12-08 249 pr_debug("Setting power limit for '%s': %llu uW\n",
a20d0ef97abf486 Daniel Lezcano 2020-12-08 250 dtpm->zone.name, power_limit);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 251
a20d0ef97abf486 Daniel Lezcano 2020-12-08 252 /*
a20d0ef97abf486 Daniel Lezcano 2020-12-08 253 * Only leaves of the dtpm tree has ops to get/set the power
a20d0ef97abf486 Daniel Lezcano 2020-12-08 254 */
a20d0ef97abf486 Daniel Lezcano 2020-12-08 255 if (dtpm->ops) {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 256 dtpm->power_limit = dtpm->ops->set_power_uw(dtpm, power_limit);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 257 } else {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 258 dtpm->power_limit = 0;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 259
a20d0ef97abf486 Daniel Lezcano 2020-12-08 260 list_for_each_entry(child, &dtpm->children, sibling) {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 261
a20d0ef97abf486 Daniel Lezcano 2020-12-08 262 /*
a20d0ef97abf486 Daniel Lezcano 2020-12-08 263 * Integer division rounding will inevitably
a20d0ef97abf486 Daniel Lezcano 2020-12-08 264 * lead to a different min or max value when
a20d0ef97abf486 Daniel Lezcano 2020-12-08 265 * set several times. In order to restore the
a20d0ef97abf486 Daniel Lezcano 2020-12-08 266 * initial value, we force the child's min or
a20d0ef97abf486 Daniel Lezcano 2020-12-08 267 * max power every time if the constraint is
a20d0ef97abf486 Daniel Lezcano 2020-12-08 268 * at the boundaries.
a20d0ef97abf486 Daniel Lezcano 2020-12-08 269 */
a20d0ef97abf486 Daniel Lezcano 2020-12-08 270 if (power_limit == dtpm->power_max) {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 271 power = child->power_max;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 272 } else if (power_limit == dtpm->power_min) {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 273 power = child->power_min;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 274 } else {
a20d0ef97abf486 Daniel Lezcano 2020-12-08 275 power = DIV_ROUND_CLOSEST(
a20d0ef97abf486 Daniel Lezcano 2020-12-08 276 power_limit * child->weight, 1024);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 277 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 278
a20d0ef97abf486 Daniel Lezcano 2020-12-08 279 pr_debug("Setting power limit for '%s': %llu uW\n",
a20d0ef97abf486 Daniel Lezcano 2020-12-08 280 child->zone.name, power);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 281
a20d0ef97abf486 Daniel Lezcano 2020-12-08 282 ret = __set_power_limit_uw(child, cid, power);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 283 if (!ret)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 284 ret = __get_power_limit_uw(child, cid, &power);
a20d0ef97abf486 Daniel Lezcano 2020-12-08 285
a20d0ef97abf486 Daniel Lezcano 2020-12-08 286 if (ret)
a20d0ef97abf486 Daniel Lezcano 2020-12-08 287 break;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 288
a20d0ef97abf486 Daniel Lezcano 2020-12-08 289 dtpm->power_limit += power;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 290 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 291 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 292
a20d0ef97abf486 Daniel Lezcano 2020-12-08 293 return ret;
a20d0ef97abf486 Daniel Lezcano 2020-12-08 294 }
a20d0ef97abf486 Daniel Lezcano 2020-12-08 295
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 19576 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-05 0:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 0:51 [linux-next:master 580/1375] drivers/powercap/dtpm.c:162 dtpm_update_power() warn: test_bit() takes a bit number kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.