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.133.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 862373BB10B for ; Fri, 26 Jun 2026 20:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782505780; cv=none; b=u+NULz0DIWzkTlSJscWry13grO9WiiDskS8n93E3aAKji/Nx9ufJOYSNUsimJraAp35zNmQvSxs3rzLFlCAWE8gIhbSjq6EaHAvQiYBzd6es2m+RlX3gtGbUx5MTVrZGX91qKbmnl1KbSo7Z8BUYVQixJsyEw6Wio+AOew3nK5U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782505780; c=relaxed/simple; bh=NQjGG4zXSYU53w2K7bTqHGdIct742qU3+RBPftHQRyk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sCVHZijpzEdMArf9aQLkwP18Iky2lj2eN0US5ryv21ExnlJ2TWCcYvxDGVWW6ZH24IXqFdCE9txA3ILaII7bbbm1BFRK78V9qRmUGyWTfTYD7JufSQWmpP33676SsTVTvLeckkKj4Kt1VPYKmGBd/Js2SRMCMTLmJR3G5cJ6OhQ= 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=DhqEy0Mt; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=YgHL1zwo; arc=none smtp.client-ip=170.10.133.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="DhqEy0Mt"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="YgHL1zwo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782505777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5fmmows0Hr70L00v6YhaNR6PFpVRD5asct1gUksFqE8=; b=DhqEy0MtmuPsHkJLwTa3eHCnqHJvybCKMX7mQDhv7Z+58WrGOOcwIlORBjAPow1rRdkjBf nCDwelFWZNGa3lYMrmp1ntN8aYb+ME8rt/GDwcH+J4zzEs0Ht/M42Xlb8cE0BZS6leTBsh Pb/PDPnK46obzecwA5PeFuz/aFbdEeU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-yhA9cCAuPVCn6SMYvR6nvg-1; Fri, 26 Jun 2026 16:29:36 -0400 X-MC-Unique: yhA9cCAuPVCn6SMYvR6nvg-1 X-Mimecast-MFC-AGG-ID: yhA9cCAuPVCn6SMYvR6nvg_1782505776 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-92a62578049so185183085a.0 for ; Fri, 26 Jun 2026 13:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782505776; x=1783110576; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5fmmows0Hr70L00v6YhaNR6PFpVRD5asct1gUksFqE8=; b=YgHL1zwox7METT2exMJ+8lInwffMIWf3Ve58IVquTcACuGUkRUDFRdMVmLSonQFeaN t+EB0I7h6avEx27gnVqKLwSghCQ3xchlbJLcdKAKhABEagEzwDJL/qfntmQKpQgQV6ZY DLWJMX1YFBGmhbFwsVhT2DGXXtvLhXWR2tCuDZA44Z+biCJUqoEYty77A9v4frCXMQpl HJRVHIPVVSScNB28T204NsfE092K5yFDgUs11iOZJIJ2o0zj/lFlDsiM3RwwD+Qge1sC 1QIi95blGB2SPF8e0YbXPKZR08t6KcOF1przzxerjVA15gTWx4QP37oAOaIVnB2h+kxy RdQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782505776; x=1783110576; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5fmmows0Hr70L00v6YhaNR6PFpVRD5asct1gUksFqE8=; b=QvKOXo4qgINa/wE5dG+p3y7cC1Wi+Inoic8U+QR5g73DzIyVbOwf95Ephorf52jFYK ZV6hzqmSjUjyh3/AO2WryhY8RFZgVsQYfaZ4phCV6CystfLYKMQVOArD/pzZysRXtn74 xmocU88xkgpV4ta286sdvSg0SXfISU3+f/8695PawVywFGcY+zYtblgE5zyBpyrAwwUT 8epm/GGk4440ZTkYhcMfPGYKBoKO+GdR52qn98x2Ysa3/1/85KFWGYGC2ld4pltiAxsh oOnhIvolALUvtGh8ioGCZxUKB+XETWI80aLG28xqKBOsNJudxMHASRs2NOEjCzxahwut dhDw== X-Forwarded-Encrypted: i=1; AFNElJ+St7eoFI2nkf9V9Vx5UB9bAoDtnyunvK4y+W9WF7qRxsTt0NFTrsopWC+ZglGLjrv9OMlI9MY04/OLoAo=@vger.kernel.org X-Gm-Message-State: AOJu0YyQpCI1M0pIW5YlA9J2Qpj7Ijr6+5IWPffYPEeqwOw385UqhuBM RfRgz5EpZwM7ozagOLlnNXbTw7bch9LE6kP4H7lGtDvrFgze98RYbf8bSU3JikC6wiBJFIwlxdY E0HSnmQDipzlB5Dtp0LufNVEQ7thGP50WZ18TvpkVmm2y/BEmnw2KBjQ3KKZd3V+N4A== X-Gm-Gg: AfdE7ck8f6AYyTHXTWOsrdUJCoWuvqJAYMvLoL7pKRQgPg0yLz245eYV/GqjF3CLny3 MYIN+TfM4MnPq+bml+W8TGXTwliCAJRqQCXNUF0RZEbyu2F3/W51ZCLhzOXktLYltbjxrT496JM LAUqtqy5W914rUL4/70HC0lE54WhsODbMXLDk1Uwn96CapwjP7f34RzkNr3srzB2fy6YvNoIzze wV5SkKYd+CIzt55OIUe+biggkFQca645pATiCkw3P4HPs51nEwfDsTQRcGrlNrvVAkQUNnCms+Y yqZwrvUm/A6xSm62K7jlpPniRv49cKvixuSzMmJIAoNomPFlTUG9AYZZbPKynpAmk9zmNwa1nKC 7kjquwWakggI9mqv12FGy0+zgTo5qR4Rei1Om/w2SXZpNJICM X-Received: by 2002:a05:620a:1a20:b0:8cf:bad7:20c5 with SMTP id af79cd13be357-92927db2b88mr1121092385a.25.1782505775449; Fri, 26 Jun 2026 13:29:35 -0700 (PDT) X-Received: by 2002:a05:620a:1a20:b0:8cf:bad7:20c5 with SMTP id af79cd13be357-92927db2b88mr1121087185a.25.1782505774892; Fri, 26 Jun 2026 13:29:34 -0700 (PDT) Received: from oak.redhat.com (c-73-148-124-98.hsd1.va.comcast.net. [73.148.124.98]) by smtp.gmail.com with ESMTPSA id af79cd13be357-926004ab49csm1239563785a.34.2026.06.26.13.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 13:29:34 -0700 (PDT) From: Joe Simmons-Talbott To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan Cc: Joe Simmons-Talbott , cui.tao@linux.dev, Andrew Morton , Nhat Pham , Waiman Long , Li Wang , Sebastian Chlad , Guopeng Zhang , cgroups@vger.kernel.org (open list:CONTROL GROUP (CGROUP)), linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5] selftests/cgroup: Adjust cpu test duration based on HZ Date: Fri, 26 Jun 2026 16:29:22 -0400 Message-ID: <20260626202925.1527524-1-joest@redhat.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Increase the test duration to accommodate for lower HZ values. Link: https://lore.kernel.org/lkml/20260625203307.1114538-1-joest@redhat.com/ Signed-off-by: Joe Simmons-Talbott --- CC: cui.tao@linux.dev v4 -> v5: - Get rid of added duration_XXX variables v3 -> v4: - Use usec for adjusting test duration for better accuracy. - Remove underscore from static function - Use 1000 as the fallback value for hz since it's the default. v2 -> v3: - Instead of changing cpu.max quota extend the test duration based on the HZ value. - don't call pclose() if popen() fails. - check return value of fscanf(). v1 -> v2: - Try checking /proc/config.gz to get the actual kernel HZ value and fallback to 1000 if the value cannot be determined. .../cgroup/lib/include/cgroup_util.h | 1 + tools/testing/selftests/cgroup/test_cpu.c | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h index febc1723d090..8ebb2b4d4ec0 100644 --- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h +++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h @@ -8,6 +8,7 @@ #define MB(x) (x << 20) +#define NSEC_PER_USEC 1000L #define USEC_PER_SEC 1000000L #define NSEC_PER_SEC 1000000000L diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c index 7a40d76b9548..a5eccfcabef5 100644 --- a/tools/testing/selftests/cgroup/test_cpu.c +++ b/tools/testing/selftests/cgroup/test_cpu.c @@ -639,6 +639,31 @@ 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 1000 (the default) to + * indicate failure. + */ +static long +get_config_hz(void) +{ + long hz = 1000; + 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 +671,18 @@ 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_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]; + duration_usec = duration_seconds * USEC_PER_SEC * 1000 / hz; + snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec); cpucg = cg_name(root, "cpucg_test"); @@ -670,8 +698,8 @@ static int test_cpucg_max(const char *root) struct cpu_hog_func_param param = { .nprocs = 1, .ts = { - .tv_sec = duration_seconds, - .tv_nsec = 0, + .tv_sec = duration_usec / USEC_PER_SEC, + .tv_nsec = duration_usec % USEC_PER_SEC * NSEC_PER_USEC, }, .clock_type = CPU_HOG_CLOCK_WALL, }; @@ -710,15 +738,18 @@ static int test_cpucg_max(const char *root) static int test_cpucg_max_nested(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_usec = duration_seconds * USEC_PER_SEC; + long duration_usec; long usage_usec, n_periods, remainder_usec, expected_usage_usec; char *parent, *child; char quota_buf[32]; + duration_usec = duration_seconds * USEC_PER_SEC * 1000 / hz; + snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec); parent = cg_name(root, "cpucg_parent"); @@ -741,8 +772,8 @@ static int test_cpucg_max_nested(const char *root) struct cpu_hog_func_param param = { .nprocs = 1, .ts = { - .tv_sec = duration_seconds, - .tv_nsec = 0, + .tv_sec = duration_usec / USEC_PER_SEC, + .tv_nsec = duration_usec % USEC_PER_SEC * NSEC_PER_USEC, }, .clock_type = CPU_HOG_CLOCK_WALL, }; -- 2.54.0