Unverified Commit 038a281b authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!4053 sched: basic infrastructure for scheduler bpf

Merge Pull Request from: @ci-robot 
 
PR sync from: Lu Jialin <lujialin4@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/PGSDN3VHRJHDWP7G3NSJX4LCBANBIAE6/ 
From: Guan Jing <guanjing6@huawei.com>

sched: basic infrastructure for scheduler bpf

Guan Jing (10):
  sched: programmable: Introduce bpf sched
  sched: programmable: Add a tag for the task
  sched: programmable: Add a tag for the task group
  sched: programmable: Add user interface of task group tag
  sched: programmable: Add user interface of task tag
  sched: basic infrastructure for scheduler bpf
  sched: introduce bpf_sched_enable()
  sched: programmable: Add hook in select_task_rq_fair()
  sched: programmable: Add hook in can_migrate_task()
  openeuler_defconfig: enable CONFIG_BPF_SCHED


-- 
2.34.1
 
https://gitee.com/openeuler/kernel/issues/I8OIT1 
 
Link:https://gitee.com/openeuler/kernel/pulls/4053

 

Reviewed-by: default avatarZucheng Zheng <zhengzucheng@huawei.com>
Reviewed-by: default avatarLiu Chao <liuchao173@huawei.com>
Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents 2e018278 657e2204
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ CONFIG_BPF_JIT_DEFAULT_ON=y
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
# CONFIG_BPF_PRELOAD is not set
# CONFIG_BPF_LSM is not set
CONFIG_BPF_SCHED=y
# end of BPF subsystem

CONFIG_PREEMPT_NONE_BUILD=y
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ CONFIG_BPF_JIT_DEFAULT_ON=y
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
# CONFIG_BPF_PRELOAD is not set
# CONFIG_BPF_LSM is not set
CONFIG_BPF_SCHED=y
# end of BPF subsystem

CONFIG_PREEMPT_BUILD=y
+61 −0
Original line number Diff line number Diff line
@@ -3672,6 +3672,64 @@ static const struct inode_operations proc_tid_comm_inode_operations = {
		.permission	= proc_tid_comm_permission,
};

#ifdef CONFIG_BPF_SCHED
static ssize_t pid_tag_write(struct file *file, const char __user *buf,
				size_t count, loff_t *offset)
{
	struct inode *inode = file_inode(file);
	struct task_struct *tsk;
	int err = 0;
	long tag = 0;

	tsk = get_proc_task(inode);
	if (!tsk)
		return -ESRCH;

	if (unlikely(tsk->pid == 1)) {
		err = -EPERM;
		goto out;
	}

	err = kstrtol_from_user(buf, count, 0, &tag);
	if (err)
		goto out;

	sched_settag(tsk, tag);

out:
	put_task_struct(tsk);
	return err < 0 ? err : count;
}

static int pid_tag_show(struct seq_file *m, void *v)
{
	struct inode *inode = m->private;
	struct task_struct *tsk;

	tsk = get_proc_task(inode);
	if (!tsk)
		return -ESRCH;

	seq_printf(m, "%ld\n", tsk->tag);
	put_task_struct(tsk);

	return 0;
}

static int pid_tag_open(struct inode *inode, struct file *flip)
{
	return single_open(flip, pid_tag_show, inode);
}

static const struct file_operations proc_pid_tag_operations = {
		.open		= pid_tag_open,
		.read		= seq_read,
		.write		= pid_tag_write,
		.llseek		= seq_lseek,
		.release	= single_release,
};
#endif

/*
 * Tasks
 */
@@ -3781,6 +3839,9 @@ static const struct pid_entry tid_base_stuff[] = {
#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY
	REG("preferred_cpuset", 0644, proc_preferred_cpuset_operations),
#endif
#ifdef CONFIG_BPF_SCHED
	REG("tag", 0644, proc_pid_tag_operations),
#endif
};

static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
+50 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_BPF_SCHED_H
#define _LINUX_BPF_SCHED_H

#include <linux/bpf.h>

#ifdef CONFIG_BPF_SCHED

#include <linux/jump_label.h>

#define BPF_SCHED_HOOK(RET, DEFAULT, NAME, ...) \
	RET bpf_sched_##NAME(__VA_ARGS__);
#include <linux/sched_hook_defs.h>
#undef BPF_SCHED_HOOK

int bpf_sched_verify_prog(struct bpf_verifier_log *vlog,
			  const struct bpf_prog *prog);

DECLARE_STATIC_KEY_FALSE(bpf_sched_enabled_key);

static inline bool bpf_sched_enabled(void)
{
	return static_branch_unlikely(&bpf_sched_enabled_key);
}

static inline void bpf_sched_inc(void)
{
	static_branch_inc(&bpf_sched_enabled_key);
}

static inline void bpf_sched_dec(void)
{
	static_branch_dec(&bpf_sched_enabled_key);
}

#else /* !CONFIG_BPF_SCHED */

static inline int bpf_sched_verify_prog(struct bpf_verifier_log *vlog,
			  const struct bpf_prog *prog)
{
	return -EOPNOTSUPP;
}

static inline bool bpf_sched_enabled(void)
{
	return false;
}

#endif /* CONFIG_BPF_SCHED */
#endif /* _LINUX_BPF_SCHED_H */
+4 −0
Original line number Diff line number Diff line
@@ -83,6 +83,10 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_SYSCALL, bpf_syscall,
BPF_PROG_TYPE(BPF_PROG_TYPE_NETFILTER, netfilter,
	      struct bpf_nf_ctx, struct bpf_nf_ctx)
#endif
#ifdef CONFIG_BPF_SCHED
BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED, bpf_sched,
	      void *, void *)
#endif /* CONFIG_BPF_SCHED */

BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops)
BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_ARRAY, percpu_array_map_ops)
Loading