aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2015-04-02 07:14:39 -0400
committerTejun Heo <tj@kernel.org>2015-04-06 11:16:04 -0400
commit6ba94429c8e7b87b0fff13c5ac90731b239b77fa (patch)
treedcdf2b22d8e5f9a515aa1d720aeae59a45d411c3 /kernel
parentbffc4375897ea01aa68877e5fc1e33c7766efa29 (diff)
workqueue: Reorder sysfs code
The sysfs code usually belongs to the botom of the file since it deals with high level objects. In the workqueue code it's misplaced and such that we'll need to work around functions references to allow the sysfs code to call APIs like apply_workqueue_attrs(). Lets move that block further in the file, almost the botom. And declare workqueue_sysfs_unregister() just before destroy_workqueue() which reference it. tj: Moved workqueue_sysfs_unregister() forward declaration where other forward declarations are. Suggested-by: Tejun Heo <tj@kernel.org> Cc: Christoph Lameter <cl@linux.com> Cc: Kevin Hilman <khilman@linaro.org> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Mike Galbraith <bitbucket@online.de> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Tejun Heo <tj@kernel.org> Cc: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/workqueue.c635
1 files changed, 318 insertions, 317 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 1ca0b1d54e70..586ad91300b0 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -332,6 +332,7 @@ EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
332static int worker_thread(void *__worker); 332static int worker_thread(void *__worker);
333static void copy_workqueue_attrs(struct workqueue_attrs *to, 333static void copy_workqueue_attrs(struct workqueue_attrs *to,
334 const struct workqueue_attrs *from); 334 const struct workqueue_attrs *from);
335static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
335 336
336#define CREATE_TRACE_POINTS 337#define CREATE_TRACE_POINTS
337#include <trace/events/workqueue.h> 338#include <trace/events/workqueue.h>
@@ -3001,323 +3002,6 @@ int execute_in_process_context(work_func_t fn, struct execute_work *ew)
3001} 3002}
3002EXPORT_SYMBOL_GPL(execute_in_process_context); 3003EXPORT_SYMBOL_GPL(execute_in_process_context);
3003 3004
3004#ifdef CONFIG_SYSFS
3005/*
3006 * Workqueues with WQ_SYSFS flag set is visible to userland via
3007 * /sys/bus/workqueue/devices/WQ_NAME. All visible workqueues have the
3008 * following attributes.
3009 *
3010 * per_cpu RO bool : whether the workqueue is per-cpu or unbound
3011 * max_active RW int : maximum number of in-flight work items
3012 *
3013 * Unbound workqueues have the following extra attributes.
3014 *
3015 * id RO int : the associated pool ID
3016 * nice RW int : nice value of the workers
3017 * cpumask RW mask : bitmask of allowed CPUs for the workers
3018 */
3019struct wq_device {
3020 struct workqueue_struct *wq;
3021 struct device dev;
3022};
3023
3024static struct workqueue_struct *dev_to_wq(struct device *dev)
3025{
3026 struct wq_device *wq_dev = container_of(dev, struct wq_device, dev);
3027
3028 return wq_dev->wq;
3029}
3030
3031static ssize_t per_cpu_show(struct device *dev, struct device_attribute *attr,
3032 char *buf)
3033{
3034 struct workqueue_struct *wq = dev_to_wq(dev);
3035
3036 return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND));
3037}
3038static DEVICE_ATTR_RO(per_cpu);
3039
3040static ssize_t max_active_show(struct device *dev,
3041 struct device_attribute *attr, char *buf)
3042{
3043 struct workqueue_struct *wq = dev_to_wq(dev);
3044
3045 return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active);
3046}
3047
3048static ssize_t max_active_store(struct device *dev,
3049 struct device_attribute *attr, const char *buf,
3050 size_t count)
3051{
3052 struct workqueue_struct *wq = dev_to_wq(dev);
3053 int val;
3054
3055 if (sscanf(buf, "%d", &val) != 1 || val <= 0)
3056 return -EINVAL;
3057
3058 workqueue_set_max_active(wq, val);
3059 return count;
3060}
3061static DEVICE_ATTR_RW(max_active);
3062
3063static struct attribute *wq_sysfs_attrs[] = {
3064 &dev_attr_per_cpu.attr,
3065 &dev_attr_max_active.attr,
3066 NULL,
3067};
3068ATTRIBUTE_GROUPS(wq_sysfs);
3069
3070static ssize_t wq_pool_ids_show(struct device *dev,
3071 struct device_attribute *attr, char *buf)
3072{
3073 struct workqueue_struct *wq = dev_to_wq(dev);
3074 const char *delim = "";
3075 int node, written = 0;
3076
3077 rcu_read_lock_sched();
3078 for_each_node(node) {
3079 written += scnprintf(buf + written, PAGE_SIZE - written,
3080 "%s%d:%d", delim, node,
3081 unbound_pwq_by_node(wq, node)->pool->id);
3082 delim = " ";
3083 }
3084 written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
3085 rcu_read_unlock_sched();
3086
3087 return written;
3088}
3089
3090static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr,
3091 char *buf)
3092{
3093 struct workqueue_struct *wq = dev_to_wq(dev);
3094 int written;
3095
3096 mutex_lock(&wq->mutex);
3097 written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice);
3098 mutex_unlock(&wq->mutex);
3099
3100 return written;
3101}
3102
3103/* prepare workqueue_attrs for sysfs store operations */
3104static struct workqueue_attrs *wq_sysfs_prep_attrs(struct workqueue_struct *wq)
3105{
3106 struct workqueue_attrs *attrs;
3107
3108 attrs = alloc_workqueue_attrs(GFP_KERNEL);
3109 if (!attrs)
3110 return NULL;
3111
3112 mutex_lock(&wq->mutex);
3113 copy_workqueue_attrs(attrs, wq->unbound_attrs);
3114 mutex_unlock(&wq->mutex);
3115 return attrs;
3116}
3117
3118static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
3119 const char *buf, size_t count)
3120{
3121 struct workqueue_struct *wq = dev_to_wq(dev);
3122 struct workqueue_attrs *attrs;
3123 int ret;
3124
3125 attrs = wq_sysfs_prep_attrs(wq);
3126 if (!attrs)
3127 return -ENOMEM;
3128
3129 if (sscanf(buf, "%d", &attrs->nice) == 1 &&
3130 attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
3131 ret = apply_workqueue_attrs(wq, attrs);
3132 else
3133 ret = -EINVAL;
3134
3135 free_workqueue_attrs(attrs);
3136 return ret ?: count;
3137}
3138
3139static ssize_t wq_cpumask_show(struct device *dev,
3140 struct device_attribute *attr, char *buf)
3141{
3142 struct workqueue_struct *wq = dev_to_wq(dev);
3143 int written;
3144
3145 mutex_lock(&wq->mutex);
3146 written = scnprintf(buf, PAGE_SIZE, "%*pb\n",
3147 cpumask_pr_args(wq->unbound_attrs->cpumask));
3148 mutex_unlock(&wq->mutex);
3149 return written;
3150}
3151
3152static ssize_t wq_cpumask_store(struct device *dev,
3153 struct device_attribute *attr,
3154 const char *buf, size_t count)
3155{
3156 struct workqueue_struct *wq = dev_to_wq(dev);
3157 struct workqueue_attrs *attrs;
3158 int ret;
3159
3160 attrs = wq_sysfs_prep_attrs(wq);
3161 if (!attrs)
3162 return -ENOMEM;
3163
3164 ret = cpumask_parse(buf, attrs->cpumask);
3165 if (!ret)
3166 ret = apply_workqueue_attrs(wq, attrs);
3167
3168 free_workqueue_attrs(attrs);
3169 return ret ?: count;
3170}
3171
3172static ssize_t wq_numa_show(struct device *dev, struct device_attribute *attr,
3173 char *buf)
3174{
3175 struct workqueue_struct *wq = dev_to_wq(dev);
3176 int written;
3177
3178 mutex_lock(&wq->mutex);
3179 written = scnprintf(buf, PAGE_SIZE, "%d\n",
3180 !wq->unbound_attrs->no_numa);
3181 mutex_unlock(&wq->mutex);
3182
3183 return written;
3184}
3185
3186static ssize_t wq_numa_store(struct device *dev, struct device_attribute *attr,
3187 const char *buf, size_t count)
3188{
3189 struct workqueue_struct *wq = dev_to_wq(dev);
3190 struct workqueue_attrs *attrs;
3191 int v, ret;
3192
3193 attrs = wq_sysfs_prep_attrs(wq);
3194 if (!attrs)
3195 return -ENOMEM;
3196
3197 ret = -EINVAL;
3198 if (sscanf(buf, "%d", &v) == 1) {
3199 attrs->no_numa = !v;
3200 ret = apply_workqueue_attrs(wq, attrs);
3201 }
3202
3203 free_workqueue_attrs(attrs);
3204 return ret ?: count;
3205}
3206
3207static struct device_attribute wq_sysfs_unbound_attrs[] = {
3208 __ATTR(pool_ids, 0444, wq_pool_ids_show, NULL),
3209 __ATTR(nice, 0644, wq_nice_show, wq_nice_store),
3210 __ATTR(cpumask, 0644, wq_cpumask_show, wq_cpumask_store),
3211 __ATTR(numa, 0644, wq_numa_show, wq_numa_store),
3212 __ATTR_NULL,
3213};
3214
3215static struct bus_type wq_subsys = {
3216 .name = "workqueue",
3217 .dev_groups = wq_sysfs_groups,
3218};
3219
3220static int __init wq_sysfs_init(void)
3221{
3222 return subsys_virtual_register(&wq_subsys, NULL);
3223}
3224core_initcall(wq_sysfs_init);
3225
3226static void wq_device_release(struct device *dev)
3227{
3228 struct wq_device *wq_dev = container_of(dev, struct wq_device, dev);
3229
3230 kfree(wq_dev);
3231}
3232
3233/**
3234 * workqueue_sysfs_register - make a workqueue visible in sysfs
3235 * @wq: the workqueue to register
3236 *
3237 * Expose @wq in sysfs under /sys/bus/workqueue/devices.
3238 * alloc_workqueue*() automatically calls this function if WQ_SYSFS is set
3239 * which is the preferred method.
3240 *
3241 * Workqueue user should use this function directly iff it wants to apply
3242 * workqueue_attrs before making the workqueue visible in sysfs; otherwise,
3243 * apply_workqueue_attrs() may race against userland updating the
3244 * attributes.
3245 *
3246 * Return: 0 on success, -errno on failure.
3247 */
3248int workqueue_sysfs_register(struct workqueue_struct *wq)
3249{
3250 struct wq_device *wq_dev;
3251 int ret;
3252
3253 /*
3254 * Adjusting max_active or creating new pwqs by applyting
3255 * attributes breaks ordering guarantee. Disallow exposing ordered
3256 * workqueues.
3257 */
3258 if (WARN_ON(wq->flags & __WQ_ORDERED))
3259 return -EINVAL;
3260
3261 wq->wq_dev = wq_dev = kzalloc(sizeof(*wq_dev), GFP_KERNEL);
3262 if (!wq_dev)
3263 return -ENOMEM;
3264
3265 wq_dev->wq = wq;
3266 wq_dev->dev.bus = &wq_subsys;
3267 wq_dev->dev.init_name = wq->name;
3268 wq_dev->dev.release = wq_device_release;
3269
3270 /*
3271 * unbound_attrs are created separately. Suppress uevent until
3272 * everything is ready.
3273 */
3274 dev_set_uevent_suppress(&wq_dev->dev, true);
3275
3276 ret = device_register(&wq_dev->dev);
3277 if (ret) {
3278 kfree(wq_dev);
3279 wq->wq_dev = NULL;
3280 return ret;
3281 }
3282
3283 if (wq->flags & WQ_UNBOUND) {
3284 struct device_attribute *attr;
3285
3286 for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++) {
3287 ret = device_create_file(&wq_dev->dev, attr);
3288 if (ret) {
3289 device_unregister(&wq_dev->dev);
3290 wq->wq_dev = NULL;
3291 return ret;
3292 }
3293 }
3294 }
3295
3296 dev_set_uevent_suppress(&wq_dev->dev, false);
3297 kobject_uevent(&wq_dev->dev.kobj, KOBJ_ADD);
3298 return 0;
3299}
3300
3301/**
3302 * workqueue_sysfs_unregister - undo workqueue_sysfs_register()
3303 * @wq: the workqueue to unregister
3304 *
3305 * If @wq is registered to sysfs by workqueue_sysfs_register(), unregister.
3306 */
3307static void workqueue_sysfs_unregister(struct workqueue_struct *wq)
3308{
3309 struct wq_device *wq_dev = wq->wq_dev;
3310
3311 if (!wq->wq_dev)
3312 return;
3313
3314 wq->wq_dev = NULL;
3315 device_unregister(&wq_dev->dev);
3316}
3317#else /* CONFIG_SYSFS */
3318static void workqueue_sysfs_unregister(struct workqueue_struct *wq) { }
3319#endif /* CONFIG_SYSFS */
3320
3321/** 3005/**
3322 * free_workqueue_attrs - free a workqueue_attrs 3006 * free_workqueue_attrs - free a workqueue_attrs
3323 * @attrs: workqueue_attrs to free 3007 * @attrs: workqueue_attrs to free
@@ -5014,6 +4698,323 @@ out_unlock:
5014} 4698}
5015#endif /* CONFIG_FREEZER */ 4699#endif /* CONFIG_FREEZER */
5016 4700
4701#ifdef CONFIG_SYSFS
4702/*
4703 * Workqueues with WQ_SYSFS flag set is visible to userland via
4704 * /sys/bus/workqueue/devices/WQ_NAME. All visible workqueues have the
4705 * following attributes.
4706 *
4707 * per_cpu RO bool : whether the workqueue is per-cpu or unbound
4708 * max_active RW int : maximum number of in-flight work items
4709 *
4710 * Unbound workqueues have the following extra attributes.
4711 *
4712 * id RO int : the associated pool ID
4713 * nice RW int : nice value of the workers
4714 * cpumask RW mask : bitmask of allowed CPUs for the workers
4715 */
4716struct wq_device {
4717 struct workqueue_struct *wq;
4718 struct device dev;
4719};
4720
4721static struct workqueue_struct *dev_to_wq(struct device *dev)
4722{
4723 struct wq_device *wq_dev = container_of(dev, struct wq_device, dev);
4724
4725 return wq_dev->wq;
4726}
4727
4728static ssize_t per_cpu_show(struct device *dev, struct device_attribute *attr,
4729 char *buf)
4730{
4731 struct workqueue_struct *wq = dev_to_wq(dev);
4732
4733 return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND));
4734}
4735static DEVICE_ATTR_RO(per_cpu);
4736
4737static ssize_t max_active_show(struct device *dev,
4738 struct device_attribute *attr, char *buf)
4739{
4740 struct workqueue_struct *wq = dev_to_wq(dev);
4741
4742 return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active);
4743}
4744
4745static ssize_t max_active_store(struct device *dev,
4746 struct device_attribute *attr, const char *buf,
4747 size_t count)
4748{
4749 struct workqueue_struct *wq = dev_to_wq(dev);
4750 int val;
4751
4752 if (sscanf(buf, "%d", &val) != 1 || val <= 0)
4753 return -EINVAL;
4754
4755 workqueue_set_max_active(wq, val);
4756 return count;
4757}
4758static DEVICE_ATTR_RW(max_active);
4759
4760static struct attribute *wq_sysfs_attrs[] = {
4761 &dev_attr_per_cpu.attr,
4762 &dev_attr_max_active.attr,
4763 NULL,
4764};
4765ATTRIBUTE_GROUPS(wq_sysfs);
4766
4767static ssize_t wq_pool_ids_show(struct device *dev,
4768 struct device_attribute *attr, char *buf)
4769{
4770 struct workqueue_struct *wq = dev_to_wq(dev);
4771 const char *delim = "";
4772 int node, written = 0;
4773
4774 rcu_read_lock_sched();
4775 for_each_node(node) {
4776 written += scnprintf(buf + written, PAGE_SIZE - written,
4777 "%s%d:%d", delim, node,
4778 unbound_pwq_by_node(wq, node)->pool->id);
4779 delim = " ";
4780 }
4781 written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
4782 rcu_read_unlock_sched();
4783
4784 return written;
4785}
4786
4787static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr,
4788 char *buf)
4789{
4790 struct workqueue_struct *wq = dev_to_wq(dev);
4791 int written;
4792
4793 mutex_lock(&wq->mutex);
4794 written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice);
4795 mutex_unlock(&wq->mutex);
4796
4797 return written;
4798}
4799
4800/* prepare workqueue_attrs for sysfs store operations */
4801static struct workqueue_attrs *wq_sysfs_prep_attrs(struct workqueue_struct *wq)
4802{
4803 struct workqueue_attrs *attrs;
4804
4805 attrs = alloc_workqueue_attrs(GFP_KERNEL);
4806 if (!attrs)
4807 return NULL;
4808
4809 mutex_lock(&wq->mutex);
4810 copy_workqueue_attrs(attrs, wq->unbound_attrs);
4811 mutex_unlock(&wq->mutex);
4812 return attrs;
4813}
4814
4815static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
4816 const char *buf, size_t count)
4817{
4818 struct workqueue_struct *wq = dev_to_wq(dev);
4819 struct workqueue_attrs *attrs;
4820 int ret;
4821
4822 attrs = wq_sysfs_prep_attrs(wq);
4823 if (!attrs)
4824 return -ENOMEM;
4825
4826 if (sscanf(buf, "%d", &attrs->nice) == 1 &&
4827 attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
4828 ret = apply_workqueue_attrs(wq, attrs);
4829 else
4830 ret = -EINVAL;
4831
4832 free_workqueue_attrs(attrs);
4833 return ret ?: count;
4834}
4835
4836static ssize_t wq_cpumask_show(struct device *dev,
4837 struct device_attribute *attr, char *buf)
4838{
4839 struct workqueue_struct *wq = dev_to_wq(dev);
4840 int written;
4841
4842 mutex_lock(&wq->mutex);
4843 written = scnprintf(buf, PAGE_SIZE, "%*pb\n",
4844 cpumask_pr_args(wq->unbound_attrs->cpumask));
4845 mutex_unlock(&wq->mutex);
4846 return written;
4847}
4848
4849static ssize_t wq_cpumask_store(struct device *dev,
4850 struct device_attribute *attr,
4851 const char *buf, size_t count)
4852{
4853 struct workqueue_struct *wq = dev_to_wq(dev);
4854 struct workqueue_attrs *attrs;
4855 int ret;
4856
4857 attrs = wq_sysfs_prep_attrs(wq);
4858 if (!attrs)
4859 return -ENOMEM;
4860
4861 ret = cpumask_parse(buf, attrs->cpumask);
4862 if (!ret)
4863 ret = apply_workqueue_attrs(wq, attrs);
4864
4865 free_workqueue_attrs(attrs);
4866 return ret ?: count;
4867}
4868
4869static ssize_t wq_numa_show(struct device *dev, struct device_attribute *attr,
4870 char *buf)
4871{
4872 struct workqueue_struct *wq = dev_to_wq(dev);
4873 int written;
4874
4875 mutex_lock(&wq->mutex);
4876 written = scnprintf(buf, PAGE_SIZE, "%d\n",
4877 !wq->unbound_attrs->no_numa);
4878 mutex_unlock(&wq->mutex);
4879
4880 return written;
4881}
4882
4883static ssize_t wq_numa_store(struct device *dev, struct device_attribute *attr,
4884 const char *buf, size_t count)
4885{
4886 struct workqueue_struct *wq = dev_to_wq(dev);
4887 struct workqueue_attrs *attrs;
4888 int v, ret;
4889
4890 attrs = wq_sysfs_prep_attrs(wq);
4891 if (!attrs)
4892 return -ENOMEM;
4893
4894 ret = -EINVAL;
4895 if (sscanf(buf, "%d", &v) == 1) {
4896 attrs->no_numa = !v;
4897 ret = apply_workqueue_attrs(wq, attrs);
4898 }
4899
4900 free_workqueue_attrs(attrs);
4901 return ret ?: count;
4902}
4903
4904static struct device_attribute wq_sysfs_unbound_attrs[] = {
4905 __ATTR(pool_ids, 0444, wq_pool_ids_show, NULL),
4906 __ATTR(nice, 0644, wq_nice_show, wq_nice_store),
4907 __ATTR(cpumask, 0644, wq_cpumask_show, wq_cpumask_store),
4908 __ATTR(numa, 0644, wq_numa_show, wq_numa_store),
4909 __ATTR_NULL,
4910};
4911
4912static struct bus_type wq_subsys = {
4913 .name = "workqueue",
4914 .dev_groups = wq_sysfs_groups,
4915};
4916
4917static int __init wq_sysfs_init(void)
4918{
4919 return subsys_virtual_register(&wq_subsys, NULL);
4920}
4921core_initcall(wq_sysfs_init);
4922
4923static void wq_device_release(struct device *dev)
4924{
4925 struct wq_device *wq_dev = container_of(dev, struct wq_device, dev);
4926
4927 kfree(wq_dev);
4928}
4929
4930/**
4931 * workqueue_sysfs_register - make a workqueue visible in sysfs
4932 * @wq: the workqueue to register
4933 *
4934 * Expose @wq in sysfs under /sys/bus/workqueue/devices.
4935 * alloc_workqueue*() automatically calls this function if WQ_SYSFS is set
4936 * which is the preferred method.
4937 *
4938 * Workqueue user should use this function directly iff it wants to apply
4939 * workqueue_attrs before making the workqueue visible in sysfs; otherwise,
4940 * apply_workqueue_attrs() may race against userland updating the
4941 * attributes.
4942 *
4943 * Return: 0 on success, -errno on failure.
4944 */
4945int workqueue_sysfs_register(struct workqueue_struct *wq)
4946{
4947 struct wq_device *wq_dev;
4948 int ret;
4949
4950 /*
4951 * Adjusting max_active or creating new pwqs by applyting
4952 * attributes breaks ordering guarantee. Disallow exposing ordered
4953 * workqueues.
4954 */
4955 if (WARN_ON(wq->flags & __WQ_ORDERED))
4956 return -EINVAL;
4957
4958 wq->wq_dev = wq_dev = kzalloc(sizeof(*wq_dev), GFP_KERNEL);
4959 if (!wq_dev)
4960 return -ENOMEM;
4961
4962 wq_dev->wq = wq;
4963 wq_dev->dev.bus = &wq_subsys;
4964 wq_dev->dev.init_name = wq->name;
4965 wq_dev->dev.release = wq_device_release;
4966
4967 /*
4968 * unbound_attrs are created separately. Suppress uevent until
4969 * everything is ready.
4970 */
4971 dev_set_uevent_suppress(&wq_dev->dev, true);
4972
4973 ret = device_register(&wq_dev->dev);
4974 if (ret) {
4975 kfree(wq_dev);
4976 wq->wq_dev = NULL;
4977 return ret;
4978 }
4979
4980 if (wq->flags & WQ_UNBOUND) {
4981 struct device_attribute *attr;
4982
4983 for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++) {
4984 ret = device_create_file(&wq_dev->dev, attr);
4985 if (ret) {
4986 device_unregister(&wq_dev->dev);
4987 wq->wq_dev = NULL;
4988 return ret;
4989 }
4990 }
4991 }
4992
4993 dev_set_uevent_suppress(&wq_dev->dev, false);
4994 kobject_uevent(&wq_dev->dev.kobj, KOBJ_ADD);
4995 return 0;
4996}
4997
4998/**
4999 * workqueue_sysfs_unregister - undo workqueue_sysfs_register()
5000 * @wq: the workqueue to unregister
5001 *
5002 * If @wq is registered to sysfs by workqueue_sysfs_register(), unregister.
5003 */
5004static void workqueue_sysfs_unregister(struct workqueue_struct *wq)
5005{
5006 struct wq_device *wq_dev = wq->wq_dev;
5007
5008 if (!wq->wq_dev)
5009 return;
5010
5011 wq->wq_dev = NULL;
5012 device_unregister(&wq_dev->dev);
5013}
5014#else /* CONFIG_SYSFS */
5015static void workqueue_sysfs_unregister(struct workqueue_struct *wq) { }
5016#endif /* CONFIG_SYSFS */
5017
5017static void __init wq_numa_init(void) 5018static void __init wq_numa_init(void)
5018{ 5019{
5019 cpumask_var_t *tbl; 5020 cpumask_var_t *tbl;