[RFC PATCH] drivers/powercap: fix build error when CONFIG_SMP is not set

Xuewen Yan
2025-03-10T03:26:57Z

When CONFIG_ENERGY_MODEL=y and CONFIG_SMP=n, there is build error:

>> drivers/powercap/dtpm_cpu.c:83:15: error: call to undeclared function 'sched_cpu_util';
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
83 | sum_util += sched_cpu_util(cpu);
| ^
1 error generated.

This is because the sched_cpu_util depends on CONFIG_SMP,
so using the #ifdef to guarantee the dependence.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202503070326.9hEUez42-lkp@intel.com/
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
drivers/powercap/dtpm_cpu.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index 6b6f51b21550..b935e8c38b45 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -68,6 +68,7 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
return power_limit;
}

+#ifdef CONFIG_SMP
static u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power)
{
unsigned long max, sum_util = 0;
@@ -84,6 +85,12 @@ static u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power)

return (power * ((sum_util << 10) / max)) >> 10;
}
+#else /* !CONFIG_SMP */
+static inline u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power)
+{
+ return power;
+}
+#endif

static u64 get_pd_power_uw(struct dtpm *dtpm)
{
--
2.25.1