Skip to content

Commit ea59cb7

Browse files
committed
Merge tag 'sched_ext-for-6.15-rc0-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext
Pull sched_ext fixes from Tejun Heo: - Calling scx_bpf_create_dsq() with the same ID would succeed creating duplicate DSQs. Fix it to return -EEXIST. - scx_select_cpu_dfl() fixes and cleanups. - Synchronize tool/sched_ext with external scheduler repo. While this isn't a fix. There's no risk to the kernel and it's better if they stay synced closer. * tag 'sched_ext-for-6.15-rc0-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext: tools/sched_ext: Sync with scx repo sched_ext: initialize built-in idle state before ops.init() sched_ext: create_dsq: Return -EEXIST on duplicate request sched_ext: Remove a meaningless conditional goto in scx_select_cpu_dfl() sched_ext: idle: Fix return code of scx_select_cpu_dfl()
2 parents 4167797 + 2bac648 commit ea59cb7

File tree

7 files changed

+103
-40
lines changed

7 files changed

+103
-40
lines changed

kernel/sched/ext.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,8 +4171,8 @@ static struct scx_dispatch_q *create_dsq(u64 dsq_id, int node)
41714171

41724172
init_dsq(dsq, dsq_id);
41734173

4174-
ret = rhashtable_insert_fast(&dsq_hash, &dsq->hash_node,
4175-
dsq_hash_params);
4174+
ret = rhashtable_lookup_insert_fast(&dsq_hash, &dsq->hash_node,
4175+
dsq_hash_params);
41764176
if (ret) {
41774177
kfree(dsq);
41784178
return ERR_PTR(ret);
@@ -5361,6 +5361,8 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
53615361
*/
53625362
cpus_read_lock();
53635363

5364+
scx_idle_enable(ops);
5365+
53645366
if (scx_ops.init) {
53655367
ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, init);
53665368
if (ret) {
@@ -5427,8 +5429,6 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
54275429
if (scx_ops.cpu_acquire || scx_ops.cpu_release)
54285430
static_branch_enable(&scx_ops_cpu_preempt);
54295431

5430-
scx_idle_enable(ops);
5431-
54325432
/*
54335433
* Lock out forks, cgroup on/offlining and moves before opening the
54345434
* floodgate so that they don't wander into the operations prematurely.

kernel/sched/ext_idle.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
544544
* core.
545545
*/
546546
if (flags & SCX_PICK_IDLE_CORE) {
547-
cpu = prev_cpu;
547+
cpu = -EBUSY;
548548
goto out_unlock;
549549
}
550550
}
@@ -584,8 +584,6 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
584584
* increasing distance.
585585
*/
586586
cpu = scx_pick_idle_cpu(p->cpus_ptr, node, flags);
587-
if (cpu >= 0)
588-
goto out_unlock;
589587

590588
out_unlock:
591589
rcu_read_unlock();
@@ -723,14 +721,14 @@ static void reset_idle_masks(struct sched_ext_ops *ops)
723721
void scx_idle_enable(struct sched_ext_ops *ops)
724722
{
725723
if (!ops->update_idle || (ops->flags & SCX_OPS_KEEP_BUILTIN_IDLE))
726-
static_branch_enable(&scx_builtin_idle_enabled);
724+
static_branch_enable_cpuslocked(&scx_builtin_idle_enabled);
727725
else
728-
static_branch_disable(&scx_builtin_idle_enabled);
726+
static_branch_disable_cpuslocked(&scx_builtin_idle_enabled);
729727

730728
if (ops->flags & SCX_OPS_BUILTIN_IDLE_PER_NODE)
731-
static_branch_enable(&scx_builtin_idle_per_node);
729+
static_branch_enable_cpuslocked(&scx_builtin_idle_per_node);
732730
else
733-
static_branch_disable(&scx_builtin_idle_per_node);
731+
static_branch_disable_cpuslocked(&scx_builtin_idle_per_node);
734732

735733
#ifdef CONFIG_SMP
736734
reset_idle_masks(ops);

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)