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

Commit 4ebb5dec authored by Tharun Kumar Merugu's avatar Tharun Kumar Merugu Committed by Mohammed Nayeem Ur Rahman
Browse files

msm: adsprpc: do pm stay awake vote in rpmsg callback



Vote with PM to keep the CPU awake in the rpmsg interrupt callback
itself, instead of voting from the fastrpc thread after it is
woken up and scheduled, to handle race between actual  remote
subsystem response and context interruption because of CPU going
into suspend.

Change-Id: I289f4307aacc895aa73c51360f7cf83131a72a13
Acked-by: default avatarThyagarajan Venkatanarayanan <venkatan@qti.qualcomm.com>
Signed-off-by: default avatarTharun Kumar Merugu <mtharu@codeaurora.org>
Signed-off-by: default avatarMohammed Nayeem Ur Rahman <mohara@codeaurora.org>
parent a4a6a33b
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -232,6 +232,7 @@ struct smq_invoke_ctx {
	uint32_t *crc;
	unsigned int magic;
	uint64_t ctxid;
	bool pm_awake_voted;
};

struct fastrpc_ctx_lst {
@@ -451,6 +452,9 @@ static struct fastrpc_channel_ctx gcinfo[NUM_CHANNELS] = {
static int hlosvm[1] = {VMID_HLOS};
static int hlosvmperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC};

static void fastrpc_pm_awake(int fl_wake_enable, bool *pm_awake_voted);
static void fastrpc_pm_relax(bool *pm_awake_voted);

static inline int64_t getnstimediff(struct timespec *start)
{
	int64_t ns;
@@ -1216,6 +1220,7 @@ static int context_alloc(struct fastrpc_file *fl, uint32_t kernel,
	ctx->tgid = fl->tgid;
	init_completion(&ctx->work);
	ctx->magic = FASTRPC_CTX_MAGIC;
	ctx->pm_awake_voted = false;

	spin_lock(&fl->hlock);
	hlist_add_head(&ctx->hn, &clst->pending);
@@ -1286,6 +1291,7 @@ static void context_free(struct smq_invoke_ctx *ctx)
static void context_notify_user(struct smq_invoke_ctx *ctx, int retval)
{
	ctx->retval = retval;
	fastrpc_pm_awake(ctx->fl->wake_enable, &ctx->pm_awake_voted);
	complete(&ctx->work);
}

@@ -1878,7 +1884,7 @@ static void fastrpc_init(struct fastrpc_apps *me)
	me->channel[CDSP_DOMAIN_ID].secure = NON_SECURE_CHANNEL;
}

static inline void fastrpc_pm_awake(int fl_wake_enable, int *wake_enable)
static inline void fastrpc_pm_awake(int fl_wake_enable, bool *pm_awake_voted)
{
	struct fastrpc_apps *me = &gfa;

@@ -1890,14 +1896,14 @@ static inline void fastrpc_pm_awake(int fl_wake_enable, int *wake_enable)
		__pm_stay_awake(me->wake_source);
	me->wake_count++;
	spin_unlock(&me->hlock);
	*wake_enable = 1;
	*pm_awake_voted = true;
}

static inline void fastrpc_pm_relax(int *wake_enable)
static inline void fastrpc_pm_relax(bool *pm_awake_voted)
{
	struct fastrpc_apps *me = &gfa;

	if (!(*wake_enable))
	if (!(*pm_awake_voted))
		return;

	spin_lock(&me->hlock);
@@ -1906,7 +1912,7 @@ static inline void fastrpc_pm_relax(int *wake_enable)
	if (!me->wake_count)
		__pm_relax(me->wake_source);
	spin_unlock(&me->hlock);
	*wake_enable = 0;
	*pm_awake_voted = false;
}

static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,
@@ -1915,13 +1921,12 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,
{
	struct smq_invoke_ctx *ctx = NULL;
	struct fastrpc_ioctl_invoke *invoke = &inv->inv;
	int cid = fl->cid;
	int interrupted = 0;
	int err = 0, wake_enable = 0;
	int err = 0, interrupted = 0, cid = fl->cid;
	struct timespec invoket = {0};
	int64_t *perf_counter = getperfcounter(fl, PERF_COUNT);
	bool pm_awake_voted = false;

	fastrpc_pm_awake(fl->wake_enable, &wake_enable);
	fastrpc_pm_awake(fl->wake_enable, &pm_awake_voted);
	if (fl->profile)
		getnstimeofday(&invoket);

@@ -1982,14 +1987,13 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,
	if (err)
		goto bail;
 wait:
	fastrpc_pm_relax(&wake_enable);
	fastrpc_pm_relax(&pm_awake_voted);
	if (kernel)
		wait_for_completion(&ctx->work);
	else
		interrupted = wait_for_completion_interruptible(&ctx->work);

	if (interrupted != -ERESTARTSYS)
		fastrpc_pm_awake(fl->wake_enable, &wake_enable);
	pm_awake_voted = ctx->pm_awake_voted;
	VERIFY(err, 0 == (err = interrupted));
	if (err)
		goto bail;
@@ -2029,7 +2033,7 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,
				*count = *count+1;
		}
	}
	fastrpc_pm_relax(&wake_enable);
	fastrpc_pm_relax(&pm_awake_voted);
	return err;
}