From: Luben Tuikov <ltuikov89@gmail.com>
To: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>,
srini@kernel.org, linux-arm-msm@vger.kernel.org
Cc: gregkh@linuxfoundation.org, quic_bkumar@quicinc.com,
linux-kernel@vger.kernel.org, quic_chennak@quicinc.com,
dri-devel@lists.freedesktop.org, arnd@arndb.de,
dmitry.baryshkov@oss.qualcomm.com,
konrad.dybcio@oss.qualcomm.com, andersson@kernel.org
Subject: Re: [PATCH v8 4/4] misc: fastrpc: Add polling mode support for fastRPC driver
Date: Thu, 16 Apr 2026 04:17:40 -0400 [thread overview]
Message-ID: <8dc8c094-63ab-4f9c-867a-96b615dff2cf@gmail.com> (raw)
In-Reply-To: <20260415112530.4083240-5-ekansh.gupta@oss.qualcomm.com>
[-- Attachment #1.1.1: Type: text/plain, Size: 7161 bytes --]
Hi Ekansh,
Good work. A couple of notes below:
On 2026-04-15 07:25, Ekansh Gupta wrote:
> For any remote call to DSP, after sending an invocation message,
> fastRPC driver waits for glink response and during this time the
> CPU can go into low power modes. This adds latency to overall fastrpc
> call as CPU wakeup and scheduling latencies are included. Add polling
> mode support with which fastRPC driver will poll continuously on a
> memory after sending a message to remote subsystem which will eliminate
> CPU wakeup and scheduling latencies and reduce fastRPC overhead. In case
> poll timeout happens, the call will fallback to normal RPC mode. Poll
> mode can be enabled by user by using FASTRPC_IOCTL_SET_OPTION ioctl
> request with FASTRPC_POLL_MODE request id.
>
> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
> ---
> drivers/misc/fastrpc.c | 137 ++++++++++++++++++++++++++++++++++--
> include/uapi/misc/fastrpc.h | 25 +++++++
> 2 files changed, 155 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index c4a3547a5c7f..5311a4ba4bb7 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -24,6 +24,8 @@
> #include <linux/of_reserved_mem.h>
> #include <linux/bits.h>
> #include <linux/bitops.h>
> +#include <linux/compiler.h>
> +#include <linux/iopoll.h>
>
> #define ADSP_DOMAIN_ID (0)
> #define MDSP_DOMAIN_ID (1)
> @@ -38,6 +40,12 @@
> #define FASTRPC_CTX_MAX (256)
> #define FASTRPC_INIT_HANDLE 1
> #define FASTRPC_DSP_UTILITIES_HANDLE 2
> +/*
> + * Maximum handle value for static handles.
> + * Static handles are pre-defined, fixed numeric values statically assigned
> + * in the IDL file or FastRPC framework.
> + */
> +#define FASTRPC_MAX_STATIC_HANDLE (20)
> #define FASTRPC_CTXID_MASK GENMASK(15, 8)
> #define INIT_FILELEN_MAX (2 * 1024 * 1024)
> #define INIT_FILE_NAMELEN_MAX (128)
> @@ -106,6 +114,12 @@
>
> #define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscdev)
>
> +/* Poll response number from remote processor for call completion */
> +#define FASTRPC_POLL_RESPONSE (0xdecaf)
> +
> +/* Polling mode timeout limit */
> +#define FASTRPC_POLL_MAX_TIMEOUT_US (10000)
> +
> struct fastrpc_phy_page {
> dma_addr_t addr; /* dma address */
> u64 size; /* size of contiguous region */
> @@ -236,8 +250,14 @@ struct fastrpc_invoke_ctx {
> u32 sc;
> u64 *fdlist;
> u32 *crc;
> + /* Poll memory that DSP updates */
> + u32 *poll;
Perhaps "poll_addr"? "poll" seems just too generic.
> u64 ctxid;
> u64 msg_sz;
> + /* work done status flag */
> + bool is_work_done;
> + /* process updates poll memory instead of glink response */
> + bool is_polled;
> struct kref refcount;
> struct list_head node; /* list of ctxs */
> struct completion work;
> @@ -308,6 +328,8 @@ struct fastrpc_user {
> int client_id;
> int pd;
> bool is_secure_dev;
> + /* Flags poll mode state */
> + bool poll_mode;
> /* Lock for lists */
> spinlock_t lock;
> /* lock for allocations */
> @@ -923,7 +945,8 @@ static int fastrpc_get_meta_size(struct fastrpc_invoke_ctx *ctx)
> sizeof(struct fastrpc_invoke_buf) +
> sizeof(struct fastrpc_phy_page)) * ctx->nscalars +
> sizeof(u64) * FASTRPC_MAX_FDLIST +
> - sizeof(u32) * FASTRPC_MAX_CRCLIST;
> + sizeof(u32) * FASTRPC_MAX_CRCLIST +
> + sizeof(u32);
>
> return size;
> }
> @@ -1019,6 +1042,9 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
> list = fastrpc_invoke_buf_start(rpra, ctx->nscalars);
> pages = fastrpc_phy_page_start(list, ctx->nscalars);
> ctx->fdlist = (u64 *)(pages + ctx->nscalars);
> + ctx->poll = (u32 *)((uintptr_t)ctx->fdlist + sizeof(u64) * FASTRPC_MAX_FDLIST +
> + sizeof(u32) * FASTRPC_MAX_CRCLIST);
> +
> args = (uintptr_t)ctx->buf->virt + metalen;
> rlen = pkt_size - metalen;
> ctx->rpra = rpra;
> @@ -1188,6 +1214,74 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx,
>
> }
>
> +static inline u32 fastrpc_poll_op(void *p)
> +{
> + struct fastrpc_invoke_ctx *ctx = p;
> +
> + dma_rmb();
> + return READ_ONCE(*ctx->poll);
I think you're better off using readl() here, but see my comment below, which obviates this function.
> +}
> +
> +static int poll_for_remote_response(struct fastrpc_invoke_ctx *ctx)
> +{
> + u32 val;
> + int ret;
> +
> + /*
> + * Poll until DSP writes FASTRPC_POLL_RESPONSE into *ctx->poll
> + * or until another path marks the work done.
> + */
> + ret = read_poll_timeout_atomic(fastrpc_poll_op, val,
> + (val == FASTRPC_POLL_RESPONSE) || ctx->is_work_done, 1,
> + FASTRPC_POLL_MAX_TIMEOUT_US, false, ctx);
Is there any reason you're not using readl_poll_timeout_atomic() as documented in linux/iopoll.h?
Does readl() not satisfy the read operation in fastrpc_poll_op()?
How can ctx->is_work_done be updated here? Perhaps you just want to use "val == FASTRPC_POLL_RESPONSE" as a condition here...
> +
> + if (!ret && val == FASTRPC_POLL_RESPONSE) {
> + ctx->is_work_done = true;
> + ctx->retval = 0;
> + }
> +
> + if (ret == -ETIMEDOUT)
> + ret = -EIO;
> +
> + return ret;
> +}
> +
> +static inline int fastrpc_wait_for_response(struct fastrpc_invoke_ctx *ctx,
> + u32 kernel)
What is "kernel" and why is it a u32 when it is used as a "bool"? Perhaps a better name can be had?
> +{
> + int err = 0;
> +
> + if (kernel) {
> + if (!wait_for_completion_timeout(&ctx->work, 10 * HZ))
> + err = -ETIMEDOUT;
> + } else {
> + err = wait_for_completion_interruptible(&ctx->work);
> + }
> +
> + return err;
> +}
> +
> +static int fastrpc_wait_for_completion(struct fastrpc_invoke_ctx *ctx,
> + u32 kernel)
> +{
> + int err;
> +
> + do {
> + if (ctx->is_polled) {
> + err = poll_for_remote_response(ctx);
> + /* If polling timed out, move to normal response mode */
> + if (err)
> + ctx->is_polled = false;
> + } else {
> + err = fastrpc_wait_for_response(ctx, kernel);
> + if (err)
> + return err;
> + }
> + } while (!ctx->is_work_done);
Perhaps you want to also check "err" here to make the exit condition more explicit. (The invariant in do-while loops is generally directly determined by something within the loop and generally not implicit.)
Is it possible that in poll_for_remote_response() you get 0 as a poll result and val is not equal to FASTRCPC_POLL_RESPONSE? In such a case, this may hang. (Is a hang desired here?)
Is it possible that if polling is enabled, then you want to poll only once, and if unsuccessful, or successful but "!work_done", then transition to fastrpc_wait_for_response() and return, without looping? (since polling is looping after all...)
> +
> + return 0;
"err" is always initialized so you can return "err" here if you exit with "err" as part of the exit condition. (And if you add "!err &&" in the loop invariant, then you don't need (if (err) return err;) after "fastrpc_wait_for_response()").
--
Regards,
Luben
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 677 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2026-04-16 8:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 11:25 [PATCH v8 0/4] misc: fastrpc: Add polling mode support Ekansh Gupta
2026-04-15 11:25 ` [PATCH v8 1/4] misc: fastrpc: Move fdlist to invoke context structure Ekansh Gupta
2026-04-15 11:25 ` [PATCH v8 2/4] misc: fastrpc: Replace hardcoded ctxid mask with GENMASK Ekansh Gupta
2026-04-15 11:25 ` [PATCH v8 3/4] misc: fastrpc: Expand context ID mask for DSP polling mode support Ekansh Gupta
2026-04-15 11:25 ` [PATCH v8 4/4] misc: fastrpc: Add polling mode support for fastRPC driver Ekansh Gupta
2026-04-16 8:17 ` Luben Tuikov [this message]
2026-04-16 13:58 ` Ekansh Gupta
2026-04-17 3:54 ` Luben Tuikov
2026-04-16 10:55 ` Dmitry Baryshkov
2026-04-16 14:02 ` Ekansh Gupta
2026-04-17 13:18 ` Dmitry Baryshkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8dc8c094-63ab-4f9c-867a-96b615dff2cf@gmail.com \
--to=ltuikov89@gmail.com \
--cc=andersson@kernel.org \
--cc=arnd@arndb.de \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ekansh.gupta@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_bkumar@quicinc.com \
--cc=quic_chennak@quicinc.com \
--cc=srini@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®