From: Joe Simmons-Talbott <josimmon@redhat.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: Joe Simmons-Talbott <joest@redhat.com>, Tejun Heo <tj@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Shuah Khan <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] selftests/cgroup: Adjust cpu test duration based on HZ
Date: Thu, 25 Jun 2026 08:45:32 -0400 [thread overview]
Message-ID: <20260625124532.GA19617@oak> (raw)
In-Reply-To: <ajzjLsBNS7rNZV2x@localhost.localdomain>
On Thu, Jun 25, 2026 at 10:23:22AM +0200, Michal Koutný wrote:
> Hi.
>
> On Wed, Jun 24, 2026 at 12:03:57PM -0400, Joe Simmons-Talbott <joest@redhat.com> wrote:
> > +/*
> > + * Best effort attempt to get the kernel's HZ value from the config.
> > + * Return the HZ value if found otherwise return -1 to indicate failure.
> > + */
> > +static long
> > +_get_config_hz(void)
>
> drop underscore from the static function
>
> > +{
> > + long hz = -1;
>
> use the default 1000 here to simplify the callers
>
> > + FILE *f;
> > + char cmd[256] = "zcat /proc/config.gz 2>/dev/null | grep '^CONFIG_HZ='";
> > +
> > + f = popen(cmd, "r");
> > +
> > + if (!f)
> > + return hz;
> > +
> > + if (fscanf(f, "CONFIG_HZ=%ld", &hz) == EOF)
> > + goto out;
> > +
> > +out:
> > + pclose(f);
> > + return hz;
> > +}
> > +
> > /*
> > * This test creates a cgroup with some maximum value within a period, and
> > * verifies that a process in the cgroup is not overscheduled.
> > @@ -646,15 +670,21 @@ test_cpucg_nested_weight_underprovisioned(const char *root)
> > static int test_cpucg_max(const char *root)
> > {
> > int ret = KSFT_FAIL;
> > + long hz = _get_config_hz();
> > long quota_usec = 1000;
> > long default_period_usec = 100000; /* cpu.max's default period */
> > - long duration_seconds = 1;
> > + long duration_seconds;
> >
> > - long duration_usec = duration_seconds * USEC_PER_SEC;
> > + long duration_usec;
> > long usage_usec, n_periods, remainder_usec, expected_usage_usec;
> > char *cpucg;
> > char quota_buf[32];
> >
> > + if (hz == -1)
> > + hz = 1000;
> > + duration_seconds = 1000 / hz;
> > + duration_usec = duration_seconds * USEC_PER_SEC;
>
> I'd do the calculation in usecs
>
> duration_usec = duration_seconds * USEC_PER_SEC * 1000 / hz;
>
> so that actual duration is more precise (for hz=300 which is the only
> that doesn't divide 1000)
>
> All in all, make the adjustments for HZ with less code (since I expect
> this will need adjustments for SMPs in future).
Hi Michal,
Thanks for your feedback. I'll make the changes you have suggested in v4.
Thanks,
Joe
prev parent reply other threads:[~2026-06-25 12:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 16:03 [PATCH v3] selftests/cgroup: Adjust cpu test duration based on HZ Joe Simmons-Talbott
2026-06-25 8:23 ` Michal Koutný
2026-06-25 12:45 ` Joe Simmons-Talbott [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260625124532.GA19617@oak \
--to=josimmon@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=joest@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=shuah@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox