qos.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Power Management Quality of Service (PM QoS) support base.
  4. *
  5. * Copyright (C) 2020 Intel Corporation
  6. *
  7. * Authors:
  8. * Mark Gross <[email protected]>
  9. * Rafael J. Wysocki <[email protected]>
  10. *
  11. * Provided here is an interface for specifying PM QoS dependencies. It allows
  12. * entities depending on QoS constraints to register their requests which are
  13. * aggregated as appropriate to produce effective constraints (target values)
  14. * that can be monitored by entities needing to respect them, either by polling
  15. * or through a built-in notification mechanism.
  16. *
  17. * In addition to the basic functionality, more specific interfaces for managing
  18. * global CPU latency QoS requests and frequency QoS requests are provided.
  19. */
  20. /*#define DEBUG*/
  21. #include <linux/pm_qos.h>
  22. #include <linux/sched.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/slab.h>
  25. #include <linux/time.h>
  26. #include <linux/fs.h>
  27. #include <linux/device.h>
  28. #include <linux/miscdevice.h>
  29. #include <linux/string.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/init.h>
  32. #include <linux/kernel.h>
  33. #include <linux/debugfs.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/export.h>
  37. #include <trace/events/power.h>
  38. #include <trace/hooks/power.h>
  39. /*
  40. * locking rule: all changes to constraints or notifiers lists
  41. * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
  42. * held, taken with _irqsave. One lock to rule them all
  43. */
  44. static DEFINE_SPINLOCK(pm_qos_lock);
  45. /**
  46. * pm_qos_read_value - Return the current effective constraint value.
  47. * @c: List of PM QoS constraint requests.
  48. */
  49. s32 pm_qos_read_value(struct pm_qos_constraints *c)
  50. {
  51. return READ_ONCE(c->target_value);
  52. }
  53. static int pm_qos_get_value(struct pm_qos_constraints *c)
  54. {
  55. if (plist_head_empty(&c->list))
  56. return c->no_constraint_value;
  57. switch (c->type) {
  58. case PM_QOS_MIN:
  59. return plist_first(&c->list)->prio;
  60. case PM_QOS_MAX:
  61. return plist_last(&c->list)->prio;
  62. default:
  63. WARN(1, "Unknown PM QoS type in %s\n", __func__);
  64. return PM_QOS_DEFAULT_VALUE;
  65. }
  66. }
  67. static void pm_qos_set_value(struct pm_qos_constraints *c, s32 value)
  68. {
  69. WRITE_ONCE(c->target_value, value);
  70. }
  71. /**
  72. * pm_qos_update_target - Update a list of PM QoS constraint requests.
  73. * @c: List of PM QoS requests.
  74. * @node: Target list entry.
  75. * @action: Action to carry out (add, update or remove).
  76. * @value: New request value for the target list entry.
  77. *
  78. * Update the given list of PM QoS constraint requests, @c, by carrying an
  79. * @action involving the @node list entry and @value on it.
  80. *
  81. * The recognized values of @action are PM_QOS_ADD_REQ (store @value in @node
  82. * and add it to the list), PM_QOS_UPDATE_REQ (remove @node from the list, store
  83. * @value in it and add it to the list again), and PM_QOS_REMOVE_REQ (remove
  84. * @node from the list, ignore @value).
  85. *
  86. * Return: 1 if the aggregate constraint value has changed, 0 otherwise.
  87. */
  88. int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
  89. enum pm_qos_req_action action, int value)
  90. {
  91. int prev_value, curr_value, new_value;
  92. unsigned long flags;
  93. spin_lock_irqsave(&pm_qos_lock, flags);
  94. prev_value = pm_qos_get_value(c);
  95. if (value == PM_QOS_DEFAULT_VALUE)
  96. new_value = c->default_value;
  97. else
  98. new_value = value;
  99. switch (action) {
  100. case PM_QOS_REMOVE_REQ:
  101. plist_del(node, &c->list);
  102. break;
  103. case PM_QOS_UPDATE_REQ:
  104. /*
  105. * To change the list, atomically remove, reinit with new value
  106. * and add, then see if the aggregate has changed.
  107. */
  108. plist_del(node, &c->list);
  109. fallthrough;
  110. case PM_QOS_ADD_REQ:
  111. plist_node_init(node, new_value);
  112. plist_add(node, &c->list);
  113. break;
  114. default:
  115. /* no action */
  116. ;
  117. }
  118. curr_value = pm_qos_get_value(c);
  119. pm_qos_set_value(c, curr_value);
  120. spin_unlock_irqrestore(&pm_qos_lock, flags);
  121. trace_pm_qos_update_target(action, prev_value, curr_value);
  122. if (prev_value == curr_value)
  123. return 0;
  124. if (c->notifiers)
  125. blocking_notifier_call_chain(c->notifiers, curr_value, NULL);
  126. return 1;
  127. }
  128. /**
  129. * pm_qos_flags_remove_req - Remove device PM QoS flags request.
  130. * @pqf: Device PM QoS flags set to remove the request from.
  131. * @req: Request to remove from the set.
  132. */
  133. static void pm_qos_flags_remove_req(struct pm_qos_flags *pqf,
  134. struct pm_qos_flags_request *req)
  135. {
  136. s32 val = 0;
  137. list_del(&req->node);
  138. list_for_each_entry(req, &pqf->list, node)
  139. val |= req->flags;
  140. pqf->effective_flags = val;
  141. }
  142. /**
  143. * pm_qos_update_flags - Update a set of PM QoS flags.
  144. * @pqf: Set of PM QoS flags to update.
  145. * @req: Request to add to the set, to modify, or to remove from the set.
  146. * @action: Action to take on the set.
  147. * @val: Value of the request to add or modify.
  148. *
  149. * Return: 1 if the aggregate constraint value has changed, 0 otherwise.
  150. */
  151. bool pm_qos_update_flags(struct pm_qos_flags *pqf,
  152. struct pm_qos_flags_request *req,
  153. enum pm_qos_req_action action, s32 val)
  154. {
  155. unsigned long irqflags;
  156. s32 prev_value, curr_value;
  157. spin_lock_irqsave(&pm_qos_lock, irqflags);
  158. prev_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags;
  159. switch (action) {
  160. case PM_QOS_REMOVE_REQ:
  161. pm_qos_flags_remove_req(pqf, req);
  162. break;
  163. case PM_QOS_UPDATE_REQ:
  164. pm_qos_flags_remove_req(pqf, req);
  165. fallthrough;
  166. case PM_QOS_ADD_REQ:
  167. req->flags = val;
  168. INIT_LIST_HEAD(&req->node);
  169. list_add_tail(&req->node, &pqf->list);
  170. pqf->effective_flags |= val;
  171. break;
  172. default:
  173. /* no action */
  174. ;
  175. }
  176. curr_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags;
  177. spin_unlock_irqrestore(&pm_qos_lock, irqflags);
  178. trace_pm_qos_update_flags(action, prev_value, curr_value);
  179. return prev_value != curr_value;
  180. }
  181. #ifdef CONFIG_CPU_IDLE
  182. /* Definitions related to the CPU latency QoS. */
  183. static struct pm_qos_constraints cpu_latency_constraints = {
  184. .list = PLIST_HEAD_INIT(cpu_latency_constraints.list),
  185. .target_value = PM_QOS_CPU_LATENCY_DEFAULT_VALUE,
  186. .default_value = PM_QOS_CPU_LATENCY_DEFAULT_VALUE,
  187. .no_constraint_value = PM_QOS_CPU_LATENCY_DEFAULT_VALUE,
  188. .type = PM_QOS_MIN,
  189. };
  190. /**
  191. * cpu_latency_qos_limit - Return current system-wide CPU latency QoS limit.
  192. */
  193. s32 cpu_latency_qos_limit(void)
  194. {
  195. return pm_qos_read_value(&cpu_latency_constraints);
  196. }
  197. /**
  198. * cpu_latency_qos_request_active - Check the given PM QoS request.
  199. * @req: PM QoS request to check.
  200. *
  201. * Return: 'true' if @req has been added to the CPU latency QoS list, 'false'
  202. * otherwise.
  203. */
  204. bool cpu_latency_qos_request_active(struct pm_qos_request *req)
  205. {
  206. return req->qos == &cpu_latency_constraints;
  207. }
  208. EXPORT_SYMBOL_GPL(cpu_latency_qos_request_active);
  209. static void cpu_latency_qos_apply(struct pm_qos_request *req,
  210. enum pm_qos_req_action action, s32 value)
  211. {
  212. int ret = pm_qos_update_target(req->qos, &req->node, action, value);
  213. if (ret > 0)
  214. wake_up_all_idle_cpus();
  215. }
  216. /**
  217. * cpu_latency_qos_add_request - Add new CPU latency QoS request.
  218. * @req: Pointer to a preallocated handle.
  219. * @value: Requested constraint value.
  220. *
  221. * Use @value to initialize the request handle pointed to by @req, insert it as
  222. * a new entry to the CPU latency QoS list and recompute the effective QoS
  223. * constraint for that list.
  224. *
  225. * Callers need to save the handle for later use in updates and removal of the
  226. * QoS request represented by it.
  227. */
  228. void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value)
  229. {
  230. if (!req)
  231. return;
  232. if (cpu_latency_qos_request_active(req)) {
  233. WARN(1, KERN_ERR "%s called for already added request\n", __func__);
  234. return;
  235. }
  236. trace_pm_qos_add_request(value);
  237. req->qos = &cpu_latency_constraints;
  238. cpu_latency_qos_apply(req, PM_QOS_ADD_REQ, value);
  239. }
  240. EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);
  241. /**
  242. * cpu_latency_qos_update_request - Modify existing CPU latency QoS request.
  243. * @req : QoS request to update.
  244. * @new_value: New requested constraint value.
  245. *
  246. * Use @new_value to update the QoS request represented by @req in the CPU
  247. * latency QoS list along with updating the effective constraint value for that
  248. * list.
  249. */
  250. void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value)
  251. {
  252. if (!req)
  253. return;
  254. if (!cpu_latency_qos_request_active(req)) {
  255. WARN(1, KERN_ERR "%s called for unknown object\n", __func__);
  256. return;
  257. }
  258. trace_pm_qos_update_request(new_value);
  259. if (new_value == req->node.prio)
  260. return;
  261. cpu_latency_qos_apply(req, PM_QOS_UPDATE_REQ, new_value);
  262. }
  263. EXPORT_SYMBOL_GPL(cpu_latency_qos_update_request);
  264. /**
  265. * cpu_latency_qos_remove_request - Remove existing CPU latency QoS request.
  266. * @req: QoS request to remove.
  267. *
  268. * Remove the CPU latency QoS request represented by @req from the CPU latency
  269. * QoS list along with updating the effective constraint value for that list.
  270. */
  271. void cpu_latency_qos_remove_request(struct pm_qos_request *req)
  272. {
  273. if (!req)
  274. return;
  275. if (!cpu_latency_qos_request_active(req)) {
  276. WARN(1, KERN_ERR "%s called for unknown object\n", __func__);
  277. return;
  278. }
  279. trace_pm_qos_remove_request(PM_QOS_DEFAULT_VALUE);
  280. cpu_latency_qos_apply(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
  281. memset(req, 0, sizeof(*req));
  282. }
  283. EXPORT_SYMBOL_GPL(cpu_latency_qos_remove_request);
  284. /* User space interface to the CPU latency QoS via misc device. */
  285. static int cpu_latency_qos_open(struct inode *inode, struct file *filp)
  286. {
  287. struct pm_qos_request *req;
  288. req = kzalloc(sizeof(*req), GFP_KERNEL);
  289. if (!req)
  290. return -ENOMEM;
  291. cpu_latency_qos_add_request(req, PM_QOS_DEFAULT_VALUE);
  292. filp->private_data = req;
  293. return 0;
  294. }
  295. static int cpu_latency_qos_release(struct inode *inode, struct file *filp)
  296. {
  297. struct pm_qos_request *req = filp->private_data;
  298. filp->private_data = NULL;
  299. cpu_latency_qos_remove_request(req);
  300. kfree(req);
  301. return 0;
  302. }
  303. static ssize_t cpu_latency_qos_read(struct file *filp, char __user *buf,
  304. size_t count, loff_t *f_pos)
  305. {
  306. struct pm_qos_request *req = filp->private_data;
  307. unsigned long flags;
  308. s32 value;
  309. if (!req || !cpu_latency_qos_request_active(req))
  310. return -EINVAL;
  311. spin_lock_irqsave(&pm_qos_lock, flags);
  312. value = pm_qos_get_value(&cpu_latency_constraints);
  313. spin_unlock_irqrestore(&pm_qos_lock, flags);
  314. return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32));
  315. }
  316. static ssize_t cpu_latency_qos_write(struct file *filp, const char __user *buf,
  317. size_t count, loff_t *f_pos)
  318. {
  319. s32 value;
  320. if (count == sizeof(s32)) {
  321. if (copy_from_user(&value, buf, sizeof(s32)))
  322. return -EFAULT;
  323. } else {
  324. int ret;
  325. ret = kstrtos32_from_user(buf, count, 16, &value);
  326. if (ret)
  327. return ret;
  328. }
  329. cpu_latency_qos_update_request(filp->private_data, value);
  330. return count;
  331. }
  332. static const struct file_operations cpu_latency_qos_fops = {
  333. .write = cpu_latency_qos_write,
  334. .read = cpu_latency_qos_read,
  335. .open = cpu_latency_qos_open,
  336. .release = cpu_latency_qos_release,
  337. .llseek = noop_llseek,
  338. };
  339. static struct miscdevice cpu_latency_qos_miscdev = {
  340. .minor = MISC_DYNAMIC_MINOR,
  341. .name = "cpu_dma_latency",
  342. .fops = &cpu_latency_qos_fops,
  343. };
  344. static int __init cpu_latency_qos_init(void)
  345. {
  346. int ret;
  347. ret = misc_register(&cpu_latency_qos_miscdev);
  348. if (ret < 0)
  349. pr_err("%s: %s setup failed\n", __func__,
  350. cpu_latency_qos_miscdev.name);
  351. return ret;
  352. }
  353. late_initcall(cpu_latency_qos_init);
  354. #endif /* CONFIG_CPU_IDLE */
  355. /* Definitions related to the frequency QoS below. */
  356. static inline bool freq_qos_value_invalid(s32 value)
  357. {
  358. return value < 0 && value != PM_QOS_DEFAULT_VALUE;
  359. }
  360. /**
  361. * freq_constraints_init - Initialize frequency QoS constraints.
  362. * @qos: Frequency QoS constraints to initialize.
  363. */
  364. void freq_constraints_init(struct freq_constraints *qos)
  365. {
  366. struct pm_qos_constraints *c;
  367. c = &qos->min_freq;
  368. plist_head_init(&c->list);
  369. c->target_value = FREQ_QOS_MIN_DEFAULT_VALUE;
  370. c->default_value = FREQ_QOS_MIN_DEFAULT_VALUE;
  371. c->no_constraint_value = FREQ_QOS_MIN_DEFAULT_VALUE;
  372. c->type = PM_QOS_MAX;
  373. c->notifiers = &qos->min_freq_notifiers;
  374. BLOCKING_INIT_NOTIFIER_HEAD(c->notifiers);
  375. c = &qos->max_freq;
  376. plist_head_init(&c->list);
  377. c->target_value = FREQ_QOS_MAX_DEFAULT_VALUE;
  378. c->default_value = FREQ_QOS_MAX_DEFAULT_VALUE;
  379. c->no_constraint_value = FREQ_QOS_MAX_DEFAULT_VALUE;
  380. c->type = PM_QOS_MIN;
  381. c->notifiers = &qos->max_freq_notifiers;
  382. BLOCKING_INIT_NOTIFIER_HEAD(c->notifiers);
  383. }
  384. /**
  385. * freq_qos_read_value - Get frequency QoS constraint for a given list.
  386. * @qos: Constraints to evaluate.
  387. * @type: QoS request type.
  388. */
  389. s32 freq_qos_read_value(struct freq_constraints *qos,
  390. enum freq_qos_req_type type)
  391. {
  392. s32 ret;
  393. switch (type) {
  394. case FREQ_QOS_MIN:
  395. ret = IS_ERR_OR_NULL(qos) ?
  396. FREQ_QOS_MIN_DEFAULT_VALUE :
  397. pm_qos_read_value(&qos->min_freq);
  398. break;
  399. case FREQ_QOS_MAX:
  400. ret = IS_ERR_OR_NULL(qos) ?
  401. FREQ_QOS_MAX_DEFAULT_VALUE :
  402. pm_qos_read_value(&qos->max_freq);
  403. break;
  404. default:
  405. WARN_ON(1);
  406. ret = 0;
  407. }
  408. return ret;
  409. }
  410. /**
  411. * freq_qos_apply - Add/modify/remove frequency QoS request.
  412. * @req: Constraint request to apply.
  413. * @action: Action to perform (add/update/remove).
  414. * @value: Value to assign to the QoS request.
  415. *
  416. * This is only meant to be called from inside pm_qos, not drivers.
  417. */
  418. int freq_qos_apply(struct freq_qos_request *req,
  419. enum pm_qos_req_action action, s32 value)
  420. {
  421. int ret;
  422. switch(req->type) {
  423. case FREQ_QOS_MIN:
  424. ret = pm_qos_update_target(&req->qos->min_freq, &req->pnode,
  425. action, value);
  426. break;
  427. case FREQ_QOS_MAX:
  428. ret = pm_qos_update_target(&req->qos->max_freq, &req->pnode,
  429. action, value);
  430. break;
  431. default:
  432. ret = -EINVAL;
  433. }
  434. return ret;
  435. }
  436. /**
  437. * freq_qos_add_request - Insert new frequency QoS request into a given list.
  438. * @qos: Constraints to update.
  439. * @req: Preallocated request object.
  440. * @type: Request type.
  441. * @value: Request value.
  442. *
  443. * Insert a new entry into the @qos list of requests, recompute the effective
  444. * QoS constraint value for that list and initialize the @req object. The
  445. * caller needs to save that object for later use in updates and removal.
  446. *
  447. * Return 1 if the effective constraint value has changed, 0 if the effective
  448. * constraint value has not changed, or a negative error code on failures.
  449. */
  450. int freq_qos_add_request(struct freq_constraints *qos,
  451. struct freq_qos_request *req,
  452. enum freq_qos_req_type type, s32 value)
  453. {
  454. int ret;
  455. if (IS_ERR_OR_NULL(qos) || !req || freq_qos_value_invalid(value))
  456. return -EINVAL;
  457. if (WARN(freq_qos_request_active(req),
  458. "%s() called for active request\n", __func__))
  459. return -EINVAL;
  460. req->qos = qos;
  461. req->type = type;
  462. ret = freq_qos_apply(req, PM_QOS_ADD_REQ, value);
  463. if (ret < 0) {
  464. req->qos = NULL;
  465. req->type = 0;
  466. }
  467. trace_android_vh_freq_qos_add_request(qos, req, type, value, ret);
  468. return ret;
  469. }
  470. EXPORT_SYMBOL_GPL(freq_qos_add_request);
  471. /**
  472. * freq_qos_update_request - Modify existing frequency QoS request.
  473. * @req: Request to modify.
  474. * @new_value: New request value.
  475. *
  476. * Update an existing frequency QoS request along with the effective constraint
  477. * value for the list of requests it belongs to.
  478. *
  479. * Return 1 if the effective constraint value has changed, 0 if the effective
  480. * constraint value has not changed, or a negative error code on failures.
  481. */
  482. int freq_qos_update_request(struct freq_qos_request *req, s32 new_value)
  483. {
  484. if (!req || freq_qos_value_invalid(new_value))
  485. return -EINVAL;
  486. if (WARN(!freq_qos_request_active(req),
  487. "%s() called for unknown object\n", __func__))
  488. return -EINVAL;
  489. trace_android_vh_freq_qos_update_request(req, new_value);
  490. if (req->pnode.prio == new_value)
  491. return 0;
  492. return freq_qos_apply(req, PM_QOS_UPDATE_REQ, new_value);
  493. }
  494. EXPORT_SYMBOL_GPL(freq_qos_update_request);
  495. /**
  496. * freq_qos_remove_request - Remove frequency QoS request from its list.
  497. * @req: Request to remove.
  498. *
  499. * Remove the given frequency QoS request from the list of constraints it
  500. * belongs to and recompute the effective constraint value for that list.
  501. *
  502. * Return 1 if the effective constraint value has changed, 0 if the effective
  503. * constraint value has not changed, or a negative error code on failures.
  504. */
  505. int freq_qos_remove_request(struct freq_qos_request *req)
  506. {
  507. int ret;
  508. if (!req)
  509. return -EINVAL;
  510. if (WARN(!freq_qos_request_active(req),
  511. "%s() called for unknown object\n", __func__))
  512. return -EINVAL;
  513. trace_android_vh_freq_qos_remove_request(req);
  514. ret = freq_qos_apply(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
  515. req->qos = NULL;
  516. req->type = 0;
  517. return ret;
  518. }
  519. EXPORT_SYMBOL_GPL(freq_qos_remove_request);
  520. /**
  521. * freq_qos_add_notifier - Add frequency QoS change notifier.
  522. * @qos: List of requests to add the notifier to.
  523. * @type: Request type.
  524. * @notifier: Notifier block to add.
  525. */
  526. int freq_qos_add_notifier(struct freq_constraints *qos,
  527. enum freq_qos_req_type type,
  528. struct notifier_block *notifier)
  529. {
  530. int ret;
  531. if (IS_ERR_OR_NULL(qos) || !notifier)
  532. return -EINVAL;
  533. switch (type) {
  534. case FREQ_QOS_MIN:
  535. ret = blocking_notifier_chain_register(qos->min_freq.notifiers,
  536. notifier);
  537. break;
  538. case FREQ_QOS_MAX:
  539. ret = blocking_notifier_chain_register(qos->max_freq.notifiers,
  540. notifier);
  541. break;
  542. default:
  543. WARN_ON(1);
  544. ret = -EINVAL;
  545. }
  546. return ret;
  547. }
  548. EXPORT_SYMBOL_GPL(freq_qos_add_notifier);
  549. /**
  550. * freq_qos_remove_notifier - Remove frequency QoS change notifier.
  551. * @qos: List of requests to remove the notifier from.
  552. * @type: Request type.
  553. * @notifier: Notifier block to remove.
  554. */
  555. int freq_qos_remove_notifier(struct freq_constraints *qos,
  556. enum freq_qos_req_type type,
  557. struct notifier_block *notifier)
  558. {
  559. int ret;
  560. if (IS_ERR_OR_NULL(qos) || !notifier)
  561. return -EINVAL;
  562. switch (type) {
  563. case FREQ_QOS_MIN:
  564. ret = blocking_notifier_chain_unregister(qos->min_freq.notifiers,
  565. notifier);
  566. break;
  567. case FREQ_QOS_MAX:
  568. ret = blocking_notifier_chain_unregister(qos->max_freq.notifiers,
  569. notifier);
  570. break;
  571. default:
  572. WARN_ON(1);
  573. ret = -EINVAL;
  574. }
  575. return ret;
  576. }
  577. EXPORT_SYMBOL_GPL(freq_qos_remove_notifier);