History

misc: fastrpc: Add polling mode support for fastRPC driver

For any remote call to DSP, after sending an invocation message, the fastRPC driver waits for a glink response, during which the CPU can enter low power modes. This adds latency to the fastRPC call due to CPU wakeup and scheduling overhead. Add polling mode support where the fastRPC driver polls a shared memory location for completion after sending the invocation, avoiding CPU wakeup and scheduling latency and reducing fastRPC overhead. If the poll times out, the call falls back to the normal interrupt/glink-based completion path. Poll mode is only applied to dynamic modules running in a user PD (handle > FASTRPC_MAX_STATIC_HANDLE), since static/root-PD handles are not expected to benefit from, or require, this optimization. Support is advertised per SoC via fastrpc_soc_data, with a closed exception list for older platforms whose DSP firmware is known to support polling but which otherwise use the default soc_data. Poll mode can be enabled by userspace via the FASTRPC_IOCTL_SET_OPTION ioctl with the FASTRPC_POLL_MODE request id. Since context IDs (ctxid) are allocated from a fixed-size, per-channel cyclic IDR shared by all processes on a DSP, a context ID can be recycled for a new request soon after it is freed. In poll mode the context can be considered complete (and released) as soon as the poll memory is updated, while the corresponding glink COMPLETE response from the DSP may still be in flight. If that response arrives after the ctxid has been reused, it would otherwise match the new context and incorrectly signal completion for it while the DSP may still be operating on the new context's buffers. To prevent this, embed a monotonically increasing per-channel sequence number in the unused upper bits of the ctxid/message context and validate it in the rpmsg callback, dropping any response whose sequence number does not match the current owner of that ctxid slot.

Ekansh Gupta committed 3 months ago

Commit 96e62cc1 parent 62373b72 files · +215 −8Browse files

Showing the changes to include/uapi/misc (1 of 2 files). Show all

Unified · Split

include/uapi/misc/fastrpc.h+29−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
16#define FASTRPC_IOCTL_INIT_CREATE_STATIC _IOWR('R', 9, struct fastrpc_init_create_static)16#define FASTRPC_IOCTL_INIT_CREATE_STATIC _IOWR('R', 9, struct fastrpc_init_create_static)
17#define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map)17#define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map)
18#define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap)18#define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap)
19#define FASTRPC_IOCTL_SET_OPTION _IOWR('R', 12, struct fastrpc_ioctl_set_option)
19#define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability)20#define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability)
20 21
21/**22/**
@@ -67,6 +68,28 @@ enum fastrpc_proc_attr { · 45 unmodified lines
67/* Fastrpc attribute for memory protection of buffers */68/* Fastrpc attribute for memory protection of buffers */
68#define FASTRPC_ATTR_SECUREMAP (1)69#define FASTRPC_ATTR_SECUREMAP (1)
69 70
71/**
72 * FASTRPC_POLL_MODE - Enable/disable poll mode for FastRPC invocations
73 *
74 * Poll mode is an optimization that allows the CPU to poll shared memory
75 * for completion instead of waiting for an interrupt-based response.
76 * This reduces latency for fast-completing operations.
77 *
78 * Restrictions:
79 * - Only supported for USER_PD (User Protection Domain)
80 * - Only applies to dynamic modules (handle > 20)
81 * - Static modules always use interrupt-based completion
82 *
83 * Values:
84 * - 0: Disable poll mode (use interrupt-based completion)
85 * - 1: Enable poll mode (poll shared memory for completion)
86 */
87#define FASTRPC_POLL_MODE (1)
88
89/* Values for FASTRPC_POLL_MODE request */
90#define FASTRPC_POLL_MODE_DISABLE 0
91#define FASTRPC_POLL_MODE_ENABLE 1
92
70struct fastrpc_invoke_args {93struct fastrpc_invoke_args {
71 __u64 ptr;94 __u64 ptr;
72 __u64 length;95 __u64 length;
@@ -133,6 +156,12 @@ struct fastrpc_mem_unmap { · 60 unmodified lines
133 __s32 reserved[5];156 __s32 reserved[5];
134};157};
135 158
159struct fastrpc_ioctl_set_option {
160 __u32 request_id; /* Request type (e.g., FASTRPC_POLL_MODE) */
161 __u32 value; /* Request-specific value */
162 __s32 reserved[6];
163};
164
136struct fastrpc_ioctl_capability {165struct fastrpc_ioctl_capability {
137 __u32 unused; /* deprecated, ignored by the kernel */166 __u32 unused; /* deprecated, ignored by the kernel */
138 __u32 attribute_id;167 __u32 attribute_id;