All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Simmons-Talbott <josimmon@redhat.com>
To: Tao Cui <cui.tao@linux.dev>
Cc: "Joe Simmons-Talbott" <joest@redhat.com>,
	"Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Shuah Khan" <shuah@kernel.org>,
	cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] selftests/cgroup: Adjust cpu.max quota based on HZ
Date: Tue, 23 Jun 2026 07:51:33 -0400	[thread overview]
Message-ID: <20260623115110.GA8885@oak> (raw)
In-Reply-To: <d8bdf9ef-a393-4734-8639-308ac3eaa05c@linux.dev>

On Tue, Jun 23, 2026 at 01:32:08PM +0800, Tao Cui wrote:
> 
> Hi Joe,
> 
> One comment on the fallback:
> 
>   quota_usec = hz != -1 ? USEC_PER_SEC / hz : 1000;
> 
> When HZ can't be determined (no CONFIG_IKCONFIG_PROC, or zcat missing),
> the fallback to 1000 is the exact value that fails at low HZ — so this
> doesn't actually fix such kernels. A larger fallback (e.g. 10000, the
> HZ=100 equivalent) would make the tests robust regardless of whether the
> config is exposed.

Hi Tao Cui,

Thank you for your review.

I am happy to use 10000 as the fallback value.  I will address this as
well as the sashiko comments in v3.

Thanks,
Joe
> 
> 在 2026/6/23 03:43, Joe Simmons-Talbott 写道:
> > For lower HZ values a quota of 1000us is much lower than the amount
> > of microseconds per tick which makes the tests test_cpucg_max and
> > test_cpugc_max_nested fail. Use the amount of microseconds per tick
> > as the quota value.
> > 
> > Signed-off-by: Joe Simmons-Talbott <joest@redhat.com>
> > ---
> > changes since v1:
> > - Try checking /proc/config.gz to get the actual kernel HZ value and
> >   fallback to 1000 if the value cannot be determined.
> > 
> >  tools/testing/selftests/cgroup/test_cpu.c | 33 +++++++++++++++++++++--
> >  1 file changed, 31 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
> > index 7a40d76b9548..65e09555309f 100644
> > --- a/tools/testing/selftests/cgroup/test_cpu.c
> > +++ b/tools/testing/selftests/cgroup/test_cpu.c
> > @@ -639,6 +639,29 @@ test_cpucg_nested_weight_underprovisioned(const char *root)
> >  	return run_cpucg_nested_weight_test(root, false);
> >  }
> >  
> > +/*
> > + * 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)
> > +{
> > +	long hz = -1;
> > +	FILE *f;
> > +	char cmd[256] = "zcat /proc/config.gz 2>/dev/null | grep '^CONFIG_HZ='";
> > +
> > +	f = popen(cmd, "r");
> > +
> > +	if (!f)
> > +		goto out;
> > +
> > +	fscanf(f, "CONFIG_HZ=%ld", &hz);
> > +
> > +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,7 +669,8 @@ test_cpucg_nested_weight_underprovisioned(const char *root)
> >  static int test_cpucg_max(const char *root)
> >  {
> >  	int ret = KSFT_FAIL;
> > -	long quota_usec = 1000;
> > +	long hz = _get_config_hz();
> > +	long quota_usec;
> >  	long default_period_usec = 100000; /* cpu.max's default period */
> >  	long duration_seconds = 1;
> >  
> > @@ -655,6 +679,8 @@ static int test_cpucg_max(const char *root)
> >  	char *cpucg;
> >  	char quota_buf[32];
> >  
> > +	quota_usec = hz != -1 ? USEC_PER_SEC / hz : 1000;
> > +
> >  	snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec);
> >  
> >  	cpucg = cg_name(root, "cpucg_test");
> > @@ -710,7 +736,8 @@ static int test_cpucg_max(const char *root)
> >  static int test_cpucg_max_nested(const char *root)
> >  {
> >  	int ret = KSFT_FAIL;
> > -	long quota_usec = 1000;
> > +	long quota_usec;
> > +	long hz = _get_config_hz();
> >  	long default_period_usec = 100000; /* cpu.max's default period */
> >  	long duration_seconds = 1;
> >  
> > @@ -719,6 +746,8 @@ static int test_cpucg_max_nested(const char *root)
> >  	char *parent, *child;
> >  	char quota_buf[32];
> >  
> > +	quota_usec = hz != -1 ? USEC_PER_SEC / hz : 1000;
> > +
> >  	snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec);
> >  
> >  	parent = cg_name(root, "cpucg_parent");
> 
> 


  reply	other threads:[~2026-06-23 11:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22 19:43 [PATCH v2] selftests/cgroup: Adjust cpu.max quota based on HZ Joe Simmons-Talbott
2026-06-23  5:32 ` Tao Cui
2026-06-23 11:51   ` Joe Simmons-Talbott [this message]
2026-06-23 13:52 ` Michal Koutný

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=20260623115110.GA8885@oak \
    --to=josimmon@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=cui.tao@linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.