rt_ipc: a new IPC mechanism called rt_ipc (real-time IPC)
Subsystems (5)
RFC 1/1 rt_ipc: a new IPC mechanism called rt_ipc (real-time IPC)
This patch set proposes a new IPC mechanism for the Linux kernel called rt_ipc (real-time IPC). This is refers to this paper: https://www.usenix.org/legacy/publications/library/proceedings/sf94/full_papers/ford.pdf
Similar in concept to Android Binder or Linux local sockets, rt_ipc is designed with a 'migrating thread model' to achieve significant real-time performance advantages.
Motivation
The primary motivation behind rt_ipc is to provide a high-performance, real-time IPC mechanism that addresses the limitations of traditional IPC methods, particularly concerning latency and priority management. This is achieved by implementing an IPC mechanism based on the migrating thread model, where a single thread abstraction moves between tasks during an RPC, with the server code being passively executed.
The value rt_ipc provides can be elaborated along these axes:
1. Accelerated Communication Performance:
Traditional IPC mechanisms, particularly those based on the 'static thread model', involve two distinct threads (client and server) and necessitate multiple thread-to-thread context switches, synchronization, and rescheduling.
This process introduces overhead, including scheduler delays due to wait and wake-up operations. In contrast, rt_ipc leverages a migrating thread model where the entire RPC operation is performed by a single thread that temporarily transitions into the server task. This design eliminates the need for synchronization, rescheduling, or a full context switch, significantly reducing communication latency. Preliminary benchmarks demonstrate a notable performance improvement:
for 1,000,000 server-client data exchanges, rt_ipc completes in approximately 1.055 seconds, whereas traditional Linux local sockets require 3.35 seconds.
2. Optimized Context Management:
The migrating thread model in rt_ipc avoids the overhead of a complete process context switch. Instead, only a partial context switch is performed where the kernel switches the address space and a subset of CPU registers, such as the user stack pointer, without switching threads or priorities, and without involving the scheduler. This approach simplifies kernel code and improves RPC performance.
3. Prevention of Priority Inversion:
proxy-exec can solve the scheduling priority inversion problem: https://github.com/johnstultz-work/linux-dev/
But rt_ipc provides different solutions:
In systems utilizing a static thread model, when a high-priority client initiates an RPC, control is transferred to a separate server thread, which may have its own independent scheduling parameters and attributes. This can lead to classic problems such as starvation and priority inversion, where a high-priority client is forced to contend with lower-priority server threads. rt_ipc addresses this by allowing the server's function to directly inherit the client process's attributes. By having the client's thread migrate and execute the server's code,
the client's own computational resources (including its priority and scheduling attributes) are utilized to provide services to itself. This inherent mechanism within the migrating thread model effectively mitigates the priority inversion problem.
--- arch/x86/entry/syscalls/syscall_64.tbl | 3 + arch/x86/include/asm/rt_ipc.h | 78 ++++++ arch/x86/kernel/Makefile | 2 + arch/x86/kernel/rt_ipc.c | 361 +++++++++++++++++++++++++ arch/x86/kernel/signal.c | 41 +-- include/linux/rt_ipc.h | 11 + include/linux/sched.h | 7 +- init/Kconfig | 4 + init/init_task.c | 4 + ipc/Makefile | 1 + ipc/rt_ipc.c | 141 ++++++++++ kernel/exit.c | 4 +- kernel/fork.c | 7 +- kernel/sched/core.c | 36 +++ tools/rt_ipc_userspace/Makefile | 13 + tools/rt_ipc_userspace/rt_ipc_action.c | 162 +++++++++++ tools/rt_ipc_userspace/rt_ipc_action.h | 56 ++++ tools/rt_ipc_userspace/rt_ipc_client.c | 89 ++++++ tools/rt_ipc_userspace/rt_ipc_server.c | 64 +++++ 19 files changed, 1062 insertions(+), 22 deletions(-) create mode 100644 arch/x86/include/asm/rt_ipc.h create mode 100644 arch/x86/kernel/rt_ipc.c create mode 100644 include/linux/rt_ipc.h create mode 100644 ipc/rt_ipc.c create mode 100644 tools/rt_ipc_userspace/Makefile create mode 100755 tools/rt_ipc_userspace/rt_ipc_action.c create mode 100755 tools/rt_ipc_userspace/rt_ipc_action.h create mode 100755 tools/rt_ipc_userspace/rt_ipc_client.c create mode 100755 tools/rt_ipc_userspace/rt_ipc_server.c
arch/x86/entry/syscalls/syscall_64.tbl +3 -0
@@ -391,6 +391,9 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common rt_ipc_register sys_rt_ipc_register +469 common rt_ipc_invoke sys_rt_ipc_invoke +470 common rt_ipc_return sys_rt_ipc_return # # Due to a historical design error, certain syscalls are numbered differently
arch/x86/include/asm/rt_ipc.h new file +78 -0
79 lines not on this page · raw message
arch/x86/kernel/Makefile +2 -0
@@ -166,3 +166,5 @@ ifeq ($(CONFIG_X86_64),y) obj-$(CONFIG_MMCONF_FAM10H) += mmconf-fam10h_64.o obj-y += vsmp_64.o endif + +obj-$(CONFIG_RT_IPC) += rt_ipc.o
arch/x86/kernel/rt_ipc.c new file +361 -0
361 lines not on this page · raw message
arch/x86/kernel/signal.c +22 -19
55 lines not on this page · raw message
include/linux/rt_ipc.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_RT_IPC_H__ +#define __LINUX_RT_IPC_H__ + +#ifdef CONFIG_RT_IPC +#include <asm/rt_ipc.h> + +void rt_ipc_deregister (struct task_struct *tsk); +#endif + +#endif /* __LINUX_RT_IPC_H__ */
include/linux/sched.h +6 -1
@@ -47,6 +47,7 @@#include <linux/uidgid_types.h> #include <linux/tracepoint-defs.h> #include <asm/kmap_size.h> +#include <linux/rt_ipc.h> /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context ;
@@ -1625,7 +1626,11 @@ struct task_struct {#ifdef CONFIG_RETHOOK struct llist_head rethooks;#endif - +#ifdef CONFIG_RT_IPC +struct list_head rt_ipc_activation_free; +struct list_head rt_ipc_activation_in_use; +spinlock_t rt_ipc_lock; +#endif #ifdef CONFIG_ARCH_HAS_PARANOID_L1D_FLUSH /* * If L1D flush is supported on mm context switch
init/Kconfig +4 -0
@@ -437,6 +437,10 @@ config SYSVIPC_COMPAT def_bool y depends on COMPAT && SYSVIPC +config RT_IPC + bool "Migrating thread model" + def_bool n + config POSIX_MQUEUE bool "POSIX Message Queues" depends on NET
init/init_task.c +4 -0
@@ -143,6 +143,10 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = { .timer_slack_ns = 50000, /* 50 usec default slack */ .thread_pid = &init_struct_pid, .thread_node =LIST_HEAD_INIT (init_signals.thread_head), +#ifdef CONFIG_RT_IPC + .rt_ipc_activation_in_use =LIST_HEAD_INIT (init_task.rt_ipc_activation_in_use), + .rt_ipc_activation_free = LIST_HEAD_INIT(init_task.rt_ipc_activation_free), +#endif #ifdef CONFIG_AUDIT .loginuid =INVALID_UID , .sessionid = AUDIT_SID_UNSET,
ipc/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o obj-$(CONFIG_IPC_NS) += namespace.o obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o +obj-$(CONFIG_RT_IPC) += rt_ipc.o
ipc/rt_ipc.c new file +141 -0
142 lines not on this page · raw message
kernel/exit.c +3 -1
@@ -963,7 +963,9 @@ void __noreturn do_exit(long code)exit_task_namespaces (tsk);exit_task_work (tsk);exit_thread (tsk); - +#ifdef CONFIG_RT_IPC +rt_ipc_deregister (tsk); +#endif sched_autogroup_exit_task (tsk);cgroup_exit (tsk);
kernel/fork.c +6 -1
@@ -122,6 +122,8 @@#include <kunit/visibility.h> +#include <linux/rt_ipc.h> +/* * Minimum number of threads to boot the kernel */
@@ -2418,7 +2420,10 @@ __latent_entropy struct task_struct *copy_process(user_events_fork (p, clone_flags);copy_oom_score_adj (clone_flags, p); - +#ifdef CONFIG_RT_IPC +INIT_LIST_HEAD (&p->rt_ipc_activation_in_use); +INIT_LIST_HEAD (&p->rt_ipc_activation_free); +#endif return p; bad_fork_core_free:
kernel/sched/core.c +36 -0
@@ -5400,6 +5400,42 @@ context_switch(struct rq *rq, struct task_struct *prev,return finish_task_switch (prev); } +#ifdef CONFIG_RT_IPC +void rt_ipc_context_switch (struct task_struct *next) +{ +struct task_struct *prev; +unsigned long flags; +struct rq *rq; +int cpu; + + cpu =smp_processor_id (); + rq =cpu_rq (cpu); + prev = rq->curr; + +raw_spin_rq_lock_irqsave (rq, flags); + +membarrier_switch_mm (rq, prev->active_mm, next->mm); +/* +* sys_membarrier() requires an smp_mb() between setting +* rq->curr / membarrier_switch_mm() and returning to userspace. +* +* The below provides this either through switch_mm(), or in +* case 'prev->active_mm == next->mm' through +* finish_task_switch()'s mmdrop(). +*/ +switch_mm_irqs_off (prev->active_mm, next->mm, next); +lru_gen_use_mm (next->mm); + +/* switch_mm_cid() requires the memory barriers above. */ +// switch_mm_cid(rq, prev, next); + +__switch_to (prev, next); +barrier (); + +raw_spin_rq_unlock_irqrestore (rq, flags); +} +#endif +/* * nr_running and nr_context_switches: *
tools/rt_ipc_userspace/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS = -Wall -Wextra -g -I. +PROGS := rt_ipc_server rt_ipc_client + +all: $(PROGS) +%: %.c + $(CC) $(CFLAGS) rt_ipc_action.c -o $@ $^ + +clean: + $(RM) $(PROGS) + +.PHONY: all clean
tools/rt_ipc_userspace/rt_ipc_action.c new file +162 -0
162 lines not on this page · raw message
tools/rt_ipc_userspace/rt_ipc_action.h new file +56 -0
56 lines not on this page · raw message
tools/rt_ipc_userspace/rt_ipc_client.c new file +89 -0
89 lines not on this page · raw message
tools/rt_ipc_userspace/rt_ipc_server.c new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.43.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi XingxingQiao,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/sched/core linus/master v6.16-rc6] [cannot apply to sysctl/sysctl-next next-20250718]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/XingxingQiao/rt_ipc-a-new-IPC-mechanism-called-rt_ipc-real-time-IPC/20250718-140945 base: tip/x86/core patch link: https://lore.kernel.org/r/20250718060634.469032-1-mnlife%40126.com patch subject: [RFC] rt_ipc: a new IPC mechanism called rt_ipc (real-time IPC) config: x86_64-buildonly-randconfig-004-20250719 (https://download.01.org/0day-ci/archive/20250719/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250719/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
ld: arch/x86/entry/syscall_64.o: in function `x64_sys_call':
>> syscall_64.c:(.text+0x17): undefined reference to `__x64_sys_rt_ipc_return' >> ld: syscall_64.c:(.text+0x1c): undefined reference to `__x64_sys_rt_ipc_invoke' >> ld: syscall_64.c:(.text+0x21): undefined reference to `__x64_sys_rt_ipc_register' ld: arch/x86/entry/syscall_64.o: in function `x32_sys_call': syscall_64.c:(.text+0x80b): undefined reference to `__x64_sys_rt_ipc_return' ld: syscall_64.c:(.text+0x810): undefined reference to `__x64_sys_rt_ipc_invoke' ld: syscall_64.c:(.text+0x815): undefined reference to `__x64_sys_rt_ipc_register' >> ld: arch/x86/entry/syscall_64.o:(.rodata+0x2e80): undefined reference to `__x64_sys_rt_ipc_register' >> ld: arch/x86/entry/syscall_64.o:(.rodata+0x2e88): undefined reference to `__x64_sys_rt_ipc_invoke' >> ld: arch/x86/entry/syscall_64.o:(.rodata+0x2e90): undefined reference to `__x64_sys_rt_ipc_return'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki