Unverified Commit f1189855 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!849 drivers/cpufreq: gain accurate CPU frequency from cpufreq/cpuinfo_cur_freq

Merge Pull Request from: @henryze 
 
When users want to get frequency by cpuinfo_cur_freq under cpufreq sysfs,
they often get the invalid result like:

$ cat /sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_cur_freq
4294967295

So this series provides fixes to the concerned issue.

Reference: https://lore.kernel.org/all/20230516133248.712242-3-zengheng4@huawei.com/ 
 
Link:https://gitee.com/openeuler/kernel/pulls/849

 

Reviewed-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents dec74be4 904d9dcd
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -488,7 +488,7 @@ CONFIG_AS_HAS_CFI_NEGATE_RA_STATE=y
#
#
# ARMv8.4 architectural features
# ARMv8.4 architectural features
#
#
# CONFIG_ARM64_AMU_EXTN is not set
CONFIG_ARM64_AMU_EXTN=y
CONFIG_AS_HAS_ARMV8_4=y
CONFIG_AS_HAS_ARMV8_4=y
CONFIG_ARM64_TLB_RANGE=y
CONFIG_ARM64_TLB_RANGE=y
# end of ARMv8.4 architectural features
# end of ARMv8.4 architectural features
+1 −0
Original line number Original line Diff line number Diff line
@@ -1588,6 +1588,7 @@ bool cpu_has_amu_feat(int cpu)
{
{
	return cpumask_test_cpu(cpu, &amu_cpus);
	return cpumask_test_cpu(cpu, &amu_cpus);
}
}
EXPORT_SYMBOL(cpu_has_amu_feat);


int get_cpu_with_amu_feat(void)
int get_cpu_with_amu_feat(void)
{
{
+20 −6
Original line number Original line Diff line number Diff line
@@ -350,23 +350,37 @@ static int cppc_get_rate_from_fbctrs(struct cppc_cpudata *cpu,
	return cppc_cpufreq_perf_to_khz(cpu, delivered_perf);
	return cppc_cpufreq_perf_to_khz(cpu, delivered_perf);
}
}


static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum)
static int cppc_get_perf_ctrs_sample(void *val)
{
{
	struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0};
	int cpunum = smp_processor_id();
	struct cppc_cpudata *cpu = all_cpu_data[cpunum];
	struct cppc_perf_fb_ctrs *fb_ctrs = val;
	int ret;
	int ret;


	ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t0);
	ret = cppc_get_perf_ctrs(cpunum, fb_ctrs);
	if (ret)
	if (ret)
		return ret;
		return ret;


	udelay(2); /* 2usec delay between sampling */
	udelay(2); /* 2usec delay between sampling */


	ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t1);
	return cppc_get_perf_ctrs(cpunum, fb_ctrs + 1);
}

static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum)
{
	struct cppc_perf_fb_ctrs fb_ctrs[2] = {0};
	struct cppc_cpudata *cpu = all_cpu_data[cpunum];
	int ret;

	if (cpu_has_amu_feat(cpunum))
		ret = smp_call_on_cpu(cpunum, cppc_get_perf_ctrs_sample,
				      fb_ctrs, false);
	else
		ret = cppc_get_perf_ctrs_sample(fb_ctrs);

	if (ret)
	if (ret)
		return ret;
		return ret;


	return cppc_get_rate_from_fbctrs(cpu, fb_ctrs_t0, fb_ctrs_t1);
	return cppc_get_rate_from_fbctrs(cpu, fb_ctrs[0], fb_ctrs[1]);
}
}


static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)
static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)