From: Alexander Pavlenko <pavlenko.alexander@huawei.com> hulk inclusion category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/8422 ---------------------------------------- Add support to initialize the xsched device memory (dmem) region during XPU device setup. Signed-off-by: Alexander Pavlenko <pavlenko.alexander@huawei.com> Signed-off-by: Liu Kai <liukai284@huawei.com> --- include/linux/xsched.h | 5 ++++ kernel/xsched/Makefile | 1 + kernel/xsched/core.c | 4 +++ kernel/xsched/dmem.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 kernel/xsched/dmem.c diff --git a/include/linux/xsched.h b/include/linux/xsched.h index 60cb43b4631f..8809ab22a50c 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -474,4 +474,9 @@ void xsched_quota_refill(struct work_struct *work); #endif +#ifdef CONFIG_CGROUP_DMEM +/* Dmem interface */ +int xsched_dmem_init(void); +#endif /* CONFIG_CGROUP_DMEM */ + #endif /* !__LINUX_XSCHED_H__ */ diff --git a/kernel/xsched/Makefile b/kernel/xsched/Makefile index a6081a7aaf14..3e23012ea298 100644 --- a/kernel/xsched/Makefile +++ b/kernel/xsched/Makefile @@ -6,4 +6,5 @@ obj-y += core.o obj-$(CONFIG_XCU_SCHED_RT) += rt.o obj-$(CONFIG_XCU_SCHED_CFS) += cfs.o cfs_quota.o obj-$(CONFIG_CGROUP_XCU) += cgroup.o +obj-$(CONFIG_CGROUP_DMEM) += dmem.o endif diff --git a/kernel/xsched/core.c b/kernel/xsched/core.c index b23f2ca7820b..c6ec746448ef 100644 --- a/kernel/xsched/core.c +++ b/kernel/xsched/core.c @@ -530,6 +530,10 @@ __init int xsched_sched_init(void) xcu_cg_subsys_init(); #endif +#ifdef CONFIG_CGROUP_DMEM + xsched_dmem_init(); +#endif + return 0; } late_initcall(xsched_sched_init); diff --git a/kernel/xsched/dmem.c b/kernel/xsched/dmem.c new file mode 100644 index 000000000000..27e0c4b1a506 --- /dev/null +++ b/kernel/xsched/dmem.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Core kernel scheduler code for XPU device + * + * Copyright (C) 2025 Huawei Technologies Co., Ltd + * + * Author: Alexander Pavlenko <pavlenko.alexander@huawei.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ +#include <linux/err.h> +#include <linux/list.h> +#include <linux/xsched.h> +#include <linux/types.h> +#include <linux/cgroup_dmem.h> + +static struct dmem_cgroup_region *hbm_regions[XSCHED_NR_CUS]; + +struct xsched_dmem_pool { + uint64_t id; + struct dmem_cgroup_pool_state *pool; + struct list_head pool_node; +}; + +int xsched_dmem_init(void) +{ + // TODO: get max memory capacity from driver info or CONFIG + const size_t hbm_size_gb = 32; + const size_t hardcoded_hbm_size = hbm_size_gb * SZ_1G; + int dev_id, retval; + + // register HBM region for each device + for (dev_id = 0; dev_id < XSCHED_NR_CUS; dev_id++) { + hbm_regions[dev_id] = dmem_cgroup_register_region( + hardcoded_hbm_size, "HBM%d", dev_id); + + if (IS_ERR_OR_NULL(hbm_regions[dev_id])) { + XSCHED_ERR("Fail to register HBM region for xcu %d\n", dev_id); + retval = PTR_ERR(hbm_regions[dev_id]); + goto err_out; + } + XSCHED_INFO("register HBM%d %zuGB region(s) in dmem\n", dev_id, hbm_size_gb); + } + + return 0; + +err_out: + for (dev_id--; dev_id >= 0; dev_id--) { + dmem_cgroup_unregister_region(hbm_regions[dev_id]); + hbm_regions[dev_id] = NULL; + } + return retval; +} -- 2.34.1