power: supply: replace use of system_wq with system_percpu_wq

Currently if a user enqueue a work item using schedule_delayed_work() the
used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use
WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to
schedule_work() that is using system_wq and queue_work(), that makes use
again of WORK_CPU_UNBOUND.

This lack of consistentcy cannot be addressed without refactoring the API.

system_unbound_wq should be the default workqueue so as not to enforce
locality constraints for random work whenever it's not required.

Adding system_dfl_wq to encourage its use when unbound work should be used.

queue_work() / queue_delayed_work() / mod_delayed_work() will now use the
new unbound wq: whether the user still use the old wq a warn will be
printed along with a wq redirect to the new one.

The old system_unbound_wq will be kept for a few release cycles.

Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
Link: https://lore.kernel.org/r/20250905090641.106297-2-marco.crivellari@suse.com
[rebased patch to cover recent changes]
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Marco Crivellari 2025-09-05 11:06:40 +02:00 committed by Sebastian Reichel
parent 7d715345a8
commit c4a7748b55
6 changed files with 12 additions and 12 deletions

View File

@ -181,7 +181,7 @@ static void adc_battery_helper_work(struct work_struct *work)
help->intern_res_avg_mohm /= win_size;
out:
queue_delayed_work(system_wq, &help->work,
queue_delayed_work(system_percpu_wq, &help->work,
(help->poll_count <= INIT_POLL_COUNT) ?
INIT_POLL_TIME : POLL_TIME);
@ -251,7 +251,7 @@ void adc_battery_helper_external_power_changed(struct power_supply *psy)
struct adc_battery_helper *help = power_supply_get_drvdata(psy);
dev_dbg(help->psy->dev.parent, "external power changed\n");
mod_delayed_work(system_wq, &help->work, SETTLE_TIME);
mod_delayed_work(system_percpu_wq, &help->work, SETTLE_TIME);
}
EXPORT_SYMBOL_GPL(adc_battery_helper_external_power_changed);
@ -260,7 +260,7 @@ static void adc_battery_helper_start_work(struct adc_battery_helper *help)
help->poll_count = 0;
help->ocv_avg_index = 0;
queue_delayed_work(system_wq, &help->work, 0);
queue_delayed_work(system_percpu_wq, &help->work, 0);
flush_delayed_work(&help->work);
}

View File

@ -842,7 +842,7 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
if (bq->automode < 1)
return NOTIFY_OK;
mod_delayed_work(system_wq, &bq->work, 0);
mod_delayed_work(system_percpu_wq, &bq->work, 0);
return NOTIFY_OK;
}

View File

@ -1467,7 +1467,7 @@ static void bq24190_charger_external_power_changed(struct power_supply *psy)
* too low default 500mA iinlim. Delay setting the input-current-limit
* for 300ms to avoid this.
*/
queue_delayed_work(system_wq, &bdi->input_current_limit_work,
queue_delayed_work(system_percpu_wq, &bdi->input_current_limit_work,
msecs_to_jiffies(300));
}

View File

@ -1127,7 +1127,7 @@ static int poll_interval_param_set(const char *val, const struct kernel_param *k
mutex_lock(&bq27xxx_list_lock);
list_for_each_entry(di, &bq27xxx_battery_devices, list)
mod_delayed_work(system_wq, &di->work, 0);
mod_delayed_work(system_percpu_wq, &di->work, 0);
mutex_unlock(&bq27xxx_list_lock);
return ret;
@ -1945,7 +1945,7 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
di->last_update = jiffies;
if (!di->removed && poll_interval > 0)
mod_delayed_work(system_wq, &di->work, poll_interval * HZ);
mod_delayed_work(system_percpu_wq, &di->work, poll_interval * HZ);
}
void bq27xxx_battery_update(struct bq27xxx_device_info *di)
@ -2221,7 +2221,7 @@ static void bq27xxx_external_power_changed(struct power_supply *psy)
struct bq27xxx_device_info *di = power_supply_get_drvdata(psy);
/* After charger plug in/out wait 0.5s for things to stabilize */
mod_delayed_work(system_wq, &di->work, HZ / 2);
mod_delayed_work(system_percpu_wq, &di->work, HZ / 2);
}
int bq27xxx_battery_setup(struct bq27xxx_device_info *di)

View File

@ -1046,7 +1046,7 @@ static void rk817_charging_monitor(struct work_struct *work)
rk817_read_props(charger);
/* Run every 8 seconds like the BSP driver did. */
queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000));
queue_delayed_work(system_percpu_wq, &charger->work, msecs_to_jiffies(8000));
}
static void rk817_cleanup_node(void *data)
@ -1206,7 +1206,7 @@ static int rk817_charger_probe(struct platform_device *pdev)
return ret;
/* Force the first update immediately. */
mod_delayed_work(system_wq, &charger->work, 0);
mod_delayed_work(system_percpu_wq, &charger->work, 0);
return 0;
}
@ -1226,7 +1226,7 @@ static int __maybe_unused rk817_resume(struct device *dev)
struct rk817_charger *charger = dev_get_drvdata(dev);
/* force an immediate update */
mod_delayed_work(system_wq, &charger->work, 0);
mod_delayed_work(system_percpu_wq, &charger->work, 0);
return 0;
}

View File

@ -493,7 +493,7 @@ static irqreturn_t ucs1002_alert_irq(int irq, void *data)
{
struct ucs1002_info *info = data;
mod_delayed_work(system_wq, &info->health_poll, 0);
mod_delayed_work(system_percpu_wq, &info->health_poll, 0);
return IRQ_HANDLED;
}