
From: Konstantin Meskhidze <konstantin.meskhidze@huawei.com> hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IC5EHB ----------------------------------------- Add xsched_ctx_init_xse() implementation: - Add 2 atomics kicks_pending_ctx_cnt and kicks_submited members to - xsched_entity structure. - Add GET_VS_TASK_TYPE macro helper. - Add xsched_xse_set_class() and bind_ctx_to_xcu() stubs. Add bind_ctx_to_xcu() implementation: - Add ctx_revmap hash table to save XCUs' history. - Add XCU_HASH_ORDER to set hashtable order. - Add additional data structure ctx_devid_revmap_data to xcu_group that is used to save XCU history in hashtable by devid. Signed-off-by: Konstantin Meskhidze <konstantin.meskhidze@huawei.com> Signed-off-by: Hui Tang <tanghui20@.huawei.com> Signed-off-by: Liu Kai <liukai284@huawei.com> Signed-off-by: Xia Fukun <xiafukun@huawei.com> --- include/linux/xcu_group.h | 11 ++++++ include/linux/xsched.h | 15 +++++++- kernel/xsched/core.c | 79 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/include/linux/xcu_group.h b/include/linux/xcu_group.h index c0168969c67a..93f732f84694 100644 --- a/include/linux/xcu_group.h +++ b/include/linux/xcu_group.h @@ -17,6 +17,17 @@ enum xcu_type { XCU_TYPE_XPU, }; +/** + * @group: value for this entry. + * @hash_node: hash node list. + * @dev_id: device id to bind with ctx. + */ +struct ctx_devid_revmap_data { + unsigned int dev_id; + struct xcu_group *group; + struct hlist_node hash_node; +}; + struct xcu_op_handler_params { int fd; struct xcu_group *group; diff --git a/include/linux/xsched.h b/include/linux/xsched.h index 7a25d2a7455b..47f0a43a72dc 100644 --- a/include/linux/xsched.h +++ b/include/linux/xsched.h @@ -2,6 +2,8 @@ #ifndef __LINUX_XSCHED_H__ #define __LINUX_XSCHED_H__ +#include <linux/hash.h> +#include <linux/hashtable.h> #include <linux/xcu_group.h> #include <linux/kref.h> #include <linux/vstream.h> @@ -31,6 +33,12 @@ #define XSCHED_EXIT_STUB() \ XSCHED_DEBUG(" -----* %s @ %s exited *-----\n", __func__, __FILE__) +#define XCU_HASH_ORDER 6 + +#define __GET_VS_TASK_TYPE(t) ((t)&0xFF) + +#define GET_VS_TASK_TYPE(vs_ptr) __GET_VS_TASK_TYPE((vs_ptr)->task_type) + enum xcu_state { XCU_INACTIVE, XCU_IDLE, @@ -77,6 +85,12 @@ struct xsched_entity { pid_t owner_pid; pid_t tgid; + /* Amount of pending kicks currently sitting on this context. */ + atomic_t kicks_pending_ctx_cnt; + + /* Amount of submitted kicks context, used for resched decision. */ + atomic_t submitted_one_kick; + /* File descriptor coming from an associated context * used for identifying a given xsched entity in * info and error prints. @@ -135,7 +149,6 @@ static inline struct xsched_context *ctx_find_by_tgid(pid_t tgid) return ret; } - static inline void xsched_init_vsm(struct vstream_metadata *vsm, struct vstream_info *vs, vstream_args_t *arg) { diff --git a/kernel/xsched/core.c b/kernel/xsched/core.c index 5064ecbbd179..3c20a493629e 100644 --- a/kernel/xsched/core.c +++ b/kernel/xsched/core.c @@ -36,6 +36,9 @@ struct xsched_cu *xsched_cu_mgr[XSCHED_NR_CUS]; struct list_head xsched_ctx_list; DEFINE_MUTEX(xsched_ctx_list_mutex); +static DEFINE_MUTEX(revmap_mutex); +static DEFINE_HASHTABLE(ctx_revmap, XCU_HASH_ORDER); + /* Frees a given vstream and also frees and dequeues it's context * if a given vstream is the last and only vstream attached to it's * corresponding context object. @@ -60,6 +63,45 @@ void xsched_task_free(struct kref *kref) kfree(ctx); } +int ctx_bind_to_xcu(vstream_info_t *vstream_info, struct xsched_context *ctx) +{ + struct ctx_devid_revmap_data *revmap_data; + struct xsched_cu *xcu_found = NULL; + uint32_t type = XCU_TYPE_XPU; + + /* Find XCU history. */ + hash_for_each_possible(ctx_revmap, revmap_data, hash_node, + (unsigned long)ctx->dev_id) { + if (revmap_data && revmap_data->group) { + /* Bind ctx to group xcu.*/ + ctx->xse.xcu = revmap_data->group->xcu; + return 0; + } + } + + revmap_data = kzalloc(sizeof(struct ctx_devid_revmap_data), GFP_KERNEL); + if (revmap_data == NULL) { + XSCHED_ERR("Revmap_data is NULL @ %s\n", __func__); + return -ENOMEM; + } + + xcu_found = xcu_find(&type, ctx->dev_id, vstream_info->channel_id); + if (!xcu_found) + return -EINVAL; + + /* Bind ctx to an XCU from channel group. */ + revmap_data->group = xcu_found->group; + ctx->xse.xcu = xcu_found; + vstream_info->xcu = xcu_found; + revmap_data->dev_id = vstream_info->dev_id; + XSCHED_DEBUG("Ctx bind to xcu %u @ %s\n", xcu_found->id, __func__); + + hash_add(ctx_revmap, &revmap_data->hash_node, + (unsigned long)ctx->dev_id); + + return 0; +} + int vstream_bind_to_xcu(vstream_info_t *vstream_info) { struct xsched_cu *xcu_found = NULL; @@ -110,11 +152,46 @@ struct xsched_cu *xcu_find(uint32_t *type, return group->xcu; } -int xsched_ctx_init_xse(struct xsched_context *ctx, struct vstream_info *vs) +int xsched_xse_set_class(struct xsched_entity *xse) { return 0; } +int xsched_ctx_init_xse(struct xsched_context *ctx, struct vstream_info *vs) +{ + int err = 0; + struct xsched_entity *xse = &ctx->xse; + + atomic_set(&xse->kicks_pending_ctx_cnt, 0); + atomic_set(&xse->submitted_one_kick, 0); + + xse->fd = ctx->fd; + xse->tgid = ctx->tgid; + + err = ctx_bind_to_xcu(vs, ctx); + if (err) { + XSCHED_ERR( + "Couldn't find valid xcu for vstream %u dev_id %u @ %s\n", + vs->id, vs->dev_id, __func__); + return -EINVAL; + } + + xse->ctx = ctx; + if (likely(vs->xcu != NULL)) + xse->xcu = vs->xcu; + + err = xsched_xse_set_class(xse); + if (err) { + XSCHED_ERR("Failed to set xse class @ %s\n", __func__); + return err; + } + + WRITE_ONCE(xse->on_rq, false); + + spin_lock_init(&xse->xse_lock); + return err; +} + static int xsched_schedule(void *input_xcu) { return 0; -- 2.34.1