提交 86d5307a 编写于 作者: O Oded Gabbay

habanalabs: rename user_ctx as compute_ctx

This patch renames the "user_ctx" field in the device structure to
"compute_ctx". This better reflects the meaning of this context.

In addition, we also check in the ctx_fini() that the debug mode should be
disabled only if the context being destroyed is the compute context. This
has no effect right now as we only have a single process and a single
context, but this makes the code more ready for multiple process support.
Signed-off-by: NOded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 02e921e4
...@@ -26,12 +26,13 @@ static void hl_ctx_fini(struct hl_ctx *ctx) ...@@ -26,12 +26,13 @@ static void hl_ctx_fini(struct hl_ctx *ctx)
dma_fence_put(ctx->cs_pending[i]); dma_fence_put(ctx->cs_pending[i]);
if (ctx->asid != HL_KERNEL_ASID_ID) { if (ctx->asid != HL_KERNEL_ASID_ID) {
/* /* The engines are stopped as there is no executing CS, but the
* The engines are stopped as there is no executing CS, but the
* Coresight might be still working by accessing addresses * Coresight might be still working by accessing addresses
* related to the stopped engines. Hence stop it explicitly. * related to the stopped engines. Hence stop it explicitly.
* Stop only if this is the compute context, as there can be
* only one compute context
*/ */
if (hdev->in_debug) if ((hdev->in_debug) && (hdev->compute_ctx == ctx))
hl_device_set_debug_mode(hdev, false); hl_device_set_debug_mode(hdev, false);
hl_vm_ctx_fini(ctx); hl_vm_ctx_fini(ctx);
...@@ -85,9 +86,11 @@ int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv) ...@@ -85,9 +86,11 @@ int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv)
hl_hpriv_get(hpriv); hl_hpriv_get(hpriv);
ctx->hpriv = hpriv; ctx->hpriv = hpriv;
/* TODO: remove for multiple contexts */ /* TODO: remove for multiple contexts per process */
hpriv->ctx = ctx; hpriv->ctx = ctx;
hdev->user_ctx = ctx;
/* TODO: remove the following line for multiple process support */
hdev->compute_ctx = ctx;
return 0; return 0;
......
...@@ -370,7 +370,7 @@ static int mmu_show(struct seq_file *s, void *data) ...@@ -370,7 +370,7 @@ static int mmu_show(struct seq_file *s, void *data)
if (dev_entry->mmu_asid == HL_KERNEL_ASID_ID) if (dev_entry->mmu_asid == HL_KERNEL_ASID_ID)
ctx = hdev->kernel_ctx; ctx = hdev->kernel_ctx;
else else
ctx = hdev->user_ctx; ctx = hdev->compute_ctx;
if (!ctx) { if (!ctx) {
dev_err(hdev->dev, "no ctx available\n"); dev_err(hdev->dev, "no ctx available\n");
...@@ -533,7 +533,7 @@ static bool hl_is_device_va(struct hl_device *hdev, u64 addr) ...@@ -533,7 +533,7 @@ static bool hl_is_device_va(struct hl_device *hdev, u64 addr)
static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr, static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
u64 *phys_addr) u64 *phys_addr)
{ {
struct hl_ctx *ctx = hdev->user_ctx; struct hl_ctx *ctx = hdev->compute_ctx;
u64 hop_addr, hop_pte_addr, hop_pte; u64 hop_addr, hop_pte_addr, hop_pte;
u64 offset_mask = HOP4_MASK | OFFSET_MASK; u64 offset_mask = HOP4_MASK | OFFSET_MASK;
int rc = 0; int rc = 0;
......
...@@ -59,7 +59,7 @@ static void hpriv_release(struct kref *ref) ...@@ -59,7 +59,7 @@ static void hpriv_release(struct kref *ref)
atomic_dec(&hdev->fd_open_cnt); atomic_dec(&hdev->fd_open_cnt);
/* This allows a new user context to open the device */ /* This allows a new user context to open the device */
hdev->user_ctx = NULL; hdev->compute_ctx = NULL;
} }
void hl_hpriv_get(struct hl_fpriv *hpriv) void hl_hpriv_get(struct hl_fpriv *hpriv)
...@@ -590,7 +590,7 @@ static void device_kill_open_processes(struct hl_device *hdev) ...@@ -590,7 +590,7 @@ static void device_kill_open_processes(struct hl_device *hdev)
} }
if (atomic_read(&hdev->fd_open_cnt)) { if (atomic_read(&hdev->fd_open_cnt)) {
task = get_pid_task(hdev->user_ctx->hpriv->taskpid, task = get_pid_task(hdev->compute_ctx->hpriv->taskpid,
PIDTYPE_PID); PIDTYPE_PID);
if (task) { if (task) {
dev_info(hdev->dev, "Killing user processes\n"); dev_info(hdev->dev, "Killing user processes\n");
...@@ -760,9 +760,9 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset, ...@@ -760,9 +760,9 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,
hl_cq_reset(hdev, &hdev->completion_queue[i]); hl_cq_reset(hdev, &hdev->completion_queue[i]);
/* Make sure the context switch phase will run again */ /* Make sure the context switch phase will run again */
if (hdev->user_ctx) { if (hdev->compute_ctx) {
atomic_set(&hdev->user_ctx->thread_ctx_switch_token, 1); atomic_set(&hdev->compute_ctx->thread_ctx_switch_token, 1);
hdev->user_ctx->thread_ctx_switch_wait_token = 0; hdev->compute_ctx->thread_ctx_switch_wait_token = 0;
} }
/* Finished tear-down, starting to re-initialize */ /* Finished tear-down, starting to re-initialize */
...@@ -793,7 +793,7 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset, ...@@ -793,7 +793,7 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,
goto out_err; goto out_err;
} }
hdev->user_ctx = NULL; hdev->compute_ctx = NULL;
rc = hl_ctx_init(hdev, hdev->kernel_ctx, true); rc = hl_ctx_init(hdev, hdev->kernel_ctx, true);
if (rc) { if (rc) {
...@@ -970,7 +970,7 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) ...@@ -970,7 +970,7 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
goto mmu_fini; goto mmu_fini;
} }
hdev->user_ctx = NULL; hdev->compute_ctx = NULL;
rc = hl_ctx_init(hdev, hdev->kernel_ctx, true); rc = hl_ctx_init(hdev, hdev->kernel_ctx, true);
if (rc) { if (rc) {
......
...@@ -910,7 +910,7 @@ struct hl_debug_params { ...@@ -910,7 +910,7 @@ struct hl_debug_params {
* @hdev: habanalabs device structure. * @hdev: habanalabs device structure.
* @filp: pointer to the given file structure. * @filp: pointer to the given file structure.
* @taskpid: current process ID. * @taskpid: current process ID.
* @ctx: current executing context. * @ctx: current executing context. TODO: remove for multiple ctx per process
* @ctx_mgr: context manager to handle multiple context for this FD. * @ctx_mgr: context manager to handle multiple context for this FD.
* @cb_mgr: command buffer manager to handle multiple buffers for this FD. * @cb_mgr: command buffer manager to handle multiple buffers for this FD.
* @debugfs_list: list of relevant ASIC debugfs. * @debugfs_list: list of relevant ASIC debugfs.
...@@ -921,7 +921,7 @@ struct hl_fpriv { ...@@ -921,7 +921,7 @@ struct hl_fpriv {
struct hl_device *hdev; struct hl_device *hdev;
struct file *filp; struct file *filp;
struct pid *taskpid; struct pid *taskpid;
struct hl_ctx *ctx; /* TODO: remove for multiple ctx */ struct hl_ctx *ctx;
struct hl_ctx_mgr ctx_mgr; struct hl_ctx_mgr ctx_mgr;
struct hl_cb_mgr cb_mgr; struct hl_cb_mgr cb_mgr;
struct list_head debugfs_list; struct list_head debugfs_list;
...@@ -1199,7 +1199,7 @@ struct hl_device_reset_work { ...@@ -1199,7 +1199,7 @@ struct hl_device_reset_work {
* @hl_debugfs: device's debugfs manager. * @hl_debugfs: device's debugfs manager.
* @cb_pool: list of preallocated CBs. * @cb_pool: list of preallocated CBs.
* @cb_pool_lock: protects the CB pool. * @cb_pool_lock: protects the CB pool.
* @user_ctx: current user context executing. * @compute_ctx: current compute context executing.
* @dram_used_mem: current DRAM memory consumption. * @dram_used_mem: current DRAM memory consumption.
* @timeout_jiffies: device CS timeout value. * @timeout_jiffies: device CS timeout value.
* @max_power: the max power of the device, as configured by the sysadmin. This * @max_power: the max power of the device, as configured by the sysadmin. This
...@@ -1276,8 +1276,7 @@ struct hl_device { ...@@ -1276,8 +1276,7 @@ struct hl_device {
struct list_head cb_pool; struct list_head cb_pool;
spinlock_t cb_pool_lock; spinlock_t cb_pool_lock;
/* TODO: remove user_ctx for multiple process support */ struct hl_ctx *compute_ctx;
struct hl_ctx *user_ctx;
atomic64_t dram_used_mem; atomic64_t dram_used_mem;
u64 timeout_jiffies; u64 timeout_jiffies;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册