Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched_ext: Add scx_bpf_task_set_slice() and scx_bpf_task_set_dsq_vtime()

With the planned hierarchical scheduler support, sub-schedulers will need to
be verified for authority before being allowed to modify task->scx.slice and
task->scx.dsq_vtime. Add scx_bpf_task_set_slice() and
scx_bpf_task_set_dsq_vtime() which will perform the necessary permission
checks.

Root schedulers can still directly write to these fields, so this doesn't
affect existing schedulers.

Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

Tejun Heo 3035addf 111a7980

+32
+30
kernel/sched/ext.c
··· 5936 5936 5937 5937 __bpf_kfunc_start_defs(); 5938 5938 5939 + /** 5940 + * scx_bpf_task_set_slice - Set task's time slice 5941 + * @p: task of interest 5942 + * @slice: time slice to set in nsecs 5943 + * 5944 + * Set @p's time slice to @slice. Returns %true on success, %false if the 5945 + * calling scheduler doesn't have authority over @p. 5946 + */ 5947 + __bpf_kfunc bool scx_bpf_task_set_slice(struct task_struct *p, u64 slice) 5948 + { 5949 + p->scx.slice = slice; 5950 + return true; 5951 + } 5952 + 5953 + /** 5954 + * scx_bpf_task_set_dsq_vtime - Set task's virtual time for DSQ ordering 5955 + * @p: task of interest 5956 + * @vtime: virtual time to set 5957 + * 5958 + * Set @p's virtual time to @vtime. Returns %true on success, %false if the 5959 + * calling scheduler doesn't have authority over @p. 5960 + */ 5961 + __bpf_kfunc bool scx_bpf_task_set_dsq_vtime(struct task_struct *p, u64 vtime) 5962 + { 5963 + p->scx.dsq_vtime = vtime; 5964 + return true; 5965 + } 5966 + 5939 5967 static void scx_kick_cpu(struct scx_sched *sch, s32 cpu, u64 flags) 5940 5968 { 5941 5969 struct rq *this_rq; ··· 6769 6741 __bpf_kfunc_end_defs(); 6770 6742 6771 6743 BTF_KFUNCS_START(scx_kfunc_ids_any) 6744 + BTF_ID_FLAGS(func, scx_bpf_task_set_slice, KF_RCU); 6745 + BTF_ID_FLAGS(func, scx_bpf_task_set_dsq_vtime, KF_RCU); 6772 6746 BTF_ID_FLAGS(func, scx_bpf_kick_cpu) 6773 6747 BTF_ID_FLAGS(func, scx_bpf_dsq_nr_queued) 6774 6748 BTF_ID_FLAGS(func, scx_bpf_destroy_dsq)
+2
tools/sched_ext/include/scx/common.bpf.h
··· 102 102 s32 scx_bpf_pick_any_cpu(const cpumask_t *cpus_allowed, u64 flags) __ksym; 103 103 bool scx_bpf_task_running(const struct task_struct *p) __ksym; 104 104 s32 scx_bpf_task_cpu(const struct task_struct *p) __ksym; 105 + bool scx_bpf_task_set_slice(struct task_struct *p, u64 slice) __ksym __weak; 106 + bool scx_bpf_task_set_dsq_vtime(struct task_struct *p, u64 vtime) __ksym __weak; 105 107 struct rq *scx_bpf_cpu_rq(s32 cpu) __ksym; 106 108 struct rq *scx_bpf_locked_rq(void) __ksym; 107 109 struct task_struct *scx_bpf_cpu_curr(s32 cpu) __ksym __weak;