Skip to content

Commit f1bbf5b

Browse files
committed
cpufreq: intel_pstate: Rearrange freq QoS updates using __free()
Move the code from the for_each_possible_cpu() loop in update_qos_request() to a separate function and use __free() for cpufreq policy reference counting in it to avoid having to call cpufreq_cpu_put() repeatedly (or using goto). While at it, rename update_qos_request() to update_qos_requests() because it updates multiple requests in one go. No intentional functional impact. Link: https://lore.kernel.org/linux-pm/CAJZ5v0gN1T5woSF0tO=TbAh+2-sWzxFjWyDbB7wG2TFCOU01iQ@mail.gmail.com/ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Zihuan Zhang <zhangzihuan@kylinos.cn> Link: https://patch.msgid.link/3026597.e9J7NaK4W3@rafael.j.wysocki [ rjw: Rename "cpu" to "cpudata" and "cpunum" to "cpu" in new code ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 69e5d50 commit f1bbf5b

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

drivers/cpufreq/intel_pstate.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,43 +1652,42 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
16521652
return count;
16531653
}
16541654

1655-
static void update_qos_request(enum freq_qos_req_type type)
1655+
static void update_cpu_qos_request(int cpu, enum freq_qos_req_type type)
16561656
{
1657+
struct cpudata *cpudata = all_cpu_data[cpu];
16571658
struct freq_qos_request *req;
1658-
struct cpufreq_policy *policy;
1659-
int i;
1659+
unsigned int freq, perf_pct;
16601660

1661-
for_each_possible_cpu(i) {
1662-
struct cpudata *cpu = all_cpu_data[i];
1663-
unsigned int freq, perf_pct;
1661+
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
1662+
if (!policy)
1663+
return;
16641664

1665-
policy = cpufreq_cpu_get(i);
1666-
if (!policy)
1667-
continue;
1665+
req = policy->driver_data;
1666+
if (!req)
1667+
return;
16681668

1669-
req = policy->driver_data;
1670-
if (!req) {
1671-
cpufreq_cpu_put(policy);
1672-
continue;
1673-
}
1669+
if (hwp_active)
1670+
intel_pstate_get_hwp_cap(cpudata);
16741671

1675-
if (hwp_active)
1676-
intel_pstate_get_hwp_cap(cpu);
1672+
if (type == FREQ_QOS_MIN) {
1673+
perf_pct = global.min_perf_pct;
1674+
} else {
1675+
req++;
1676+
perf_pct = global.max_perf_pct;
1677+
}
16771678

1678-
if (type == FREQ_QOS_MIN) {
1679-
perf_pct = global.min_perf_pct;
1680-
} else {
1681-
req++;
1682-
perf_pct = global.max_perf_pct;
1683-
}
1679+
freq = DIV_ROUND_UP(cpudata->pstate.turbo_freq * perf_pct, 100);
16841680

1685-
freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100);
1681+
if (freq_qos_update_request(req, freq) < 0)
1682+
pr_warn("Failed to update freq constraint: CPU%d\n", cpu);
1683+
}
16861684

1687-
if (freq_qos_update_request(req, freq) < 0)
1688-
pr_warn("Failed to update freq constraint: CPU%d\n", i);
1685+
static void update_qos_requests(enum freq_qos_req_type type)
1686+
{
1687+
int i;
16891688

1690-
cpufreq_cpu_put(policy);
1691-
}
1689+
for_each_possible_cpu(i)
1690+
update_cpu_qos_request(i, type);
16921691
}
16931692

16941693
static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
@@ -1717,7 +1716,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
17171716
if (intel_pstate_driver == &intel_pstate)
17181717
intel_pstate_update_policies();
17191718
else
1720-
update_qos_request(FREQ_QOS_MAX);
1719+
update_qos_requests(FREQ_QOS_MAX);
17211720

17221721
mutex_unlock(&intel_pstate_driver_lock);
17231722

@@ -1751,7 +1750,7 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct kobj_attribute *b,
17511750
if (intel_pstate_driver == &intel_pstate)
17521751
intel_pstate_update_policies();
17531752
else
1754-
update_qos_request(FREQ_QOS_MIN);
1753+
update_qos_requests(FREQ_QOS_MIN);
17551754

17561755
mutex_unlock(&intel_pstate_driver_lock);
17571756

0 commit comments

Comments
 (0)