From nobody Tue Feb 10 01:20:07 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40ECE1A4E77 for ; Fri, 20 Dec 2024 06:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734675645; cv=none; b=nW9rPnavNGyNojLsi5pJokaC5jfe/yKlW9w4JW3Mp8NgHIrZNPXGJBr3mH7SS7NxjN05QkhmiBVQqRLUgx37YnJ87dVRiEHjjmTTBHILHv04TOSMjGuxC4wEVWsFLA9LoYh/YIv9rQnmN356AxDTeff9ofZXBWRKcfKKk0nVc6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734675645; c=relaxed/simple; bh=tw/sZ6xyV0Pw2jZXspaHJWiWfZ9xSORxU2ivpIey0fc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RL0Jq2kurJVzAgTau/b4a9ceplcTT690MkEI1gPjhliZvzyvSdvvaflG6x2F6vl47zCMeyYnlnOChTYGtktO8+cH4/yCSYcP/VUg6SF5ISKPTKKG8fzC1G9Ev3JE066jG01ahDXYVjbMW8YD/WO64kz5fDvssXm6LtanWvI/4tE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ddcu/3Kp; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ddcu/3Kp" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-725ee6f56b4so1403650b3a.3 for ; Thu, 19 Dec 2024 22:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734675643; x=1735280443; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K16k0CtGst/uGn1z/pOeYRcdvDetSUcyUB4347UZ9Ic=; b=ddcu/3KpY9dAYAg7n50JJnkK+jPrKXkJdAEijwHRzpW0N+KUIDbsUGQ6zKbzrEVqDQ jVbe2z+qCSXtBWx8Zt29kgAqrcidypv0AVQBbB3qUy/UafoZZg9HNsSiw0Iy+V585fU7 caZnUgz+zxF3a5sYaDXlUe0kHyGGoxoINfmzaxuKjghsFMB32CSJoCWKjRFeg3h61s1e 4EjQ10G641h//g8bFlM8w7bbSjJo7WeUIzA+kMCRN40MSfEf3HgfHEW8h0FDtEnNSG7B VWRWoEzTaRoJNqvyyW9gUSqPvZXyMbhly1o2IUzH7CJhlztr3Z4MQOqH/Ka69jieSGOI Gpyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734675643; x=1735280443; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K16k0CtGst/uGn1z/pOeYRcdvDetSUcyUB4347UZ9Ic=; b=gx1dJj2auO2uvF8XdpIvXprBOU88XRmjZbE3Rn5wkDIL9gEOEx3QQIMh6msliiA5Yu j14LweyyjNpV5bheEgMfHqeeUyahTotFf5idu8IA37t7rLbeLuIenULZ1jHNskpH1abT Y0ZgNG7PFNWjd+mizqKKUPocXKiAiog012ozz2ovIHnpwG02HnU7dgPn0XilR+CdGuh3 FlPNMPsG3e1U2Gs9fdZFvXgVFrTVNRYgv+gyBlAsox6rSEoDAdne6gA7ffM1INFELnzL 3GUFaOz8OfKs9XyNsiTy1tuz7ecAcisEF2q9/dQfp9x8jd0fLpMKZdS78sTp9jomrrI4 migQ== X-Forwarded-Encrypted: i=1; AJvYcCX9Qg5hlXP7dBKk3HV7wkGKy0xOpCNkuq2sxHUWr+x1BuG2opLFFulpOLy8sFJ4V10c0K/mymiR9qDkqO8=@vger.kernel.org X-Gm-Message-State: AOJu0YzT0dkl+3R7DWCNoEjVeLhnVsB3Mjjx84TfAc+EghnJUGJevRfC D415mFViPp/nl7nHn4uv3ScSrARep5RSXpoe5rJZfLO3Hryfibl0 X-Gm-Gg: ASbGncuirFMBPPEixp6dusm4kMCuT9mMUz4TZ78e+U//zy5Bj5rrNdbwlsVVV1Le8Av TDGIAg6sUNrT+AdGQ7Ns0qJBxHl0NA0pDES+ir+tQP0q+18A5uZiNJif7K0zXnir/JeV4yvXE1j rBNRuCQDBuHkanq5HDGjskPSouyVBR5hi/ZAxcZiVmhXkf0FtutotkjpMKCyrWJ7ur621L8isCN 5epxpNoECdF6iYRcGhJm3146vbQhF31ff7/ttufRIfX2UexkmdFxgdHhaXjivK0ZUMf3NkaX6R+ XqlNbo7slB6t X-Google-Smtp-Source: AGHT+IEG8yKNHZTP2e3oJeY29omPQVOECmUYMI8B/vEBuZ866QlbRGQ/4iV6FrdGCZLOi1HpwCP6UA== X-Received: by 2002:a05:6a00:8c4:b0:727:3c37:d5f9 with SMTP id d2e1a72fcca58-72abdeff523mr2136986b3a.26.1734675643359; Thu, 19 Dec 2024 22:20:43 -0800 (PST) Received: from localhost ([58.29.143.236]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad90c1bcsm2411084b3a.187.2024.12.19.22.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 22:20:43 -0800 (PST) From: Changwoo Min X-Google-Original-From: Changwoo Min To: tj@kernel.org, void@manifault.com, arighi@nvidia.com, mingo@redhat.com, peterz@infradead.org Cc: changwoo@igalia.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org Subject: [PATCH v6 4/6] sched_ext: Add time helpers for BPF schedulers Date: Fri, 20 Dec 2024 15:20:23 +0900 Message-ID: <20241220062025.27724-5-changwoo@igalia.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220062025.27724-1-changwoo@igalia.com> References: <20241220062025.27724-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The following functions are added for BPF schedulers: - vtime_delta(after, before) - vtime_after(a, b) - vtime_before(a, b) - vtime_after_eq(a, b) - vtime_before_eq(a, b) - vtime_in_range(a, b, c) - vtime_in_range_open(a, b, c) Signed-off-by: Changwoo Min --- tools/sched_ext/include/scx/common.bpf.h | 94 ++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/inc= lude/scx/common.bpf.h index 79f0798a5350..923bbf57e4f1 100644 --- a/tools/sched_ext/include/scx/common.bpf.h +++ b/tools/sched_ext/include/scx/common.bpf.h @@ -408,6 +408,100 @@ static __always_inline const struct cpumask *cast_mas= k(struct bpf_cpumask *mask) void bpf_rcu_read_lock(void) __ksym; void bpf_rcu_read_unlock(void) __ksym; =20 +/* + * Time helpers, most of which are from jiffies.h. + */ + +/** + * vtime_delta - Calculate the delta between new and old time stamp + * @after: first comparable as u64 + * @before: second comparable as u64 + * + * Return: the time difference, which is >=3D 0 + */ +static inline s64 vtime_delta(u64 after, u64 before) +{ + return (s64)(after - before) > 0 ? : 0; +} + +/** + * vtime_after - returns true if the time a is after time b. + * @a: first comparable as u64 + * @b: second comparable as u64 + * + * Do this with "<0" and ">=3D0" to only test the sign of the result. A + * good compiler would generate better code (and a really good compiler + * wouldn't care). Gcc is currently neither. + * + * Return: %true is time a is after time b, otherwise %false. + */ +static inline bool vtime_after(u64 a, u64 b) +{ + return (s64)(b - a) < 0; +} + +/** + * vtime_before - returns true if the time a is before time b. + * @a: first comparable as u64 + * @b: second comparable as u64 + * + * Return: %true is time a is before time b, otherwise %false. + */ +static inline bool vtime_before(u64 a, u64 b) +{ + return vtime_after(b, a); +} + +/** + * vtime_after_eq - returns true if the time a is after or the same as tim= e b. + * @a: first comparable as u64 + * @b: second comparable as u64 + * + * Return: %true is time a is after or the same as time b, otherwise %fals= e. + */ +static inline bool vtime_after_eq(u64 a, u64 b) +{ + return (s64)(a - b) >=3D 0; +} + +/** + * vtime_before_eq - returns true if the time a is before or the same as t= ime b. + * @a: first comparable as u64 + * @b: second comparable as u64 + * + * Return: %true is time a is before or the same as time b, otherwise %fal= se. + */ +static inline bool vtime_before_eq(u64 a, u64 b) +{ + return vtime_after_eq(b, a); +} + +/** + * vtime_in_range - Calculate whether a is in the range of [b, c]. + * @a: time to test + * @b: beginning of the range + * @c: end of the range + * + * Return: %true is time a is in the range [b, c], otherwise %false. + */ +static inline bool vtime_in_range(u64 a, u64 b, u64 c) +{ + return vtime_after_eq(a, b) && vtime_before_eq(a, c); +} + +/** + * vtime_in_range_open - Calculate whether a is in the range of [b, c). + * @a: time to test + * @b: beginning of the range + * @c: end of the range + * + * Return: %true is time a is in the range [b, c), otherwise %false. + */ +static inline bool vtime_in_range_open(u64 a, u64 b, u64 c) +{ + return vtime_after_eq(a, b) && vtime_before(a, c); +} + =20 /* * Other helpers --=20 2.47.1