qos.c 18 KB

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