{
struct hl_ctx_mgr *mgr = &hpriv->ctx_mgr;
struct hl_ctx *ctx;
- int rc;
+ int rc, id;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) {
hpriv->ctx = ctx;
hdev->user_ctx = ctx;
- mutex_lock(&mgr->ctx_lock);
- rc = idr_alloc(&mgr->ctx_handles, ctx, 1, 0, GFP_KERNEL);
- mutex_unlock(&mgr->ctx_lock);
-
+ rc = xa_alloc(&mgr->ctx_handles, &id, ctx, xa_limit_31b, GFP_KERNEL);
if (rc < 0) {
- dev_err(hdev->dev, "Failed to allocate IDR for a new CTX\n");
+ dev_err(hdev->dev, "Failed to allocate ID for a new CTX\n");
hl_ctx_free(hdev, ctx);
goto out_err;
}
*/
void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr)
{
- mutex_init(&mgr->ctx_lock);
- idr_init(&mgr->ctx_handles);
+ xa_init_flags(&mgr->ctx_handles, XA_FLAGS_ALLOC1);
}
/*
void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr)
{
struct hl_ctx *ctx;
- struct idr *idp;
- u32 id;
-
- idp = &mgr->ctx_handles;
+ unsigned long id;
- idr_for_each_entry(idp, ctx, id)
+ xa_for_each(&mgr->ctx_handles, id, ctx)
hl_ctx_free(hdev, ctx);
-
- idr_destroy(&mgr->ctx_handles);
- mutex_destroy(&mgr->ctx_lock);
}
/**
* struct hl_ctx_mgr - for handling multiple contexts.
- * @ctx_lock: protects ctx_handles.
- * @ctx_handles: idr to hold all ctx handles.
+ * @ctx_handles: holds all ctx handles.
*/
struct hl_ctx_mgr {
- struct mutex ctx_lock;
- struct idr ctx_handles;
+ struct xarray ctx_handles;
};