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 48DD82EEE93 for ; Thu, 25 Jun 2026 20:33:20 +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=1782419601; cv=none; b=PF0v+gih0OoMQC5XgWyJOdrMSpKUQk/N7Cpeh7NBE5GTqjogmEcr4U7bgvoY09HGSWS9PWNtiCpLqL1mOYeLe5PhAWcupyNpqPdnMCHXEml/eTGcKxzfmVqijhuctl9X/q9vlwAUCwIxJ+C4coJxXNjKAbzunJfSLgBjjQ454QA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782419601; c=relaxed/simple; bh=Ib7zT38GwZXZa3psJDnOOJi5CQ6/V0vu2dtXG6oowj8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fPx7CsUCNi8EDIBKLtp2RjhA6MwxxKUG0vH0rHdTcsH3UnTUfQoFrjvfSGNckZLAK0bm/EYgUdxKXnbt2Kwf6JbzyC1UjBMDEkUec9LLJHrpR+L8O43D3pch33saI368/nvKj0KpoxDNlMEu0VHwGMAbYdSQnyMfg6JrCMfW13Q= 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=DvjeuUzg; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=dxnTHald; 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="DvjeuUzg"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="dxnTHald" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782419599; 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=ifHti/d727ookmtUS07phWJpYrrkEhsutg001BDn0q8=; b=DvjeuUzg6pSdUSnOYp8eBP+T2+oMhH8ryPFmnxv/TBhzEYJ32tl1/ia3bMXVVwNEgGGXt+ QcUq+Fp/qcYvE/Z7N/jHr1gMxzWbshT4pF3yohGSJzQ84L4asdkmIby45eX9yx8WphzLbZ 7vfFZTHRRbqpKg8WY4ce+kytS0xl8fY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-SBfszhSEORmql2lTQX7B2Q-1; Thu, 25 Jun 2026 16:33:18 -0400 X-MC-Unique: SBfszhSEORmql2lTQX7B2Q-1 X-Mimecast-MFC-AGG-ID: SBfszhSEORmql2lTQX7B2Q_1782419597 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-8dc0a6ab3bbso6473586d6.1 for ; Thu, 25 Jun 2026 13:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782419597; x=1783024397; 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=ifHti/d727ookmtUS07phWJpYrrkEhsutg001BDn0q8=; b=dxnTHaldAwRH3zE3IZVm4iRMDvGWeZjwmOYRSjMO3m+2xjKz7/kNCqUBnma0wj7QrH ISqSVJiinDeG7pxIUpYPxzTJvZqFaN4iDyXG9C+mHNuMW1pv05u7jbH34RFLg/aTOTKy fsS7rXgCdkiWYlDZqB1NFqQWPWAT0oZNR8gH2N6rMFGVpZcD7srVERVRizq0uu79eSCL DUC/1648w9qp+SJQsGV10dxgD/f9OxYnE60S9thloz4D+f9ocKQrWomvsHv+FfyhXLQe /qPFyrYiwiO3TYSMrNk9FjmPagEhDz89KlKTWmZnokIFoJom/PSFc9xDHHmQ4itWmP+X Epmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782419597; x=1783024397; 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=ifHti/d727ookmtUS07phWJpYrrkEhsutg001BDn0q8=; b=CqU5oAG4b2vGAlRN30JFBhZKdmab/PP/n8J6K+TlGyTFR7CFTrCTjZeSjuRRQXRx2v Er7UIoQ3Yz1RuHY/dK1LiBKn9gFHi6h01vL/IIiqFDZgUBTF8LeAGeuZ+9YtwBNE7kiV wUOEhsxHp/960jAw7D/R1WSrmslPgl9mkwyKaYSYkryBhiH6rxkcJqnA4CR//Iq75Xm4 GmCYurDv/qe3vO9NEIOOD5I9byfjjwzYhqDRGGAHfgCh7zm2w+nUp6QW/wgkczXsaQf3 pIxTO6Lj37ErDUWNMqWIO0VaX4jp4IR7gBIcbWU6LDMRHaIAl3PfuI/HHB3Iyp3Oz2m6 5Saw== X-Forwarded-Encrypted: i=1; AHgh+RqMWJyAyKiAbQGMiG5eXJc5CjFfAu0x6ieI5znnNXO7EqNuUCBTFVLlkBjzV94tvOldRx8LCy+884PU7jg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy54z6PeTLiiN2VSfcSGSzrep4T+d3eNUWw8P/8xk1O3hu9VCw5 tLkxJD+luL2U0zJ9AIZRoqMSxlQgNS8ofBBpjWz8u9RimOLSitmMBjF6E5pkNeZnION4sKXovcQ Mspxydlcy2gC0hY7FEvBIZqstHDrs8qutjyoZCkVZaS7T9TOqHYhh8iyCV0waR6rgKQ== X-Gm-Gg: AfdE7cmn+pGK6yERb6jlElO+pkqh+SytG9j0s8eC8AOzT1TH0k/Vm+lVWLJWbng4bPS KyT/R13NcIn6JAPmXWulVl6ZL25DCu6Li8ZoakpNVIeMbNRJFlyiJ4WZIwz9kBGD0omZAel1gtY tSi7Pp/3N1AtpUeJzJqhH7zci7hfSco+JM+UKJ6/dc1t3sG6yZ922MlYk6YC3EmvZmDSriXWMyW FZo/7PhDj96EpcLoVeBbmvo/PJ1xtv8OTsCvOYCA8oIAdZ1Wg6EqbjGvF6Ifp0BTw8y8gMyHyhG U5WknQMA0wUXbMJjzDRgcOGbr4VB9KiUu2nawGrd/1PXRbfO/NR86qEogXKZZ6Z+b6Fuaj6ZHxY 2aXs82m73j2079UGt9bOAERllQmpviN6rDBbiGSVH76WH+OR1 X-Received: by 2002:a05:6214:230f:b0:8ce:ba04:7bc2 with SMTP id 6a1803df08f44-8e6d6e61085mr68947916d6.38.1782419596806; Thu, 25 Jun 2026 13:33:16 -0700 (PDT) X-Received: by 2002:a05:6214:230f:b0:8ce:ba04:7bc2 with SMTP id 6a1803df08f44-8e6d6e61085mr68946986d6.38.1782419596122; Thu, 25 Jun 2026 13:33:16 -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 6a1803df08f44-8df7f5ff5e6sm188635156d6.12.2026.06.25.13.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 13:33:15 -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, Li Wang , Shakeel Butt , Nhat Pham , Guopeng Zhang , Sebastian Chlad , 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 RESEND v4] selftests/cgroup: Adjust cpu test duration based on HZ Date: Thu, 25 Jun 2026 16:33:04 -0400 Message-ID: <20260625203307.1114538-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/20260624160358.430354-1-joest@redhat.com/ Signed-off-by: Joe Simmons-Talbott --- CC: cui.tao@linux.dev 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 | 47 ++++++++++++++++--- 2 files changed, 42 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..1f280c1db68a 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,20 @@ 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, duration_sec, duration_nsec; 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; + duration_sec = duration_usec / USEC_PER_SEC; + duration_nsec = duration_usec % USEC_PER_SEC * NSEC_PER_USEC; + snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec); cpucg = cg_name(root, "cpucg_test"); @@ -670,8 +700,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_sec, + .tv_nsec = duration_nsec, }, .clock_type = CPU_HOG_CLOCK_WALL, }; @@ -710,15 +740,20 @@ 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, duration_sec, duration_nsec; 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; + duration_sec = duration_usec / USEC_PER_SEC; + duration_nsec = duration_usec % USEC_PER_SEC * NSEC_PER_USEC; + snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec); parent = cg_name(root, "cpucg_parent"); @@ -741,8 +776,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_sec, + .tv_nsec = duration_nsec, }, .clock_type = CPU_HOG_CLOCK_WALL, }; -- 2.54.0