cpufreq: Skip scheduling when update work is pending
PATCH 1/1 cpufreq: Skip scheduling when update work is pending
Avoid scheduling cpufreq policy update work when it's already pending by checking work_pending() before schedule_work(). This reduces unnecessary work queue churn and scheduling overhead under frequent notifier events.
--- drivers/cpufreq/cpufreq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/cpufreq/cpufreq.c +5 -3
@@ -1222,7 +1222,8 @@ static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, { struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min); -schedule_work (&policy->update); +if (!work_pending (&policy->update)) +schedule_work (&policy->update);return 0 ; }
@@ -1231,7 +1232,8 @@ static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, { struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max); -schedule_work (&policy->update); +if (!work_pending (&policy->update)) +schedule_work (&policy->update);return 0 ; }
@@ -1841,7 +1843,7 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, breturn policy->cur;cpufreq_out_of_sync (policy, new_freq); -if (update) +if (update && !work_pending (&policy->update))schedule_work (&policy->update); }
Signature · 1 line
2.34.1
Rafael J. Wysocki
maintainerQuoted 16 lines · Kaushlendra Kumar
Avoid scheduling cpufreq policy update work when it's already pending by checking
work_pending()beforeschedule_work(). This reduces unnecessary work queue churn and scheduling overhead under frequent notifier events.Signed-off-by Kaushlendra Kumar <[email protected]>--- drivers/cpufreq/cpufreq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/cpufreq/cpufreq.c +0
-0
drivers/cpufreq/cpufreq.c static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, · line 1226
Quoted 6 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1222,7 +1222,8 @@ static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, { struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min); -schedule_work (&policy->update); +if (!work_pending (&policy->update)) +schedule_work (&policy->update);
This duplicates the test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) check in queue_work_on(). Why exactly?
drivers/cpufreq/cpufreq.c static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, · line 1236
Quoted 10 lines
drivers/cpufreq/cpufreq.c +2
-1return 0 ; }@@ -1231,7 +1232,8 @@ static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, { struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max); -schedule_work (&policy->update); +if (!work_pending (&policy->update)) +schedule_work (&policy->update);
And same here.
Quoted 13 lines
drivers/cpufreq/cpufreq.c +1
-2return 0 ; }@@ -1841,7 +1843,7 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, breturn policy->cur;cpufreq_out_of_sync (policy, new_freq); -if (update) +if (update && !work_pending (&policy->update))schedule_work (&policy->update); } --
Quoted 2 lines
This duplicates the
test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))check inqueue_work_on(). Why exactly?
You're right — the work_pending() guards are redundant. schedule_work() / queue_work_on() already perform the atomic test‑and‑set internally.
Thanks for the review.
BR,
Kaushlendra