diff options
Diffstat (limited to 'Documentation')
| -rw-r--r-- | Documentation/DocBook/device-drivers.tmpl | 1 | ||||
| -rw-r--r-- | Documentation/DocBook/kernel-api.tmpl | 1 | ||||
| -rw-r--r-- | Documentation/block/cfq-iosched.txt | 45 | ||||
| -rw-r--r-- | Documentation/cgroups/blkio-controller.txt | 28 | ||||
| -rw-r--r-- | Documentation/gpio.txt | 22 | ||||
| -rw-r--r-- | Documentation/hwmon/sysfs-interface | 7 | ||||
| -rw-r--r-- | Documentation/kernel-doc-nano-HOWTO.txt | 5 | ||||
| -rw-r--r-- | Documentation/power/regulator/overview.txt | 2 | ||||
| -rw-r--r-- | Documentation/sound/alsa/HD-Audio-Models.txt | 1 | ||||
| -rw-r--r-- | Documentation/workqueue.txt | 380 |
10 files changed, 477 insertions, 15 deletions
diff --git a/Documentation/DocBook/device-drivers.tmpl b/Documentation/DocBook/device-drivers.tmpl index ecd35e9d4410..feca0758391e 100644 --- a/Documentation/DocBook/device-drivers.tmpl +++ b/Documentation/DocBook/device-drivers.tmpl | |||
| @@ -46,7 +46,6 @@ | |||
| 46 | 46 | ||
| 47 | <sect1><title>Atomic and pointer manipulation</title> | 47 | <sect1><title>Atomic and pointer manipulation</title> |
| 48 | !Iarch/x86/include/asm/atomic.h | 48 | !Iarch/x86/include/asm/atomic.h |
| 49 | !Iarch/x86/include/asm/unaligned.h | ||
| 50 | </sect1> | 49 | </sect1> |
| 51 | 50 | ||
| 52 | <sect1><title>Delaying, scheduling, and timer routines</title> | 51 | <sect1><title>Delaying, scheduling, and timer routines</title> |
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl index a20c6f6fffc3..6899f471fb15 100644 --- a/Documentation/DocBook/kernel-api.tmpl +++ b/Documentation/DocBook/kernel-api.tmpl | |||
| @@ -57,7 +57,6 @@ | |||
| 57 | </para> | 57 | </para> |
| 58 | 58 | ||
| 59 | <sect1><title>String Conversions</title> | 59 | <sect1><title>String Conversions</title> |
| 60 | !Ilib/vsprintf.c | ||
| 61 | !Elib/vsprintf.c | 60 | !Elib/vsprintf.c |
| 62 | </sect1> | 61 | </sect1> |
| 63 | <sect1><title>String Manipulation</title> | 62 | <sect1><title>String Manipulation</title> |
diff --git a/Documentation/block/cfq-iosched.txt b/Documentation/block/cfq-iosched.txt new file mode 100644 index 000000000000..e578feed6d81 --- /dev/null +++ b/Documentation/block/cfq-iosched.txt | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | CFQ ioscheduler tunables | ||
| 2 | ======================== | ||
| 3 | |||
| 4 | slice_idle | ||
| 5 | ---------- | ||
| 6 | This specifies how long CFQ should idle for next request on certain cfq queues | ||
| 7 | (for sequential workloads) and service trees (for random workloads) before | ||
| 8 | queue is expired and CFQ selects next queue to dispatch from. | ||
| 9 | |||
| 10 | By default slice_idle is a non-zero value. That means by default we idle on | ||
| 11 | queues/service trees. This can be very helpful on highly seeky media like | ||
| 12 | single spindle SATA/SAS disks where we can cut down on overall number of | ||
| 13 | seeks and see improved throughput. | ||
| 14 | |||
| 15 | Setting slice_idle to 0 will remove all the idling on queues/service tree | ||
| 16 | level and one should see an overall improved throughput on faster storage | ||
| 17 | devices like multiple SATA/SAS disks in hardware RAID configuration. The down | ||
| 18 | side is that isolation provided from WRITES also goes down and notion of | ||
| 19 | IO priority becomes weaker. | ||
| 20 | |||
| 21 | So depending on storage and workload, it might be useful to set slice_idle=0. | ||
| 22 | In general I think for SATA/SAS disks and software RAID of SATA/SAS disks | ||
| 23 | keeping slice_idle enabled should be useful. For any configurations where | ||
| 24 | there are multiple spindles behind single LUN (Host based hardware RAID | ||
| 25 | controller or for storage arrays), setting slice_idle=0 might end up in better | ||
| 26 | throughput and acceptable latencies. | ||
| 27 | |||
| 28 | CFQ IOPS Mode for group scheduling | ||
| 29 | =================================== | ||
| 30 | Basic CFQ design is to provide priority based time slices. Higher priority | ||
| 31 | process gets bigger time slice and lower priority process gets smaller time | ||
| 32 | slice. Measuring time becomes harder if storage is fast and supports NCQ and | ||
| 33 | it would be better to dispatch multiple requests from multiple cfq queues in | ||
| 34 | request queue at a time. In such scenario, it is not possible to measure time | ||
| 35 | consumed by single queue accurately. | ||
| 36 | |||
| 37 | What is possible though is to measure number of requests dispatched from a | ||
| 38 | single queue and also allow dispatch from multiple cfq queue at the same time. | ||
| 39 | This effectively becomes the fairness in terms of IOPS (IO operations per | ||
| 40 | second). | ||
| 41 | |||
| 42 | If one sets slice_idle=0 and if storage supports NCQ, CFQ internally switches | ||
| 43 | to IOPS mode and starts providing fairness in terms of number of requests | ||
| 44 | dispatched. Note that this mode switching takes effect only for group | ||
| 45 | scheduling. For non-cgroup users nothing should change. | ||
diff --git a/Documentation/cgroups/blkio-controller.txt b/Documentation/cgroups/blkio-controller.txt index 48e0b21b0059..6919d62591d9 100644 --- a/Documentation/cgroups/blkio-controller.txt +++ b/Documentation/cgroups/blkio-controller.txt | |||
| @@ -217,6 +217,7 @@ Details of cgroup files | |||
| 217 | CFQ sysfs tunable | 217 | CFQ sysfs tunable |
| 218 | ================= | 218 | ================= |
| 219 | /sys/block/<disk>/queue/iosched/group_isolation | 219 | /sys/block/<disk>/queue/iosched/group_isolation |
| 220 | ----------------------------------------------- | ||
| 220 | 221 | ||
| 221 | If group_isolation=1, it provides stronger isolation between groups at the | 222 | If group_isolation=1, it provides stronger isolation between groups at the |
| 222 | expense of throughput. By default group_isolation is 0. In general that | 223 | expense of throughput. By default group_isolation is 0. In general that |
| @@ -243,6 +244,33 @@ By default one should run with group_isolation=0. If that is not sufficient | |||
| 243 | and one wants stronger isolation between groups, then set group_isolation=1 | 244 | and one wants stronger isolation between groups, then set group_isolation=1 |
| 244 | but this will come at cost of reduced throughput. | 245 | but this will come at cost of reduced throughput. |
| 245 | 246 | ||
| 247 | /sys/block/<disk>/queue/iosched/slice_idle | ||
| 248 | ------------------------------------------ | ||
| 249 | On a faster hardware CFQ can be slow, especially with sequential workload. | ||
| 250 | This happens because CFQ idles on a single queue and single queue might not | ||
| 251 | drive deeper request queue depths to keep the storage busy. In such scenarios | ||
| 252 | one can try setting slice_idle=0 and that would switch CFQ to IOPS | ||
| 253 | (IO operations per second) mode on NCQ supporting hardware. | ||
| 254 | |||
| 255 | That means CFQ will not idle between cfq queues of a cfq group and hence be | ||
| 256 | able to driver higher queue depth and achieve better throughput. That also | ||
| 257 | means that cfq provides fairness among groups in terms of IOPS and not in | ||
| 258 | terms of disk time. | ||
| 259 | |||
| 260 | /sys/block/<disk>/queue/iosched/group_idle | ||
| 261 | ------------------------------------------ | ||
| 262 | If one disables idling on individual cfq queues and cfq service trees by | ||
| 263 | setting slice_idle=0, group_idle kicks in. That means CFQ will still idle | ||
| 264 | on the group in an attempt to provide fairness among groups. | ||
| 265 | |||
| 266 | By default group_idle is same as slice_idle and does not do anything if | ||
| 267 | slice_idle is enabled. | ||
| 268 | |||
| 269 | One can experience an overall throughput drop if you have created multiple | ||
| 270 | groups and put applications in that group which are not driving enough | ||
| 271 | IO to keep disk busy. In that case set group_idle=0, and CFQ will not idle | ||
| 272 | on individual groups and throughput should improve. | ||
| 273 | |||
| 246 | What works | 274 | What works |
| 247 | ========== | 275 | ========== |
| 248 | - Currently only sync IO queues are support. All the buffered writes are | 276 | - Currently only sync IO queues are support. All the buffered writes are |
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt index d96a6dba5748..9633da01ff46 100644 --- a/Documentation/gpio.txt +++ b/Documentation/gpio.txt | |||
| @@ -109,17 +109,19 @@ use numbers 2000-2063 to identify GPIOs in a bank of I2C GPIO expanders. | |||
| 109 | 109 | ||
| 110 | If you want to initialize a structure with an invalid GPIO number, use | 110 | If you want to initialize a structure with an invalid GPIO number, use |
| 111 | some negative number (perhaps "-EINVAL"); that will never be valid. To | 111 | some negative number (perhaps "-EINVAL"); that will never be valid. To |
| 112 | test if a number could reference a GPIO, you may use this predicate: | 112 | test if such number from such a structure could reference a GPIO, you |
| 113 | may use this predicate: | ||
| 113 | 114 | ||
| 114 | int gpio_is_valid(int number); | 115 | int gpio_is_valid(int number); |
| 115 | 116 | ||
| 116 | A number that's not valid will be rejected by calls which may request | 117 | A number that's not valid will be rejected by calls which may request |
| 117 | or free GPIOs (see below). Other numbers may also be rejected; for | 118 | or free GPIOs (see below). Other numbers may also be rejected; for |
| 118 | example, a number might be valid but unused on a given board. | 119 | example, a number might be valid but temporarily unused on a given board. |
| 119 | |||
| 120 | Whether a platform supports multiple GPIO controllers is currently a | ||
| 121 | platform-specific implementation issue. | ||
| 122 | 120 | ||
| 121 | Whether a platform supports multiple GPIO controllers is a platform-specific | ||
| 122 | implementation issue, as are whether that support can leave "holes" in the space | ||
| 123 | of GPIO numbers, and whether new controllers can be added at runtime. Such issues | ||
| 124 | can affect things including whether adjacent GPIO numbers are both valid. | ||
| 123 | 125 | ||
| 124 | Using GPIOs | 126 | Using GPIOs |
| 125 | ----------- | 127 | ----------- |
| @@ -480,12 +482,16 @@ To support this framework, a platform's Kconfig will "select" either | |||
| 480 | ARCH_REQUIRE_GPIOLIB or ARCH_WANT_OPTIONAL_GPIOLIB | 482 | ARCH_REQUIRE_GPIOLIB or ARCH_WANT_OPTIONAL_GPIOLIB |
| 481 | and arrange that its <asm/gpio.h> includes <asm-generic/gpio.h> and defines | 483 | and arrange that its <asm/gpio.h> includes <asm-generic/gpio.h> and defines |
| 482 | three functions: gpio_get_value(), gpio_set_value(), and gpio_cansleep(). | 484 | three functions: gpio_get_value(), gpio_set_value(), and gpio_cansleep(). |
| 483 | They may also want to provide a custom value for ARCH_NR_GPIOS. | ||
| 484 | 485 | ||
| 485 | ARCH_REQUIRE_GPIOLIB means that the gpio-lib code will always get compiled | 486 | It may also provide a custom value for ARCH_NR_GPIOS, so that it better |
| 487 | reflects the number of GPIOs in actual use on that platform, without | ||
| 488 | wasting static table space. (It should count both built-in/SoC GPIOs and | ||
| 489 | also ones on GPIO expanders. | ||
| 490 | |||
| 491 | ARCH_REQUIRE_GPIOLIB means that the gpiolib code will always get compiled | ||
| 486 | into the kernel on that architecture. | 492 | into the kernel on that architecture. |
| 487 | 493 | ||
| 488 | ARCH_WANT_OPTIONAL_GPIOLIB means the gpio-lib code defaults to off and the user | 494 | ARCH_WANT_OPTIONAL_GPIOLIB means the gpiolib code defaults to off and the user |
| 489 | can enable it and build it into the kernel optionally. | 495 | can enable it and build it into the kernel optionally. |
| 490 | 496 | ||
| 491 | If neither of these options are selected, the platform does not support | 497 | If neither of these options are selected, the platform does not support |
diff --git a/Documentation/hwmon/sysfs-interface b/Documentation/hwmon/sysfs-interface index ff45d1f837c8..48ceabedf55d 100644 --- a/Documentation/hwmon/sysfs-interface +++ b/Documentation/hwmon/sysfs-interface | |||
| @@ -91,12 +91,11 @@ name The chip name. | |||
| 91 | I2C devices get this attribute created automatically. | 91 | I2C devices get this attribute created automatically. |
| 92 | RO | 92 | RO |
| 93 | 93 | ||
| 94 | update_rate The rate at which the chip will update readings. | 94 | update_interval The interval at which the chip will update readings. |
| 95 | Unit: millisecond | 95 | Unit: millisecond |
| 96 | RW | 96 | RW |
| 97 | Some devices have a variable update rate. This attribute | 97 | Some devices have a variable update rate or interval. |
| 98 | can be used to change the update rate to the desired | 98 | This attribute can be used to change it to the desired value. |
| 99 | frequency. | ||
| 100 | 99 | ||
| 101 | 100 | ||
| 102 | ************ | 101 | ************ |
diff --git a/Documentation/kernel-doc-nano-HOWTO.txt b/Documentation/kernel-doc-nano-HOWTO.txt index 27a52b35d55b..3d8a97747f77 100644 --- a/Documentation/kernel-doc-nano-HOWTO.txt +++ b/Documentation/kernel-doc-nano-HOWTO.txt | |||
| @@ -345,5 +345,10 @@ documentation, in <filename>, for the functions listed. | |||
| 345 | section titled <section title> from <filename>. | 345 | section titled <section title> from <filename>. |
| 346 | Spaces are allowed in <section title>; do not quote the <section title>. | 346 | Spaces are allowed in <section title>; do not quote the <section title>. |
| 347 | 347 | ||
| 348 | !C<filename> is replaced by nothing, but makes the tools check that | ||
| 349 | all DOC: sections and documented functions, symbols, etc. are used. | ||
| 350 | This makes sense to use when you use !F/!P only and want to verify | ||
| 351 | that all documentation is included. | ||
| 352 | |||
| 348 | Tim. | 353 | Tim. |
| 349 | */ <twaugh@redhat.com> | 354 | */ <twaugh@redhat.com> |
diff --git a/Documentation/power/regulator/overview.txt b/Documentation/power/regulator/overview.txt index 9363e056188a..8ed17587a74b 100644 --- a/Documentation/power/regulator/overview.txt +++ b/Documentation/power/regulator/overview.txt | |||
| @@ -13,7 +13,7 @@ regulators (where voltage output is controllable) and current sinks (where | |||
| 13 | current limit is controllable). | 13 | current limit is controllable). |
| 14 | 14 | ||
| 15 | (C) 2008 Wolfson Microelectronics PLC. | 15 | (C) 2008 Wolfson Microelectronics PLC. |
| 16 | Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 16 | Author: Liam Girdwood <lrg@slimlogic.co.uk> |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | Nomenclature | 19 | Nomenclature |
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt index ce46fa1e643e..37c6aad5e590 100644 --- a/Documentation/sound/alsa/HD-Audio-Models.txt +++ b/Documentation/sound/alsa/HD-Audio-Models.txt | |||
| @@ -296,6 +296,7 @@ Conexant 5051 | |||
| 296 | Conexant 5066 | 296 | Conexant 5066 |
| 297 | ============= | 297 | ============= |
| 298 | laptop Basic Laptop config (default) | 298 | laptop Basic Laptop config (default) |
| 299 | hp-laptop HP laptops, e g G60 | ||
| 299 | dell-laptop Dell laptops | 300 | dell-laptop Dell laptops |
| 300 | dell-vostro Dell Vostro | 301 | dell-vostro Dell Vostro |
| 301 | olpc-xo-1_5 OLPC XO 1.5 | 302 | olpc-xo-1_5 OLPC XO 1.5 |
diff --git a/Documentation/workqueue.txt b/Documentation/workqueue.txt new file mode 100644 index 000000000000..e4498a2872c3 --- /dev/null +++ b/Documentation/workqueue.txt | |||
| @@ -0,0 +1,380 @@ | |||
| 1 | |||
| 2 | Concurrency Managed Workqueue (cmwq) | ||
| 3 | |||
| 4 | September, 2010 Tejun Heo <tj@kernel.org> | ||
| 5 | Florian Mickler <florian@mickler.org> | ||
| 6 | |||
| 7 | CONTENTS | ||
| 8 | |||
| 9 | 1. Introduction | ||
| 10 | 2. Why cmwq? | ||
| 11 | 3. The Design | ||
| 12 | 4. Application Programming Interface (API) | ||
| 13 | 5. Example Execution Scenarios | ||
| 14 | 6. Guidelines | ||
| 15 | |||
| 16 | |||
| 17 | 1. Introduction | ||
| 18 | |||
| 19 | There are many cases where an asynchronous process execution context | ||
| 20 | is needed and the workqueue (wq) API is the most commonly used | ||
| 21 | mechanism for such cases. | ||
| 22 | |||
| 23 | When such an asynchronous execution context is needed, a work item | ||
| 24 | describing which function to execute is put on a queue. An | ||
| 25 | independent thread serves as the asynchronous execution context. The | ||
| 26 | queue is called workqueue and the thread is called worker. | ||
| 27 | |||
| 28 | While there are work items on the workqueue the worker executes the | ||
| 29 | functions associated with the work items one after the other. When | ||
| 30 | there is no work item left on the workqueue the worker becomes idle. | ||
| 31 | When a new work item gets queued, the worker begins executing again. | ||
| 32 | |||
| 33 | |||
| 34 | 2. Why cmwq? | ||
| 35 | |||
| 36 | In the original wq implementation, a multi threaded (MT) wq had one | ||
| 37 | worker thread per CPU and a single threaded (ST) wq had one worker | ||
| 38 | thread system-wide. A single MT wq needed to keep around the same | ||
| 39 | number of workers as the number of CPUs. The kernel grew a lot of MT | ||
| 40 | wq users over the years and with the number of CPU cores continuously | ||
| 41 | rising, some systems saturated the default 32k PID space just booting | ||
| 42 | up. | ||
| 43 | |||
| 44 | Although MT wq wasted a lot of resource, the level of concurrency | ||
| 45 | provided was unsatisfactory. The limitation was common to both ST and | ||
| 46 | MT wq albeit less severe on MT. Each wq maintained its own separate | ||
| 47 | worker pool. A MT wq could provide only one execution context per CPU | ||
| 48 | while a ST wq one for the whole system. Work items had to compete for | ||
| 49 | those very limited execution contexts leading to various problems | ||
| 50 | including proneness to deadlocks around the single execution context. | ||
| 51 | |||
| 52 | The tension between the provided level of concurrency and resource | ||
| 53 | usage also forced its users to make unnecessary tradeoffs like libata | ||
| 54 | choosing to use ST wq for polling PIOs and accepting an unnecessary | ||
| 55 | limitation that no two polling PIOs can progress at the same time. As | ||
| 56 | MT wq don't provide much better concurrency, users which require | ||
| 57 | higher level of concurrency, like async or fscache, had to implement | ||
| 58 | their own thread pool. | ||
| 59 | |||
| 60 | Concurrency Managed Workqueue (cmwq) is a reimplementation of wq with | ||
| 61 | focus on the following goals. | ||
| 62 | |||
| 63 | * Maintain compatibility with the original workqueue API. | ||
| 64 | |||
| 65 | * Use per-CPU unified worker pools shared by all wq to provide | ||
| 66 | flexible level of concurrency on demand without wasting a lot of | ||
| 67 | resource. | ||
| 68 | |||
| 69 | * Automatically regulate worker pool and level of concurrency so that | ||
| 70 | the API users don't need to worry about such details. | ||
| 71 | |||
| 72 | |||
| 73 | 3. The Design | ||
| 74 | |||
| 75 | In order to ease the asynchronous execution of functions a new | ||
| 76 | abstraction, the work item, is introduced. | ||
| 77 | |||
| 78 | A work item is a simple struct that holds a pointer to the function | ||
| 79 | that is to be executed asynchronously. Whenever a driver or subsystem | ||
| 80 | wants a function to be executed asynchronously it has to set up a work | ||
| 81 | item pointing to that function and queue that work item on a | ||
| 82 | workqueue. | ||
| 83 | |||
| 84 | Special purpose threads, called worker threads, execute the functions | ||
| 85 | off of the queue, one after the other. If no work is queued, the | ||
| 86 | worker threads become idle. These worker threads are managed in so | ||
| 87 | called thread-pools. | ||
| 88 | |||
| 89 | The cmwq design differentiates between the user-facing workqueues that | ||
| 90 | subsystems and drivers queue work items on and the backend mechanism | ||
| 91 | which manages thread-pool and processes the queued work items. | ||
| 92 | |||
| 93 | The backend is called gcwq. There is one gcwq for each possible CPU | ||
| 94 | and one gcwq to serve work items queued on unbound workqueues. | ||
| 95 | |||
| 96 | Subsystems and drivers can create and queue work items through special | ||
| 97 | workqueue API functions as they see fit. They can influence some | ||
| 98 | aspects of the way the work items are executed by setting flags on the | ||
| 99 | workqueue they are putting the work item on. These flags include | ||
| 100 | things like CPU locality, reentrancy, concurrency limits and more. To | ||
| 101 | get a detailed overview refer to the API description of | ||
| 102 | alloc_workqueue() below. | ||
| 103 | |||
| 104 | When a work item is queued to a workqueue, the target gcwq is | ||
| 105 | determined according to the queue parameters and workqueue attributes | ||
| 106 | and appended on the shared worklist of the gcwq. For example, unless | ||
| 107 | specifically overridden, a work item of a bound workqueue will be | ||
| 108 | queued on the worklist of exactly that gcwq that is associated to the | ||
| 109 | CPU the issuer is running on. | ||
| 110 | |||
| 111 | For any worker pool implementation, managing the concurrency level | ||
| 112 | (how many execution contexts are active) is an important issue. cmwq | ||
| 113 | tries to keep the concurrency at a minimal but sufficient level. | ||
| 114 | Minimal to save resources and sufficient in that the system is used at | ||
| 115 | its full capacity. | ||
| 116 | |||
| 117 | Each gcwq bound to an actual CPU implements concurrency management by | ||
| 118 | hooking into the scheduler. The gcwq is notified whenever an active | ||
| 119 | worker wakes up or sleeps and keeps track of the number of the | ||
| 120 | currently runnable workers. Generally, work items are not expected to | ||
| 121 | hog a CPU and consume many cycles. That means maintaining just enough | ||
| 122 | concurrency to prevent work processing from stalling should be | ||
| 123 | optimal. As long as there are one or more runnable workers on the | ||
| 124 | CPU, the gcwq doesn't start execution of a new work, but, when the | ||
| 125 | last running worker goes to sleep, it immediately schedules a new | ||
| 126 | worker so that the CPU doesn't sit idle while there are pending work | ||
| 127 | items. This allows using a minimal number of workers without losing | ||
| 128 | execution bandwidth. | ||
| 129 | |||
| 130 | Keeping idle workers around doesn't cost other than the memory space | ||
| 131 | for kthreads, so cmwq holds onto idle ones for a while before killing | ||
| 132 | them. | ||
| 133 | |||
| 134 | For an unbound wq, the above concurrency management doesn't apply and | ||
| 135 | the gcwq for the pseudo unbound CPU tries to start executing all work | ||
| 136 | items as soon as possible. The responsibility of regulating | ||
| 137 | concurrency level is on the users. There is also a flag to mark a | ||
| 138 | bound wq to ignore the concurrency management. Please refer to the | ||
| 139 | API section for details. | ||
| 140 | |||
| 141 | Forward progress guarantee relies on that workers can be created when | ||
| 142 | more execution contexts are necessary, which in turn is guaranteed | ||
| 143 | through the use of rescue workers. All work items which might be used | ||
| 144 | on code paths that handle memory reclaim are required to be queued on | ||
| 145 | wq's that have a rescue-worker reserved for execution under memory | ||
| 146 | pressure. Else it is possible that the thread-pool deadlocks waiting | ||
| 147 | for execution contexts to free up. | ||
| 148 | |||
| 149 | |||
| 150 | 4. Application Programming Interface (API) | ||
| 151 | |||
| 152 | alloc_workqueue() allocates a wq. The original create_*workqueue() | ||
| 153 | functions are deprecated and scheduled for removal. alloc_workqueue() | ||
| 154 | takes three arguments - @name, @flags and @max_active. @name is the | ||
| 155 | name of the wq and also used as the name of the rescuer thread if | ||
| 156 | there is one. | ||
| 157 | |||
| 158 | A wq no longer manages execution resources but serves as a domain for | ||
| 159 | forward progress guarantee, flush and work item attributes. @flags | ||
| 160 | and @max_active control how work items are assigned execution | ||
| 161 | resources, scheduled and executed. | ||
| 162 | |||
| 163 | @flags: | ||
| 164 | |||
| 165 | WQ_NON_REENTRANT | ||
| 166 | |||
| 167 | By default, a wq guarantees non-reentrance only on the same | ||
| 168 | CPU. A work item may not be executed concurrently on the same | ||
| 169 | CPU by multiple workers but is allowed to be executed | ||
| 170 | concurrently on multiple CPUs. This flag makes sure | ||
| 171 | non-reentrance is enforced across all CPUs. Work items queued | ||
| 172 | to a non-reentrant wq are guaranteed to be executed by at most | ||
| 173 | one worker system-wide at any given time. | ||
| 174 | |||
| 175 | WQ_UNBOUND | ||
| 176 | |||
| 177 | Work items queued to an unbound wq are served by a special | ||
| 178 | gcwq which hosts workers which are not bound to any specific | ||
| 179 | CPU. This makes the wq behave as a simple execution context | ||
| 180 | provider without concurrency management. The unbound gcwq | ||
| 181 | tries to start execution of work items as soon as possible. | ||
| 182 | Unbound wq sacrifices locality but is useful for the following | ||
| 183 | cases. | ||
| 184 | |||
| 185 | * Wide fluctuation in the concurrency level requirement is | ||
| 186 | expected and using bound wq may end up creating large number | ||
| 187 | of mostly unused workers across different CPUs as the issuer | ||
| 188 | hops through different CPUs. | ||
| 189 | |||
| 190 | * Long running CPU intensive workloads which can be better | ||
| 191 | managed by the system scheduler. | ||
| 192 | |||
| 193 | WQ_FREEZEABLE | ||
| 194 | |||
| 195 | A freezeable wq participates in the freeze phase of the system | ||
| 196 | suspend operations. Work items on the wq are drained and no | ||
| 197 | new work item starts execution until thawed. | ||
| 198 | |||
| 199 | WQ_RESCUER | ||
| 200 | |||
| 201 | All wq which might be used in the memory reclaim paths _MUST_ | ||
| 202 | have this flag set. This reserves one worker exclusively for | ||
| 203 | the execution of this wq under memory pressure. | ||
| 204 | |||
| 205 | WQ_HIGHPRI | ||
| 206 | |||
| 207 | Work items of a highpri wq are queued at the head of the | ||
| 208 | worklist of the target gcwq and start execution regardless of | ||
| 209 | the current concurrency level. In other words, highpri work | ||
| 210 | items will always start execution as soon as execution | ||
| 211 | resource is available. | ||
| 212 | |||
| 213 | Ordering among highpri work items is preserved - a highpri | ||
| 214 | work item queued after another highpri work item will start | ||
| 215 | execution after the earlier highpri work item starts. | ||
| 216 | |||
| 217 | Although highpri work items are not held back by other | ||
| 218 | runnable work items, they still contribute to the concurrency | ||
| 219 | level. Highpri work items in runnable state will prevent | ||
| 220 | non-highpri work items from starting execution. | ||
| 221 | |||
| 222 | This flag is meaningless for unbound wq. | ||
| 223 | |||
| 224 | WQ_CPU_INTENSIVE | ||
| 225 | |||
| 226 | Work items of a CPU intensive wq do not contribute to the | ||
| 227 | concurrency level. In other words, runnable CPU intensive | ||
| 228 | work items will not prevent other work items from starting | ||
| 229 | execution. This is useful for bound work items which are | ||
| 230 | expected to hog CPU cycles so that their execution is | ||
| 231 | regulated by the system scheduler. | ||
| 232 | |||
| 233 | Although CPU intensive work items don't contribute to the | ||
| 234 | concurrency level, start of their executions is still | ||
| 235 | regulated by the concurrency management and runnable | ||
| 236 | non-CPU-intensive work items can delay execution of CPU | ||
| 237 | intensive work items. | ||
| 238 | |||
| 239 | This flag is meaningless for unbound wq. | ||
| 240 | |||
| 241 | WQ_HIGHPRI | WQ_CPU_INTENSIVE | ||
| 242 | |||
| 243 | This combination makes the wq avoid interaction with | ||
| 244 | concurrency management completely and behave as a simple | ||
| 245 | per-CPU execution context provider. Work items queued on a | ||
| 246 | highpri CPU-intensive wq start execution as soon as resources | ||
| 247 | are available and don't affect execution of other work items. | ||
| 248 | |||
| 249 | @max_active: | ||
| 250 | |||
| 251 | @max_active determines the maximum number of execution contexts per | ||
| 252 | CPU which can be assigned to the work items of a wq. For example, | ||
| 253 | with @max_active of 16, at most 16 work items of the wq can be | ||
| 254 | executing at the same time per CPU. | ||
| 255 | |||
| 256 | Currently, for a bound wq, the maximum limit for @max_active is 512 | ||
| 257 | and the default value used when 0 is specified is 256. For an unbound | ||
| 258 | wq, the limit is higher of 512 and 4 * num_possible_cpus(). These | ||
| 259 | values are chosen sufficiently high such that they are not the | ||
| 260 | limiting factor while providing protection in runaway cases. | ||
| 261 | |||
| 262 | The number of active work items of a wq is usually regulated by the | ||
| 263 | users of the wq, more specifically, by how many work items the users | ||
| 264 | may queue at the same time. Unless there is a specific need for | ||
| 265 | throttling the number of active work items, specifying '0' is | ||
| 266 | recommended. | ||
| 267 | |||
| 268 | Some users depend on the strict execution ordering of ST wq. The | ||
| 269 | combination of @max_active of 1 and WQ_UNBOUND is used to achieve this | ||
| 270 | behavior. Work items on such wq are always queued to the unbound gcwq | ||
| 271 | and only one work item can be active at any given time thus achieving | ||
| 272 | the same ordering property as ST wq. | ||
| 273 | |||
| 274 | |||
| 275 | 5. Example Execution Scenarios | ||
| 276 | |||
| 277 | The following example execution scenarios try to illustrate how cmwq | ||
| 278 | behave under different configurations. | ||
| 279 | |||
| 280 | Work items w0, w1, w2 are queued to a bound wq q0 on the same CPU. | ||
| 281 | w0 burns CPU for 5ms then sleeps for 10ms then burns CPU for 5ms | ||
| 282 | again before finishing. w1 and w2 burn CPU for 5ms then sleep for | ||
| 283 | 10ms. | ||
| 284 | |||
| 285 | Ignoring all other tasks, works and processing overhead, and assuming | ||
| 286 | simple FIFO scheduling, the following is one highly simplified version | ||
| 287 | of possible sequences of events with the original wq. | ||
| 288 | |||
| 289 | TIME IN MSECS EVENT | ||
| 290 | 0 w0 starts and burns CPU | ||
| 291 | 5 w0 sleeps | ||
| 292 | 15 w0 wakes up and burns CPU | ||
| 293 | 20 w0 finishes | ||
| 294 | 20 w1 starts and burns CPU | ||
| 295 | 25 w1 sleeps | ||
| 296 | 35 w1 wakes up and finishes | ||
| 297 | 35 w2 starts and burns CPU | ||
| 298 | 40 w2 sleeps | ||
| 299 | 50 w2 wakes up and finishes | ||
| 300 | |||
| 301 | And with cmwq with @max_active >= 3, | ||
| 302 | |||
| 303 | TIME IN MSECS EVENT | ||
| 304 | 0 w0 starts and burns CPU | ||
| 305 | 5 w0 sleeps | ||
| 306 | 5 w1 starts and burns CPU | ||
| 307 | 10 w1 sleeps | ||
| 308 | 10 w2 starts and burns CPU | ||
| 309 | 15 w2 sleeps | ||
| 310 | 15 w0 wakes up and burns CPU | ||
| 311 | 20 w0 finishes | ||
| 312 | 20 w1 wakes up and finishes | ||
| 313 | 25 w2 wakes up and finishes | ||
| 314 | |||
| 315 | If @max_active == 2, | ||
| 316 | |||
| 317 | TIME IN MSECS EVENT | ||
| 318 | 0 w0 starts and burns CPU | ||
| 319 | 5 w0 sleeps | ||
| 320 | 5 w1 starts and burns CPU | ||
| 321 | 10 w1 sleeps | ||
| 322 | 15 w0 wakes up and burns CPU | ||
| 323 | 20 w0 finishes | ||
| 324 | 20 w1 wakes up and finishes | ||
| 325 | 20 w2 starts and burns CPU | ||
| 326 | 25 w2 sleeps | ||
| 327 | 35 w2 wakes up and finishes | ||
| 328 | |||
| 329 | Now, let's assume w1 and w2 are queued to a different wq q1 which has | ||
| 330 | WQ_HIGHPRI set, | ||
| 331 | |||
| 332 | TIME IN MSECS EVENT | ||
| 333 | 0 w1 and w2 start and burn CPU | ||
| 334 | 5 w1 sleeps | ||
| 335 | 10 w2 sleeps | ||
| 336 | 10 w0 starts and burns CPU | ||
| 337 | 15 w0 sleeps | ||
| 338 | 15 w1 wakes up and finishes | ||
| 339 | 20 w2 wakes up and finishes | ||
| 340 | 25 w0 wakes up and burns CPU | ||
| 341 | 30 w0 finishes | ||
| 342 | |||
| 343 | If q1 has WQ_CPU_INTENSIVE set, | ||
| 344 | |||
| 345 | TIME IN MSECS EVENT | ||
| 346 | 0 w0 starts and burns CPU | ||
| 347 | 5 w0 sleeps | ||
| 348 | 5 w1 and w2 start and burn CPU | ||
| 349 | 10 w1 sleeps | ||
| 350 | 15 w2 sleeps | ||
| 351 | 15 w0 wakes up and burns CPU | ||
| 352 | 20 w0 finishes | ||
| 353 | 20 w1 wakes up and finishes | ||
| 354 | 25 w2 wakes up and finishes | ||
| 355 | |||
| 356 | |||
| 357 | 6. Guidelines | ||
| 358 | |||
| 359 | * Do not forget to use WQ_RESCUER if a wq may process work items which | ||
| 360 | are used during memory reclaim. Each wq with WQ_RESCUER set has one | ||
| 361 | rescuer thread reserved for it. If there is dependency among | ||
| 362 | multiple work items used during memory reclaim, they should be | ||
| 363 | queued to separate wq each with WQ_RESCUER. | ||
| 364 | |||
| 365 | * Unless strict ordering is required, there is no need to use ST wq. | ||
| 366 | |||
| 367 | * Unless there is a specific need, using 0 for @max_active is | ||
| 368 | recommended. In most use cases, concurrency level usually stays | ||
| 369 | well under the default limit. | ||
| 370 | |||
| 371 | * A wq serves as a domain for forward progress guarantee (WQ_RESCUER), | ||
| 372 | flush and work item attributes. Work items which are not involved | ||
| 373 | in memory reclaim and don't need to be flushed as a part of a group | ||
| 374 | of work items, and don't require any special attribute, can use one | ||
| 375 | of the system wq. There is no difference in execution | ||
| 376 | characteristics between using a dedicated wq and a system wq. | ||
| 377 | |||
| 378 | * Unless work items are expected to consume a huge amount of CPU | ||
| 379 | cycles, using a bound wq is usually beneficial due to the increased | ||
| 380 | level of locality in wq operations and work item execution. | ||
