[LTP] [PATCH v2] device-drivers/cpufreq_boost: Don't hardcode to CPU0
Mike Tipton
mike.tipton@oss.qualcomm.com
Thu Jul 3 18:22:58 CEST 2025
On Thu, Jul 03, 2025 at 09:00:13AM -0400, Wei Gao wrote:
> On Mon, Jun 30, 2025 at 07:51:28AM -0700, Mike Tipton via ltp wrote:
> > Some systems don't support boost on every CPU, such as on many Qualcomm
> > chipsets. And if boost isn't supported on CPU0, then the test will fail
> > since there's no performance improvement.
> >
> > Instead of hardcoding CPU0, find the first CPU that belongs to a cpufreq
> > policy with boost enabled.
> >
> > Signed-off-by: Mike Tipton <mike.tipton@oss.qualcomm.com>
> > ---
> > Changes in v2:
> > - Use proper maxspeed buf size in snprintf.
> > - Link to v1: https://lore.kernel.org/ltp/20250626194707.3053036-1-mike.tipton@oss.qualcomm.com/
> >
> > .../device-drivers/cpufreq/cpufreq_boost.c | 58 ++++++++++++++++---
> > 1 file changed, 50 insertions(+), 8 deletions(-)
> >
> > diff --git a/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c b/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
> > index 67917b3fea25..bbb5f602de4b 100644
> > --- a/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
> > +++ b/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
> > @@ -55,10 +55,14 @@ static int id = -1;
> >
> > static int boost_value;
> >
> > -const char governor[] = SYSFS_CPU_DIR "cpu0/cpufreq/scaling_governor";
> > +static int cpu;
> > +
> > +static const char _governor[] = SYSFS_CPU_DIR "cpu%d/cpufreq/scaling_governor";
> > +static char governor[64];
> > static char governor_name[16];
> >
> > -const char maxspeed[] = SYSFS_CPU_DIR "cpu0/cpufreq/scaling_max_freq";
> > +static const char _maxspeed[] = SYSFS_CPU_DIR "cpu%d/cpufreq/scaling_max_freq";
> > +static char maxspeed[64];
> >
> > static void check_set_turbo(char *file, char *off)
> > {
> > @@ -84,6 +88,40 @@ static void cleanup(void)
> > FILE_PRINTF(governor, "%s", governor_name);
> > }
> >
> > +static int find_boost_cpu(void)
> > +{
> > + char buf[64];
> > + int fd, i;
> > +
> > + /*
> > + * The files we're looking for only exist for acpi_cpufreq. Continue
> > + * assuming CPU0 for intel_pstate.
> > + */
> > + if (!strcmp(cdrv[id].name, "intel_pstate"))
> > + return 0;
> > +
> > + for (i = 0;; i++) {
> > + snprintf(buf, sizeof(buf), SYSFS_CPU_DIR "cpu%d", i);
> > + fd = open(buf, O_RDONLY);
> > + if (fd == -1)
> > + break;
> > +
> > + close(fd);
> > +
> > + snprintf(buf, sizeof(buf), SYSFS_CPU_DIR "cpu%d/cpufreq/boost", i);
> > + fd = open(buf, O_RDONLY);
> > + if (fd == -1)
> > + continue;
> > +
> > + close(fd);
> > + tst_resm(TINFO, "found boost-capable CPU (CPU%d)", i);
> > + return i;
> > + }
> > +
> > + tst_resm(TINFO, "didn't find boost-capable CPU (assuming CPU0)");
> > + return 0;
>
> If not find any boost-capable CPU, i suppose we need give TCONF "not
> support" message? Correct me if any misunderstanding. Thanks.
Yeah, we should.
Historically, this would have been covered by the existing check for
cdrv::file at the beginning of setup(), since the top-level
cpufreq/boost file was only created if at least one policy actually
supported it. The individual cpufreq drivers only called
cpufreq_enable_boost_support() when initializing a boost-capable policy.
However, this was recently simplified in [1] to remove that per-driver
logic, and now the cpufreq/boost sysfs file is created whenever the
driver defines a set_boost() callback, which is unconditional. So, now
it's possible for the driver-level boost feature to be enabled even when
zero policies actually support it.
I'll update it for this.
[1] - https://lore.kernel.org/all/cover.1737707712.git.viresh.kumar@linaro.org/
Thanks,
Mike
More information about the ltp
mailing list