[LTP] [PATCH v3] device-drivers/cpufreq_boost: Don't hardcode to CPU0
Mike Tipton
mike.tipton@oss.qualcomm.com
Thu Jul 10 03:46:09 CEST 2025
On Thu, Jul 10, 2025 at 08:42:35AM -0400, Wei Gao wrote:
> On Wed, Jul 09, 2025 at 08:14:39AM -0700, Mike Tipton 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 v3:
> > - Abort when no CPUs report supporting boost instead of assuming CPU0.
> > - Link to v2: https://lore.kernel.org/ltp/20250630145128.1254269-1-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..17d89c0cc164 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_brkm(TCONF, NULL, "boost not supported by any CPUs");
> > + return 0;
> I suppose we do not need above line since brkm will jump out of the test
> directly.
Yes, that's true. But it feels wrong to reach the end of a non-void
function without returning something. Even though in this case it'll
never actually reach the return statement.
>
> Other parts LGTM, thanks for your patch.
> Acked-by: Wei Gao <wegao@suse.com>
>
Thanks!
Mike
More information about the ltp
mailing list