]> www.infradead.org Git - nvme.git/commitdiff
tools/sched_ext: Sync with scx repo
authorTejun Heo <tj@kernel.org>
Wed, 2 Apr 2025 19:08:33 +0000 (09:08 -1000)
committerTejun Heo <tj@kernel.org>
Wed, 2 Apr 2025 19:08:33 +0000 (09:08 -1000)
Synchronize with https://github.com/sched-ext/scx at dc44584874f0 ("kernel:
Synchronize with kernel tools/sched_ext").

- READ/WRITE_ONCE() is made more proper and READA_ONCE_ARENA() is dropped.

- scale_by_task_weight[_inverse]() helpers added.

- Enum defs expanded to cover more and new enums.

- Don't trigger fatal error when some enums are missing from kernel BTF.

Signed-off-by: Tejun Heo <tj@kernel.org>
tools/sched_ext/include/scx/common.bpf.h
tools/sched_ext/include/scx/enum_defs.autogen.h
tools/sched_ext/include/scx/enums.autogen.bpf.h
tools/sched_ext/include/scx/enums.autogen.h
tools/sched_ext/include/scx/enums.h

index dc4333d23189fdfa227343461d1f807a4cd700e4..8787048c6762535e55ef60c2859342faf7f4fbf1 100644 (file)
@@ -586,36 +586,48 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
        }
 }
 
-#define READ_ONCE(x)                                   \
-({                                                     \
-       union { typeof(x) __val; char __c[1]; } __u =   \
-               { .__c = { 0 } };                       \
-       __read_once_size(&(x), __u.__c, sizeof(x));     \
-       __u.__val;                                      \
-})
-
-#define WRITE_ONCE(x, val)                             \
-({                                                     \
-       union { typeof(x) __val; char __c[1]; } __u =   \
-               { .__val = (val) };                     \
-       __write_once_size(&(x), __u.__c, sizeof(x));    \
-       __u.__val;                                      \
-})
-
-#define READ_ONCE_ARENA(type, x)                               \
-({                                                             \
-       union { type __val; char __c[1]; } __u =                \
-               { .__c = { 0 } };                               \
-       __read_once_size((void *)&(x), __u.__c, sizeof(x));     \
-       __u.__val;                                              \
+/*
+ * __unqual_typeof(x) - Declare an unqualified scalar type, leaving
+ *                     non-scalar types unchanged,
+ *
+ * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
+ * is not type-compatible with 'signed char', and we define a separate case.
+ *
+ * This is copied verbatim from kernel's include/linux/compiler_types.h, but
+ * with default expression (for pointers) changed from (x) to (typeof(x)0).
+ *
+ * This is because LLVM has a bug where for lvalue (x), it does not get rid of
+ * an extra address_space qualifier, but does in case of rvalue (typeof(x)0).
+ * Hence, for pointers, we need to create an rvalue expression to get the
+ * desired type. See https://github.com/llvm/llvm-project/issues/53400.
+ */
+#define __scalar_type_to_expr_cases(type) \
+       unsigned type : (unsigned type)0, signed type : (signed type)0
+
+#define __unqual_typeof(x)                              \
+       typeof(_Generic((x),                            \
+               char: (char)0,                          \
+               __scalar_type_to_expr_cases(char),      \
+               __scalar_type_to_expr_cases(short),     \
+               __scalar_type_to_expr_cases(int),       \
+               __scalar_type_to_expr_cases(long),      \
+               __scalar_type_to_expr_cases(long long), \
+               default: (typeof(x))0))
+
+#define READ_ONCE(x)                                                           \
+({                                                                             \
+       union { __unqual_typeof(x) __val; char __c[1]; } __u =                  \
+               { .__c = { 0 } };                                               \
+       __read_once_size((__unqual_typeof(x) *)&(x), __u.__c, sizeof(x));       \
+       __u.__val;                                                              \
 })
 
-#define WRITE_ONCE_ARENA(type, x, val)                         \
-({                                                             \
-       union { type __val; char __c[1]; } __u =                \
-               { .__val = (val) };                             \
-       __write_once_size((void *)&(x), __u.__c, sizeof(x));    \
-       __u.__val;                                              \
+#define WRITE_ONCE(x, val)                                                     \
+({                                                                             \
+       union { __unqual_typeof(x) __val; char __c[1]; } __u =                  \
+               { .__val = (val) };                                             \
+       __write_once_size((__unqual_typeof(x) *)&(x), __u.__c, sizeof(x));      \
+       __u.__val;                                                              \
 })
 
 /*
@@ -648,6 +660,23 @@ static inline u32 log2_u64(u64 v)
                 return log2_u32(v) + 1;
 }
 
+/*
+ * Return a value proportionally scaled to the task's weight.
+ */
+static inline u64 scale_by_task_weight(const struct task_struct *p, u64 value)
+{
+       return (value * p->scx.weight) / 100;
+}
+
+/*
+ * Return a value inversely proportional to the task's weight.
+ */
+static inline u64 scale_by_task_weight_inverse(const struct task_struct *p, u64 value)
+{
+       return value * 100 / p->scx.weight;
+}
+
+
 #include "compat.bpf.h"
 #include "enums.bpf.h"
 
index 6e6c45f14fe1f16d962ded0699bd9500d873f52d..c2c33df9292c257f2cb41ca77953f5ff2cd9950f 100644 (file)
@@ -88,6 +88,8 @@
 #define HAVE_SCX_OPS_ENQ_LAST
 #define HAVE_SCX_OPS_ENQ_EXITING
 #define HAVE_SCX_OPS_SWITCH_PARTIAL
+#define HAVE_SCX_OPS_ENQ_MIGRATION_DISABLED
+#define HAVE_SCX_OPS_ALLOW_QUEUED_WAKEUP
 #define HAVE_SCX_OPS_HAS_CGROUP_WEIGHT
 #define HAVE_SCX_OPS_ALL_FLAGS
 #define HAVE_SCX_OPSS_NONE
 #define HAVE_SCX_RQ_BAL_PENDING
 #define HAVE_SCX_RQ_BAL_KEEP
 #define HAVE_SCX_RQ_BYPASSING
+#define HAVE_SCX_RQ_CLK_VALID
 #define HAVE_SCX_RQ_IN_WAKEUP
 #define HAVE_SCX_RQ_IN_BALANCE
 #define HAVE_SCX_TASK_NONE
index 0e941a0d6f8888426805985c2e908a17ba48b420..2f8002bcc19ade5c52dd0691b81e61adeb47ef96 100644 (file)
@@ -13,6 +13,30 @@ const volatile u64 __SCX_SLICE_DFL __weak;
 const volatile u64 __SCX_SLICE_INF __weak;
 #define SCX_SLICE_INF __SCX_SLICE_INF
 
+const volatile u64 __SCX_RQ_ONLINE __weak;
+#define SCX_RQ_ONLINE __SCX_RQ_ONLINE
+
+const volatile u64 __SCX_RQ_CAN_STOP_TICK __weak;
+#define SCX_RQ_CAN_STOP_TICK __SCX_RQ_CAN_STOP_TICK
+
+const volatile u64 __SCX_RQ_BAL_PENDING __weak;
+#define SCX_RQ_BAL_PENDING __SCX_RQ_BAL_PENDING
+
+const volatile u64 __SCX_RQ_BAL_KEEP __weak;
+#define SCX_RQ_BAL_KEEP __SCX_RQ_BAL_KEEP
+
+const volatile u64 __SCX_RQ_BYPASSING __weak;
+#define SCX_RQ_BYPASSING __SCX_RQ_BYPASSING
+
+const volatile u64 __SCX_RQ_CLK_VALID __weak;
+#define SCX_RQ_CLK_VALID __SCX_RQ_CLK_VALID
+
+const volatile u64 __SCX_RQ_IN_WAKEUP __weak;
+#define SCX_RQ_IN_WAKEUP __SCX_RQ_IN_WAKEUP
+
+const volatile u64 __SCX_RQ_IN_BALANCE __weak;
+#define SCX_RQ_IN_BALANCE __SCX_RQ_IN_BALANCE
+
 const volatile u64 __SCX_DSQ_FLAG_BUILTIN __weak;
 #define SCX_DSQ_FLAG_BUILTIN __SCX_DSQ_FLAG_BUILTIN
 
index 88137a140e726db3d145daeb00bf491db212ba10..fedec938584be0e9f87d0d668980ae4f3e063cec 100644 (file)
@@ -8,6 +8,14 @@
        SCX_ENUM_SET(skel, scx_public_consts, SCX_OPS_NAME_LEN); \
        SCX_ENUM_SET(skel, scx_public_consts, SCX_SLICE_DFL); \
        SCX_ENUM_SET(skel, scx_public_consts, SCX_SLICE_INF); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_ONLINE); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_CAN_STOP_TICK); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_BAL_PENDING); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_BAL_KEEP); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_BYPASSING); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_CLK_VALID); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_IN_WAKEUP); \
+       SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_IN_BALANCE); \
        SCX_ENUM_SET(skel, scx_dsq_id_flags, SCX_DSQ_FLAG_BUILTIN); \
        SCX_ENUM_SET(skel, scx_dsq_id_flags, SCX_DSQ_FLAG_LOCAL_ON); \
        SCX_ENUM_SET(skel, scx_dsq_id_flags, SCX_DSQ_INVALID); \
index 34cbebe974b7b71d8f678b370242f1e57de59a94..8e7c91575f0b32616bd4fbd503a0db8bd5adc664 100644 (file)
@@ -14,7 +14,8 @@ static inline void __ENUM_set(u64 *val, char *type, char *name)
        bool res;
 
        res = __COMPAT_read_enum(type, name, val);
-       SCX_BUG_ON(!res, "enum not found(%s)", name);
+       if (!res)
+               *val = 0;
 }
 
 #define SCX_ENUM_SET(skel, type, name) do {                    \