Skip to content

Commit 2bac648

Browse files
committed
tools/sched_ext: Sync with scx repo
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>
1 parent f0c6eab commit 2bac648

File tree

5 files changed

+94
-29
lines changed

5 files changed

+94
-29
lines changed

tools/sched_ext/include/scx/common.bpf.h

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -586,36 +586,48 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
586586
}
587587
}
588588

589-
#define READ_ONCE(x) \
590-
({ \
591-
union { typeof(x) __val; char __c[1]; } __u = \
592-
{ .__c = { 0 } }; \
593-
__read_once_size(&(x), __u.__c, sizeof(x)); \
594-
__u.__val; \
595-
})
596-
597-
#define WRITE_ONCE(x, val) \
598-
({ \
599-
union { typeof(x) __val; char __c[1]; } __u = \
600-
{ .__val = (val) }; \
601-
__write_once_size(&(x), __u.__c, sizeof(x)); \
602-
__u.__val; \
603-
})
604-
605-
#define READ_ONCE_ARENA(type, x) \
606-
({ \
607-
union { type __val; char __c[1]; } __u = \
608-
{ .__c = { 0 } }; \
609-
__read_once_size((void *)&(x), __u.__c, sizeof(x)); \
610-
__u.__val; \
589+
/*
590+
* __unqual_typeof(x) - Declare an unqualified scalar type, leaving
591+
* non-scalar types unchanged,
592+
*
593+
* Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
594+
* is not type-compatible with 'signed char', and we define a separate case.
595+
*
596+
* This is copied verbatim from kernel's include/linux/compiler_types.h, but
597+
* with default expression (for pointers) changed from (x) to (typeof(x)0).
598+
*
599+
* This is because LLVM has a bug where for lvalue (x), it does not get rid of
600+
* an extra address_space qualifier, but does in case of rvalue (typeof(x)0).
601+
* Hence, for pointers, we need to create an rvalue expression to get the
602+
* desired type. See https://github.com/llvm/llvm-project/issues/53400.
603+
*/
604+
#define __scalar_type_to_expr_cases(type) \
605+
unsigned type : (unsigned type)0, signed type : (signed type)0
606+
607+
#define __unqual_typeof(x) \
608+
typeof(_Generic((x), \
609+
char: (char)0, \
610+
__scalar_type_to_expr_cases(char), \
611+
__scalar_type_to_expr_cases(short), \
612+
__scalar_type_to_expr_cases(int), \
613+
__scalar_type_to_expr_cases(long), \
614+
__scalar_type_to_expr_cases(long long), \
615+
default: (typeof(x))0))
616+
617+
#define READ_ONCE(x) \
618+
({ \
619+
union { __unqual_typeof(x) __val; char __c[1]; } __u = \
620+
{ .__c = { 0 } }; \
621+
__read_once_size((__unqual_typeof(x) *)&(x), __u.__c, sizeof(x)); \
622+
__u.__val; \
611623
})
612624

613-
#define WRITE_ONCE_ARENA(type, x, val) \
614-
({ \
615-
union { type __val; char __c[1]; } __u = \
616-
{ .__val = (val) }; \
617-
__write_once_size((void *)&(x), __u.__c, sizeof(x)); \
618-
__u.__val; \
625+
#define WRITE_ONCE(x, val) \
626+
({ \
627+
union { __unqual_typeof(x) __val; char __c[1]; } __u = \
628+
{ .__val = (val) }; \
629+
__write_once_size((__unqual_typeof(x) *)&(x), __u.__c, sizeof(x)); \
630+
__u.__val; \
619631
})
620632

621633
/*
@@ -648,6 +660,23 @@ static inline u32 log2_u64(u64 v)
648660
return log2_u32(v) + 1;
649661
}
650662

663+
/*
664+
* Return a value proportionally scaled to the task's weight.
665+
*/
666+
static inline u64 scale_by_task_weight(const struct task_struct *p, u64 value)
667+
{
668+
return (value * p->scx.weight) / 100;
669+
}
670+
671+
/*
672+
* Return a value inversely proportional to the task's weight.
673+
*/
674+
static inline u64 scale_by_task_weight_inverse(const struct task_struct *p, u64 value)
675+
{
676+
return value * 100 / p->scx.weight;
677+
}
678+
679+
651680
#include "compat.bpf.h"
652681
#include "enums.bpf.h"
653682

tools/sched_ext/include/scx/enum_defs.autogen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
#define HAVE_SCX_OPS_ENQ_LAST
8989
#define HAVE_SCX_OPS_ENQ_EXITING
9090
#define HAVE_SCX_OPS_SWITCH_PARTIAL
91+
#define HAVE_SCX_OPS_ENQ_MIGRATION_DISABLED
92+
#define HAVE_SCX_OPS_ALLOW_QUEUED_WAKEUP
9193
#define HAVE_SCX_OPS_HAS_CGROUP_WEIGHT
9294
#define HAVE_SCX_OPS_ALL_FLAGS
9395
#define HAVE_SCX_OPSS_NONE
@@ -104,6 +106,7 @@
104106
#define HAVE_SCX_RQ_BAL_PENDING
105107
#define HAVE_SCX_RQ_BAL_KEEP
106108
#define HAVE_SCX_RQ_BYPASSING
109+
#define HAVE_SCX_RQ_CLK_VALID
107110
#define HAVE_SCX_RQ_IN_WAKEUP
108111
#define HAVE_SCX_RQ_IN_BALANCE
109112
#define HAVE_SCX_TASK_NONE

tools/sched_ext/include/scx/enums.autogen.bpf.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ const volatile u64 __SCX_SLICE_DFL __weak;
1313
const volatile u64 __SCX_SLICE_INF __weak;
1414
#define SCX_SLICE_INF __SCX_SLICE_INF
1515

16+
const volatile u64 __SCX_RQ_ONLINE __weak;
17+
#define SCX_RQ_ONLINE __SCX_RQ_ONLINE
18+
19+
const volatile u64 __SCX_RQ_CAN_STOP_TICK __weak;
20+
#define SCX_RQ_CAN_STOP_TICK __SCX_RQ_CAN_STOP_TICK
21+
22+
const volatile u64 __SCX_RQ_BAL_PENDING __weak;
23+
#define SCX_RQ_BAL_PENDING __SCX_RQ_BAL_PENDING
24+
25+
const volatile u64 __SCX_RQ_BAL_KEEP __weak;
26+
#define SCX_RQ_BAL_KEEP __SCX_RQ_BAL_KEEP
27+
28+
const volatile u64 __SCX_RQ_BYPASSING __weak;
29+
#define SCX_RQ_BYPASSING __SCX_RQ_BYPASSING
30+
31+
const volatile u64 __SCX_RQ_CLK_VALID __weak;
32+
#define SCX_RQ_CLK_VALID __SCX_RQ_CLK_VALID
33+
34+
const volatile u64 __SCX_RQ_IN_WAKEUP __weak;
35+
#define SCX_RQ_IN_WAKEUP __SCX_RQ_IN_WAKEUP
36+
37+
const volatile u64 __SCX_RQ_IN_BALANCE __weak;
38+
#define SCX_RQ_IN_BALANCE __SCX_RQ_IN_BALANCE
39+
1640
const volatile u64 __SCX_DSQ_FLAG_BUILTIN __weak;
1741
#define SCX_DSQ_FLAG_BUILTIN __SCX_DSQ_FLAG_BUILTIN
1842

tools/sched_ext/include/scx/enums.autogen.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
SCX_ENUM_SET(skel, scx_public_consts, SCX_OPS_NAME_LEN); \
99
SCX_ENUM_SET(skel, scx_public_consts, SCX_SLICE_DFL); \
1010
SCX_ENUM_SET(skel, scx_public_consts, SCX_SLICE_INF); \
11+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_ONLINE); \
12+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_CAN_STOP_TICK); \
13+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_BAL_PENDING); \
14+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_BAL_KEEP); \
15+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_BYPASSING); \
16+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_CLK_VALID); \
17+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_IN_WAKEUP); \
18+
SCX_ENUM_SET(skel, scx_rq_flags, SCX_RQ_IN_BALANCE); \
1119
SCX_ENUM_SET(skel, scx_dsq_id_flags, SCX_DSQ_FLAG_BUILTIN); \
1220
SCX_ENUM_SET(skel, scx_dsq_id_flags, SCX_DSQ_FLAG_LOCAL_ON); \
1321
SCX_ENUM_SET(skel, scx_dsq_id_flags, SCX_DSQ_INVALID); \

tools/sched_ext/include/scx/enums.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ static inline void __ENUM_set(u64 *val, char *type, char *name)
1414
bool res;
1515

1616
res = __COMPAT_read_enum(type, name, val);
17-
SCX_BUG_ON(!res, "enum not found(%s)", name);
17+
if (!res)
18+
*val = 0;
1819
}
1920

2021
#define SCX_ENUM_SET(skel, type, name) do { \

0 commit comments

Comments
 (0)