Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5c298ba authored by Da Hoon Pyun's avatar Da Hoon Pyun
Browse files

msm: npu: Allow context switch after processing IPC message



Some of the IPC message requires long processing time. If there
are multiple messages in the queue, driver will finish processing
all of them before user process can be waken up. This change is to
force context switch each time after processing each IPC message
to allow user process to have a chance to run.

Change-Id: If7295c85dfb7daab8ad7d4d31b5b2b79f2ff1186
Signed-off-by: default avatarDa Hoon Pyun <dpyun@codeaurora.org>
parent 3a7043cb
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ static void free_network(struct npu_host_ctx *ctx, struct npu_client *client,
	int64_t id);
static int network_get(struct npu_network *network);
static int network_put(struct npu_network *network);
static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg);
static int app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg);
static void log_msg_proc(struct npu_device *npu_dev, uint32_t *msg);
static void host_session_msg_hdlr(struct npu_device *npu_dev);
static void host_session_log_hdlr(struct npu_device *npu_dev);
@@ -1593,7 +1593,7 @@ int npu_process_kevent(struct npu_client *client, struct npu_kevent *kevt)
	return ret;
}

static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
static int app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
{
	uint32_t msg_id;
	struct npu_network *network = NULL;
@@ -1601,6 +1601,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
	struct npu_device *npu_dev = host_ctx->npu_dev;
	struct npu_network_cmd *network_cmd = NULL;
	struct npu_misc_cmd *misc_cmd = NULL;
	int need_ctx_switch = 0;

	msg_id = msg[1];
	switch (msg_id) {
@@ -1645,7 +1646,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
				NPU_ERR("queue npu event failed\n");
		}
		network_put(network);

		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_EXECUTE_V2_DONE:
@@ -1705,6 +1706,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
			complete(&network_cmd->cmd_done);
		}
		network_put(network);
		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_LOAD_DONE:
@@ -1743,6 +1745,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)

		complete(&network_cmd->cmd_done);
		network_put(network);
		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_UNLOAD_DONE:
@@ -1775,6 +1778,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)

		complete(&network_cmd->cmd_done);
		network_put(network);
		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_LOOPBACK_DONE:
@@ -1795,6 +1799,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)

		misc_cmd->ret_status = lb_rsp_pkt->header.status;
		complete_all(&misc_cmd->cmd_done);
		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_SET_PROPERTY_DONE:
@@ -1818,6 +1823,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)

		misc_cmd->ret_status = prop_rsp_pkt->header.status;
		complete(&misc_cmd->cmd_done);
		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_GET_PROPERTY_DONE:
@@ -1856,6 +1862,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
		}

		complete_all(&misc_cmd->cmd_done);
		need_ctx_switch = 1;
		break;
	}
	case NPU_IPC_MSG_GENERAL_NOTIFY:
@@ -1886,12 +1893,15 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
			msg_id);
		break;
	}

	return need_ctx_switch;
}

static void host_session_msg_hdlr(struct npu_device *npu_dev)
{
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;

retry:
	mutex_lock(&host_ctx->lock);
	if (host_ctx->fw_state != FW_ENABLED) {
		NPU_WARN("handle npu session msg when FW is disabled\n");
@@ -1901,7 +1911,15 @@ static void host_session_msg_hdlr(struct npu_device *npu_dev)
	while (npu_host_ipc_read_msg(npu_dev, IPC_QUEUE_APPS_RSP,
		host_ctx->ipc_msg_buf) == 0) {
		NPU_DBG("received from msg queue\n");
		app_msg_proc(host_ctx, host_ctx->ipc_msg_buf);
		if (app_msg_proc(host_ctx, host_ctx->ipc_msg_buf)) {
			/*
			 * force context switch to let user
			 * process have chance to run
			 */
			mutex_unlock(&host_ctx->lock);
			usleep_range(500, 501);
			goto retry;
		}
	}

skip_read_msg:
@@ -2776,6 +2794,8 @@ int32_t npu_host_exec_network_v2(struct npu_client *client,
		exec_ioctl->stats_buf_size = 0;
	}


	NPU_DBG("Execute done %x\n", ret);
free_exec_cmd:
	npu_dequeue_network_cmd(network, exec_cmd);
	npu_free_network_cmd(host_ctx, exec_cmd);