qos.c 17 KB

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