diff options
| author | Mark Gross <mgross@linux.intel.com> | 2008-02-05 01:30:09 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:22 -0500 |
| commit | f011e2e2df3393c16b0fdc48e855e909b7e021ee (patch) | |
| tree | 1ad56011597c739336d7068c8182fd9cfdddad5b | |
| parent | d82b35186eaa816267f044bd70cc0acb3c7971a3 (diff) | |
latency.c: use QoS infrastructure
Replace latency.c use with pm_qos_params use.
Signed-off-by: mark gross <mgross@linux.intel.com>
Cc: "John W. Linville" <linville@tuxdriver.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Jaroslav Kysela <perex@suse.cz>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | drivers/acpi/processor_idle.c | 18 | ||||
| -rw-r--r-- | drivers/net/wireless/ipw2100.c | 12 | ||||
| -rw-r--r-- | include/linux/latency.h | 25 | ||||
| -rw-r--r-- | kernel/Makefile | 2 | ||||
| -rw-r--r-- | kernel/latency.c | 280 | ||||
| -rw-r--r-- | sound/core/pcm_native.c | 11 |
6 files changed, 26 insertions, 322 deletions
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index eb1f82f79153..199ea2146153 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
| @@ -38,7 +38,7 @@ | |||
| 38 | #include <linux/dmi.h> | 38 | #include <linux/dmi.h> |
| 39 | #include <linux/moduleparam.h> | 39 | #include <linux/moduleparam.h> |
| 40 | #include <linux/sched.h> /* need_resched() */ | 40 | #include <linux/sched.h> /* need_resched() */ |
| 41 | #include <linux/latency.h> | 41 | #include <linux/pm_qos_params.h> |
| 42 | #include <linux/clockchips.h> | 42 | #include <linux/clockchips.h> |
| 43 | #include <linux/cpuidle.h> | 43 | #include <linux/cpuidle.h> |
| 44 | 44 | ||
| @@ -648,7 +648,8 @@ static void acpi_processor_idle(void) | |||
| 648 | if (cx->promotion.state && | 648 | if (cx->promotion.state && |
| 649 | ((cx->promotion.state - pr->power.states) <= max_cstate)) { | 649 | ((cx->promotion.state - pr->power.states) <= max_cstate)) { |
| 650 | if (sleep_ticks > cx->promotion.threshold.ticks && | 650 | if (sleep_ticks > cx->promotion.threshold.ticks && |
| 651 | cx->promotion.state->latency <= system_latency_constraint()) { | 651 | cx->promotion.state->latency <= |
| 652 | pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) { | ||
| 652 | cx->promotion.count++; | 653 | cx->promotion.count++; |
| 653 | cx->demotion.count = 0; | 654 | cx->demotion.count = 0; |
| 654 | if (cx->promotion.count >= | 655 | if (cx->promotion.count >= |
| @@ -692,7 +693,8 @@ static void acpi_processor_idle(void) | |||
| 692 | * or if the latency of the current state is unacceptable | 693 | * or if the latency of the current state is unacceptable |
| 693 | */ | 694 | */ |
| 694 | if ((pr->power.state - pr->power.states) > max_cstate || | 695 | if ((pr->power.state - pr->power.states) > max_cstate || |
| 695 | pr->power.state->latency > system_latency_constraint()) { | 696 | pr->power.state->latency > |
| 697 | pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) { | ||
| 696 | if (cx->demotion.state) | 698 | if (cx->demotion.state) |
| 697 | next_state = cx->demotion.state; | 699 | next_state = cx->demotion.state; |
| 698 | } | 700 | } |
| @@ -1200,7 +1202,7 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset) | |||
| 1200 | "maximum allowed latency: %d usec\n", | 1202 | "maximum allowed latency: %d usec\n", |
| 1201 | pr->power.state ? pr->power.state - pr->power.states : 0, | 1203 | pr->power.state ? pr->power.state - pr->power.states : 0, |
| 1202 | max_cstate, (unsigned)pr->power.bm_activity, | 1204 | max_cstate, (unsigned)pr->power.bm_activity, |
| 1203 | system_latency_constraint()); | 1205 | pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)); |
| 1204 | 1206 | ||
| 1205 | seq_puts(seq, "states:\n"); | 1207 | seq_puts(seq, "states:\n"); |
| 1206 | 1208 | ||
| @@ -1718,8 +1720,9 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | |||
| 1718 | "ACPI: processor limited to max C-state %d\n", | 1720 | "ACPI: processor limited to max C-state %d\n", |
| 1719 | max_cstate); | 1721 | max_cstate); |
| 1720 | first_run++; | 1722 | first_run++; |
| 1721 | #if !defined (CONFIG_CPU_IDLE) && defined (CONFIG_SMP) | 1723 | #if !defined(CONFIG_CPU_IDLE) && defined(CONFIG_SMP) |
| 1722 | register_latency_notifier(&acpi_processor_latency_notifier); | 1724 | pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY, |
| 1725 | &acpi_processor_latency_notifier); | ||
| 1723 | #endif | 1726 | #endif |
| 1724 | } | 1727 | } |
| 1725 | 1728 | ||
| @@ -1806,7 +1809,8 @@ int acpi_processor_power_exit(struct acpi_processor *pr, | |||
| 1806 | */ | 1809 | */ |
| 1807 | cpu_idle_wait(); | 1810 | cpu_idle_wait(); |
| 1808 | #ifdef CONFIG_SMP | 1811 | #ifdef CONFIG_SMP |
| 1809 | unregister_latency_notifier(&acpi_processor_latency_notifier); | 1812 | pm_qos_remove_notifier(PM_QOS_CPU_DMA_LATENCY, |
| 1813 | &acpi_processor_latency_notifier); | ||
| 1810 | #endif | 1814 | #endif |
| 1811 | } | 1815 | } |
| 1812 | #endif | 1816 | #endif |
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c index 2ab107f45793..5bf9e00b070c 100644 --- a/drivers/net/wireless/ipw2100.c +++ b/drivers/net/wireless/ipw2100.c | |||
| @@ -162,7 +162,7 @@ that only one external action is invoked at a time. | |||
| 162 | #include <linux/firmware.h> | 162 | #include <linux/firmware.h> |
| 163 | #include <linux/acpi.h> | 163 | #include <linux/acpi.h> |
| 164 | #include <linux/ctype.h> | 164 | #include <linux/ctype.h> |
| 165 | #include <linux/latency.h> | 165 | #include <linux/pm_qos_params.h> |
| 166 | 166 | ||
| 167 | #include "ipw2100.h" | 167 | #include "ipw2100.h" |
| 168 | 168 | ||
| @@ -1701,7 +1701,7 @@ static int ipw2100_up(struct ipw2100_priv *priv, int deferred) | |||
| 1701 | /* the ipw2100 hardware really doesn't want power management delays | 1701 | /* the ipw2100 hardware really doesn't want power management delays |
| 1702 | * longer than 175usec | 1702 | * longer than 175usec |
| 1703 | */ | 1703 | */ |
| 1704 | modify_acceptable_latency("ipw2100", 175); | 1704 | pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175); |
| 1705 | 1705 | ||
| 1706 | /* If the interrupt is enabled, turn it off... */ | 1706 | /* If the interrupt is enabled, turn it off... */ |
| 1707 | spin_lock_irqsave(&priv->low_lock, flags); | 1707 | spin_lock_irqsave(&priv->low_lock, flags); |
| @@ -1856,7 +1856,8 @@ static void ipw2100_down(struct ipw2100_priv *priv) | |||
| 1856 | ipw2100_disable_interrupts(priv); | 1856 | ipw2100_disable_interrupts(priv); |
| 1857 | spin_unlock_irqrestore(&priv->low_lock, flags); | 1857 | spin_unlock_irqrestore(&priv->low_lock, flags); |
| 1858 | 1858 | ||
| 1859 | modify_acceptable_latency("ipw2100", INFINITE_LATENCY); | 1859 | pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", |
| 1860 | PM_QOS_DEFAULT_VALUE); | ||
| 1860 | 1861 | ||
| 1861 | /* We have to signal any supplicant if we are disassociating */ | 1862 | /* We have to signal any supplicant if we are disassociating */ |
| 1862 | if (associated) | 1863 | if (associated) |
| @@ -6554,7 +6555,8 @@ static int __init ipw2100_init(void) | |||
| 6554 | if (ret) | 6555 | if (ret) |
| 6555 | goto out; | 6556 | goto out; |
| 6556 | 6557 | ||
| 6557 | set_acceptable_latency("ipw2100", INFINITE_LATENCY); | 6558 | pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", |
| 6559 | PM_QOS_DEFAULT_VALUE); | ||
| 6558 | #ifdef CONFIG_IPW2100_DEBUG | 6560 | #ifdef CONFIG_IPW2100_DEBUG |
| 6559 | ipw2100_debug_level = debug; | 6561 | ipw2100_debug_level = debug; |
| 6560 | ret = driver_create_file(&ipw2100_pci_driver.driver, | 6562 | ret = driver_create_file(&ipw2100_pci_driver.driver, |
| @@ -6576,7 +6578,7 @@ static void __exit ipw2100_exit(void) | |||
| 6576 | &driver_attr_debug_level); | 6578 | &driver_attr_debug_level); |
| 6577 | #endif | 6579 | #endif |
| 6578 | pci_unregister_driver(&ipw2100_pci_driver); | 6580 | pci_unregister_driver(&ipw2100_pci_driver); |
| 6579 | remove_acceptable_latency("ipw2100"); | 6581 | pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100"); |
| 6580 | } | 6582 | } |
| 6581 | 6583 | ||
| 6582 | module_init(ipw2100_init); | 6584 | module_init(ipw2100_init); |
diff --git a/include/linux/latency.h b/include/linux/latency.h deleted file mode 100644 index c08b52bb55b0..000000000000 --- a/include/linux/latency.h +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * latency.h: Explicit system-wide latency-expectation infrastructure | ||
| 3 | * | ||
| 4 | * (C) Copyright 2006 Intel Corporation | ||
| 5 | * Author: Arjan van de Ven <arjan@linux.intel.com> | ||
| 6 | * | ||
| 7 | */ | ||
| 8 | |||
| 9 | #ifndef _INCLUDE_GUARD_LATENCY_H_ | ||
| 10 | #define _INCLUDE_GUARD_LATENCY_H_ | ||
| 11 | |||
| 12 | #include <linux/notifier.h> | ||
| 13 | |||
| 14 | void set_acceptable_latency(char *identifier, int usecs); | ||
| 15 | void modify_acceptable_latency(char *identifier, int usecs); | ||
| 16 | void remove_acceptable_latency(char *identifier); | ||
| 17 | void synchronize_acceptable_latency(void); | ||
| 18 | int system_latency_constraint(void); | ||
| 19 | |||
| 20 | int register_latency_notifier(struct notifier_block * nb); | ||
| 21 | int unregister_latency_notifier(struct notifier_block * nb); | ||
| 22 | |||
| 23 | #define INFINITE_LATENCY 1000000 | ||
| 24 | |||
| 25 | #endif | ||
diff --git a/kernel/Makefile b/kernel/Makefile index 8331243a4e5e..135a1b943446 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -8,7 +8,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ | |||
| 8 | signal.o sys.o kmod.o workqueue.o pid.o \ | 8 | signal.o sys.o kmod.o workqueue.o pid.o \ |
| 9 | rcupdate.o extable.o params.o posix-timers.o \ | 9 | rcupdate.o extable.o params.o posix-timers.o \ |
| 10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ | 10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ |
| 11 | hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \ | 11 | hrtimer.o rwsem.o nsproxy.o srcu.o \ |
| 12 | utsname.o notifier.o ksysfs.o pm_qos_params.o | 12 | utsname.o notifier.o ksysfs.o pm_qos_params.o |
| 13 | 13 | ||
| 14 | obj-$(CONFIG_SYSCTL) += sysctl_check.o | 14 | obj-$(CONFIG_SYSCTL) += sysctl_check.o |
diff --git a/kernel/latency.c b/kernel/latency.c deleted file mode 100644 index e63fcacb61a7..000000000000 --- a/kernel/latency.c +++ /dev/null | |||
| @@ -1,280 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * latency.c: Explicit system-wide latency-expectation infrastructure | ||
| 3 | * | ||
| 4 | * The purpose of this infrastructure is to allow device drivers to set | ||
| 5 | * latency constraint they have and to collect and summarize these | ||
| 6 | * expectations globally. The cummulated result can then be used by | ||
| 7 | * power management and similar users to make decisions that have | ||
| 8 | * tradoffs with a latency component. | ||
| 9 | * | ||
| 10 | * An example user of this are the x86 C-states; each higher C state saves | ||
| 11 | * more power, but has a higher exit latency. For the idle loop power | ||
| 12 | * code to make a good decision which C-state to use, information about | ||
| 13 | * acceptable latencies is required. | ||
| 14 | * | ||
| 15 | * An example announcer of latency is an audio driver that knowns it | ||
| 16 | * will get an interrupt when the hardware has 200 usec of samples | ||
| 17 | * left in the DMA buffer; in that case the driver can set a latency | ||
| 18 | * constraint of, say, 150 usec. | ||
| 19 | * | ||
| 20 | * Multiple drivers can each announce their maximum accepted latency, | ||
| 21 | * to keep these appart, a string based identifier is used. | ||
| 22 | * | ||
| 23 | * | ||
| 24 | * (C) Copyright 2006 Intel Corporation | ||
| 25 | * Author: Arjan van de Ven <arjan@linux.intel.com> | ||
| 26 | * | ||
| 27 | * This program is free software; you can redistribute it and/or | ||
| 28 | * modify it under the terms of the GNU General Public License | ||
| 29 | * as published by the Free Software Foundation; version 2 | ||
| 30 | * of the License. | ||
| 31 | */ | ||
| 32 | |||
| 33 | #include <linux/latency.h> | ||
| 34 | #include <linux/list.h> | ||
| 35 | #include <linux/spinlock.h> | ||
| 36 | #include <linux/slab.h> | ||
| 37 | #include <linux/module.h> | ||
| 38 | #include <linux/notifier.h> | ||
| 39 | #include <linux/jiffies.h> | ||
| 40 | #include <asm/atomic.h> | ||
| 41 | |||
| 42 | struct latency_info { | ||
| 43 | struct list_head list; | ||
| 44 | int usecs; | ||
| 45 | char *identifier; | ||
| 46 | }; | ||
| 47 | |||
| 48 | /* | ||
| 49 | * locking rule: all modifications to current_max_latency and | ||
| 50 | * latency_list need to be done while holding the latency_lock. | ||
| 51 | * latency_lock needs to be taken _irqsave. | ||
| 52 | */ | ||
| 53 | static atomic_t current_max_latency; | ||
| 54 | static DEFINE_SPINLOCK(latency_lock); | ||
| 55 | |||
| 56 | static LIST_HEAD(latency_list); | ||
| 57 | static BLOCKING_NOTIFIER_HEAD(latency_notifier); | ||
| 58 | |||
| 59 | /* | ||
| 60 | * This function returns the maximum latency allowed, which | ||
| 61 | * happens to be the minimum of all maximum latencies on the | ||
| 62 | * list. | ||
| 63 | */ | ||
| 64 | static int __find_max_latency(void) | ||
| 65 | { | ||
| 66 | int min = INFINITE_LATENCY; | ||
| 67 | struct latency_info *info; | ||
| 68 | |||
| 69 | list_for_each_entry(info, &latency_list, list) { | ||
| 70 | if (info->usecs < min) | ||
| 71 | min = info->usecs; | ||
| 72 | } | ||
| 73 | return min; | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * set_acceptable_latency - sets the maximum latency acceptable | ||
| 78 | * @identifier: string that identifies this driver | ||
| 79 | * @usecs: maximum acceptable latency for this driver | ||
| 80 | * | ||
| 81 | * This function informs the kernel that this device(driver) | ||
| 82 | * can accept at most usecs latency. This setting is used for | ||
| 83 | * power management and similar tradeoffs. | ||
| 84 | * | ||
| 85 | * This function sleeps and can only be called from process | ||
| 86 | * context. | ||
| 87 | * Calling this function with an existing identifier is valid | ||
| 88 | * and will cause the existing latency setting to be changed. | ||
| 89 | */ | ||
| 90 | void set_acceptable_latency(char *identifier, int usecs) | ||
| 91 | { | ||
| 92 | struct latency_info *info, *iter; | ||
| 93 | unsigned long flags; | ||
| 94 | int found_old = 0; | ||
| 95 | |||
| 96 | info = kzalloc(sizeof(struct latency_info), GFP_KERNEL); | ||
| 97 | if (!info) | ||
| 98 | return; | ||
| 99 | info->usecs = usecs; | ||
| 100 | info->identifier = kstrdup(identifier, GFP_KERNEL); | ||
| 101 | if (!info->identifier) | ||
| 102 | goto free_info; | ||
| 103 | |||
| 104 | spin_lock_irqsave(&latency_lock, flags); | ||
| 105 | list_for_each_entry(iter, &latency_list, list) { | ||
| 106 | if (strcmp(iter->identifier, identifier)==0) { | ||
| 107 | found_old = 1; | ||
| 108 | iter->usecs = usecs; | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | if (!found_old) | ||
| 113 | list_add(&info->list, &latency_list); | ||
| 114 | |||
| 115 | if (usecs < atomic_read(¤t_max_latency)) | ||
| 116 | atomic_set(¤t_max_latency, usecs); | ||
| 117 | |||
| 118 | spin_unlock_irqrestore(&latency_lock, flags); | ||
| 119 | |||
| 120 | blocking_notifier_call_chain(&latency_notifier, | ||
| 121 | atomic_read(¤t_max_latency), NULL); | ||
| 122 | |||
| 123 | /* | ||
| 124 | * if we inserted the new one, we're done; otherwise there was | ||
| 125 | * an existing one so we need to free the redundant data | ||
| 126 | */ | ||
| 127 | if (!found_old) | ||
| 128 | return; | ||
| 129 | |||
| 130 | kfree(info->identifier); | ||
| 131 | free_info: | ||
| 132 | kfree(info); | ||
| 133 | } | ||
| 134 | EXPORT_SYMBOL_GPL(set_acceptable_latency); | ||
| 135 | |||
| 136 | /** | ||
| 137 | * modify_acceptable_latency - changes the maximum latency acceptable | ||
| 138 | * @identifier: string that identifies this driver | ||
| 139 | * @usecs: maximum acceptable latency for this driver | ||
| 140 | * | ||
| 141 | * This function informs the kernel that this device(driver) | ||
| 142 | * can accept at most usecs latency. This setting is used for | ||
| 143 | * power management and similar tradeoffs. | ||
| 144 | * | ||
| 145 | * This function does not sleep and can be called in any context. | ||
| 146 | * Trying to use a non-existing identifier silently gets ignored. | ||
| 147 | * | ||
| 148 | * Due to the atomic nature of this function, the modified latency | ||
| 149 | * value will only be used for future decisions; past decisions | ||
| 150 | * can still lead to longer latencies in the near future. | ||
| 151 | */ | ||
| 152 | void modify_acceptable_latency(char *identifier, int usecs) | ||
| 153 | { | ||
| 154 | struct latency_info *iter; | ||
| 155 | unsigned long flags; | ||
| 156 | |||
| 157 | spin_lock_irqsave(&latency_lock, flags); | ||
| 158 | list_for_each_entry(iter, &latency_list, list) { | ||
| 159 | if (strcmp(iter->identifier, identifier) == 0) { | ||
| 160 | iter->usecs = usecs; | ||
| 161 | break; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | if (usecs < atomic_read(¤t_max_latency)) | ||
| 165 | atomic_set(¤t_max_latency, usecs); | ||
| 166 | spin_unlock_irqrestore(&latency_lock, flags); | ||
| 167 | } | ||
| 168 | EXPORT_SYMBOL_GPL(modify_acceptable_latency); | ||
| 169 | |||
| 170 | /** | ||
| 171 | * remove_acceptable_latency - removes the maximum latency acceptable | ||
| 172 | * @identifier: string that identifies this driver | ||
| 173 | * | ||
| 174 | * This function removes a previously set maximum latency setting | ||
| 175 | * for the driver and frees up any resources associated with the | ||
| 176 | * bookkeeping needed for this. | ||
| 177 | * | ||
| 178 | * This function does not sleep and can be called in any context. | ||
| 179 | * Trying to use a non-existing identifier silently gets ignored. | ||
| 180 | */ | ||
| 181 | void remove_acceptable_latency(char *identifier) | ||
| 182 | { | ||
| 183 | unsigned long flags; | ||
| 184 | int newmax = 0; | ||
| 185 | struct latency_info *iter, *temp; | ||
| 186 | |||
| 187 | spin_lock_irqsave(&latency_lock, flags); | ||
| 188 | |||
| 189 | list_for_each_entry_safe(iter, temp, &latency_list, list) { | ||
| 190 | if (strcmp(iter->identifier, identifier) == 0) { | ||
| 191 | list_del(&iter->list); | ||
| 192 | newmax = iter->usecs; | ||
| 193 | kfree(iter->identifier); | ||
| 194 | kfree(iter); | ||
| 195 | break; | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | /* If we just deleted the system wide value, we need to | ||
| 200 | * recalculate with a full search | ||
| 201 | */ | ||
| 202 | if (newmax == atomic_read(¤t_max_latency)) { | ||
| 203 | newmax = __find_max_latency(); | ||
| 204 | atomic_set(¤t_max_latency, newmax); | ||
| 205 | } | ||
| 206 | spin_unlock_irqrestore(&latency_lock, flags); | ||
| 207 | } | ||
| 208 | EXPORT_SYMBOL_GPL(remove_acceptable_latency); | ||
| 209 | |||
| 210 | /** | ||
| 211 | * system_latency_constraint - queries the system wide latency maximum | ||
| 212 | * | ||
| 213 | * This function returns the system wide maximum latency in | ||
| 214 | * microseconds. | ||
| 215 | * | ||
| 216 | * This function does not sleep and can be called in any context. | ||
| 217 | */ | ||
| 218 | int system_latency_constraint(void) | ||
| 219 | { | ||
| 220 | return atomic_read(¤t_max_latency); | ||
| 221 | } | ||
| 222 | EXPORT_SYMBOL_GPL(system_latency_constraint); | ||
| 223 | |||
| 224 | /** | ||
| 225 | * synchronize_acceptable_latency - recalculates all latency decisions | ||
| 226 | * | ||
| 227 | * This function will cause a callback to various kernel pieces that | ||
| 228 | * will make those pieces rethink their latency decisions. This implies | ||
| 229 | * that if there are overlong latencies in hardware state already, those | ||
| 230 | * latencies get taken right now. When this call completes no overlong | ||
| 231 | * latency decisions should be active anymore. | ||
| 232 | * | ||
| 233 | * Typical usecase of this is after a modify_acceptable_latency() call, | ||
| 234 | * which in itself is non-blocking and non-synchronizing. | ||
| 235 | * | ||
| 236 | * This function blocks and should not be called with locks held. | ||
| 237 | */ | ||
| 238 | |||
| 239 | void synchronize_acceptable_latency(void) | ||
| 240 | { | ||
| 241 | blocking_notifier_call_chain(&latency_notifier, | ||
| 242 | atomic_read(¤t_max_latency), NULL); | ||
| 243 | } | ||
| 244 | EXPORT_SYMBOL_GPL(synchronize_acceptable_latency); | ||
| 245 | |||
| 246 | /* | ||
| 247 | * Latency notifier: this notifier gets called when a non-atomic new | ||
| 248 | * latency value gets set. The expectation nof the caller of the | ||
| 249 | * non-atomic set is that when the call returns, future latencies | ||
| 250 | * are within bounds, so the functions on the notifier list are | ||
| 251 | * expected to take the overlong latencies immediately, inside the | ||
| 252 | * callback, and not make a overlong latency decision anymore. | ||
| 253 | * | ||
| 254 | * The callback gets called when the new latency value is made | ||
| 255 | * active so system_latency_constraint() returns the new latency. | ||
| 256 | */ | ||
| 257 | int register_latency_notifier(struct notifier_block * nb) | ||
| 258 | { | ||
| 259 | return blocking_notifier_chain_register(&latency_notifier, nb); | ||
| 260 | } | ||
| 261 | EXPORT_SYMBOL_GPL(register_latency_notifier); | ||
| 262 | |||
| 263 | int unregister_latency_notifier(struct notifier_block * nb) | ||
| 264 | { | ||
| 265 | return blocking_notifier_chain_unregister(&latency_notifier, nb); | ||
| 266 | } | ||
| 267 | EXPORT_SYMBOL_GPL(unregister_latency_notifier); | ||
| 268 | |||
| 269 | static __init int latency_init(void) | ||
| 270 | { | ||
| 271 | atomic_set(¤t_max_latency, INFINITE_LATENCY); | ||
| 272 | /* | ||
| 273 | * we don't want by default to have longer latencies than 2 ticks, | ||
| 274 | * since that would cause lost ticks | ||
| 275 | */ | ||
| 276 | set_acceptable_latency("kernel", 2*1000000/HZ); | ||
| 277 | return 0; | ||
| 278 | } | ||
| 279 | |||
| 280 | module_init(latency_init); | ||
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 62449117ee14..61f5d425b630 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c | |||
| @@ -23,7 +23,7 @@ | |||
| 23 | #include <linux/file.h> | 23 | #include <linux/file.h> |
| 24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 25 | #include <linux/time.h> | 25 | #include <linux/time.h> |
| 26 | #include <linux/latency.h> | 26 | #include <linux/pm_qos_params.h> |
| 27 | #include <linux/uio.h> | 27 | #include <linux/uio.h> |
| 28 | #include <sound/core.h> | 28 | #include <sound/core.h> |
| 29 | #include <sound/control.h> | 29 | #include <sound/control.h> |
| @@ -443,9 +443,11 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, | |||
| 443 | snd_pcm_timer_resolution_change(substream); | 443 | snd_pcm_timer_resolution_change(substream); |
| 444 | runtime->status->state = SNDRV_PCM_STATE_SETUP; | 444 | runtime->status->state = SNDRV_PCM_STATE_SETUP; |
| 445 | 445 | ||
| 446 | remove_acceptable_latency(substream->latency_id); | 446 | pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, |
| 447 | substream->latency_id); | ||
| 447 | if ((usecs = period_to_usecs(runtime)) >= 0) | 448 | if ((usecs = period_to_usecs(runtime)) >= 0) |
| 448 | set_acceptable_latency(substream->latency_id, usecs); | 449 | pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, |
| 450 | substream->latency_id, usecs); | ||
| 449 | return 0; | 451 | return 0; |
| 450 | _error: | 452 | _error: |
| 451 | /* hardware might be unuseable from this time, | 453 | /* hardware might be unuseable from this time, |
| @@ -505,7 +507,8 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream) | |||
| 505 | if (substream->ops->hw_free) | 507 | if (substream->ops->hw_free) |
| 506 | result = substream->ops->hw_free(substream); | 508 | result = substream->ops->hw_free(substream); |
| 507 | runtime->status->state = SNDRV_PCM_STATE_OPEN; | 509 | runtime->status->state = SNDRV_PCM_STATE_OPEN; |
| 508 | remove_acceptable_latency(substream->latency_id); | 510 | pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, |
| 511 | substream->latency_id); | ||
| 509 | return result; | 512 | return result; |
| 510 | } | 513 | } |
| 511 | 514 | ||
