Commit c923cbe8 authored by Hui Tang's avatar Hui Tang
Browse files

bpf:programmable: Add helper to set preferred node

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9GZAQ


CVE: NA

--------------------------------

Introduce the bpf helper to set preferred nodes for
relationship group.

Signed-off-by: default avatarHui Tang <tanghui20@huawei.com>
parent c5a54a00
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@ struct bpf_relationship_get_args {
	struct bpf_net_relationship net;
};

struct bpf_relationship_set_args {
	nodemask_t preferred_node;
};

struct relationship_hdr {
	refcount_t refcount;
	spinlock_t lock;
@@ -161,6 +165,8 @@ extern void numa_faults_update_and_sort(int nid, int new,
extern void task_tick_relationship(struct rq *rq, struct task_struct *curr);

extern void task_preferred_node_work(struct callback_head *work);
extern void
sched_set_curr_preferred_node(struct bpf_relationship_set_args *args);

DECLARE_STATIC_KEY_FALSE(__relationship_switch);
static inline bool task_relationship_used(void)
+7 −0
Original line number Diff line number Diff line
@@ -3908,6 +3908,12 @@ union bpf_attr {
 *		get relationship statistics of *tsk* and store in *stats*.
 *	Return
 *		0 on success, or a negative error in case of failure.
 *
 * int bpf_sched_set_curr_preferred_node(struct bpf_relationship_set_args *args, int len)
 *	Description
 *		set current task preferred node.
 *	Return
 *		0 on success, or a negative error in case of failure.
 */
#define __BPF_FUNC_MAPPER(FN)		\
	FN(unspec),			\
@@ -4082,6 +4088,7 @@ union bpf_attr {
	FN(cpus_share_cache),		\
	FN(nodemask_op),		\
	FN(get_task_relationship_stats),\
	FN(sched_set_curr_preferred_node),\
	/* */

/* integer value in 'imm' field of BPF_CALL instruction selects which helper
+20 −0
Original line number Diff line number Diff line
@@ -369,6 +369,24 @@ const struct bpf_func_proto bpf_get_task_relationship_stats_proto = {
	.arg2_type	= ARG_CONST_MAP_PTR,
	.arg3_type	= ARG_PTR_TO_MAP_VALUE_OR_NULL,
};

BPF_CALL_2(bpf_sched_set_curr_preferred_node,
	   struct bpf_relationship_set_args *, args, int, len)
{
	if (!args || len != sizeof(*args))
		return -EINVAL;

	sched_set_curr_preferred_node(args);
	return 0;
}

const struct bpf_func_proto bpf_sched_set_curr_preferred_node_proto = {
	.func		= bpf_sched_set_curr_preferred_node,
	.gpl_only	= false,
	.ret_type	= RET_INTEGER,
	.arg1_type	= ARG_PTR_TO_UNINIT_MEM,
	.arg2_type	= ARG_CONST_SIZE,
};
#endif

static const struct bpf_func_proto *
@@ -398,6 +416,8 @@ bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
#ifdef CONFIG_SCHED_TASK_RELATIONSHIP
	case BPF_FUNC_get_task_relationship_stats:
		return &bpf_get_task_relationship_stats_proto;
	case BPF_FUNC_sched_set_curr_preferred_node:
		return &bpf_sched_set_curr_preferred_node_proto;
#endif
	default:
		return bpf_base_func_proto(func_id);
+10 −0
Original line number Diff line number Diff line
@@ -3116,6 +3116,16 @@ void sched_get_mm_relationship(struct task_struct *tsk,
	}
#endif
}

void sched_set_curr_preferred_node(struct bpf_relationship_set_args *args)
{
#ifdef CONFIG_NUMA_BALANCING
	struct numa_group *grp = rcu_dereference_raw(current->numa_group);

	grp->preferred_nid = args->preferred_node;
	schedstat_inc(grp->nodes_switch_cnt);
#endif
}
#endif

#endif
+4 −0
Original line number Diff line number Diff line
@@ -447,6 +447,8 @@ class PrinterHelpers(Printer):
            'struct sched_migrate_node',
            'struct nodemask_op_args',
            'struct bpf_relationship_get_args',
            'struct bpf_relationship_set_args',
            'struct sched_preferred_node_ctx',
    ]
    known_types = {
            '...',
@@ -502,6 +504,8 @@ class PrinterHelpers(Printer):
            'struct sched_migrate_node',
            'struct nodemask_op_args',
            'struct bpf_relationship_get_args',
            'struct bpf_relationship_set_args',
            'struct sched_preferred_node_ctx',
    }
    mapped_types = {
            'u8': '__u8',
Loading