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

Commit fe544196 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: npu: Allow context switch after processing IPC message"

parents 2f9a4a4b c2ef9eae
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -49,7 +49,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);
@@ -1630,7 +1630,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;
@@ -1638,6 +1638,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) {
@@ -1682,7 +1683,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:
@@ -1742,6 +1743,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:
@@ -1780,6 +1782,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:
@@ -1812,6 +1815,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:
@@ -1832,6 +1836,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:
@@ -1855,6 +1860,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:
@@ -1893,6 +1899,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:
@@ -1923,12 +1930,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");
@@ -1938,7 +1948,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:
@@ -2859,6 +2877,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);