Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq

Pull workqueue updates from Tejun Heo:
"Workqueue now prints debug information at the end of sysrq-t which
should be helpful when tracking down suspected workqueue stalls. It
only prints out the ones with something currently going on so it
shouldn't add much output in most cases"

* 'for-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq:
workqueue: Reorder sysfs code
percpu: Fix trivial typos in comments
workqueue: dump workqueues on sysrq-t
workqueue: keep track of the flushing task and pool manager
workqueue: make the workqueues list RCU walkable

+518 -335
+1
drivers/tty/sysrq.c
··· 275 275 static void sysrq_handle_showstate(int key) 276 276 { 277 277 show_state(); 278 + show_workqueue_state(); 278 279 } 279 280 static struct sysrq_key_op sysrq_showstate_op = { 280 281 .handler = sysrq_handle_showstate,
+1
include/linux/workqueue.h
··· 454 454 extern unsigned int work_busy(struct work_struct *work); 455 455 extern __printf(1, 2) void set_worker_desc(const char *fmt, ...); 456 456 extern void print_worker_info(const char *log_lvl, struct task_struct *task); 457 + extern void show_workqueue_state(void); 457 458 458 459 /** 459 460 * queue_work - queue work on a workqueue
+514 -333
kernel/workqueue.c
··· 159 159 160 160 /* see manage_workers() for details on the two manager mutexes */ 161 161 struct mutex manager_arb; /* manager arbitration */ 162 + struct worker *manager; /* L: purely informational */ 162 163 struct mutex attach_mutex; /* attach/detach exclusion */ 163 164 struct list_head workers; /* A: attached workers */ 164 165 struct completion *detach_completion; /* all workers detached */ ··· 231 230 */ 232 231 struct workqueue_struct { 233 232 struct list_head pwqs; /* WR: all pwqs of this wq */ 234 - struct list_head list; /* PL: list of all workqueues */ 233 + struct list_head list; /* PR: list of all workqueues */ 235 234 236 235 struct mutex mutex; /* protects this wq */ 237 236 int work_color; /* WQ: current work color */ ··· 257 256 struct lockdep_map lockdep_map; 258 257 #endif 259 258 char name[WQ_NAME_LEN]; /* I: workqueue name */ 259 + 260 + /* 261 + * Destruction of workqueue_struct is sched-RCU protected to allow 262 + * walking the workqueues list without grabbing wq_pool_mutex. 263 + * This is used to dump all workqueues from sysrq. 264 + */ 265 + struct rcu_head rcu; 260 266 261 267 /* hot fields used during command issue, aligned to cacheline */ 262 268 unsigned int flags ____cacheline_aligned; /* WQ: WQ_* flags */ ··· 296 288 static DEFINE_MUTEX(wq_pool_mutex); /* protects pools and workqueues list */ 297 289 static DEFINE_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */ 298 290 299 - static LIST_HEAD(workqueues); /* PL: list of all workqueues */ 291 + static LIST_HEAD(workqueues); /* PR: list of all workqueues */ 300 292 static bool workqueue_freezing; /* PL: have wqs started freezing? */ 301 293 302 294 /* the per-cpu worker pools */ ··· 332 324 static int worker_thread(void *__worker); 333 325 static void copy_workqueue_attrs(struct workqueue_attrs *to, 334 326 const struct workqueue_attrs *from); 327 + static void workqueue_sysfs_unregister(struct workqueue_struct *wq); 335 328 336 329 #define CREATE_TRACE_POINTS 337 330 #include <trace/events/workqueue.h> ··· 1920 1911 */ 1921 1912 if (!mutex_trylock(&pool->manager_arb)) 1922 1913 return false; 1914 + pool->manager = worker; 1923 1915 1924 1916 maybe_create_worker(pool); 1925 1917 1918 + pool->manager = NULL; 1926 1919 mutex_unlock(&pool->manager_arb); 1927 1920 return true; 1928 1921 } ··· 2314 2303 struct wq_barrier { 2315 2304 struct work_struct work; 2316 2305 struct completion done; 2306 + struct task_struct *task; /* purely informational */ 2317 2307 }; 2318 2308 2319 2309 static void wq_barrier_func(struct work_struct *work) ··· 2363 2351 INIT_WORK_ONSTACK(&barr->work, wq_barrier_func); 2364 2352 __set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&barr->work)); 2365 2353 init_completion(&barr->done); 2354 + barr->task = current; 2366 2355 2367 2356 /* 2368 2357 * If @target is currently being executed, schedule the ··· 3002 2989 } 3003 2990 EXPORT_SYMBOL_GPL(execute_in_process_context); 3004 2991 3005 - #ifdef CONFIG_SYSFS 3006 - /* 3007 - * Workqueues with WQ_SYSFS flag set is visible to userland via 3008 - * /sys/bus/workqueue/devices/WQ_NAME. All visible workqueues have the 3009 - * following attributes. 3010 - * 3011 - * per_cpu RO bool : whether the workqueue is per-cpu or unbound 3012 - * max_active RW int : maximum number of in-flight work items 3013 - * 3014 - * Unbound workqueues have the following extra attributes. 3015 - * 3016 - * id RO int : the associated pool ID 3017 - * nice RW int : nice value of the workers 3018 - * cpumask RW mask : bitmask of allowed CPUs for the workers 3019 - */ 3020 - struct wq_device { 3021 - struct workqueue_struct *wq; 3022 - struct device dev; 3023 - }; 3024 - 3025 - static struct workqueue_struct *dev_to_wq(struct device *dev) 3026 - { 3027 - struct wq_device *wq_dev = container_of(dev, struct wq_device, dev); 3028 - 3029 - return wq_dev->wq; 3030 - } 3031 - 3032 - static ssize_t per_cpu_show(struct device *dev, struct device_attribute *attr, 3033 - char *buf) 3034 - { 3035 - struct workqueue_struct *wq = dev_to_wq(dev); 3036 - 3037 - return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND)); 3038 - } 3039 - static DEVICE_ATTR_RO(per_cpu); 3040 - 3041 - static ssize_t max_active_show(struct device *dev, 3042 - struct device_attribute *attr, char *buf) 3043 - { 3044 - struct workqueue_struct *wq = dev_to_wq(dev); 3045 - 3046 - return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active); 3047 - } 3048 - 3049 - static ssize_t max_active_store(struct device *dev, 3050 - struct device_attribute *attr, const char *buf, 3051 - size_t count) 3052 - { 3053 - struct workqueue_struct *wq = dev_to_wq(dev); 3054 - int val; 3055 - 3056 - if (sscanf(buf, "%d", &val) != 1 || val <= 0) 3057 - return -EINVAL; 3058 - 3059 - workqueue_set_max_active(wq, val); 3060 - return count; 3061 - } 3062 - static DEVICE_ATTR_RW(max_active); 3063 - 3064 - static struct attribute *wq_sysfs_attrs[] = { 3065 - &dev_attr_per_cpu.attr, 3066 - &dev_attr_max_active.attr, 3067 - NULL, 3068 - }; 3069 - ATTRIBUTE_GROUPS(wq_sysfs); 3070 - 3071 - static ssize_t wq_pool_ids_show(struct device *dev, 3072 - struct device_attribute *attr, char *buf) 3073 - { 3074 - struct workqueue_struct *wq = dev_to_wq(dev); 3075 - const char *delim = ""; 3076 - int node, written = 0; 3077 - 3078 - rcu_read_lock_sched(); 3079 - for_each_node(node) { 3080 - written += scnprintf(buf + written, PAGE_SIZE - written, 3081 - "%s%d:%d", delim, node, 3082 - unbound_pwq_by_node(wq, node)->pool->id); 3083 - delim = " "; 3084 - } 3085 - written += scnprintf(buf + written, PAGE_SIZE - written, "\n"); 3086 - rcu_read_unlock_sched(); 3087 - 3088 - return written; 3089 - } 3090 - 3091 - static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr, 3092 - char *buf) 3093 - { 3094 - struct workqueue_struct *wq = dev_to_wq(dev); 3095 - int written; 3096 - 3097 - mutex_lock(&wq->mutex); 3098 - written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice); 3099 - mutex_unlock(&wq->mutex); 3100 - 3101 - return written; 3102 - } 3103 - 3104 - /* prepare workqueue_attrs for sysfs store operations */ 3105 - static struct workqueue_attrs *wq_sysfs_prep_attrs(struct workqueue_struct *wq) 3106 - { 3107 - struct workqueue_attrs *attrs; 3108 - 3109 - attrs = alloc_workqueue_attrs(GFP_KERNEL); 3110 - if (!attrs) 3111 - return NULL; 3112 - 3113 - mutex_lock(&wq->mutex); 3114 - copy_workqueue_attrs(attrs, wq->unbound_attrs); 3115 - mutex_unlock(&wq->mutex); 3116 - return attrs; 3117 - } 3118 - 3119 - static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr, 3120 - const char *buf, size_t count) 3121 - { 3122 - struct workqueue_struct *wq = dev_to_wq(dev); 3123 - struct workqueue_attrs *attrs; 3124 - int ret; 3125 - 3126 - attrs = wq_sysfs_prep_attrs(wq); 3127 - if (!attrs) 3128 - return -ENOMEM; 3129 - 3130 - if (sscanf(buf, "%d", &attrs->nice) == 1 && 3131 - attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE) 3132 - ret = apply_workqueue_attrs(wq, attrs); 3133 - else 3134 - ret = -EINVAL; 3135 - 3136 - free_workqueue_attrs(attrs); 3137 - return ret ?: count; 3138 - } 3139 - 3140 - static ssize_t wq_cpumask_show(struct device *dev, 3141 - struct device_attribute *attr, char *buf) 3142 - { 3143 - struct workqueue_struct *wq = dev_to_wq(dev); 3144 - int written; 3145 - 3146 - mutex_lock(&wq->mutex); 3147 - written = scnprintf(buf, PAGE_SIZE, "%*pb\n", 3148 - cpumask_pr_args(wq->unbound_attrs->cpumask)); 3149 - mutex_unlock(&wq->mutex); 3150 - return written; 3151 - } 3152 - 3153 - static ssize_t wq_cpumask_store(struct device *dev, 3154 - struct device_attribute *attr, 3155 - const char *buf, size_t count) 3156 - { 3157 - struct workqueue_struct *wq = dev_to_wq(dev); 3158 - struct workqueue_attrs *attrs; 3159 - int ret; 3160 - 3161 - attrs = wq_sysfs_prep_attrs(wq); 3162 - if (!attrs) 3163 - return -ENOMEM; 3164 - 3165 - ret = cpumask_parse(buf, attrs->cpumask); 3166 - if (!ret) 3167 - ret = apply_workqueue_attrs(wq, attrs); 3168 - 3169 - free_workqueue_attrs(attrs); 3170 - return ret ?: count; 3171 - } 3172 - 3173 - static ssize_t wq_numa_show(struct device *dev, struct device_attribute *attr, 3174 - char *buf) 3175 - { 3176 - struct workqueue_struct *wq = dev_to_wq(dev); 3177 - int written; 3178 - 3179 - mutex_lock(&wq->mutex); 3180 - written = scnprintf(buf, PAGE_SIZE, "%d\n", 3181 - !wq->unbound_attrs->no_numa); 3182 - mutex_unlock(&wq->mutex); 3183 - 3184 - return written; 3185 - } 3186 - 3187 - static ssize_t wq_numa_store(struct device *dev, struct device_attribute *attr, 3188 - const char *buf, size_t count) 3189 - { 3190 - struct workqueue_struct *wq = dev_to_wq(dev); 3191 - struct workqueue_attrs *attrs; 3192 - int v, ret; 3193 - 3194 - attrs = wq_sysfs_prep_attrs(wq); 3195 - if (!attrs) 3196 - return -ENOMEM; 3197 - 3198 - ret = -EINVAL; 3199 - if (sscanf(buf, "%d", &v) == 1) { 3200 - attrs->no_numa = !v; 3201 - ret = apply_workqueue_attrs(wq, attrs); 3202 - } 3203 - 3204 - free_workqueue_attrs(attrs); 3205 - return ret ?: count; 3206 - } 3207 - 3208 - static struct device_attribute wq_sysfs_unbound_attrs[] = { 3209 - __ATTR(pool_ids, 0444, wq_pool_ids_show, NULL), 3210 - __ATTR(nice, 0644, wq_nice_show, wq_nice_store), 3211 - __ATTR(cpumask, 0644, wq_cpumask_show, wq_cpumask_store), 3212 - __ATTR(numa, 0644, wq_numa_show, wq_numa_store), 3213 - __ATTR_NULL, 3214 - }; 3215 - 3216 - static struct bus_type wq_subsys = { 3217 - .name = "workqueue", 3218 - .dev_groups = wq_sysfs_groups, 3219 - }; 3220 - 3221 - static int __init wq_sysfs_init(void) 3222 - { 3223 - return subsys_virtual_register(&wq_subsys, NULL); 3224 - } 3225 - core_initcall(wq_sysfs_init); 3226 - 3227 - static void wq_device_release(struct device *dev) 3228 - { 3229 - struct wq_device *wq_dev = container_of(dev, struct wq_device, dev); 3230 - 3231 - kfree(wq_dev); 3232 - } 3233 - 3234 - /** 3235 - * workqueue_sysfs_register - make a workqueue visible in sysfs 3236 - * @wq: the workqueue to register 3237 - * 3238 - * Expose @wq in sysfs under /sys/bus/workqueue/devices. 3239 - * alloc_workqueue*() automatically calls this function if WQ_SYSFS is set 3240 - * which is the preferred method. 3241 - * 3242 - * Workqueue user should use this function directly iff it wants to apply 3243 - * workqueue_attrs before making the workqueue visible in sysfs; otherwise, 3244 - * apply_workqueue_attrs() may race against userland updating the 3245 - * attributes. 3246 - * 3247 - * Return: 0 on success, -errno on failure. 3248 - */ 3249 - int workqueue_sysfs_register(struct workqueue_struct *wq) 3250 - { 3251 - struct wq_device *wq_dev; 3252 - int ret; 3253 - 3254 - /* 3255 - * Adjusting max_active or creating new pwqs by applyting 3256 - * attributes breaks ordering guarantee. Disallow exposing ordered 3257 - * workqueues. 3258 - */ 3259 - if (WARN_ON(wq->flags & __WQ_ORDERED)) 3260 - return -EINVAL; 3261 - 3262 - wq->wq_dev = wq_dev = kzalloc(sizeof(*wq_dev), GFP_KERNEL); 3263 - if (!wq_dev) 3264 - return -ENOMEM; 3265 - 3266 - wq_dev->wq = wq; 3267 - wq_dev->dev.bus = &wq_subsys; 3268 - wq_dev->dev.init_name = wq->name; 3269 - wq_dev->dev.release = wq_device_release; 3270 - 3271 - /* 3272 - * unbound_attrs are created separately. Suppress uevent until 3273 - * everything is ready. 3274 - */ 3275 - dev_set_uevent_suppress(&wq_dev->dev, true); 3276 - 3277 - ret = device_register(&wq_dev->dev); 3278 - if (ret) { 3279 - kfree(wq_dev); 3280 - wq->wq_dev = NULL; 3281 - return ret; 3282 - } 3283 - 3284 - if (wq->flags & WQ_UNBOUND) { 3285 - struct device_attribute *attr; 3286 - 3287 - for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++) { 3288 - ret = device_create_file(&wq_dev->dev, attr); 3289 - if (ret) { 3290 - device_unregister(&wq_dev->dev); 3291 - wq->wq_dev = NULL; 3292 - return ret; 3293 - } 3294 - } 3295 - } 3296 - 3297 - dev_set_uevent_suppress(&wq_dev->dev, false); 3298 - kobject_uevent(&wq_dev->dev.kobj, KOBJ_ADD); 3299 - return 0; 3300 - } 3301 - 3302 - /** 3303 - * workqueue_sysfs_unregister - undo workqueue_sysfs_register() 3304 - * @wq: the workqueue to unregister 3305 - * 3306 - * If @wq is registered to sysfs by workqueue_sysfs_register(), unregister. 3307 - */ 3308 - static void workqueue_sysfs_unregister(struct workqueue_struct *wq) 3309 - { 3310 - struct wq_device *wq_dev = wq->wq_dev; 3311 - 3312 - if (!wq->wq_dev) 3313 - return; 3314 - 3315 - wq->wq_dev = NULL; 3316 - device_unregister(&wq_dev->dev); 3317 - } 3318 - #else /* CONFIG_SYSFS */ 3319 - static void workqueue_sysfs_unregister(struct workqueue_struct *wq) { } 3320 - #endif /* CONFIG_SYSFS */ 3321 - 3322 2992 /** 3323 2993 * free_workqueue_attrs - free a workqueue_attrs 3324 2994 * @attrs: workqueue_attrs to free ··· 3118 3422 if (!pool->attrs) 3119 3423 return -ENOMEM; 3120 3424 return 0; 3425 + } 3426 + 3427 + static void rcu_free_wq(struct rcu_head *rcu) 3428 + { 3429 + struct workqueue_struct *wq = 3430 + container_of(rcu, struct workqueue_struct, rcu); 3431 + 3432 + if (!(wq->flags & WQ_UNBOUND)) 3433 + free_percpu(wq->cpu_pwqs); 3434 + else 3435 + free_workqueue_attrs(wq->unbound_attrs); 3436 + 3437 + kfree(wq->rescuer); 3438 + kfree(wq); 3121 3439 } 3122 3440 3123 3441 static void rcu_free_pool(struct rcu_head *rcu) ··· 3311 3601 3312 3602 /* 3313 3603 * If we're the last pwq going away, @wq is already dead and no one 3314 - * is gonna access it anymore. Free it. 3604 + * is gonna access it anymore. Schedule RCU free. 3315 3605 */ 3316 - if (is_last) { 3317 - free_workqueue_attrs(wq->unbound_attrs); 3318 - kfree(wq); 3319 - } 3606 + if (is_last) 3607 + call_rcu_sched(&wq->rcu, rcu_free_wq); 3320 3608 } 3321 3609 3322 3610 /** ··· 3851 4143 pwq_adjust_max_active(pwq); 3852 4144 mutex_unlock(&wq->mutex); 3853 4145 3854 - list_add(&wq->list, &workqueues); 4146 + list_add_tail_rcu(&wq->list, &workqueues); 3855 4147 3856 4148 mutex_unlock(&wq_pool_mutex); 3857 4149 ··· 3907 4199 * flushing is complete in case freeze races us. 3908 4200 */ 3909 4201 mutex_lock(&wq_pool_mutex); 3910 - list_del_init(&wq->list); 4202 + list_del_rcu(&wq->list); 3911 4203 mutex_unlock(&wq_pool_mutex); 3912 4204 3913 4205 workqueue_sysfs_unregister(wq); 3914 4206 3915 - if (wq->rescuer) { 4207 + if (wq->rescuer) 3916 4208 kthread_stop(wq->rescuer->task); 3917 - kfree(wq->rescuer); 3918 - wq->rescuer = NULL; 3919 - } 3920 4209 3921 4210 if (!(wq->flags & WQ_UNBOUND)) { 3922 4211 /* 3923 4212 * The base ref is never dropped on per-cpu pwqs. Directly 3924 - * free the pwqs and wq. 4213 + * schedule RCU free. 3925 4214 */ 3926 - free_percpu(wq->cpu_pwqs); 3927 - kfree(wq); 4215 + call_rcu_sched(&wq->rcu, rcu_free_wq); 3928 4216 } else { 3929 4217 /* 3930 4218 * We're the sole accessor of @wq at this point. Directly ··· 4139 4435 pr_cont(" (%s)", desc); 4140 4436 pr_cont("\n"); 4141 4437 } 4438 + } 4439 + 4440 + static void pr_cont_pool_info(struct worker_pool *pool) 4441 + { 4442 + pr_cont(" cpus=%*pbl", nr_cpumask_bits, pool->attrs->cpumask); 4443 + if (pool->node != NUMA_NO_NODE) 4444 + pr_cont(" node=%d", pool->node); 4445 + pr_cont(" flags=0x%x nice=%d", pool->flags, pool->attrs->nice); 4446 + } 4447 + 4448 + static void pr_cont_work(bool comma, struct work_struct *work) 4449 + { 4450 + if (work->func == wq_barrier_func) { 4451 + struct wq_barrier *barr; 4452 + 4453 + barr = container_of(work, struct wq_barrier, work); 4454 + 4455 + pr_cont("%s BAR(%d)", comma ? "," : "", 4456 + task_pid_nr(barr->task)); 4457 + } else { 4458 + pr_cont("%s %pf", comma ? "," : "", work->func); 4459 + } 4460 + } 4461 + 4462 + static void show_pwq(struct pool_workqueue *pwq) 4463 + { 4464 + struct worker_pool *pool = pwq->pool; 4465 + struct work_struct *work; 4466 + struct worker *worker; 4467 + bool has_in_flight = false, has_pending = false; 4468 + int bkt; 4469 + 4470 + pr_info(" pwq %d:", pool->id); 4471 + pr_cont_pool_info(pool); 4472 + 4473 + pr_cont(" active=%d/%d%s\n", pwq->nr_active, pwq->max_active, 4474 + !list_empty(&pwq->mayday_node) ? " MAYDAY" : ""); 4475 + 4476 + hash_for_each(pool->busy_hash, bkt, worker, hentry) { 4477 + if (worker->current_pwq == pwq) { 4478 + has_in_flight = true; 4479 + break; 4480 + } 4481 + } 4482 + if (has_in_flight) { 4483 + bool comma = false; 4484 + 4485 + pr_info(" in-flight:"); 4486 + hash_for_each(pool->busy_hash, bkt, worker, hentry) { 4487 + if (worker->current_pwq != pwq) 4488 + continue; 4489 + 4490 + pr_cont("%s %d%s:%pf", comma ? "," : "", 4491 + task_pid_nr(worker->task), 4492 + worker == pwq->wq->rescuer ? "(RESCUER)" : "", 4493 + worker->current_func); 4494 + list_for_each_entry(work, &worker->scheduled, entry) 4495 + pr_cont_work(false, work); 4496 + comma = true; 4497 + } 4498 + pr_cont("\n"); 4499 + } 4500 + 4501 + list_for_each_entry(work, &pool->worklist, entry) { 4502 + if (get_work_pwq(work) == pwq) { 4503 + has_pending = true; 4504 + break; 4505 + } 4506 + } 4507 + if (has_pending) { 4508 + bool comma = false; 4509 + 4510 + pr_info(" pending:"); 4511 + list_for_each_entry(work, &pool->worklist, entry) { 4512 + if (get_work_pwq(work) != pwq) 4513 + continue; 4514 + 4515 + pr_cont_work(comma, work); 4516 + comma = !(*work_data_bits(work) & WORK_STRUCT_LINKED); 4517 + } 4518 + pr_cont("\n"); 4519 + } 4520 + 4521 + if (!list_empty(&pwq->delayed_works)) { 4522 + bool comma = false; 4523 + 4524 + pr_info(" delayed:"); 4525 + list_for_each_entry(work, &pwq->delayed_works, entry) { 4526 + pr_cont_work(comma, work); 4527 + comma = !(*work_data_bits(work) & WORK_STRUCT_LINKED); 4528 + } 4529 + pr_cont("\n"); 4530 + } 4531 + } 4532 + 4533 + /** 4534 + * show_workqueue_state - dump workqueue state 4535 + * 4536 + * Called from a sysrq handler and prints out all busy workqueues and 4537 + * pools. 4538 + */ 4539 + void show_workqueue_state(void) 4540 + { 4541 + struct workqueue_struct *wq; 4542 + struct worker_pool *pool; 4543 + unsigned long flags; 4544 + int pi; 4545 + 4546 + rcu_read_lock_sched(); 4547 + 4548 + pr_info("Showing busy workqueues and worker pools:\n"); 4549 + 4550 + list_for_each_entry_rcu(wq, &workqueues, list) { 4551 + struct pool_workqueue *pwq; 4552 + bool idle = true; 4553 + 4554 + for_each_pwq(pwq, wq) { 4555 + if (pwq->nr_active || !list_empty(&pwq->delayed_works)) { 4556 + idle = false; 4557 + break; 4558 + } 4559 + } 4560 + if (idle) 4561 + continue; 4562 + 4563 + pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags); 4564 + 4565 + for_each_pwq(pwq, wq) { 4566 + spin_lock_irqsave(&pwq->pool->lock, flags); 4567 + if (pwq->nr_active || !list_empty(&pwq->delayed_works)) 4568 + show_pwq(pwq); 4569 + spin_unlock_irqrestore(&pwq->pool->lock, flags); 4570 + } 4571 + } 4572 + 4573 + for_each_pool(pool, pi) { 4574 + struct worker *worker; 4575 + bool first = true; 4576 + 4577 + spin_lock_irqsave(&pool->lock, flags); 4578 + if (pool->nr_workers == pool->nr_idle) 4579 + goto next_pool; 4580 + 4581 + pr_info("pool %d:", pool->id); 4582 + pr_cont_pool_info(pool); 4583 + pr_cont(" workers=%d", pool->nr_workers); 4584 + if (pool->manager) 4585 + pr_cont(" manager: %d", 4586 + task_pid_nr(pool->manager->task)); 4587 + list_for_each_entry(worker, &pool->idle_list, entry) { 4588 + pr_cont(" %s%d", first ? "idle: " : "", 4589 + task_pid_nr(worker->task)); 4590 + first = false; 4591 + } 4592 + pr_cont("\n"); 4593 + next_pool: 4594 + spin_unlock_irqrestore(&pool->lock, flags); 4595 + } 4596 + 4597 + rcu_read_unlock_sched(); 4142 4598 } 4143 4599 4144 4600 /* ··· 4697 4833 mutex_unlock(&wq_pool_mutex); 4698 4834 } 4699 4835 #endif /* CONFIG_FREEZER */ 4836 + 4837 + #ifdef CONFIG_SYSFS 4838 + /* 4839 + * Workqueues with WQ_SYSFS flag set is visible to userland via 4840 + * /sys/bus/workqueue/devices/WQ_NAME. All visible workqueues have the 4841 + * following attributes. 4842 + * 4843 + * per_cpu RO bool : whether the workqueue is per-cpu or unbound 4844 + * max_active RW int : maximum number of in-flight work items 4845 + * 4846 + * Unbound workqueues have the following extra attributes. 4847 + * 4848 + * id RO int : the associated pool ID 4849 + * nice RW int : nice value of the workers 4850 + * cpumask RW mask : bitmask of allowed CPUs for the workers 4851 + */ 4852 + struct wq_device { 4853 + struct workqueue_struct *wq; 4854 + struct device dev; 4855 + }; 4856 + 4857 + static struct workqueue_struct *dev_to_wq(struct device *dev) 4858 + { 4859 + struct wq_device *wq_dev = container_of(dev, struct wq_device, dev); 4860 + 4861 + return wq_dev->wq; 4862 + } 4863 + 4864 + static ssize_t per_cpu_show(struct device *dev, struct device_attribute *attr, 4865 + char *buf) 4866 + { 4867 + struct workqueue_struct *wq = dev_to_wq(dev); 4868 + 4869 + return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND)); 4870 + } 4871 + static DEVICE_ATTR_RO(per_cpu); 4872 + 4873 + static ssize_t max_active_show(struct device *dev, 4874 + struct device_attribute *attr, char *buf) 4875 + { 4876 + struct workqueue_struct *wq = dev_to_wq(dev); 4877 + 4878 + return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active); 4879 + } 4880 + 4881 + static ssize_t max_active_store(struct device *dev, 4882 + struct device_attribute *attr, const char *buf, 4883 + size_t count) 4884 + { 4885 + struct workqueue_struct *wq = dev_to_wq(dev); 4886 + int val; 4887 + 4888 + if (sscanf(buf, "%d", &val) != 1 || val <= 0) 4889 + return -EINVAL; 4890 + 4891 + workqueue_set_max_active(wq, val); 4892 + return count; 4893 + } 4894 + static DEVICE_ATTR_RW(max_active); 4895 + 4896 + static struct attribute *wq_sysfs_attrs[] = { 4897 + &dev_attr_per_cpu.attr, 4898 + &dev_attr_max_active.attr, 4899 + NULL, 4900 + }; 4901 + ATTRIBUTE_GROUPS(wq_sysfs); 4902 + 4903 + static ssize_t wq_pool_ids_show(struct device *dev, 4904 + struct device_attribute *attr, char *buf) 4905 + { 4906 + struct workqueue_struct *wq = dev_to_wq(dev); 4907 + const char *delim = ""; 4908 + int node, written = 0; 4909 + 4910 + rcu_read_lock_sched(); 4911 + for_each_node(node) { 4912 + written += scnprintf(buf + written, PAGE_SIZE - written, 4913 + "%s%d:%d", delim, node, 4914 + unbound_pwq_by_node(wq, node)->pool->id); 4915 + delim = " "; 4916 + } 4917 + written += scnprintf(buf + written, PAGE_SIZE - written, "\n"); 4918 + rcu_read_unlock_sched(); 4919 + 4920 + return written; 4921 + } 4922 + 4923 + static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr, 4924 + char *buf) 4925 + { 4926 + struct workqueue_struct *wq = dev_to_wq(dev); 4927 + int written; 4928 + 4929 + mutex_lock(&wq->mutex); 4930 + written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice); 4931 + mutex_unlock(&wq->mutex); 4932 + 4933 + return written; 4934 + } 4935 + 4936 + /* prepare workqueue_attrs for sysfs store operations */ 4937 + static struct workqueue_attrs *wq_sysfs_prep_attrs(struct workqueue_struct *wq) 4938 + { 4939 + struct workqueue_attrs *attrs; 4940 + 4941 + attrs = alloc_workqueue_attrs(GFP_KERNEL); 4942 + if (!attrs) 4943 + return NULL; 4944 + 4945 + mutex_lock(&wq->mutex); 4946 + copy_workqueue_attrs(attrs, wq->unbound_attrs); 4947 + mutex_unlock(&wq->mutex); 4948 + return attrs; 4949 + } 4950 + 4951 + static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr, 4952 + const char *buf, size_t count) 4953 + { 4954 + struct workqueue_struct *wq = dev_to_wq(dev); 4955 + struct workqueue_attrs *attrs; 4956 + int ret; 4957 + 4958 + attrs = wq_sysfs_prep_attrs(wq); 4959 + if (!attrs) 4960 + return -ENOMEM; 4961 + 4962 + if (sscanf(buf, "%d", &attrs->nice) == 1 && 4963 + attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE) 4964 + ret = apply_workqueue_attrs(wq, attrs); 4965 + else 4966 + ret = -EINVAL; 4967 + 4968 + free_workqueue_attrs(attrs); 4969 + return ret ?: count; 4970 + } 4971 + 4972 + static ssize_t wq_cpumask_show(struct device *dev, 4973 + struct device_attribute *attr, char *buf) 4974 + { 4975 + struct workqueue_struct *wq = dev_to_wq(dev); 4976 + int written; 4977 + 4978 + mutex_lock(&wq->mutex); 4979 + written = scnprintf(buf, PAGE_SIZE, "%*pb\n", 4980 + cpumask_pr_args(wq->unbound_attrs->cpumask)); 4981 + mutex_unlock(&wq->mutex); 4982 + return written; 4983 + } 4984 + 4985 + static ssize_t wq_cpumask_store(struct device *dev, 4986 + struct device_attribute *attr, 4987 + const char *buf, size_t count) 4988 + { 4989 + struct workqueue_struct *wq = dev_to_wq(dev); 4990 + struct workqueue_attrs *attrs; 4991 + int ret; 4992 + 4993 + attrs = wq_sysfs_prep_attrs(wq); 4994 + if (!attrs) 4995 + return -ENOMEM; 4996 + 4997 + ret = cpumask_parse(buf, attrs->cpumask); 4998 + if (!ret) 4999 + ret = apply_workqueue_attrs(wq, attrs); 5000 + 5001 + free_workqueue_attrs(attrs); 5002 + return ret ?: count; 5003 + } 5004 + 5005 + static ssize_t wq_numa_show(struct device *dev, struct device_attribute *attr, 5006 + char *buf) 5007 + { 5008 + struct workqueue_struct *wq = dev_to_wq(dev); 5009 + int written; 5010 + 5011 + mutex_lock(&wq->mutex); 5012 + written = scnprintf(buf, PAGE_SIZE, "%d\n", 5013 + !wq->unbound_attrs->no_numa); 5014 + mutex_unlock(&wq->mutex); 5015 + 5016 + return written; 5017 + } 5018 + 5019 + static ssize_t wq_numa_store(struct device *dev, struct device_attribute *attr, 5020 + const char *buf, size_t count) 5021 + { 5022 + struct workqueue_struct *wq = dev_to_wq(dev); 5023 + struct workqueue_attrs *attrs; 5024 + int v, ret; 5025 + 5026 + attrs = wq_sysfs_prep_attrs(wq); 5027 + if (!attrs) 5028 + return -ENOMEM; 5029 + 5030 + ret = -EINVAL; 5031 + if (sscanf(buf, "%d", &v) == 1) { 5032 + attrs->no_numa = !v; 5033 + ret = apply_workqueue_attrs(wq, attrs); 5034 + } 5035 + 5036 + free_workqueue_attrs(attrs); 5037 + return ret ?: count; 5038 + } 5039 + 5040 + static struct device_attribute wq_sysfs_unbound_attrs[] = { 5041 + __ATTR(pool_ids, 0444, wq_pool_ids_show, NULL), 5042 + __ATTR(nice, 0644, wq_nice_show, wq_nice_store), 5043 + __ATTR(cpumask, 0644, wq_cpumask_show, wq_cpumask_store), 5044 + __ATTR(numa, 0644, wq_numa_show, wq_numa_store), 5045 + __ATTR_NULL, 5046 + }; 5047 + 5048 + static struct bus_type wq_subsys = { 5049 + .name = "workqueue", 5050 + .dev_groups = wq_sysfs_groups, 5051 + }; 5052 + 5053 + static int __init wq_sysfs_init(void) 5054 + { 5055 + return subsys_virtual_register(&wq_subsys, NULL); 5056 + } 5057 + core_initcall(wq_sysfs_init); 5058 + 5059 + static void wq_device_release(struct device *dev) 5060 + { 5061 + struct wq_device *wq_dev = container_of(dev, struct wq_device, dev); 5062 + 5063 + kfree(wq_dev); 5064 + } 5065 + 5066 + /** 5067 + * workqueue_sysfs_register - make a workqueue visible in sysfs 5068 + * @wq: the workqueue to register 5069 + * 5070 + * Expose @wq in sysfs under /sys/bus/workqueue/devices. 5071 + * alloc_workqueue*() automatically calls this function if WQ_SYSFS is set 5072 + * which is the preferred method. 5073 + * 5074 + * Workqueue user should use this function directly iff it wants to apply 5075 + * workqueue_attrs before making the workqueue visible in sysfs; otherwise, 5076 + * apply_workqueue_attrs() may race against userland updating the 5077 + * attributes. 5078 + * 5079 + * Return: 0 on success, -errno on failure. 5080 + */ 5081 + int workqueue_sysfs_register(struct workqueue_struct *wq) 5082 + { 5083 + struct wq_device *wq_dev; 5084 + int ret; 5085 + 5086 + /* 5087 + * Adjusting max_active or creating new pwqs by applyting 5088 + * attributes breaks ordering guarantee. Disallow exposing ordered 5089 + * workqueues. 5090 + */ 5091 + if (WARN_ON(wq->flags & __WQ_ORDERED)) 5092 + return -EINVAL; 5093 + 5094 + wq->wq_dev = wq_dev = kzalloc(sizeof(*wq_dev), GFP_KERNEL); 5095 + if (!wq_dev) 5096 + return -ENOMEM; 5097 + 5098 + wq_dev->wq = wq; 5099 + wq_dev->dev.bus = &wq_subsys; 5100 + wq_dev->dev.init_name = wq->name; 5101 + wq_dev->dev.release = wq_device_release; 5102 + 5103 + /* 5104 + * unbound_attrs are created separately. Suppress uevent until 5105 + * everything is ready. 5106 + */ 5107 + dev_set_uevent_suppress(&wq_dev->dev, true); 5108 + 5109 + ret = device_register(&wq_dev->dev); 5110 + if (ret) { 5111 + kfree(wq_dev); 5112 + wq->wq_dev = NULL; 5113 + return ret; 5114 + } 5115 + 5116 + if (wq->flags & WQ_UNBOUND) { 5117 + struct device_attribute *attr; 5118 + 5119 + for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++) { 5120 + ret = device_create_file(&wq_dev->dev, attr); 5121 + if (ret) { 5122 + device_unregister(&wq_dev->dev); 5123 + wq->wq_dev = NULL; 5124 + return ret; 5125 + } 5126 + } 5127 + } 5128 + 5129 + dev_set_uevent_suppress(&wq_dev->dev, false); 5130 + kobject_uevent(&wq_dev->dev.kobj, KOBJ_ADD); 5131 + return 0; 5132 + } 5133 + 5134 + /** 5135 + * workqueue_sysfs_unregister - undo workqueue_sysfs_register() 5136 + * @wq: the workqueue to unregister 5137 + * 5138 + * If @wq is registered to sysfs by workqueue_sysfs_register(), unregister. 5139 + */ 5140 + static void workqueue_sysfs_unregister(struct workqueue_struct *wq) 5141 + { 5142 + struct wq_device *wq_dev = wq->wq_dev; 5143 + 5144 + if (!wq->wq_dev) 5145 + return; 5146 + 5147 + wq->wq_dev = NULL; 5148 + device_unregister(&wq_dev->dev); 5149 + } 5150 + #else /* CONFIG_SYSFS */ 5151 + static void workqueue_sysfs_unregister(struct workqueue_struct *wq) { } 5152 + #endif /* CONFIG_SYSFS */ 4700 5153 4701 5154 static void __init wq_numa_init(void) 4702 5155 {
+2 -2
mm/percpu.c
··· 1310 1310 * and, from the second one, the backing allocator (currently either vm or 1311 1311 * km) provides translation. 1312 1312 * 1313 - * The addr can be tranlated simply without checking if it falls into the 1313 + * The addr can be translated simply without checking if it falls into the 1314 1314 * first chunk. But the current code reflects better how percpu allocator 1315 1315 * actually works, and the verification can discover both bugs in percpu 1316 1316 * allocator itself and per_cpu_ptr_to_phys() callers. So we keep current ··· 1762 1762 * and other parameters considering needed percpu size, allocation 1763 1763 * atom size and distances between CPUs. 1764 1764 * 1765 - * Groups are always mutliples of atom size and CPUs which are of 1765 + * Groups are always multiples of atom size and CPUs which are of 1766 1766 * LOCAL_DISTANCE both ways are grouped together and share space for 1767 1767 * units in the same group. The returned configuration is guaranteed 1768 1768 * to have CPUs on different nodes on different groups and >=75% usage