[LTP] [External] : [PATCH] device-drivers/cpufreq_boost: Don't hardcode to CPU0
Mike Tipton
mike.tipton@oss.qualcomm.com
Fri Jun 27 18:02:44 CEST 2025
On Fri, Jun 27, 2025 at 08:43:31AM +0530, ALOK TIWARI wrote:
>
>
> On 6/27/2025 1:17 AM, 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>
> > ---
> > .../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..5469126d2d12 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;
> > +}
> > +
> > static void setup(void)
> > {
> > int fd;
> > @@ -109,6 +147,10 @@ static void setup(void)
> > tst_resm(TINFO, "found '%s' driver, sysfs knob '%s'",
> > cdrv[id].name, cdrv[id].file);
> > + cpu = find_boost_cpu();
> > + snprintf(governor, sizeof(governor), _governor, cpu);
> > + snprintf(maxspeed, sizeof(governor), _maxspeed, cpu);
>
> why sizeof(governor) not sizeof(maxspeed)
Whoops, copy/paste mistake. I'll fix that.
Thanks,
Mike
More information about the ltp
mailing list