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 0D8103C0A1B for ; Wed, 24 Jun 2026 16:04: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=1782317062; cv=none; b=ULSLctcts1NxUiWtN9PDWELBBQqS3v2jA2e2CmNFo036pDnYkfV6hxK3lJsNH5wkutvO0ykOBtKE6dnsYSIVJJfNjD2yBqUH5ZqeHf1zxe1kQsdnmhgtj0apdO/pIOUF5YiRBffP9CqCw5NoVeTbxcavnUF54HOyyS/sS3tXqe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782317062; c=relaxed/simple; bh=P7p7FAcln0ct9nNUJa2Ctd2eiERl+AOGFhIrcJgzXAQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hKlZ0Bfznhf+gGABs+5bLJdLkUGeepNgZmUFbzsfJ75WFswYglqjlIeVz8MPVmOlSsluNSy+NLdvB6ZNPIEBIqXJMtwpLohA5DkmkYJumFkr+8WZfUAsgy7yec7WQTiTBplcjoCPuudGZ1MoGMxQ/R6OntfhgPoqP3U3z8R6Ov0= 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=KRKK5RQa; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ncwze8Vk; 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="KRKK5RQa"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ncwze8Vk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782317060; 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=xip2bYaGq+4ASYS6Hehw4QNPCcstYUL5jPvaPb6o9/E=; b=KRKK5RQaOF5Fw1FMIT4KbmNpDnZPcselIBnpVG1u+0US6Nqcru4MWwdN32AeF9HQMtyKFk wV47MLoXwrELs/LOjR+nGp0503ulj5Rj/FWlPfFSs8rKaad4URMYMlk7MN96H+P6bKW3fH ukXPMiYzWqy6RIhdN8u8uJxRAdUQgZI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-CVA0aeomPOqzmfdTNOYjbQ-1; Wed, 24 Jun 2026 12:04:18 -0400 X-MC-Unique: CVA0aeomPOqzmfdTNOYjbQ-1 X-Mimecast-MFC-AGG-ID: CVA0aeomPOqzmfdTNOYjbQ_1782317058 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-9157de5360fso2826985a.0 for ; Wed, 24 Jun 2026 09:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782317058; x=1782921858; 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=xip2bYaGq+4ASYS6Hehw4QNPCcstYUL5jPvaPb6o9/E=; b=Ncwze8Vk+6liBNGoKAUu3D0k60b+knTlodf1Wu2O4f+cCwgZD6d0yCwPI8Q2P/DsIt Q8eMmBV/5uBY+kw3Yg5gsTlK/laKsvRqfSy9Fr5VazJRKs6o8zJcXn7V0Jx6dk5C+q5f VyJjCdHOQJNCreCQz1lTIijP0tmFHfO3LEodrFNM+m6imtvexSjUEvIirEigNUeiGG33 ePNUMEyzgQb2PEmtZ7Huvs7LrCT4QiwxKctO/uiapHP7IYA8acb1JxDBRqQWVJ/CWh5Z KaqWOsIyaz9itgxZUzE+aZondCZ0t4rEMJbvHOlHwlDFQ3s75mTWaboQG+y5azrSyzr1 qLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782317058; x=1782921858; 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=xip2bYaGq+4ASYS6Hehw4QNPCcstYUL5jPvaPb6o9/E=; b=VZA8gMCtr7IQaPEM3GWzyJ9OoU51qvgOQWKFJ4hP1dbx19rAC3gzo5zrnU8KVc8BEa Au6dXYbP4Qro3G9/WLILsWMOVIBevpAO6PSDs0vBK2fiCsHghEXBNGB38qHlGzcf6ISe 0WyX8yopjxdEawUGCKZb+I/TpMU6v7r6oqkKKwEvjGv1HiJGQLbbZbvdObabJHru5Snr w0w0onP6ilWI99DEameAmbttU6Ui/mdFUdChRC+U4oMmWHkUeVv1c8nz3CCXMjs0LOe+ C1ZD/pdwq74GmIAdaI9yfNFjWatjpSmda8tzPY+2A811X8EHpefcy7X46hDUiiQ3h+/Y mo+Q== X-Forwarded-Encrypted: i=1; AFNElJ/DkB65ZKskL2LhryeoAYakhkrLv9tgyeNZjN4obuEjjRdRo4lV3p4Bh2nmj5ycvUucX7vkpAWaXIdkaC4=@vger.kernel.org X-Gm-Message-State: AOJu0YzxELMm7g03T1kzm+PZF7tfsu6OoellmTxVu0pqkbrQgsvEiilh myAFmKS24w9WfOFEDeOfzVXKQccMIqtj5sr0OWV26OiDoyFbETeXnjONO0ONIDhn/rZ4N7gHw/C jKuIQJ93d0mv4OLrG2LuGtNWBdWO34rrtHVNo84a3bOFj9KJjmAsjRJrcutfGx5k9FA== X-Gm-Gg: AfdE7ckTdXb8T+SFSWu81tlSlk1nlx0RMCPW7Ue3kpbNpR6FjYjun7WZ/RQYV6zAys8 o9M2q6hKlQA9PFGzDwtWGSw8ufSH4BbDLN5OwGI65d6DXUFxxOFGwGBeA2OZ7xdNgQjYZaR/IHF iuxTW7W60iPSsHcJmBth1MyCnxxkQZdYNi/X3HxGApeynnefep5/6pT7XZhHCa71/s/pSQ493AL LF7bZ01D+YDCJekUCghRmJB5/0Z9jd3RC/MOVpATztKlPN9VSwX1FDxTmBC+uozaMSdKhZn/D/r M69xD9LBnIAaZ+Uil7febay+N3g3o4foigETL3Kjysym6XKyjg+6arvdL8E/lQyR8pfiElruEDp rmGKDIVm3bcjix00Z8/wpzdISQVD+fNV1JA== X-Received: by 2002:a05:620a:4052:b0:912:671b:d0b1 with SMTP id af79cd13be357-92882e6d436mr156029785a.2.1782317057922; Wed, 24 Jun 2026 09:04:17 -0700 (PDT) X-Received: by 2002:a05:620a:4052:b0:912:671b:d0b1 with SMTP id af79cd13be357-92882e6d436mr156021185a.2.1782317057358; Wed, 24 Jun 2026 09:04:17 -0700 (PDT) Received: from oak (c-73-148-124-98.hsd1.va.comcast.net. [73.148.124.98]) by smtp.gmail.com with ESMTPSA id af79cd13be357-926000c343bsm594979085a.28.2026.06.24.09.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 09:04:16 -0700 (PDT) From: Joe Simmons-Talbott To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan Cc: Joe Simmons-Talbott , cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] selftests/cgroup: Adjust cpu test duration based on HZ Date: Wed, 24 Jun 2026 12:03:57 -0400 Message-ID: <20260624160358.430354-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/20260623194239.GA899029@oak/ Signed-off-by: Joe Simmons-Talbott --- 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. tools/testing/selftests/cgroup/test_cpu.c | 44 ++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c index 7a40d76b9548..feb7eb6a875c 100644 --- a/tools/testing/selftests/cgroup/test_cpu.c +++ b/tools/testing/selftests/cgroup/test_cpu.c @@ -639,6 +639,30 @@ 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) + 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; + snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec); cpucg = cg_name(root, "cpucg_test"); @@ -710,15 +740,21 @@ 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_seconds; - 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]; + if (hz == -1) + hz = 1000; + duration_seconds = 1000 / hz; + duration_usec = duration_seconds * USEC_PER_SEC; + snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec); parent = cg_name(root, "cpucg_parent"); -- 2.54.0