From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 132C4281530 for ; Tue, 23 Jun 2026 19:44:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782243843; cv=none; b=vAS/WlYdRmFUx3AwJf+H/pTGixgLkEWGDlJD4JJ6uvQEPtikpYE3uZ0FJfgtR2UTpypa7gOwZtUNzZj7PF0oJ9+doqez+PLaCy/g9RHHXpjpKgmU3h1kW7ny0+7NJpP8EBet86apO+Lc3RcVS3dVx9WEe99ZFrhS6SR79pBvkrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782243843; c=relaxed/simple; bh=Ww9gRwwW5OyRm9/FcGjCmZ/h7+HlYlxCRlQnZQEWa0I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=is16ASIG5efLSkllza4013sQmTq4FG0RVwUfOvIwCWlwM/CHM6Bpj1t0DQe6Rwlq3eRe8820fnZXjhvTX2ijbQOMjTpUhsKh5wzlzRgs5sUa8gi2x4zZgsbzh/DFpu8QQNMHlGdhmp7qEjPcu04DHyP3CceSqaPQQw3ZspU4uTE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TWE1kL3s; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TWE1kL3s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782243841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kygwExbrozp64++sRcXVlZDrcpqusoOkCOx9RMb2NQE=; b=TWE1kL3skVakNBHy4yauYWLcBLXfXut7JH77nh3x064q9Cz00F8Dq7Ha+9iw+pHYmdzsbi oKNoi9oU1kcoauoxaWGEckVSuz6DOKHIeoE1gMByr4nSyEWdfC1ovw/lUn74oVwWz7UlKf 9/N2RSe5OA0lJQzNwzYReK2CqKcjRtc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-pEOWMlLbMK26X_fS5f1ljA-1; Tue, 23 Jun 2026 15:42:49 -0400 X-MC-Unique: pEOWMlLbMK26X_fS5f1ljA-1 X-Mimecast-MFC-AGG-ID: pEOWMlLbMK26X_fS5f1ljA_1782243768 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADB3518052C9; Tue, 23 Jun 2026 19:42:47 +0000 (UTC) Received: from oak (unknown [10.22.65.142]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A7A6C1800591; Tue, 23 Jun 2026 19:42:45 +0000 (UTC) Date: Tue, 23 Jun 2026 15:42:39 -0400 From: Joe Simmons-Talbott To: Michal =?iso-8859-1?Q?Koutn=FD?= Cc: Joe Simmons-Talbott , Tejun Heo , Johannes Weiner , Shuah Khan , cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Chlad Subject: Re: [PATCH v2] selftests/cgroup: Adjust cpu.max quota based on HZ Message-ID: <20260623194239.GA899029@oak> References: <20260622194305.601392-1-joest@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On Tue, Jun 23, 2026 at 03:52:30PM +0200, Michal Koutný wrote: > On Mon, Jun 22, 2026 at 03:43:04PM -0400, Joe Simmons-Talbott wrote: > > +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; > > +} > > I like that you voiced this dependency on CONFIG_HZ and also that > _SC_CLK_TCK is useless in this regards. > (I see that BPF selftests have similar infra for this.) > > > > + > > /* > > * 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; > > I would not bend the tested value but it's expectation (so that > approximately same quantity is tested acroos configs). > > I reckon the problem might be tasks that overrun the quota due to long > tick, fortunately, we can assume this is compensated over multiple > periods, so _on average_ quota should be honored (more) precisely. > But the test duration may be not well aligned with all the compensation > periods, to that must be accounted for in the expectation. > > When I write it all down, I get this: > > --- a/tools/testing/selftests/cgroup/test_cpu.c > +++ b/tools/testing/selftests/cgroup/test_cpu.c > @@ -651,7 +651,9 @@ static int test_cpucg_max(const char *root) > long duration_seconds = 1; > > long duration_usec = duration_seconds * USEC_PER_SEC; > - long usage_usec, n_periods, remainder_usec, expected_usage_usec; > + long usage_usec, expected_usage_usec; > + long n_periods, spread_periods, unaligned; > + long tick_usec, low_usage, high_usage; > char *cpucg; > char quota_buf[32]; > > @@ -687,9 +689,16 @@ static int test_cpucg_max(const char *root) > * the cpu hog is set to run as per wall-clock time > */ > n_periods = duration_usec / default_period_usec; > - remainder_usec = duration_usec - n_periods * default_period_usec; > - expected_usage_usec > - = n_periods * quota_usec + MIN(remainder_usec, quota_usec); > + tick_usec = USEC_PER_SEC / hz; > + /* Up to tick_usec (over)run is compensated over multiple periods */ > + spread_periods = MAX(1, tick_usec / quota_usec); > + low_usage = n_periods / spread_periods; > + high_usage = (n_periods + spread_periods - 1) / spread_periods; > + unaligned = n_periods % spread_periods; > + > + expected_usage_usec = quota_usec * ( > + unaligned * high_usage + > + (spread_periods - unaligned) * low_usage); > > if (!values_close_report(usage_usec, expected_usage_usec, 10)) > goto cleanup; > > > (I neglected (and dropped) remainder_usec because it is zero with > default values) > > However, not all preemptions are tick-based, so there'd be noise > and one has to tune the values_clone_report(,,err) anyway. > > Then to reduce noise, the simpler solution is to let the test run > longer > > duration_usec = duration_seconds * USEC_PER_SEC * 1000 / hz; > > (where 1000 is the CONFIG_HZ=1000 where the test runs sufficiently [1] well.) > > Joe, how do to the two variants above (unalignment account and prolonged > duration) affect test_cpu behavior on your setup? Hi Michal, Thank you for your review. I tried both approaches, unalignment account and prolonged duration, and both allowed me to run 10 iterations of the test_cpu tests without any failures. I will use the simpler prolonged duration approach in v3 if that is okay. Thanks, Joe > > (I'm personally wondering what is bigger quantity: systemic error due to > HZ quantization or random (SMP) error.) > > Thanks, > Michal > > [1] Even there one runs into noise depending on nr_cpus, thus even that > fixed err=10 is not ideal.