@@ -326,7 +326,7 @@ static struct rcuwait manager_wait = __RCUWAIT_INITIALIZER(manager_wait);
326
326
static LIST_HEAD (workqueues ); /* PR: list of all workqueues */
327
327
static bool workqueue_freezing ; /* PL: have wqs started freezing? */
328
328
329
- /* PL: allowable cpus for unbound wqs and work items */
329
+ /* PL&A : allowable cpus for unbound wqs and work items */
330
330
static cpumask_var_t wq_unbound_cpumask ;
331
331
332
332
/* CPU where unbound work was last round robin scheduled from this CPU */
@@ -3956,7 +3956,8 @@ static void apply_wqattrs_cleanup(struct apply_wqattrs_ctx *ctx)
3956
3956
/* allocate the attrs and pwqs for later installation */
3957
3957
static struct apply_wqattrs_ctx *
3958
3958
apply_wqattrs_prepare (struct workqueue_struct * wq ,
3959
- const struct workqueue_attrs * attrs )
3959
+ const struct workqueue_attrs * attrs ,
3960
+ const cpumask_var_t unbound_cpumask )
3960
3961
{
3961
3962
struct apply_wqattrs_ctx * ctx ;
3962
3963
struct workqueue_attrs * new_attrs , * tmp_attrs ;
@@ -3972,14 +3973,15 @@ apply_wqattrs_prepare(struct workqueue_struct *wq,
3972
3973
goto out_free ;
3973
3974
3974
3975
/*
3975
- * Calculate the attrs of the default pwq.
3976
+ * Calculate the attrs of the default pwq with unbound_cpumask
3977
+ * which is wq_unbound_cpumask or to set to wq_unbound_cpumask.
3976
3978
* If the user configured cpumask doesn't overlap with the
3977
3979
* wq_unbound_cpumask, we fallback to the wq_unbound_cpumask.
3978
3980
*/
3979
3981
copy_workqueue_attrs (new_attrs , attrs );
3980
- cpumask_and (new_attrs -> cpumask , new_attrs -> cpumask , wq_unbound_cpumask );
3982
+ cpumask_and (new_attrs -> cpumask , new_attrs -> cpumask , unbound_cpumask );
3981
3983
if (unlikely (cpumask_empty (new_attrs -> cpumask )))
3982
- cpumask_copy (new_attrs -> cpumask , wq_unbound_cpumask );
3984
+ cpumask_copy (new_attrs -> cpumask , unbound_cpumask );
3983
3985
3984
3986
/*
3985
3987
* We may create multiple pwqs with differing cpumasks. Make a
@@ -4076,7 +4078,7 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,
4076
4078
wq -> flags &= ~__WQ_ORDERED ;
4077
4079
}
4078
4080
4079
- ctx = apply_wqattrs_prepare (wq , attrs );
4081
+ ctx = apply_wqattrs_prepare (wq , attrs , wq_unbound_cpumask );
4080
4082
if (!ctx )
4081
4083
return - ENOMEM ;
4082
4084
@@ -5377,7 +5379,7 @@ void thaw_workqueues(void)
5377
5379
}
5378
5380
#endif /* CONFIG_FREEZER */
5379
5381
5380
- static int workqueue_apply_unbound_cpumask (void )
5382
+ static int workqueue_apply_unbound_cpumask (const cpumask_var_t unbound_cpumask )
5381
5383
{
5382
5384
LIST_HEAD (ctxs );
5383
5385
int ret = 0 ;
@@ -5393,7 +5395,7 @@ static int workqueue_apply_unbound_cpumask(void)
5393
5395
if (wq -> flags & __WQ_ORDERED )
5394
5396
continue ;
5395
5397
5396
- ctx = apply_wqattrs_prepare (wq , wq -> unbound_attrs );
5398
+ ctx = apply_wqattrs_prepare (wq , wq -> unbound_attrs , unbound_cpumask );
5397
5399
if (!ctx ) {
5398
5400
ret = - ENOMEM ;
5399
5401
break ;
@@ -5408,6 +5410,11 @@ static int workqueue_apply_unbound_cpumask(void)
5408
5410
apply_wqattrs_cleanup (ctx );
5409
5411
}
5410
5412
5413
+ if (!ret ) {
5414
+ mutex_lock (& wq_pool_attach_mutex );
5415
+ cpumask_copy (wq_unbound_cpumask , unbound_cpumask );
5416
+ mutex_unlock (& wq_pool_attach_mutex );
5417
+ }
5411
5418
return ret ;
5412
5419
}
5413
5420
@@ -5426,7 +5433,6 @@ static int workqueue_apply_unbound_cpumask(void)
5426
5433
int workqueue_set_unbound_cpumask (cpumask_var_t cpumask )
5427
5434
{
5428
5435
int ret = - EINVAL ;
5429
- cpumask_var_t saved_cpumask ;
5430
5436
5431
5437
/*
5432
5438
* Not excluding isolated cpus on purpose.
@@ -5440,23 +5446,8 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
5440
5446
goto out_unlock ;
5441
5447
}
5442
5448
5443
- if (!zalloc_cpumask_var (& saved_cpumask , GFP_KERNEL )) {
5444
- ret = - ENOMEM ;
5445
- goto out_unlock ;
5446
- }
5447
-
5448
- /* save the old wq_unbound_cpumask. */
5449
- cpumask_copy (saved_cpumask , wq_unbound_cpumask );
5450
-
5451
- /* update wq_unbound_cpumask at first and apply it to wqs. */
5452
- cpumask_copy (wq_unbound_cpumask , cpumask );
5453
- ret = workqueue_apply_unbound_cpumask ();
5454
-
5455
- /* restore the wq_unbound_cpumask when failed. */
5456
- if (ret < 0 )
5457
- cpumask_copy (wq_unbound_cpumask , saved_cpumask );
5449
+ ret = workqueue_apply_unbound_cpumask (cpumask );
5458
5450
5459
- free_cpumask_var (saved_cpumask );
5460
5451
out_unlock :
5461
5452
apply_wqattrs_unlock ();
5462
5453
}
0 commit comments