sched,mm,x86/uaccess: implement User Managed Concurrency Groups
Subsystems (11)
cover sched,mm,x86/uaccess: implement User Managed Concurrency Groups
User Managed Concurrency Groups (UMCG) is an M:N threading subsystem/toolkit that lets user space application developers implement in-process user space schedulers.
Key changes from the previous patchset
https://lore.kernel.org/all/[email protected]/:
- added libumcg tools/lib/umcg;
- worker "wakeup" is reworked so that it is now purely a userspace op, instead of waking the thread in order for it to block on return to the userspace immediately;
- a couple of minor fixes and refactorings.
These big things remain to be addressed (in no particular order):
- support tracing/debugging
- make context switches faster (see umcg_do_context_switch in umcg.c)
- support other architectures
- cleanup and post selftests in tools/testing/selftests/umcg/
- allow cross-mm wakeups (securely)
Peter Oskolkov (6):
sched/umcg: add WF_CURRENT_CPU and externise ttwu mm, x86/uaccess: add userspace atomic helpers sched/umcg: implement UMCG syscalls sched/umcg, lib/umcg: implement libumcg sched/umcg: add Documentation/userspace-api/umcg.txt sched/umcg, lib/umcg: add tools/lib/umcg/libumcg.txt
Documentation/userspace-api/umcg.txt | 598 ++++++++++++ arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/x86/include/asm/uaccess_64.h | 93 ++ fs/exec.c | 1 + include/linux/sched.h | 71 ++ include/linux/syscalls.h | 3 + include/linux/uaccess.h | 46 + include/uapi/asm-generic/unistd.h | 6 +- include/uapi/linux/umcg.h | 137 +++ init/Kconfig | 10 + kernel/entry/common.c | 4 +- kernel/exit.c | 5 + kernel/sched/Makefile | 1 + kernel/sched/core.c | 12 +- kernel/sched/fair.c | 4 + kernel/sched/sched.h | 15 +- kernel/sched/umcg.c | 949 +++++++++++++++++++ kernel/sys_ni.c | 4 + mm/maccess.c | 264 ++++++ tools/lib/umcg/.gitignore | 4 + tools/lib/umcg/Makefile | 11 + tools/lib/umcg/libumcg.c | 1201 ++++++++++++++++++++++++ tools/lib/umcg/libumcg.h | 299 ++++++ tools/lib/umcg/libumcg.txt | 438 +++++++++ 24 files changed, 4166 insertions(+), 12 deletions(-) create mode 100644 Documentation/userspace-api/umcg.txt create mode 100644 include/uapi/linux/umcg.h create mode 100644 kernel/sched/umcg.c create mode 100644 tools/lib/umcg/.gitignore create mode 100644 tools/lib/umcg/Makefile create mode 100644 tools/lib/umcg/libumcg.c create mode 100644 tools/lib/umcg/libumcg.h create mode 100644 tools/lib/umcg/libumcg.txt
base-commit: 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd --
2.25.1
PATCH 1/6 sched/umcg: add WF_CURRENT_CPU and externise ttwu
Add WF_CURRENT_CPU wake flag that advices the scheduler to move the wakee to the current CPU. This is useful for fast on-CPU context switching use cases such as UMCG.
In addition, make ttwu external rather than static so that the flag could be passed to it from outside of sched/core.c.
--- kernel/sched/core.c | 3 +-- kernel/sched/fair.c | 4 ++++ kernel/sched/sched.h | 15 +++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-)
kernel/sched/core.c +1 -2
@@ -3963,8 +3963,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)* Return: %true if @p->state changes (an actual wakeup was done), * %false otherwise. */ -static int -try_to_wake_up (struct task_struct *p,unsigned int state,int wake_flags) +int try_to_wake_up (struct task_struct *p,unsigned int state,int wake_flags) {unsigned long flags;int cpu, success =0 ;
kernel/sched/fair.c +4 -0
@@ -6890,6 +6890,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)if (wake_flags &WF_TTWU ) {record_wakee (p); +if ((wake_flags &WF_CURRENT_CPU ) && +cpumask_test_cpu (cpu, p->cpus_ptr)) +return cpu; +if (sched_energy_enabled ()) { new_cpu =find_energy_efficient_cpu (p, prev_cpu);if (new_cpu >=0 )
kernel/sched/sched.h +9 -6
@@ -2028,13 +2028,14 @@ static inline int task_on_rq_migrating(struct task_struct *p) }/* Wake flags. The first three directly map to some SD flag value */ -#define WF_EXEC 0x02/* Wakeup after exec; maps to SD_BALANCE_EXEC */ -#define WF_FORK 0x04/* Wakeup after fork; maps to SD_BALANCE_FORK */ -#define WF_TTWU 0x08/* Wakeup; maps to SD_BALANCE_WAKE */ +#define WF_EXEC 0x02/* Wakeup after exec; maps to SD_BALANCE_EXEC */ +#define WF_FORK 0x04/* Wakeup after fork; maps to SD_BALANCE_FORK */ +#define WF_TTWU 0x08/* Wakeup; maps to SD_BALANCE_WAKE */ -#define WF_SYNC 0x10/* Waker goes to sleep after wakeup */ -#define WF_MIGRATED 0x20/* Internal use, task got migrated */ -#define WF_ON_CPU 0x40/* Wakee is on_cpu */ +#define WF_SYNC 0x10/* Waker goes to sleep after wakeup */ +#define WF_MIGRATED 0x20/* Internal use, task got migrated */ +#define WF_ON_CPU 0x40/* Wakee is on_cpu */ +#define WF_CURRENT_CPU 0x80/* Prefer to move the wakee to the current CPU. */ #ifdef CONFIG_SMP static_assert (WF_EXEC ==SD_BALANCE_EXEC );
@@ -3052,6 +3053,8 @@ static inline bool is_per_cpu_kthread(struct task_struct *p)extern void swake_up_all_locked (struct swait_queue_head *q);extern void __prepare_to_swait (struct swait_queue_head *q,struct swait_queue *wait); +extern int try_to_wake_up (struct task_struct *tsk,unsigned int state,int wake_flags); +#ifdef CONFIG_PREEMPT_DYNAMIC extern int preempt_dynamic_mode;extern int sched_dynamic_mode (const char *str);
--
2.25.1
PATCH 2/6 mm, x86/uaccess: add userspace atomic helpers
In reply to Peter OskolkovIn addition to futexes needing to do atomic operations in the userspace, a second use case is now in the works (UMCG, see
https://lore.kernel.org/all/[email protected]/),
so a generic facility to perform these operations has been called for (see https://lore.kernel.org/all/87ilyk9xc0.ffs@tglx/).
Add a set of generic helpers to perform 32/64-bit xchg and cmpxchg operations in the userspace. Also implement the required architecture-specific support on x86_64.
--- arch/x86/include/asm/uaccess_64.h | 93 +++++++++++ include/linux/uaccess.h | 46 ++++++ mm/maccess.c | 264 ++++++++++++++++++++++++++++++ 3 files changed, 403 insertions(+)
arch/x86/include/asm/uaccess_64.h +93 -0
@@ -79,4 +79,97 @@ __copy_from_user_flushcache(void *dst, const void __user *src, unsigned size)kasan_check_write (dst, size);return __copy_user_flushcache (dst, src, size); } + +#define ARCH_HAS_ATOMIC_UACCESS_HELPERS 1 + +static inline int __try_cmpxchg_user_32 (u32 *uval,u32 __user *uaddr, +u32 oldval,u32 newval) +{ +int ret =0 ; + + asmvolatile ("\n" +"1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" +"2:\n" +"\t.section .fixup, \"ax\"\n" +"3:\tmov %3, %0\n" +"\tjmp 2b\n" +"\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "+r" (ret), "=a" (oldval), "+m" (*uaddr) + : "i" (-EFAULT), "r" (newval), "1" (oldval) + : "memory" + ); + *uval = oldval; +return ret; +} + +static inline int __try_cmpxchg_user_64 (u64 *uval,u64 __user *uaddr, +u64 oldval,u64 newval) +{ +int ret =0 ; + + asmvolatile ("\n" +"1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" +"2:\n" +"\t.section .fixup, \"ax\"\n" +"3:\tmov %3, %0\n" +"\tjmp 2b\n" +"\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "+r" (ret), "=a" (oldval), "+m" (*uaddr) + : "i" (-EFAULT), "r" (newval), "1" (oldval) + : "memory" + ); + *uval = oldval; +return ret; +} + +static inline int __try_xchg_user_32 (u32 *oval,u32 __user *uaddr,u32 newval) +{ +u32 oldval =0 ; +int ret =0 ; + + asm volatile("\n" + "1:\txchgl %0, %2\n" + "2:\n" + "\t.section .fixup, \"ax\"\n" + "3:\tmov %3, %1\n" + "\tjmp 2b\n" + "\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "=r" (oldval), "=r" (ret), "+m" (*uaddr) + : "i" (-EFAULT), "0" (newval), "1" (0) + ); + +if (ret) +return ret; + + *oval = oldval; +return 0 ; +} + +static inline int __try_xchg_user_64 (u64 *oval,u64 __user *uaddr,u64 newval) +{ +u64 oldval =0 ; +int ret =0 ; + + asm volatile("\n" + "1:\txchgq %0, %2\n" + "2:\n" + "\t.section .fixup, \"ax\"\n" + "3:\tmov %3, %1\n" + "\tjmp 2b\n" + "\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "=r" (oldval), "=r" (ret), "+m" (*uaddr) + : "i" (-EFAULT), "0" (newval), "1" (0) + ); + +if (ret) +return ret; + + *oval = oldval; +return 0 ; +} +#endif /* _ASM_X86_UACCESS_64_H */
include/linux/uaccess.h +46 -0
50 lines not on this page · raw message
mm/maccess.c +264 -0
267 lines not on this page · raw message
--
2.25.1
PATCH 3/6 sched/umcg: implement UMCG syscalls
In reply to Peter OskolkovDefine struct umcg_task and two syscalls: sys_umcg_ctl sys_umcg_wait.
User Managed Concurrency Groups is an M:N threading toolkit that allows constructing user space schedulers designed to efficiently manage heterogeneous in-process workloads while maintaining high CPU utilization (95%+).
In addition, M:N threading and cooperative user space scheduling enables synchronous coding style and better cache locality when compared to asynchronous callback/continuation style of programming.
UMCG kernel API is build around the following ideas:
* UMCG server: a task/thread representing "kernel threads", or (v)CPUs;
* UMCG worker: a task/thread representing "application threads", to be scheduled over servers;
* UMCG task state: (NONE), RUNNING, BLOCKED, IDLE: states a UMCG task (a server or a worker) can be in;
* UMCG task state flag: LOCKED, PREEMPTED: additional state flags that can be ORed with the task state to communicate additional information to the kernel;
* struct umcg_task: a per-task userspace set of data fields, usually residing in the TLS, that fully reflects the current task's UMCG state and controls the way the kernel manages the task;
* sys_umcg_ctl(): a syscall used to register the current task/thread as a server or a worker, or to unregister a UMCG task;
* sys_umcg_wait(): a syscall used to put the current task to sleep and/or wake another task, pontentially context-switching between the two tasks on-CPU synchronously.
In short, servers can be thought of as CPUs over which application threads (workers) are scheduled; at any one time a worker is either:
- RUNNING: has a server and is schedulable by the kernel;
- BLOCKED: blocked in the kernel (e.g. on I/O, or a futex);
- IDLE: is not blocked, but cannot be scheduled by the kernel to run because it has no server assigned to it (e.g. because all available servers are busy "running" other workers).
Usually the number of servers in a process is equal to the number of CPUs available to the kernel if the process is supposed to consume the whole machine, or less than the number of CPUs available if the process is sharing the machine with other workloads. The number of workers in a process can grow very large: tens of thousands is normal; hundreds of thousands and more (millions) is something that would be desirable to achieve in the future, as lightweight userspace threads in Java and Go easily scale to millions, and UMCG workers are (intended to be) conceptually similar to those.
Detailed use cases and API behavior are provided in Documentation/userspace-api/umcg.txt (see sibling patches).
Some high-level implementation notes:
UMCG tasks (workers and servers) are "tagged" with struct umcg_task residing in userspace (usually in TLS) to facilitate kernel/userspace communication. This makes the kernel-side code much simpler (see e.g. the implementation of sys_umcg_wait), but also requires some careful uaccess handling and page pinning (see below).
The main UMCG server/worker interaction looks like:
a. worker W1 is RUNNING, with a server S attached to it sleeping
in IDLE state;
b. worker W1 blocks in the kernel, e.g. on I/O;
c. the kernel marks W1 as BLOCKED, the attached server S
as RUNNING, and wakes S (the "block detection" event);
d. the server now picks another IDLE worker W2 to run: marks
W2 as RUNNING, itself as IDLE, ands calls sys_umcg_wait();
e. when the blocking operation of W1 completes, the worker
is marked by the kernel as IDLE and added to idle workers list (see struct umcg_task) for the userspace to pick up and later run (the "wake detection" event).
While there are additional operations such as worker-to-worker context switch, preemption, workers "yielding", etc., the "workflow" above is the main worker/server interaction that drives the implementation.
Specifically:
- most operations are conceptually context switches:
- scheduling a worker: a running server goes to sleep and "runs" a worker in its place;
- block detection: worker is descheduled, and its server is woken;
- wake detection: woken worker, running in the kernel, is descheduled, and if there is an idle server, it is woken to process the wake detection event;
- to faciliate low scheduling latencies and cache locality, most server/worker interactions described above are performed synchronously "on CPU" via WF_CURRENT_CPU flag passed to ttwu; while at the moment the context switches are simulated by putting the switch-out task to sleep and waking the switch-into task on the same cpu, it is very much the long-term goal of this project to make the context switch much lighter, by tweaking runtime accounting and, maybe, even bypassing __schedule();
- worker blocking is detected in a hook to sched_submit_work; as mentioned above, the server is to be woken on the same CPU, synchronously; this code may not pagefault, so to access worker's and server's userspace memory (struct umcg_task), memory pages containing the worker's and the server's structs umcg_task are pinned when the worker is exiting to the userspace, and unpinned when the worker is descheduled;
- worker wakeup is detected in a hook to sched_update_worker, and processed in the exit to usermode loop (via TIF_NOTIFY_RESUME); workers CAN pagefault on the wakeup path;
- worker preemption is implemented by the userspace tagging the worker with UMCG_TF_PREEMPTED state flag and sending a NOOP signal to it; on the exit to usermode the worker is intercepted and its server is woken (see Documentation/userspace-api/umcg.txt for more details);
- each state change is tagged with a unique timestamp (of MONOTONIC variety), so that
- scheduling instrumentation is naturally available;
- racing state changes are easily detected and ABA issues are avoided;
see umcg_update_state() in umcg.c for implementation details, and Documentation/userspace-api/umcg.txt for a higher-level description.
The previous version of the patchset can be found at
https://lore.kernel.org/all/[email protected]/
containing some additional context and links to earlier discussions.
More details are available in Documentation/userspace-api/umcg.txt in sibling patches, and in doc-comments in the code.
--- arch/x86/entry/syscalls/syscall_64.tbl | 2 + fs/exec.c | 1 + include/linux/sched.h | 71 ++ include/linux/syscalls.h | 3 + include/uapi/asm-generic/unistd.h | 6 +- include/uapi/linux/umcg.h | 137 ++++ init/Kconfig | 10 + kernel/entry/common.c | 4 +- kernel/exit.c | 5 + kernel/sched/Makefile | 1 + kernel/sched/core.c | 9 +- kernel/sched/umcg.c | 949 +++++++++++++++++++++++++ kernel/sys_ni.c | 4 + 13 files changed, 1198 insertions(+), 4 deletions(-) create mode 100644 include/uapi/linux/umcg.h create mode 100644 kernel/sched/umcg.c
arch/x86/entry/syscalls/syscall_64.tbl +2 -0
@@ -370,6 +370,8 @@ 446 common landlock_restrict_self sys_landlock_restrict_self 447 common memfd_secret sys_memfd_secret 448 common process_mrelease sys_process_mrelease +449 common umcg_ctl sys_umcg_ctl +450 common umcg_wait sys_umcg_wait # # Due to a historical design error, certain syscalls are numbered differently
fs/exec.c +1 -0
@@ -1840,6 +1840,7 @@ static int bprm_execve(struct linux_binprm *bprm, current->fs->in_exec =0 ; current->in_execve =0 ;rseq_execve (current); +umcg_execve (current);acct_update_integrals (current);task_numa_free (current, false);return retval;
include/linux/sched.h +71 -0
95 lines not on this page · raw message
include/linux/syscalls.h +3 -0
@@ -71,6 +71,7 @@ struct open_how;struct mount_attr ;struct landlock_ruleset_attr ;enum landlock_rule_type ; +struct umcg_task ;#include <linux/types.h> #include <linux/aio_abi.h>
@@ -1052,6 +1053,8 @@ asmlinkage long sys_landlock_add_rule(int ruleset_fd, enum landlock_rule_type ru const void __user *rule_attr, __u32 flags);asmlinkage long sys_landlock_restrict_self (int ruleset_fd,__u32 flags);asmlinkage long sys_memfd_secret (unsigned int flags); +asmlinkage long sys_umcg_ctl (u32 flags,struct umcg_task __user *self); +asmlinkage long sys_umcg_wait (u32 flags,u64 abs_timeout);/* * Architecture-specific system calls
include/uapi/asm-generic/unistd.h +5 -1
@@ -879,9 +879,13 @@ __SYSCALL(__NR_memfd_secret, sys_memfd_secret)#endif #define __NR_process_mrelease 448 __SYSCALL(__NR_process_mrelease, sys_process_mrelease) +#define __NR_umcg_ctl 449 +__SYSCALL(__NR_umcg_ctl, sys_umcg_ctl) +#define __NR_umcg_wait 450 +__SYSCALL(__NR_umcg_wait, sys_umcg_wait)#undef __NR_syscalls -#define __NR_syscalls 449 +#define __NR_syscalls 451/* * 32 bit systems traditionally used different
include/uapi/linux/umcg.h new file +137 -0
137 lines not on this page · raw message
init/Kconfig +10 -0
@@ -1688,6 +1688,16 @@ config MEMBARRIER If unsure, say Y. +config UMCG + bool "Enable User Managed Concurrency Groups API" + depends on X86_64 + default n + help + Enable User Managed Concurrency Groups API, which form the basis + for an in-process M:N userspace scheduling framework. + At the moment this is an experimental/RFC feature that is not + guaranteed to be backward-compatible. + config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EXPERT default y
kernel/entry/common.c +3 -1
@@ -171,8 +171,10 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))handle_signal_work (regs, ti_work); -if (ti_work & _TIF_NOTIFY_RESUME) +if (ti_work & _TIF_NOTIFY_RESUME) { +umcg_handle_notify_resume ();tracehook_notify_resume (regs); + }/* Architecture specific TIF work */ arch_exit_to_user_mode_work (regs, ti_work);
kernel/exit.c +5 -0
@@ -745,6 +745,10 @@ void __noreturn do_exit(long code)if (unlikely (!tsk->pid))panic ("Attempted to kill the idle task!" ); +/* Turn off UMCG sched hooks. */ +if (unlikely (tsk->flags &PF_UMCG_WORKER )) + tsk->flags &= ~PF_UMCG_WORKER ; +/* * If do_exit is called because this processes oopsed, it's possible * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
@@ -781,6 +785,7 @@ void __noreturn do_exit(long code)io_uring_files_cancel ();exit_signals (tsk);/* sets PF_EXITING */ +umcg_handle_exit ();/* sync mm's RSS info before statistics gathering */ if (tsk->mm)
kernel/sched/Makefile +1 -0
@@ -41,3 +41,4 @@ obj-$(CONFIG_MEMBARRIER) += membarrier.o obj-$(CONFIG_CPU_ISOLATION) += isolation.o obj-$(CONFIG_PSI) += psi.o obj-$(CONFIG_SCHED_CORE) += core_sched.o +obj-$(CONFIG_UMCG) += umcg.o
kernel/sched/core.c +7 -2
@@ -4255,6 +4255,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p) p->wake_entry.u_flags =CSD_TYPE_TTWU ; p->migration_pending =NULL ;#endif +umcg_clear_child (p); }DEFINE_STATIC_KEY_FALSE (sched_numa_balancing);
@@ -6284,9 +6285,11 @@ static inline void sched_submit_work(struct task_struct *tsk)* If a worker goes to sleep, notify and ask workqueue whether it * wants to wake up a task to maintain concurrency. */ -if (task_flags & (PF_WQ_WORKER |PF_IO_WORKER )) { +if (task_flags & (PF_WQ_WORKER |PF_IO_WORKER |PF_UMCG_WORKER )) {if (task_flags &PF_WQ_WORKER )wq_worker_sleeping (tsk); +else if (task_flags &PF_UMCG_WORKER ) +umcg_wq_worker_sleeping (tsk);else io_wq_worker_sleeping (tsk); }
@@ -6304,9 +6307,11 @@ static inline void sched_submit_work(struct task_struct *tsk)static void sched_update_worker (struct task_struct *tsk) { -if (tsk->flags & (PF_WQ_WORKER |PF_IO_WORKER )) { +if (tsk->flags & (PF_WQ_WORKER |PF_IO_WORKER |PF_UMCG_WORKER )) {if (tsk->flags &PF_WQ_WORKER )wq_worker_running (tsk); +else if (tsk->flags &PF_UMCG_WORKER ) +umcg_wq_worker_running (tsk);else io_wq_worker_running (tsk); }
kernel/sched/umcg.c new file +949 -0
949 lines not on this page · raw message
kernel/sys_ni.c +4 -0
@@ -272,6 +272,10 @@ COND_SYSCALL(landlock_create_ruleset);COND_SYSCALL (landlock_add_rule);COND_SYSCALL (landlock_restrict_self); +/* kernel/sched/umcg.c */ +COND_SYSCALL (umcg_ctl); +COND_SYSCALL (umcg_wait); +/* arch/example/kernel/sys_example.c */ /* mm/fadvise.c */
--
2.25.1
PATCH 4/6 sched/umcg, lib/umcg: implement libumcg
In reply to Peter OskolkovImplement libumcg in tools/lib/umcg. Define higher-level UMCG API that hides kernel-level UMCG API intricacies.
As a higher-level API, libumcg makes subtle changes to server/worker interactions, compared to the kernel UMCG API, and introduces the following new concepts:
- UMCG Group: a collection of servers and workers in a process that can interact with each other; UMCG groups are useful to partition servers and workers within a process in order to, for example, affine work to specific NUMA nodes;
- UMCG basic tasks: these are UMCG servers, from the kernel point of view; they do not interact with UMCG workers and thus do not need in UMCG groups; used for cooperative wait/wake/swap operations.
The main difference of server/worker interaction in libumcg vs the kernel-side UMCG API is that a wakeup can be queued:
if umcg_wake() is called on a RUNNING UMCG task, the fact is recorded (in the userspace), and when the task calls umcg_wait() or umcg_swap(), the wakeup is consumed and the task is not marked IDLE.
Libumcg exports the following API:
umcg_enabled()
umcg_get_utid()
umcg_set_task_tag()
umcg_get_task_tag()
umcg_create_group()
umcg_destroy_group()
umcg_register_basic_task()
umcg_register_worker()
umcg_register_server()
umcg_unregister_task()
umcg_wait()
umcg_wake()
umcg_swap()
umcg_get_idle_worker()
umcg_run_worker()
umcg_preempt_worker()
umcg_get_time_ns()See tools/lib/umcg/libumcg.txt for details.
Notes:
- this is still somewhat work-in-progress: while the kernel side code has been more or less stable over the last couple of months, the userspace side of things is less so;
- while libumcg is intended to be the main/primary/only direct user of the kernel UMCG API, at the moment the implementation is more geared more towards testing and correctness than live production usage, with a lot of asserts and similar development helpers;
- I have a number of umcg selftests that I plan to clean up and post shortly.
--- tools/lib/umcg/.gitignore | 4 + tools/lib/umcg/Makefile | 11 + tools/lib/umcg/libumcg.c | 1201 +++++++++++++++++++++++++++++++++++++ tools/lib/umcg/libumcg.h | 299 +++++++++ 4 files changed, 1515 insertions(+) create mode 100644 tools/lib/umcg/.gitignore create mode 100644 tools/lib/umcg/Makefile create mode 100644 tools/lib/umcg/libumcg.c create mode 100644 tools/lib/umcg/libumcg.h
tools/lib/umcg/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +PDX-License-Identifier: GPL-2.0-only +libumcg.a +libumcg.o +
tools/lib/umcg/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -g -I../../include/ -I../../../usr/include/ + +libumcg.a: libumcg.o + ar rc libumcg.a libumcg.o + +libumcg.o: libumcg.c + +clean : + rm libumcg.a libumcg.o
tools/lib/umcg/libumcg.c new file +1201 -0
1,201 lines not on this page · raw message
tools/lib/umcg/libumcg.h new file +299 -0
299 lines not on this page · raw message
--
2.25.1
PATCH 5/6 sched/umcg: add Documentation/userspace-api/umcg.txt
In reply to Peter OskolkovDocument User Managed Concurrency Groups syscalls, data structures, state transitions, etc. in UMGG kernel API.
--- Documentation/userspace-api/umcg.txt | 598 +++++++++++++++++++++++++++ 1 file changed, 598 insertions(+) create mode 100644 Documentation/userspace-api/umcg.txt
Documentation/userspace-api/umcg.txt new file +598 -0
@@ -0,0 +1,598 @@ +UMCG API (KERNEL) + +User Managed Concurrency Groups (UMCG) is an M:N threading +subsystem/toolkit that lets user space application developers implement +in-process user space schedulers. + +See tools/lib/umcg/umcg.txt for LIBUMCG API, as opposed to UMCG API (kernel) +described here. The first three subsections are the same in both documents. + + +CONTENTS + + WHY? HETEROGENEOUS IN-PROCESS WORKLOADS + REQUIREMENTS + WHY TWO APIS: UMCG (KERNEL) AND LIBUMCG (USERSPACE)? + UMCG API (KERNEL) + SERVERS + WORKERS + UMCG TASK STATES + STRUCT UMCG_TASK + SYS_UMCG_CTL() + SYS_UMCG_WAIT() + STATE TRANSITIONS + SERVER-ONLY USE CASES + + +WHY? HETEROGENEOUS IN-PROCESS WORKLOADS + +Linux kernel's CFS scheduler is designed for the "common" use case, with +efficiency/throughput in mind. Work isolation and workloads of different +"urgency" are addressed by tools such as cgroups, CPU affinity, priorities, +etc., which are difficult or impossible to efficiently use in-process. + +For example, a single DBMS process may receive tens of thousands requests +per second; some of these requests may have strong response latency +requirements as they serve live user requests (e.g. login authentication); +some of these requests may not care much about latency but must be served +within a certain time period (e.g. an hourly aggregate usage report); some +of these requests are to be served only on a best-effort basis and can be +NACKed under high load (e.g. an exploratory research/hypothesis testing +workload). + +Beyond different work item latency/throughput requirements as outlined +above, the DBMS may need to provide certain guarantees to different users; +for example, user A may "reserve" 1 CPU for their high-priority/low-latency +requests, 2 CPUs for mid-level throughput workloads, and be allowed to send +as many best-effort requests as possible, which may or may not be served, +depending on the DBMS load. Besides, the best-effort work, started when the +load was low, may need to be delayed if suddenly a large amount of +higher-priority work arrives. With hundreds or thousands of users like +this, it is very difficult to guarantee the application's responsiveness +using standard Linux tools while maintaining high CPU utilization. + +Gaming is another use case: some in-process work must be completed before a +certain deadline dictated by frame rendering schedule, while other work +items can be delayed; some work may need to be cancelled/discarded because +the deadline has passed; etc. + +User Managed Concurrency Groups is an M:N threading toolkit that allows +constructing user space schedulers designed to efficiently manage +heterogeneous in-process workloads described above while maintaining high +CPU utilization (95%+). + + +REQUIREMENTS + +One relatively established way to design high-efficiency, low-latency +systems is to split all work into small on-cpu work items, with +asynchronous I/O and continuations, all executed on a thread pool with the +number of threads not exceeding the number of available CPUs. Although this +approach works, it is quite difficult to develop and maintain such a +system, as, for example, small continuations are difficult to piece +together when debugging. Besides, such asynchronous callback-based systems +tend to be somewhat cache-inefficient, as continuations can get scheduled +on any CPU regardless of cache locality. + +M:N threading and cooperative user space scheduling enables controlled CPU +usage (minimal OS preemption), synchronous coding style, and better cache +locality. + +Specifically: + +* a variable/fluctuating number M of "application" threads should be + "scheduled over" a relatively fixed number N of "kernel" threads, where + N is less than or equal to the number of CPUs available; +* only those application threads that are attached to kernel threads are + scheduled "on CPU"; +* application threads should be able to cooperatively yield to each other; +* when an application thread blocks in kernel (e.g. in I/O), this becomes + a scheduling event ("block") that the userspace scheduler should be able + to efficiently detect, and reassign a waiting application thread to the + freeded "kernel" thread; +* when a blocked application thread wakes (e.g. its I/O operation + completes), this event ("wake") should also be detectable by the + userspace scheduler, which should be able to either quickly dispatch the + newly woken thread to an idle "kernel" thread or, if all "kernel" + threads are busy, put it in the waiting queue; +* in addition to the above, it would be extremely useful for a separate + in-process "watchdog" facility to be able to monitor the state of each + of the M+N threads, and to intervene in case of runaway workloads + (interrupt/preempt). + + +WHY THE TWO APIS: UMCG (KERNEL) AND LIBUMCG (USERSPACE)? + +UMCG syscalls, sys_umcg_ctl() and sys_umcg_wait(), are designed to make +the kernel-side UMCG implementation as lightweight as possible. LIBUMCG, +on the other hand, is designed to expose the key abstractions to users +in a much more usable, higher-level way. + +See tools/lib/umcg/libumcg.txt for more details on LIBUMCG API. + + +UMCG API (KERNEL) + +Based on the requrements above, UMCG API (kernel) is build around the +following ideas: + +* UMCG server: a task/thread representing "kernel threads", or CPUs from + the requirements above; +* UMCG worker: a task/thread representing "application threads", to be + scheduled over servers; +* UMCG task state: (NONE), RUNNING, BLOCKED, IDLE: states a UMCG task (a + server or a worker) can be in; +* UMCG task state flag: LOCKED, PREEMPTED: additional state flags that + can be ORed with the task state to communicate additional information to + the kernel; +* struct umcg_task: a per-task userspace set of data fields, usually + residing in the TLS, that fully reflects the current task's UMCG state + and controls the way the kernel manages the task; +* sys_umcg_ctl(): a syscall used to register the current task/thread as a + server or a worker, or to unregister a UMCG task; +* sys_umcg_wait(): a syscall used to put the current task to sleep and/or + wake another task, pontentially context-switching between the two tasks + on-CPU synchronously. + + +SERVERS + +When a task/thread is registered as a server, it is in RUNNING state and +behaves like any other normal task/thread. In addition, servers can +interact with other UMCG tasks via sys_umcg_wait(): + +* servers can voluntarily suspend their execution (wait), becoming IDLE; +* servers can wake other IDLE servers; +* servers can context-switch between each other. + +Note that if a server blocks in the kernel not via sys_umcg_wait(), it +still retains its RUNNING state. + + +WORKERS + +A worker cannot be RUNNING without having a server associated with it, so +when a task is first registered as a worker, it enters the IDLE state. + +* a worker becomes RUNNING when a server calls sys_umcg_wait to + context-switch into it; the server goes IDLE, and the worker becomes + RUNNING in its place; +* when a RUNNING worker blocks in the kernel, it becomes BLOCKED, its + associated server becomes RUNNING and the server's sys_umcg_wait() call + from the bullet above returns; this transition is sometimes called + "block detection"; +* when the syscall on which a BLOCKED worker completes, the worker + becomes IDLE and is added to the list of idle workers; if there is an + idle server waiting, the kernel wakes it; this transition is sometimes + called "wake detection"; +* RUNNING workers can voluntarily suspend their execution (wait), + becoming IDLE; their associated servers are woken; +* a RUNNING worker can context-switch with an IDLE worker; the server of + the switched-out worker is transferred to the switched-in worker; +* any UMCG task can "wake" an IDLE worker via sys_umcg_wait(); unless + this is a server running the worker as described in the first bullet in + this list, the worker remain IDLE but is added to the idle workers list; + this "wake" operation exists for completeness, to make sure + wait/wake/context-switch operations are available for all UMCG tasks; +* the userspace can preempt a RUNNING worker by marking it + RUNNING|PREEMPTED and sending a signal to it; the userspace should have + installed a NOP signal handler for the signal; the kernel will then + transition the worker into IDLE|PREEMPTED state and wake its associated + server. + + +UMCG TASK STATES + +Important: all state transitions described below involve at least two +steps: the change of the state field in struct umcg_task, for example +RUNNING to IDLE, and the corresponding change in struct task_struct state, +for example a transition between the task running on CPU and being +descheduled and removed from the kernel runqueue. The key principle of UMCG +API design is that the party initiating the state transition modifies the +state variable. + +For example, a task going IDLE first changes its state from RUNNING to IDLE +in the userpace and then calls sys_umcg_wait(), which completes the +transition. + +Note on documentation: in include/uapi/linux/umcg.h, task states have the +form UMCG_TASK_RUNNING, UMCG_TASK_BLOCKED, etc. In this document these are +usually referred to simply RUNNING and BLOCKED, unless it creates +ambiguity. Task state flags, e.g. UMCG_TF_PREEMPTED, are treated similarly. + +UMCG task states reflect the view from the userspace, rather than from the +kernel. There are three fundamental task states: + +* RUNNING: indicates that the task is schedulable by the kernel; applies + to both servers and workers; +* IDLE: indicates that the task is not schedulable by the kernel (see + umcg_idle_loop() in kernel/sched/umcg.c); applies to both servers and + workers; +* BLOCKED: indicates that the worker is blocked in the kernel; does not + apply to servers. + +In addition to the three states above, two state flags help with state +transitions: + +* LOCKED: the userspace is preparing the worker for a state transition + and "locks" the worker until the worker is ready for the kernel to act + on the state transition; used similarly to preempt_disable or + irq_disable in the kernel; applies only to workers in RUNNING or IDLE + state; RUNNING|LOCKED means "this worker is about to become RUNNING, + while IDLE|LOCKED means "this worker is about to become IDLE or + unregister; +* PREEMPTED: the userspace indicates it wants the worker to be preempted; + there are no situations when both LOCKED and PREEMPTED flags are set at + the same time. + + +STRUCT UMCG_TASK + +From include/uapi/linux/umcg.h: + +struct umcg_task { + uint64_t state_ts; /* r/w */ + uint32_t next_tid; /* r */ + uint32_t flags; /* reserved */ + uint64_t idle_workers_ptr; /* r/w */ + uint64_t idle_server_tid_ptr; /* r* */ +}; + +Each UMCG task is identified by struct umcg_task, which is provided to the +kernel when the task is registered via sys_umcg_ctl(). + +* uint64_t state_ts: the current state of the task this struct + identifies, as described in the previous section, combined with a + unique timestamp indicating when the last state change happened. + + Readable/writable by both the kernel and the userspace. + + bits 0 - 5: task state (RUNNING, IDLE, BLOCKED); + bits 6 - 7: state flags (LOCKED, PREEMPTED); + bits 8 - 12: reserved; must be zeroes; + bits 13 - 17: for userspace use; + bits 18 - 63: timestamp. + + Timestamp: a 46-bit CLOCK_MONOTONIC timestamp, at 16ns resolution. + + It is highly benefitical to tag each state change with a unique + timestamp: + + - timestamps will naturally provide instrumentation to measure + scheduling delays, both in the kernel and in the userspace; + - uniqueness of timestamps (module overflow) guarantees that state + change races, especially ABA races, are easily detected and avoided. + + Each timestamp represents the moment in time the state change happened, + in nanoseconds, with the lower 4 bits and the upper 16 bits stripped. + + In this document 'umcg_task.state' is often used to talk about + 'umcg_task.state_ts' field, as timestamps do not carry semantic + meaning at the moment. + + This is how umcg_task.state_ts is updated in the kernel: + + /* kernel side */ + /** + * umcg_update_state: atomically update umcg_task.state_ts, set new timestamp. + * @state_ts - points to the state_ts member of struct umcg_task to update; + * @expected - the expected value of state_ts, including the timestamp; + * @desired - the desired value of state_ts, state part only; + * @may_fault - whether to use normal or _nofault cmpxchg. + * + * The function is basically cmpxchg(state_ts, expected, desired), with extra + * code to set the timestamp in @desired. + */ + static int umcg_update_state(u64 __user *state_ts, u64 *expected, u64 desired, + bool may_fault) + { + u64 curr_ts = (*expected) >> (64 - UMCG_STATE_TIMESTAMP_BITS); + u64 next_ts = ktime_get_ns() >> UMCG_STATE_TIMESTAMP_GRANULARITY; + + /* Cut higher order bits. */ + next_ts &= ((1ULL << UMCG_STATE_TIMESTAMP_BITS) - 1); + + if (next_ts == curr_ts) + ++next_ts; + + /* Remove an old timestamp, if any. */ + desired &= ((1ULL << (64 - UMCG_STATE_TIMESTAMP_BITS)) - 1); + + /* Set the new timestamp. */ + desired |= (next_ts << (64 - UMCG_STATE_TIMESTAMP_BITS)); + + if (may_fault) + return cmpxchg_user_64(state_ts, expected, desired); + + return cmpxchg_user_64_nofault(state_ts, expected, desired); + } + +* uint32_t next_tid: contains the TID of the task to context-switch-into + in sys_umcg_wait(); can be zero; writable by the userspace, readable by + the kernel; if this is a RUNNING worker, this field contains the TID of + the server that should be woken when this worker blocks; see + sys_umcg_wait() for more details; + +* uint32_t flags: reserved; must be zero. + +* uint64_t idle_workers_ptr: this field forms a single-linked list of + idle workers: all RUNNING workers have this field set to point to the + head of the list (a pointer variable in the userspace). + + When a worker's blocking operation in the kernel completes, the kernel + changes the worker's state from BLOCKED to IDLE and adds the worker to + the top of the list of idle workers using this logic: + + /* kernel side */ + /** + * enqueue_idle_worker - push an idle worker onto idle_workers_ptr + * list/stack. + * + * Returns true on success, false on a fatal failure. + */ + static bool enqueue_idle_worker(struct umcg_task __user *ut_worker) + { + u64 __user *node = &ut_worker->idle_workers_ptr; + u64 __user *head_ptr; + u64 first = (u64)node; + u64 head; + + if (get_user_nosleep(head, node) || !head) + return false; + + head_ptr = (u64 __user *)head; + + if (put_user_nosleep(UMCG_IDLE_NODE_PENDING, node)) + return false; + + if (xchg_user_64(head_ptr, &first)) + return false; + + if (put_user_nosleep(first, node)) + return false; + + return true; + } + + In the userspace the list is cleared atomically using this logic: + + /* userspace side */ + uint64_t *idle_workers = (uint64_t *)*head; + + atomic_exchange(&idle_workers, NULL); + + The userspace re-points workers' idle_workers_ptr to the list head + variable before the worker is allowed to become RUNNING again. + + When processing the idle workers list, the userspace should wait for + workers marked as UMCG_IDLE_NODE_PENDING to have the flag cleared (see + enqueue_idle_worker() above). + +* uint64_t idle_server_tid_ptr: points to a variable in the userspace + that points to an idle server, i.e. a server in IDLE state waiting in + sys_umcg_wait(); read-only; workers must have this field set; not used + in servers. + + When a worker's blocking operation in the kernel completes, the kernel + changes the worker's state from BLOCKED to IDLE, adds the worker to the + list of idle workers, and wakes the idle server if present; the kernel + atomically exchanges (*idle_server_tid_ptr) with 0, thus waking the idle + server, if present, only once. See State transitions below for more + details. + + +SYS_UMCG_CTL() + +int sys_umcg_ctl(uint32_t flags, struct umcg_task *self) is used to +register or unregister the current task as a worker or server. Flags can be +one of the following: + + UMCG_CTL_REGISTER: register a server; + UMCG_CTL_REGISTER | UMCG_CTL_WORKER: register a worker; + UMCG_CTL_UNREGISTER: unregister the current server or worker. + +When registering a task, self must point to struct umcg_task describing +this server or worker; the pointer must remain valid until the task is +unregistered. + +When registering a server, self->state must be RUNNING; all other fields in +self must be zeroes. + +When registering a worker, self->state must be BLOCKED; +self->idle_server_tid_ptr and self->idle_workers_ptr must be valid pointers +as described in struct umcg_task; self->next_tid must be zero. + +When unregistering a task, self must be NULL. + + +SYS_UMCG_WAIT() + +int sys_umcg_wait(uint32_t flags, uint64_t abs_timeout) operates on +registered UMCG servers and workers: struct umcg_task *self provided to +sys_umcg_ctl() when registering the current task is consulted in addition +to flags and abs_timeout parameters. + +The function can be used to perform one of the three operations: + +* wait: if self->next_tid is zero, sys_umcg_wait() puts the current + task to sleep; +* wake: if self->next_tid is not zero, and flags & UMCG_WAIT_WAKE_ONLY, + the task identified by next_tid is woken; +* context switch: if self->next_tid is not zero, and !(flags & + UMCG_WAIT_WAKE_ONLY), the current task is put to sleep and the next task + is woken, synchronously switching between the tasks on the current CPU + on the fast path. + +Flags can be zero or a combination of the following values: + +* UMCG_WAIT_WAKE_ONLY: wake the next task, don't put the current task to + sleep; +* UMCG_WAIT_WF_CURRENT_CPU: wake the next task on the curent CPU; this + flag has an effect only if UMCG_WAIT_WAKE_ONLY is set: context switching + is always attempted to happen on the curent CPU. + +The section below provides more details on how servers and workers interact +via sys_umcg_wait(), during worker block/wake events, and during worker +preemption. + + +STATE TRANSITIONS + +As mentioned above, the key principle of UMCG state transitions is that the +party initiating the state transition modifies the state of affected tasks. + +Below, "TASK:STATE" indicates a task T, where T can be either W for worker +or S for server, in state S, where S can be one of the three states, +potentially ORed with a state flag. Each individual state transition is an +atomic operation (cmpxchg) unless indicated otherwise. Also note that the +order of state transitions is important and is part of the contract between +the userspace and the kernel. The kernel is free to kill the task (SIGKILL) +if the contract is broken. + +Some worker state transitions below include adding LOCKED flag to worker +state. This is done to indicate to the kernel that the worker is +transitioning state and should not participate in the block/wake detection +routines, which can happen due to interrupts/pagefaults/signals. + +IDLE|LOCKED means that a running worker is preparing to sleep, so +interrupts should not lead to server wakeup; RUNNING|LOCKED means that an +idle worker is going to be "scheduled to run", but may not yet have its +server set up properly. + +The key invariant: a RUNNING worker (not LOCKED) must have a server +assigned to it. + +Key state transitions: + +* server to worker context switch ("schedule a worker to run"): + S:RUNNING+W:IDLE => S:IDLE+W:RUNNING: + in the userspace, in the context of the server S running: + S:RUNNING => S:IDLE (mark self as idle) + W:IDLE => W:RUNNING|LOCKED (mark the worker as running) + W.next_tid := S.tid; S.next_tid := W.tid (link the server with + the worker) + W:RUNNING|LOCKED => W:RUNNING (unlock the worker) + S: sys_umcg_wait() (make the syscall) + the kernel context switches from the server to the worker; the + server sleeps until it becomes RUNNING during one of the + transitions below; + +* worker to server context switch (worker "yields"): S:IDLE+W:RUNNING => +S:RUNNING+W:IDLE: + in the userspace, in the context of the worker W running (note that + a running worker has its next_tid set to point to its server): + W:RUNNING => W:IDLE|LOCKED (mark self as idle) + S:IDLE => S:RUNNING (mark the server as running) + W: sys_umcg_wait() (make the syscall) + the kernel removes the LOCKED flag from the worker's state and + context switches from the worker to the server; the worker sleeps + until it becomes RUNNING; + +* worker to worker context switch: W1:RUNNING+W2:IDLE => + W1:IDLE+W2:RUNNING: + in the userspace, in the context of W1 running: + W2:IDLE => W2:RUNNING|LOCKED (mark W2 as running) + W1:RUNNING => W1:IDLE|LOCKED (mark self as idle) + W2.next_tid := W1.next_tid; S.next_tid := W2.tid (transfer the + server W1 => W2) + W1:next_tid := W2.tid (indicate that W1 should context-switch + into W2) + W2:RUNNING|LOCKED => W2:RUNNING (unlock W2) + W1: sys_umcg_wait() (make the syscall) + same as above, the kernel removes the LOCKED flag from the W1's + state and context switches to next_tid; + +* worker wakeup: W:IDLE => W:IDLE, W queued into the idle worker list: + in the userspace, a server S can wake a worker W sleeping in + sys_umcg_wait() without "running" it. This is a purely + userspace operation that adds the worker to the idle worker list. + +* block detection: worker blocks in the kernel: S:IDLE+W:RUNNING => + S:RUNNING+W:BLOCKED: + when a worker blocks in the kernel in RUNNING state (not LOCKED), + before descheduling the task from the CPU the kernel performs + these operations: + W:RUNNING => W:BLOCKED + S := W.next_tid + S:IDLE => S:RUNNING + try_to_wake_up(S) + if any of the first three operations above fail, the worker is + killed via SIGKILL. Note that ttwu(S) is not required to succeed, + as the server may still be transitioning to sleep in + sys_umcg_wait(); before actually putting the server to sleep its + UMCG state is checked and, if it is RUNNING, sys_umcg_wait() + returns to the userspace; + if the worker has its LOCKED flag set, block detection does not + trigger, as the worker is assumed to be in the userspace + scheduling code. + +* wake detection: worker wakes in the kernel: W:BLOCKED => W:IDLE: + all workers' returns to the userspace are intercepted: + start: (a label) + if W:RUNNING & W.next_tid != 0: let the worker exit to the + userspace, as this is a RUNNING worker with a server; + W:* => W:IDLE (previously blocked or woken without servers + workers are not allowed to return to the userspace); + the worker is appended to W.idle_workers_ptr idle workers list; + S := *W.idle_server_tid_ptr; if (S != 0) S:IDLE => S.RUNNING; + ttwu(S) + idle_loop(W): this is the same idle loop that sys_umcg_wait() + uses: it breaks only when the worker becomes RUNNING; when + the idle loop exits, it is assumed that the userspace has + properly removed the worker from the idle workers list + before marking it RUNNING; + goto start; (repeat from the beginning). + + the logic above is a bit more complicated in the presence of + LOCKED or PREEMPTED flags, but the main invariants + stay the same: + only RUNNING workers with servers assigned are allowed to run + in the userspace (unless LOCKED); + newly IDLE workers are added to the idle workers list; any + user-initiated state change assumes the userspace + properly removed the worker from the list; + as with wake detection, any "breach of contract" by the + userspace will result in the task termination via SIGKILL. + +* worker preemption: S:IDLE+W:RUNNING => S:RUNNING+W:IDLE|PREEMPTED: + when the userspace wants to preempt a RUNNING worker, it changes it + state, atomically, RUNNING => RUNNING|PREEMPTED and sends a + signal to the worker via tgkill(); the signal handler, previously + set up by the userspace, can be a NOP (note that only RUNNING + workers can be preempted); + + if the worker, at the moment the signal arrived, continued to be + running on-CPU in the userspace, the "wake detection" code will be + triggered that, in addition to what was described above, will + check if the worker is in RUNNING|PREEMPTED state: + W:RUNNING|PREEMPTED => W:IDLE|PREEMPTED + S := W.next_tid + S:IDLE => S:RUNNING + try_to_wakeup(S) + + if the signal arrives after the worker blocks in the kernel, + the "block detection" happened as described above, with the + following change: + W:RUNNING|PREEMPTED => W:BLOCKED|PREEMPTED + S := W.next_tid + S:IDLE => S:RUNNING + try_to_wake_up(S) + + in any case, the worker's server is woken, with its attached + worker (S.next_tid) either in BLOCKED|PREEMPTED or IDLE|PREEMPTED + state. + + +SERVER-ONLY USE CASES + +Some workloads/applications may benefit from fast and synchronous on-CPU +user-initiated context switches without the need for full userspace +scheduling (block/wake detection). These applications can use "standalone" +UMCG servers to wait/wake/context-switch. At the moment only in-process +operations are allowed. In the future this restriction will be lifted, +and wait/wake/context-switch operations between servers in related processes +be permitted (when it is safe to do so, e.g. if the processes belong +to the same user and/or cgroup). + +These "worker-less" operations involve trivial RUNNING <==> IDLE state +changes, not discussed here for brevity.
--
2.25.1
PATCH 6/6 sched/umcg, lib/umcg: add tools/lib/umcg/libumcg.txt
In reply to Peter OskolkovDocument libumcg.
--- tools/lib/umcg/libumcg.txt | 438 +++++++++++++++++++++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 tools/lib/umcg/libumcg.txt
tools/lib/umcg/libumcg.txt new file +438 -0
@@ -0,0 +1,438 @@ +LIBUMCG API (USERSPACE) + +User Managed Concurrency Groups (UMCG) is an M:N threading +subsystem/toolkit that lets user space application developers implement +in-process user space schedulers. + +See Documentation/userspace-api/umcg.txt for UMCG API (kernel), as opposed +to LIBUMCG API described here. The first three subsections are the +same in both documents. + + +CONTENTS + + WHY? HETEROGENEOUS IN-PROCESS WORKLOADS + REQUIREMENTS + WHY THE TWO APIS: UMCG (KERNEL) AND LIBUMCG (USERSPACE)? + LIBUMCG API (USERSPACE) + SERVERS + WORKERS + BASIC UMCG TASKS + LIBUMCG API + umcg_t + umcg_tid + UMCG_NONE + umcg_enabled() + umcg_get_utid() + umcg_set_task_tag() + umcg_get_task_tag() + umcg_create_group() + umcg_destroy_group() + umcg_register_basic_task() + umcg_register_worker() + umcg_register_server() + umcg_unregister_task() + umcg_wait() + umcg_wake() + umcg_swap() + umcg_get_idle_worker() + umcg_run_worker() + umcg_preempt_worker() + umcg_get_time_ns() + + +WHY? HETEROGENEOUS IN-PROCESS WORKLOADS + +Linux kernel's CFS scheduler is designed for the "common" use case, with +efficiency/throughput in mind. Work isolation and workloads of different +"urgency" are addressed by tools such as cgroups, CPU affinity, priorities, +etc., which are difficult or impossible to efficiently use in-process. + +For example, a single DBMS process may receive tens of thousands requests +per second; some of these requests may have strong response latency +requirements as they serve live user requests (e.g. login authentication); +some of these requests may not care much about latency but must be served +within a certain time period (e.g. an hourly aggregate usage report); some +of these requests are to be served only on a best-effort basis and can be +NACKed under high load (e.g. an exploratory research/hypothesis testing +workload). + +Beyond different work item latency/throughput requirements as outlined +above, the DBMS may need to provide certain guarantees to different users; +for example, user A may "reserve" 1 CPU for their high-priority/low-latency +requests, 2 CPUs for mid-level throughput workloads, and be allowed to send +as many best-effort requests as possible, which may or may not be served, +depending on the DBMS load. Besides, the best-effort work, started when the +load was low, may need to be delayed if suddenly a large amount of +higher-priority work arrives. With hundreds or thousands of users like +this, it is very difficult to guarantee the application's responsiveness +using standard Linux tools while maintaining high CPU utilization. + +Gaming is another use case: some in-process work must be completed before a +certain deadline dictated by frame rendering schedule, while other work +items can be delayed; some work may need to be cancelled/discarded because +the deadline has passed; etc. + +User Managed Concurrency Groups is an M:N threading toolkit that allows +constructing user space schedulers designed to efficiently manage +heterogeneous in-process workloads described above while maintaining high +CPU utilization (95%+). + + +REQUIREMENTS + +One relatively established way to design high-efficiency, low-latency +systems is to split all work into small on-cpu work items, with +asynchronous I/O and continuations, all executed on a thread pool with the +number of threads not exceeding the number of available CPUs. Although this +approach works, it is quite difficult to develop and maintain such a +system, as, for example, small continuations are difficult to piece +together when debugging. Besides, such asynchronous callback-based systems +tend to be somewhat cache-inefficient, as continuations can get scheduled +on any CPU regardless of cache locality. + +M:N threading and cooperative user space scheduling enables controlled CPU +usage (minimal OS preemption), synchronous coding style, and better cache +locality. + +Specifically: + +* a variable/fluctuating number M of "application" threads should be + "scheduled over" a relatively fixed number N of "kernel" threads, where + N is less than or equal to the number of CPUs available; +* only those application threads that are attached to kernel threads are + scheduled "on CPU"; +* application threads should be able to cooperatively yield to each other; +* when an application thread blocks in kernel (e.g. in I/O), this becomes + a scheduling event ("block") that the userspace scheduler should be able + to efficiently detect, and reassign a waiting application thread to the + freeded "kernel" thread; +* when a blocked application thread wakes (e.g. its I/O operation + completes), this event ("wake") should also be detectable by the + userspace scheduler, which should be able to either quickly dispatch the + newly woken thread to an idle "kernel" thread or, if all "kernel" + threads are busy, put it in the waiting queue; +* in addition to the above, it would be extremely useful for a separate + in-process "watchdog" facility to be able to monitor the state of each + of the M+N threads, and to intervene in case of runaway workloads + (interrupt/preempt). + + +WHY THE TWO APIS: UMCG (KERNEL) AND LIBUMCG (USERSPACE)? + +UMCG syscalls, sys_umcg_ctl() and sys_umcg_wait(), are designed to make +the kernel-side UMCG implementation as lightweight as possible. LIBUMCG, +on the other hand, is designed to expose the key abstractions to users +in a much more usable, higher-level way. + +See Documentation/userspace-api/umcg.txt for more details on +UMCG API (kernel). + +Please note that LIBUMCG API is itself a rather low-level API intended +to be used to construct higher-level userspace schedulers. + +Note: to avoid confusion, in this document "UMCG servers/workers" refer +UMCG tasks when considered in the context of the kernel UMCG API (syscalls), +while "LIBUMCG servers/workers" refer to the same tasks when considered +in the context of the userspace LIBUMC API outlined below. When the +distinction is not important, "UMCG servers/workers" is used generically. + + +LIBUMCG API (USERSPACE) + +Based on the requrements above, LIBUMCG API (userspace) is build around the +following ideas: + +* UMCG server: a thread representing "kernel threads", or CPUs from + the requirements above; +* UMCG worker: a thread representing "application threads", to be + scheduled over servers; +* UMCG group: a collection of servers and workers that can interact with + each other; a single process may contain several UMCG groups (e.g. a + group per NUMA node); +* a set of functions (API) that allows workers to be "scheduled" over + servers and to interact with one another cooperatively. + + +LIBUMCG SERVERS + +When a thread is registered as a server, it behaves like any other normal +thread. + +Servers can interact with other servers in the same UMCG group: + +* servers can voluntarily suspend their execution by calling umcg_wait(); +* servers can wake other servers by calling umcg_wake(); +* servers can context-switch between each other by calling umcg_swap(). + +Servers can also interact with workers in their UMCG group: + +* servers can schedule ("run") workers in their place by calling + umcg_run_worker(); when the worker blocks, the function returns; +* servers can query for workers that finished their blocking operations + by calling umcg_get_idle_worker(); +* servers can force running workers into idle state and have the + servers running those workers to wakeup by calling umcg_preempt_worker(). + + +LIBUMCG WORKERS + +A worker cannot be running without having a server associated with it, so +when a task is first registered as a worker, it is blocked until a server +"runs" it (new workers are added to the idle worker list). + +Workers can interact with other workers in their UMCG group: + +* workers can voluntarily suspend their execution by calling umcg_wait(); +* workers can wake other workers by calling umcg_wake(); +* workers can context-switch between each other by calling umcg_swap(). + + +LIBUMCG BASIC UMCG TASKS + +If the application is only interested in server-to-server interactions, +it does not need to create a UMCG group and may register a server as a +"basic UMCG task". Same umcg_[wait|wake|swap] functions are available. + + +LIBUMCG API: umcg_t + +umcg_t is an opaque pointer indicating a UMCG group. + + +LIBUMCG API: umcg_tid + +umcg_tid is an opaque pointer indicating a UMCG task (a basic task, +a server, or a worker). + + +LIBUMCG API: UMCG_NONE + +UMCG_NONE holds a NULL value for variables of type umcg_t or umcg_tid. + + +LIBUMCG API: umcg_enabled() + +bool umcg_enabled(void) - returns true if the running kernel exposes + UMCG kernel API (sys_umcg_ctl and sys_umcg_wait). + + +LIBUMCG API: umcg_get_utid + +umcg_tid umcg_get_utid(void) - returns the umcg_tid value identifying + the current thread as a UMCG task. The value + is guaranteed to be stable over the life + of the thread, but may be reused between + different threads (it is a pointer to a TLS + variable). + + +LIBUMCG API: umg_set_task_tag() + +void umcg_set_task_tag(umcg_tid utid, intptr_t tag) - a helper function + used to associate an arbitrary user-provided value + with a umcg task/thread. + + +LIBUMCG API: umcg_get_task_tag() + +intptr_t umcg_get_task_tag(umcg_tid utid) - returns a previously set + task tag, or zero. + + +LIBUMCG API: umcg_create_group() + +umcg_t umcg_create_group(uint32_t flags) - create a UMCG group. + + UMCG servers and workers at LIBUMCG level must belong to the same UMCG + group to interact; note that this is different from UMCG kernel API, + where servers and workers can all interact within the same process. + + UMCG groups are used to partition UMCG tasks (servers and workers) within + a process, e.g. to allow NUMA-aware scheduling. + + +LIBUMCG API: umcg_destroy_group() + +int umcg_destroy_group(umcg_t umcg) - destroy a UMCG group. The group must + be empty, i.e. all its servers and workers must have + unregistered. + + +LIBUMCG API: umcg_register_basic_task() + +umcg_tid umcg_register_basic_task(intptr_t tag) - register the current + thread as a basic LIBUMCG task. + + Basic LIBUMCG tasks do not belong to UMCG groups, and thus cannot + interact with LIBUMCG workers. + + At the kernel level basic LIBUMCG tasks are servers. + + +LIBUMCG API: umcg_register_worker() + +umcg_tid umcg_register_worker(umcg_t group_id, intptr_t tag) - register + the current thread as a LIBUMCG worker in a group. + + LIBUMCG workers, once registered, can forget about being UMCG workers, + as the only difference vs "normal" threads is that now workers are + scheduled not by the kernel, but by servers in their UMCG group, which + happens "transparently" to UMCG workers. + + LIBUMCG workers may call umcg_[wait|wake|swap] to cooperatively share + workload with other LIBUMCG workers in the same group. + + Note: at the moment UMCG workers, once registered, cannnot receive + non-fatal signals. + + +LIBUMCG API: umcg_register_server() + +umcg_tid umcg_register_server(umcg_t group_id, intptr_t tag) - register + the current thread as a LIBUMCG server in a group. + + LIBUMCG servers schedule LIBUMCG workers in the same group via + umcg_get_idle_worker(), umcg_run_worker(), and umcg_preempt_worker(). + See descriptions of these functions below for more details. + + +LIBUMCG API: umcg_unregister_task() + +int umcg_unregister_task(void) - unregister the current thread as a UMCG task. + + A thread can be only one type of a UMCG task at a time. Once unregistered, + a thread can register again as a different UMCG task type, in the same + or a different group. + + +LIBUMCG API: umcg_wait() + +int umcg_wait(uint64_t timeout) - block the current UMCG task until + the timeout expires or it is woken via umcg_wake() or umcg_swap(). + + All UMCG task types can call umcg_wait(). + + +LIBUMCG API: umcg_wake() + +int umcg_wake(umcg_tid next, bool wf_current_cpu) - wake a UMCG task. + + Wake a umcg task if it is blocked as a result of calling umcg_wait() or + umcg_swap(). If @next is NOT blocked in umcg_wait() or umcg_swap(), + it will be marked as "wakeup queued"; when @next calls umcg_wait() or + umcg_swap() later, the "wakeup queued" flag will be removed and + the function will not block. + + Only one wakeup can be queued per task, so calling umcg_wake for + a task with a wakeup queued will spin (in the userspace) until the + wakeup flag is cleared. + + If @next is a worker blocked in umcg_wait(), the worker is added + to the idle workers list so that it will the be picked up by + umcg_get_idle_worker(). + + Note that "wakeup queued" is a purely LIBUMCG (userspace) concept: + the kernel (UMCG kernel API) is unaware of it. + + +LIBUMCG API: umcg_swap() + +int umcg_swap(umcg_tid next, u64 timeout) - block the current task; wake @next. + + umcg_swap() can be used for server-to-server or worker-to-worker + context switches, but NOT server-to-worker or worker-to-server. + If a server wants to context switch with a worker, the server + should call umcg_run_worker(). If a worker wants to context switch + to its server, it should call umcg_wait(). + + In server-to-server context switches, the switching-out server + is RUNNING; the switching-in server can either be IDLE or RUNNING. + If the switching-in server is running, it will have a wakeup queued. + If the switching-out server has a wakeup queued, umcg_swap() will + consume the wakeup. + + In worker-to-worker context switches, the "normal" behavior is that + the RUNNING switching-out worker becomes IDLE, its server is + transferred to the IDLE switching-in worker, and the switching-in + worker becomes RUNNING. + + The switching-in worker MUST NOT be in the idle worker list: it + can either be in umcg_wait(), or pulled out of the idle worker list + previously. + + Same wakeup-queued rules apply to swapping workers as they apply + to swapping servers. + + Note that while with servers umcg_swap() is technically equivalent + to { umcg_wake(); umcg_wait(); }, with possible on-cpu optimizations, + with workers there is a difference, as umcg_swap() will RUN an + idle worker, while umcg_wake() will add it to the idle worker list. + + This difference, however, is transparent for workers: workers + engaging is cooperative scheduling via wait/wake/swap will observe + exactly the same behavior as if they were servers or basic UMCG tasks. + + +LIBUMCG API: umcg_get_idle_worker() + +umcg_tid umcg_get_idle_worker(bool wait) - get an idle worker from + the idle worker list. + + Servers can query for unblocked workers by calling umcg_get_idle_worker(). + + There are two idle worker lists per UMCG group; the kernel-side list, + as described in Documentation/userspace-api/umcg.txt, and the + userspace-side list. umcg_get_idle_worker() first checks the userspace + list and, if it is not empty, returns the first available idle worker, + removing it from the list. + + If the userspace list is empty, the function swaps it with the kernel-side + list of empty workers, and then checks the userspace list again. + + If @wait is true, the function blocks if there are no idle workers + available. The server will be added to the group's idle server list. + The server may also be pointed at by struct umcg_task.idle_server_tid_ptr. + + It is safe to call umcg_get_idle_worker() concurrently. + + +LIBUMCG API: umcg_run_worker() + +umcg_tid umcg_run_worker(umcg_tid worker) - run the worker. + + Servers "run" workers by calling umcg_run_worker(). @worker must be + IDLE, and must NOT be in the idle worker list. I.e. a server may + run a worker that is blocked in umcg_wait() either if umcg_wake() + has NOT been called on the @worker, or if umcg_wake() HAD been + called, and the worker then was returned via umcg_get_idle_worker(). + + umcg_run_worker() will block; if the worker the server is running + swaps with another worker, the server will get reassigned to that + new worker. + + When the worker the server is running blocks, umcg_run_worker returns + the worker's umcg_tid, or UMCG_NONE if the worker unregisters. + + +LIBUMCG API: umcg_preempt_worker() + +int umcg_preempt_worker(umcg_tid worker) - preempt a RUNNING worker. + + The function interrupgs a RUNNING worker and wakes its server. If + the worker is not RUNNING (i.e. BLOCKED or IDLE), the function + returns an error with errno set to EAGAIN. + + The group the worker belongs to must be created with + UMCG_GROUP_ENABLE_PREEMPTION flag set. + + The function may be called from any thread in the process that + @worker belongs to. + + +LIBUMCG API: umcg_get_time_ns() + +uint64_t umcg_get_time_ns(void) - return the current absolute time. + + This function can be used to calculate the absolute timeouts passed + to umcg_wait() and umcg_swap().
--
2.25.1
kernel test robot
build botRe: [PATCH v0.8 2/6] mm, x86/uaccess: add userspace atomic helpers
In reply to Peter OskolkovThank you for the patch! Perhaps something to improve:
Hi Peter,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd]
url: https://github.com/0day-ci/linux/commits/Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 base: 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd config: arm-randconfig-r026-20211105 (attached as .config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 847a6807332b13f43704327c2d30103ec0347c77)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/23012d2a531975af519f3a7c7a3152197efcbe13
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 git checkout 23012d2a531975af519f3a7c7a3152197efcbe13
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> mm/maccess.c:491: warning: expecting prototype for xchg_user_[32|64][_nofault|]() - exchange 32/64(). Prototype was for xchg_user_32_nofault() instead
vim +491 mm/maccess.c
474
475 /**
476 * xchg_user_[32|64][_nofault|]() - exchange 32/64-bit values
477 * @uaddr: Destination address, in user space;
478 * @val: Source address, in kernel space.
479 *
480 * This is the standard atomic xchg: exchange values pointed to by @uaddr and @val.
481 *
482 * The _nofault versions don't fault and can be used in
483 * atomic/preempt-disabled contexts.
484 *
485 * Return:
486 * 0 : OK/success;
487 * -EINVAL: @uaddr is not properly aligned ('may fault' versions only);
488 * -EFAULT: memory access error (including mis-aligned @uaddr in _nofault).
489 */
490 int xchg_user_32_nofault(u32 __user *uaddr, u32 *val)
> 491 { 492 int ret;
493
494 if (unlikely(!access_ok(uaddr, sizeof(*uaddr))))
495 return -EFAULT;
496
497 pagefault_disable();
498
499 if (!user_access_begin(uaddr, sizeof(*uaddr))) {
500 pagefault_enable();
501 return -EFAULT;
502 }
503
504 ret = __try_xchg_user_32(val, uaddr, *val);
505 user_access_end();
506
507 pagefault_enable();
508
509 return ret;
510 }
511
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Peter OskolkovThank you for the patch! Perhaps something to improve:
Hi Peter,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd]
url: https://github.com/0day-ci/linux/commits/Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 base: 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/93e6110356346b226e3a41044aafe3d3b0906d10
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 git checkout 93e6110356346b226e3a41044aafe3d3b0906d10
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
| ^~~~~~~~~~~~~~~~~~~
kernel/sys_ni.c:249:1: note: in expansion of macro 'COND_SYSCALL_COMPAT'
249 | COND_SYSCALL_COMPAT(getsockopt);
| ^~~~~~~~~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_sendto' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:250:1: note: in expansion of macro 'COND_SYSCALL'
250 | COND_SYSCALL(sendto);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_shutdown' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:251:1: note: in expansion of macro 'COND_SYSCALL'
251 | COND_SYSCALL(shutdown);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_recvfrom' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:252:1: note: in expansion of macro 'COND_SYSCALL'
252 | COND_SYSCALL(recvfrom);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:41:32: warning: no previous prototype for '__arm64_compat_sys_recvfrom' [-Wmissing-prototypes]
41 | asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~~~~~~~~
kernel/sys_ni.c:253:1: note: in expansion of macro 'COND_SYSCALL_COMPAT'
253 | COND_SYSCALL_COMPAT(recvfrom);
| ^~~~~~~~~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_sendmsg' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:254:1: note: in expansion of macro 'COND_SYSCALL'
254 | COND_SYSCALL(sendmsg);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:41:32: warning: no previous prototype for '__arm64_compat_sys_sendmsg' [-Wmissing-prototypes]
41 | asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~~~~~~~~
kernel/sys_ni.c:255:1: note: in expansion of macro 'COND_SYSCALL_COMPAT'
255 | COND_SYSCALL_COMPAT(sendmsg);
| ^~~~~~~~~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_recvmsg' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:256:1: note: in expansion of macro 'COND_SYSCALL'
256 | COND_SYSCALL(recvmsg);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:41:32: warning: no previous prototype for '__arm64_compat_sys_recvmsg' [-Wmissing-prototypes]
41 | asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~~~~~~~~
kernel/sys_ni.c:257:1: note: in expansion of macro 'COND_SYSCALL_COMPAT'
257 | COND_SYSCALL_COMPAT(recvmsg);
| ^~~~~~~~~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_mremap' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:262:1: note: in expansion of macro 'COND_SYSCALL'
262 | COND_SYSCALL(mremap);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_add_key' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:265:1: note: in expansion of macro 'COND_SYSCALL'
265 | COND_SYSCALL(add_key);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_request_key' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:266:1: note: in expansion of macro 'COND_SYSCALL'
266 | COND_SYSCALL(request_key);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_keyctl' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:267:1: note: in expansion of macro 'COND_SYSCALL'
267 | COND_SYSCALL(keyctl);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:41:32: warning: no previous prototype for '__arm64_compat_sys_keyctl' [-Wmissing-prototypes]
41 | asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~~~~~~~~
kernel/sys_ni.c:268:1: note: in expansion of macro 'COND_SYSCALL_COMPAT'
268 | COND_SYSCALL_COMPAT(keyctl);
| ^~~~~~~~~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_landlock_create_ruleset' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:271:1: note: in expansion of macro 'COND_SYSCALL'
271 | COND_SYSCALL(landlock_create_ruleset);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_landlock_add_rule' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:272:1: note: in expansion of macro 'COND_SYSCALL'
272 | COND_SYSCALL(landlock_add_rule);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_landlock_restrict_self' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:273:1: note: in expansion of macro 'COND_SYSCALL'
273 | COND_SYSCALL(landlock_restrict_self);
| ^~~~~~~~~~~~
>> arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_umcg_ctl' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:276:1: note: in expansion of macro 'COND_SYSCALL'
276 | COND_SYSCALL(umcg_ctl);
| ^~~~~~~~~~~~
>> arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_umcg_wait' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:277:1: note: in expansion of macro 'COND_SYSCALL'
277 | COND_SYSCALL(umcg_wait);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_fadvise64_64' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:282:1: note: in expansion of macro 'COND_SYSCALL'
282 | COND_SYSCALL(fadvise64_64);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_swapon' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:285:1: note: in expansion of macro 'COND_SYSCALL'
285 | COND_SYSCALL(swapon);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_swapoff' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:286:1: note: in expansion of macro 'COND_SYSCALL'
286 | COND_SYSCALL(swapoff);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_mprotect' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:287:1: note: in expansion of macro 'COND_SYSCALL'
287 | COND_SYSCALL(mprotect);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_msync' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:288:1: note: in expansion of macro 'COND_SYSCALL'
288 | COND_SYSCALL(msync);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_mlock' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:289:1: note: in expansion of macro 'COND_SYSCALL'
289 | COND_SYSCALL(mlock);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_munlock' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:290:1: note: in expansion of macro 'COND_SYSCALL'
290 | COND_SYSCALL(munlock);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_mlockall' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:291:1: note: in expansion of macro 'COND_SYSCALL'
291 | COND_SYSCALL(mlockall);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_munlockall' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:292:1: note: in expansion of macro 'COND_SYSCALL'
292 | COND_SYSCALL(munlockall);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_mincore' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:293:1: note: in expansion of macro 'COND_SYSCALL'
293 | COND_SYSCALL(mincore);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_madvise' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:294:1: note: in expansion of macro 'COND_SYSCALL'
294 | COND_SYSCALL(madvise);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_process_madvise' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:295:1: note: in expansion of macro 'COND_SYSCALL'
295 | COND_SYSCALL(process_madvise);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_process_mrelease' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:296:1: note: in expansion of macro 'COND_SYSCALL'
296 | COND_SYSCALL(process_mrelease);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_remap_file_pages' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:297:1: note: in expansion of macro 'COND_SYSCALL'
297 | COND_SYSCALL(remap_file_pages);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_mbind' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:298:1: note: in expansion of macro 'COND_SYSCALL'
298 | COND_SYSCALL(mbind);
| ^~~~~~~~~~~~
arch/arm64/include/asm/syscall_wrapper.h:76:32: warning: no previous prototype for '__arm64_sys_get_mempolicy' [-Wmissing-prototypes]
76 | asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
| ^~~~~~~~~~~~
kernel/sys_ni.c:299:1: note: in expansion of macro 'COND_SYSCALL'
299 | COND_SYSCALL(get_mempolicy);vim +/__arm64_sys_umcg_ctl +76 arch/arm64/include/asm/syscall_wrapper.h
4378a7d4be30ec Mark Rutland 2018-07-11 50
4378a7d4be30ec Mark Rutland 2018-07-11 51 #define __SYSCALL_DEFINEx(x, name, ...) \
4378a7d4be30ec Mark Rutland 2018-07-11 52 asmlinkage long __arm64_sys##name(const struct pt_regs *regs); \
4378a7d4be30ec Mark Rutland 2018-07-11 53 ALLOW_ERROR_INJECTION(__arm64_sys##name, ERRNO); \
4378a7d4be30ec Mark Rutland 2018-07-11 54 static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
4378a7d4be30ec Mark Rutland 2018-07-11 55 static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
4378a7d4be30ec Mark Rutland 2018-07-11 56 asmlinkage long __arm64_sys##name(const struct pt_regs *regs) \
4378a7d4be30ec Mark Rutland 2018-07-11 57 { \
4378a7d4be30ec Mark Rutland 2018-07-11 58 return __se_sys##name(SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__)); \
4378a7d4be30ec Mark Rutland 2018-07-11 59 } \
4378a7d4be30ec Mark Rutland 2018-07-11 60 static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
4378a7d4be30ec Mark Rutland 2018-07-11 61 { \
4378a7d4be30ec Mark Rutland 2018-07-11 62 long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \
4378a7d4be30ec Mark Rutland 2018-07-11 63 __MAP(x,__SC_TEST,__VA_ARGS__); \
4378a7d4be30ec Mark Rutland 2018-07-11 64 __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \
4378a7d4be30ec Mark Rutland 2018-07-11 65 return ret; \
4378a7d4be30ec Mark Rutland 2018-07-11 66 } \
4378a7d4be30ec Mark Rutland 2018-07-11 67 static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
4378a7d4be30ec Mark Rutland 2018-07-11 68
4378a7d4be30ec Mark Rutland 2018-07-11 69 #define SYSCALL_DEFINE0(sname) \
4378a7d4be30ec Mark Rutland 2018-07-11 70 SYSCALL_METADATA(_##sname, 0); \
0e358bd7b7ebd2 Sami Tolvanen 2019-05-24 71 asmlinkage long __arm64_sys_##sname(const struct pt_regs *__unused); \
4378a7d4be30ec Mark Rutland 2018-07-11 72 ALLOW_ERROR_INJECTION(__arm64_sys_##sname, ERRNO); \
0e358bd7b7ebd2 Sami Tolvanen 2019-05-24 73 asmlinkage long __arm64_sys_##sname(const struct pt_regs *__unused)
4378a7d4be30ec Mark Rutland 2018-07-11 74
c27eccfe4d6c74 Sami Tolvanen 2019-09-10 75 #define COND_SYSCALL(name) \
c27eccfe4d6c74 Sami Tolvanen 2019-09-10 @76 asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs) \
c27eccfe4d6c74 Sami Tolvanen 2019-09-10 77 { \
c27eccfe4d6c74 Sami Tolvanen 2019-09-10 78 return sys_ni_syscall(); \
c27eccfe4d6c74 Sami Tolvanen 2019-09-10 79 }4378a7d4be30ec Mark Rutland 2018-07-11 80
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Peter OskolkovQuoted 14 lines · Peter Oskolkov
kernel/sched/umcg.c new file +14
-0+/* +* Try to wake up. May be called with preempt_disable set. May be called +* cross-process. +* +* Note: umcg_ttwu succeeds even if ttwu fails: see wait/wake state +* ordering logic. +*/ +static int umcg_ttwu (u32 next_tid,int wake_flags) +{ + struct task_struct *next; + + rcu_read_lock(); + next = find_task_by_vpid(next_tid); + if (!next || !umcg_wakeup_allowed(next)) {
kernel/sched/umcg.c line 460
Quoted 10 lines
kernel/sched/umcg.c new file +10
-0+ rcu_read_unlock(); + return -ESRCH; + } + + /* The result of ttwu below is ignored. */ + try_to_wake_up(next, TASK_NORMAL, wake_flags); + rcu_read_unlock(); + + return 0; +}
Doesn't try_to_wake_up return different values based on whether or not a task was woken up? I think it could be useful to propagate that result instead of always returning zero. Even if it only helps for debugging.
Quoted 16 lines
kernel/sched/umcg.c new file +16
-0+static bool enqueue_idle_worker (struct umcg_task __user *ut_worker) +{ + u64 __user *node = &ut_worker->idle_workers_ptr; + u64 __user *head_ptr; + u64 first = (u64)node; + u64 head; + + if (get_user(head, node) || !head) + return false; + + head_ptr = (u64 __user *)head; + + /* Mark the worker as pending. */ + if (put_user(UMCG_IDLE_NODE_PENDING, node)) + return false; +
kernel/sched/umcg.c line 788
Quoted 10 lines
kernel/sched/umcg.c new file +10
-0+ /* Make the head point to the worker. */ + if (xchg_user_64(head_ptr, &first)) + return false; + + /* Make the worker point to the previous head. */ + if (put_user(first, node)) + return false; + + return true; +}
If the last two operation return false, whichever task tries to consume the list could deadlock, depending on whether or not the ensuing force_sig(SIGKILL); reaches the consuming task. Does the force_sig kill the task or the entire process. Is it possible to consume this list from a different process that shares the memory? I'm wondering if the last two "return false" should attempt to retract the UMCG_IDLE_NODE_PENDING.
Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Peter OskolkovHi Peter,
Quoted 8 lines · Peter Oskolkov
kernel/sched/umcg.c new file +8
-0+/** +* umcg_update_state: atomically update umcg_task.state_ts, set new timestamp. +* @state_ts - points to the state_ts member of struct umcg_task to update; +* @expected - the expected value of state_ts, including the timestamp; +* @desired - the desired value of state_ts, state part only; +* @may_fault - whether to use normal or _nofault cmpxchg. +* +* The function is basically cmpxchg(state_ts, expected, desired), with extra
kernel/sched/umcg.c line 148
Quoted 10 lines
kernel/sched/umcg.c new file +10
-0+* code to set the timestamp in @desired. +*/ +static int umcg_update_state (u64 __user *state_ts,u64 *expected,u64 desired, +bool may_fault) +{ +u64 curr_ts = (*expected) >> (64 -UMCG_STATE_TIMESTAMP_BITS ); +u64 next_ts =ktime_get_ns () >>UMCG_STATE_TIMESTAMP_GRANULARITY ; + +/* Cut higher order bits. */ + next_ts &=UMCG_TASK_STATE_MASK_FULL ;
next_ts &= (1 << UMCG_STATE_TIMESTAMP_BITS) - 1; or am I wrong.
Quoted 71 lines
kernel/sched/umcg.c new file +71
-0+if (next_ts == curr_ts) + ++next_ts; + +/* Remove an old timestamp, if any. */ + desired &=UMCG_TASK_STATE_MASK_FULL ; + +/* Set the new timestamp. */ + desired |= (next_ts << (64 -UMCG_STATE_TIMESTAMP_BITS )); + +if (may_fault) +return cmpxchg_user_64 (state_ts, expected, desired); + +return cmpxchg_user_64_nofault (state_ts, expected, desired); +} + +/** +* sys_umcg_ctl: (un)register the current task as a UMCG task. +* @flags: ORed values from enum umcg_ctl_flag; see below; +* @self: a pointer to struct umcg_task that describes this +* task and governs the behavior of sys_umcg_wait if +* registering; must be NULL if unregistering. +* +* @flags & UMCG_CTL_REGISTER: register a UMCG task: +* UMCG workers: +* - @flags & UMCG_CTL_WORKER +* - self->state must be UMCG_TASK_BLOCKED +* UMCG servers: +* - !(@flags & UMCG_CTL_WORKER) +* - self->state must be UMCG_TASK_RUNNING +* +* All tasks: +* - self->next_tid must be zero +* +* If the conditions above are met, sys_umcg_ctl() immediately returns +* if the registered task is a server; a worker will be added to +* idle_workers_ptr, and the worker put to sleep; an idle server +* from idle_server_tid_ptr will be woken, if present. +* +* @flags == UMCG_CTL_UNREGISTER: unregister a UMCG task. If the current task +* is a UMCG worker, the userspace is responsible for waking its +* server (before or after calling sys_umcg_ctl). +* +* Return: +* 0 - success +* -EFAULT - failed to read @self +* -EINVAL - some other error occurred +*/ +SYSCALL_DEFINE2(umcg_ctl, u32, flags, struct umcg_task __user *, self) +{ +struct umcg_task ut; + +if (flags ==UMCG_CTL_UNREGISTER ) { +if (self || !current->umcg_task) +return -EINVAL ; + +if (current->flags &PF_UMCG_WORKER ) +umcg_handle_exiting_worker (); +else +umcg_clear_task (current); + +return 0 ; + } + +if (!(flags &UMCG_CTL_REGISTER )) +return -EINVAL ; + + flags &= ~UMCG_CTL_REGISTER ; +if (flags && flags !=UMCG_CTL_WORKER ) +return -EINVAL ; + +if (current->umcg_task || !self)
kernel/sched/umcg.c line 230
Quoted 10 lines
kernel/sched/umcg.c new file +10
-0+return -EINVAL ; + +if (copy_from_user (&ut, self,sizeof (ut))) +return -EFAULT ; + +if (ut.next_tid) +return -EINVAL ; + +if (flags ==UMCG_CTL_WORKER ) { +if ((ut.state_ts &UMCG_TASK_STATE_MASK_FULL ) !=UMCG_TASK_BLOCKED )
Or use UMCG_TASK_STATE_MASK that is enough.
kernel/sched/umcg.c line 239
Quoted 9 lines
kernel/sched/umcg.c new file +9
-0+return -EINVAL ; + +WRITE_ONCE (current->umcg_task, self); + current->flags |=PF_UMCG_WORKER ; + +/* Trigger umcg_handle_resuming_worker() */ +set_tsk_thread_flag (current,TIF_NOTIFY_RESUME ); + }else { +if ((ut.state_ts &UMCG_TASK_STATE_MASK_FULL ) !=UMCG_TASK_RUNNING )
The same here.
kernel/sched/umcg.c line 247
Quoted 8 lines
kernel/sched/umcg.c new file +8
-0+return -EINVAL ; + +WRITE_ONCE (current->umcg_task, self); + } + +return 0 ; +} +
Thanks,
Tao
Re: [PATCH v0.8 4/6] sched/umcg, lib/umcg: implement libumcg
In reply to Peter OskolkovQuoted 14 lines · Peter Oskolkov
tools/lib/umcg/libumcg.c new file +14
-0+/* Update the state variable, set new timestamp. */ +static bool umcg_update_state (uint64_t *state,uint64_t *prev,uint64_t next) +{ +uint64_t prev_ts = (*prev) >> (64 -UMCG_STATE_TIMESTAMP_BITS ); +struct timespec now; +uint64_t next_ts; +int res; + +/* +* clock_gettime(CLOCK_MONOTONIC, ...) takes less than 20ns on a +* typical Intel processor on average, even when run concurrently, +* so the overhead is low enough for most applications. +* +* If this is still too high, `next_ts = prev_ts + 1` should work
tools/lib/umcg/libumcg.c line 179
Quoted 10 lines
tools/lib/umcg/libumcg.c new file +10
-0+* as well. The only real requirement is that the "timestamps" are +* uniqueue per thread within a reasonable time frame. +*/ + res =clock_gettime (CLOCK_MONOTONIC , &now); +assert (!res); + next_ts = (now.tv_sec *NSEC_PER_SEC + now.tv_nsec) >> +UMCG_STATE_TIMESTAMP_GRANULARITY ; + +/* Cut higher order bits. */ + next_ts &= ((1ULL <<UMCG_STATE_TIMESTAMP_BITS ) -1 );
This is the right cut.. The same to the kernel side.
Quoted 27 lines
tools/lib/umcg/libumcg.c new file +27
-0+ +if (next_ts == prev_ts) + ++next_ts; + +#ifndef NDEBUG +if (prev_ts > next_ts) { +fprintf (stderr,"%s: time goes back: prev_ts: %lu " +"next_ts: %lu diff: %lu\n" , __func__, + prev_ts, next_ts, prev_ts - next_ts); + } +#endif + +/* Remove old timestamp, if any. */ + next &= ((1ULL << (64 -UMCG_STATE_TIMESTAMP_BITS )) -1 ); + +/* Set the new timestamp. */ + next |= (next_ts << (64 -UMCG_STATE_TIMESTAMP_BITS )); + +/* +* TODO: review whether memory order below can be weakened to +* memory_order_acq_rel for success and memory_order_acquire for +* failure. +*/ +return atomic_compare_exchange_strong_explicit (state, prev, next, + memory_order_seq_cst, memory_order_seq_cst); +} +
tools/lib/umcg/libumcg.c line 263
Quoted 10 lines
tools/lib/umcg/libumcg.c new file +9
-0+static void task_unlock (struct umcg_task_tls *task,uint64_t expected_state, +uint64_t new_state) +{ +bool ok; +uint64_t next; +uint64_t prev =atomic_load_explicit (&task->umcg_task.state_ts, + memory_order_acquire); + + next = ((prev & ~UMCG_TASK_STATE_MASK_FULL ) | new_state) & ~UMCG_TF_LOCKED ;
Use UMCG_TASK_STATE_MASK instead and the other state flag can be checked.
All others places that use UMCG_TASK_STATE_MASK_FULL to mask to check the task state may seems reasonable if the state flag not allowed to be set when we check that task state, otherwise use UMCG_TASK_STATE_MASK will be enough.
Not sure.
Thanks,
Tao
Quoted 6 lines
tools/lib/umcg/libumcg.c new file +6
-0+assert (next != prev); +assert ((prev &UMCG_TASK_STATE_MASK_FULL & ~UMCG_TF_LOCKED ) == expected_state); + + ok =umcg_update_state (&task->umcg_task.state_ts, &prev, next); +assert (ok); +}
Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Tao ZhouQuoted 17 lines · Tao Zhou
Hi Peter,
Quoted 12 lines · Peter Oskolkov
kernel/sched/umcg.c new file +12
-0+/** +* umcg_update_state: atomically update umcg_task.state_ts, set new timestamp. +* @state_ts - points to the state_ts member of struct umcg_task to update; +* @expected - the expected value of state_ts, including the timestamp; +* @desired - the desired value of state_ts, state part only; +* @may_fault - whether to use normal or _nofault cmpxchg. +* +* The function is basically cmpxchg(state_ts, expected, desired), with extra +* code to set the timestamp in @desired. +*/ +static int umcg_update_state (u64 __user *state_ts,u64 *expected,u64 desired, +bool may_fault)
Quoted 8 lines
kernel/sched/umcg.c line 148
Quoted 6 lines
kernel/sched/umcg.c new file +6
-0+{ +u64 curr_ts = (*expected) >> (64 -UMCG_STATE_TIMESTAMP_BITS ); +u64 next_ts =ktime_get_ns () >>UMCG_STATE_TIMESTAMP_GRANULARITY ; + +/* Cut higher order bits. */ + next_ts &=UMCG_TASK_STATE_MASK_FULL ;
next_ts&= (1 <<UMCG_STATE_TIMESTAMP_BITS) - 1; or am I wrong.
Right, thanks. I'll fix it in the next patchset version, if any. But at the moment I don't think this is bad enough to prevent merging, if the maintainers feel like it - basically, the condition below will always be false, so if the state is updated within 16 nanoseconds, the timestamps may sometimes match. For this to be an issue, this should result in ABA updates, so two state changes should happen in 16 nanoseconds, which is extremely unlikely (impossible?), as most state changes are accompanied by other atomic ops.
Quoted 76 lines
Quoted 76 lines
kernel/sched/umcg.c new file +75
-0+if (next_ts == curr_ts) + ++next_ts; + +/* Remove an old timestamp, if any. */ + desired &=UMCG_TASK_STATE_MASK_FULL ; + +/* Set the new timestamp. */ + desired |= (next_ts << (64 -UMCG_STATE_TIMESTAMP_BITS )); + +if (may_fault) +return cmpxchg_user_64 (state_ts, expected, desired); + +return cmpxchg_user_64_nofault (state_ts, expected, desired); +} + +/** +* sys_umcg_ctl: (un)register the current task as a UMCG task. +* @flags: ORed values from enum umcg_ctl_flag; see below; +* @self: a pointer to struct umcg_task that describes this +* task and governs the behavior of sys_umcg_wait if +* registering; must be NULL if unregistering. +* +* @flags & UMCG_CTL_REGISTER: register a UMCG task: +* UMCG workers: +* - @flags & UMCG_CTL_WORKER +* - self->state must be UMCG_TASK_BLOCKED +* UMCG servers: +* - !(@flags & UMCG_CTL_WORKER) +* - self->state must be UMCG_TASK_RUNNING +* +* All tasks: +* - self->next_tid must be zero +* +* If the conditions above are met, sys_umcg_ctl() immediately returns +* if the registered task is a server; a worker will be added to +* idle_workers_ptr, and the worker put to sleep; an idle server +* from idle_server_tid_ptr will be woken, if present. +* +* @flags == UMCG_CTL_UNREGISTER: unregister a UMCG task. If the current task +* is a UMCG worker, the userspace is responsible for waking its +* server (before or after calling sys_umcg_ctl). +* +* Return: +* 0 - success +* -EFAULT - failed to read @self +* -EINVAL - some other error occurred +*/ +SYSCALL_DEFINE2(umcg_ctl, u32, flags, struct umcg_task __user *, self) +{ +struct umcg_task ut; + +if (flags ==UMCG_CTL_UNREGISTER ) { +if (self || !current->umcg_task) +return -EINVAL ; + +if (current->flags &PF_UMCG_WORKER ) +umcg_handle_exiting_worker (); +else +umcg_clear_task (current); + +return 0 ; + } + +if (!(flags &UMCG_CTL_REGISTER )) +return -EINVAL ; + + flags &= ~UMCG_CTL_REGISTER ; +if (flags && flags !=UMCG_CTL_WORKER ) +return -EINVAL ; + +if (current->umcg_task || !self) +return -EINVAL ; + +if (copy_from_user (&ut, self,sizeof (ut))) +return -EFAULT ;
Quoted 8 lines
kernel/sched/umcg.c line 230
Quoted 6 lines
kernel/sched/umcg.c new file +6
-0+ +if (ut.next_tid) +return -EINVAL ; + +if (flags ==UMCG_CTL_WORKER ) { +if ((ut.state_ts &UMCG_TASK_STATE_MASK_FULL ) !=UMCG_TASK_BLOCKED )Or use
UMCG_TASK_STATE_MASKthat is enough.
Do you have a use case for this (i.e. when state flags can be legitimately set here)? At the moment I can't think of it, and I'd rather keep things more strict to avoid dealing with unexpected use cases in the future.
Quoted 12 lines
kernel/sched/umcg.c line 239
Quoted 10 lines
kernel/sched/umcg.c new file +9
-0+return -EINVAL ; + +WRITE_ONCE (current->umcg_task, self); + current->flags |=PF_UMCG_WORKER ; + +/* Trigger umcg_handle_resuming_worker() */ +set_tsk_thread_flag (current,TIF_NOTIFY_RESUME ); + }else { +if ((ut.state_ts &UMCG_TASK_STATE_MASK_FULL ) !=UMCG_TASK_RUNNING )The same here.
Yes, the same here - why do you think task state flags should be allowed here?
Quoted 13 lines
kernel/sched/umcg.c line 247
Quoted 9 lines
kernel/sched/umcg.c new file +8
-0+return -EINVAL ; + +WRITE_ONCE (current->umcg_task, self); + } + +return 0 ; +} +Thanks,
Tao
Re: [PATCH v0.8 4/6] sched/umcg, lib/umcg: implement libumcg
In reply to Tao ZhouQuoted 21 lines · Tao Zhou
Quoted 18 lines · Peter Oskolkov
tools/lib/umcg/libumcg.c new file +18
-0+/* Update the state variable, set new timestamp. */ +static bool umcg_update_state (uint64_t *state,uint64_t *prev,uint64_t next) +{ +uint64_t prev_ts = (*prev) >> (64 -UMCG_STATE_TIMESTAMP_BITS ); +struct timespec now; +uint64_t next_ts; +int res; + +/* +* clock_gettime(CLOCK_MONOTONIC, ...) takes less than 20ns on a +* typical Intel processor on average, even when run concurrently, +* so the overhead is low enough for most applications. +* +* If this is still too high, `next_ts = prev_ts + 1` should work +* as well. The only real requirement is that the "timestamps" are +* uniqueue per thread within a reasonable time frame. +*/ + res =clock_gettime (CLOCK_MONOTONIC , &now);
Quoted 8 lines
tools/lib/umcg/libumcg.c line 179
Quoted 6 lines
tools/lib/umcg/libumcg.c new file +6
-0+assert (!res); + next_ts = (now.tv_sec *NSEC_PER_SEC + now.tv_nsec) >> +UMCG_STATE_TIMESTAMP_GRANULARITY ; + +/* Cut higher order bits. */ + next_ts &= ((1ULL <<UMCG_STATE_TIMESTAMP_BITS ) -1 );This is the right cut.. The same to the kernel side.
Yes, thanks!
Quoted 29 lines
Quoted 28 lines
tools/lib/umcg/libumcg.c new file +27
-0+ +if (next_ts == prev_ts) + ++next_ts; + +#ifndef NDEBUG +if (prev_ts > next_ts) { +fprintf (stderr,"%s: time goes back: prev_ts: %lu " +"next_ts: %lu diff: %lu\n" , __func__, + prev_ts, next_ts, prev_ts - next_ts); + } +#endif + +/* Remove old timestamp, if any. */ + next &= ((1ULL << (64 -UMCG_STATE_TIMESTAMP_BITS )) -1 ); + +/* Set the new timestamp. */ + next |= (next_ts << (64 -UMCG_STATE_TIMESTAMP_BITS )); + +/* +* TODO: review whether memory order below can be weakened to +* memory_order_acq_rel for success and memory_order_acquire for +* failure. +*/ +return atomic_compare_exchange_strong_explicit (state, prev, next, + memory_order_seq_cst, memory_order_seq_cst); +} +
Quoted 11 lines
tools/lib/umcg/libumcg.c line 263
Quoted 9 lines
tools/lib/umcg/libumcg.c new file +9
-0+static void task_unlock (struct umcg_task_tls *task,uint64_t expected_state, +uint64_t new_state) +{ +bool ok; +uint64_t next; +uint64_t prev =atomic_load_explicit (&task->umcg_task.state_ts, + memory_order_acquire); + + next = ((prev & ~UMCG_TASK_STATE_MASK_FULL ) | new_state) & ~UMCG_TF_LOCKED ;Use
UMCG_TASK_STATE_MASKinstead and the other state flag can be checked.
Why? We want to clear the TF_LOCKED flag and keep every other bit of state, including other state flags (but excluding timestamp).
Quoted 17 lines
All others places that use
UMCG_TASK_STATE_MASK_FULLto mask to check the task state may seems reasonable if the state flag not allowed to be set when we check that task state, otherwise useUMCG_TASK_STATE_MASKwill be enough.Not sure.
Thanks,
TaoQuoted 6 lines
tools/lib/umcg/libumcg.c new file +6
-0+assert (next != prev); +assert ((prev &UMCG_TASK_STATE_MASK_FULL & ~UMCG_TF_LOCKED ) == expected_state); + + ok =umcg_update_state (&task->umcg_task.state_ts, &prev, next); +assert (ok); +}
Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Thierry DelisleQuoted 23 lines · Thierry Delisle
Quoted 21 lines · Peter Oskolkov
kernel/sched/umcg.c new file +21
-0+/* +* Try to wake up. May be called with preempt_disable set. May be called +* cross-process. +* +* Note: umcg_ttwu succeeds even if ttwu fails: see wait/wake state +* ordering logic. +*/ +static int umcg_ttwu (u32 next_tid,int wake_flags) +{ +struct task_struct *next; + +rcu_read_lock (); + next =find_task_by_vpid (next_tid); +if (!next || !umcg_wakeup_allowed (next)) { +rcu_read_unlock (); +return -ESRCH ; + } + +/* The result of ttwu below is ignored. */ +try_to_wake_up (next,TASK_NORMAL , wake_flags); +rcu_read_unlock ();
Quoted 9 lines
kernel/sched/umcg.c line 86
Quoted 3 lines
kernel/sched/umcg.c new file +3
-0+ +return 0 ; +}Doesn't
try_to_wake_upreturn different values based on whether or not a task
was woken up? I think it could be useful to propagate that result instead of always returning zero. Even if it only helps for debugging.
The protocol is to mark the wakee as UMCG_TASK_RUNNING and call ttwu; if you look at umcg_idle_loop(), you will see that the ordering is set so that the wakee will indeed either wake or not go to sleep at all, regardless of whether ttwu succeeds. So in terms of correctness we do not need to check ttwu result; returning anything different here "for debugging"? Maybe. If/when this is merged, feel free to send a patch. Or maybe I'll add this in a next patchset version...
Quoted 29 lines
Quoted 18 lines
kernel/sched/umcg.c new file +16
-0+static bool enqueue_idle_worker (struct umcg_task __user *ut_worker) +{ +u64 __user *node = &ut_worker->idle_workers_ptr; +u64 __user *head_ptr; +u64 first = (u64 )node; +u64 head; + +if (get_user (head, node) || !head) +return false; + + head_ptr = (u64 __user *)head; + +/* Mark the worker as pending. */ +if (put_user (UMCG_IDLE_NODE_PENDING , node)) +return false; +kernel/sched/umcg.c line 788
Quoted 10 lines
kernel/sched/umcg.c new file +10
-0+/* Make the head point to the worker. */ +if (xchg_user_64 (head_ptr, &first)) +return false; + +/* Make the worker point to the previous head. */ +if (put_user (first, node)) +return false; + +return true; +}
Quoted 7 lines
If the last two operation return false, whichever task tries to consume the list could deadlock, depending on whether or not the ensuing
force_sig(SIGKILL); reaches the consuming task. Does theforce_sigkill the task or the entire process. Is it possible to consume this list from a different process that shares the memory? I'm wondering if the last two "return false" should attempt to retract theUMCG_IDLE_NODE_PENDING.
The function will return false only on a memory access error, and the whole process will be killed as a result. At least this is the intention. Do you think the code does anything different?
Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Peter OskolkovQuoted 27 lines · Peter Oskolkov
Quoted 17 lines · Tao Zhou
Hi Peter,
Quoted 12 lines · Peter Oskolkov
kernel/sched/umcg.c new file +12
-0+/** +* umcg_update_state: atomically update umcg_task.state_ts, set new timestamp. +* @state_ts - points to the state_ts member of struct umcg_task to update; +* @expected - the expected value of state_ts, including the timestamp; +* @desired - the desired value of state_ts, state part only; +* @may_fault - whether to use normal or _nofault cmpxchg. +* +* The function is basically cmpxchg(state_ts, expected, desired), with extra +* code to set the timestamp in @desired. +*/ +static int umcg_update_state (u64 __user *state_ts,u64 *expected,u64 desired, +bool may_fault)Quoted 8 lines
kernel/sched/umcg.c line 148
Quoted 6 lines
kernel/sched/umcg.c new file +6
-0+{ +u64 curr_ts = (*expected) >> (64 -UMCG_STATE_TIMESTAMP_BITS ); +u64 next_ts =ktime_get_ns () >>UMCG_STATE_TIMESTAMP_GRANULARITY ; + +/* Cut higher order bits. */ + next_ts &=UMCG_TASK_STATE_MASK_FULL ;
next_ts&= (1 <<UMCG_STATE_TIMESTAMP_BITS) - 1; or am I wrong.
Quoted 7 lines
Right, thanks. I'll fix it in the next patchset version, if any. But at the moment I don't think this is bad enough to prevent merging, if the maintainers feel like it - basically, the condition below will always be false, so if the state is updated within 16 nanoseconds, the timestamps may sometimes match. For this to be an issue, this should result in ABA updates, so two state changes should happen in 16 nanoseconds, which is extremely unlikely (impossible?), as most state
The task state occupy 0-5 bits and use 2 bits(00, 01, 10, 11) to denote NONE, RUNNING, IDLE, BLOCK. Is it possible to grasp 4 bits from here to used to extend the timestamp resolution.
Quoted 87 lines
changes are accompanied by other atomic ops.
Quoted 76 lines
Quoted 76 lines
kernel/sched/umcg.c new file +75
-0+if (next_ts == curr_ts) + ++next_ts; + +/* Remove an old timestamp, if any. */ + desired &=UMCG_TASK_STATE_MASK_FULL ; + +/* Set the new timestamp. */ + desired |= (next_ts << (64 -UMCG_STATE_TIMESTAMP_BITS )); + +if (may_fault) +return cmpxchg_user_64 (state_ts, expected, desired); + +return cmpxchg_user_64_nofault (state_ts, expected, desired); +} + +/** +* sys_umcg_ctl: (un)register the current task as a UMCG task. +* @flags: ORed values from enum umcg_ctl_flag; see below; +* @self: a pointer to struct umcg_task that describes this +* task and governs the behavior of sys_umcg_wait if +* registering; must be NULL if unregistering. +* +* @flags & UMCG_CTL_REGISTER: register a UMCG task: +* UMCG workers: +* - @flags & UMCG_CTL_WORKER +* - self->state must be UMCG_TASK_BLOCKED +* UMCG servers: +* - !(@flags & UMCG_CTL_WORKER) +* - self->state must be UMCG_TASK_RUNNING +* +* All tasks: +* - self->next_tid must be zero +* +* If the conditions above are met, sys_umcg_ctl() immediately returns +* if the registered task is a server; a worker will be added to +* idle_workers_ptr, and the worker put to sleep; an idle server +* from idle_server_tid_ptr will be woken, if present. +* +* @flags == UMCG_CTL_UNREGISTER: unregister a UMCG task. If the current task +* is a UMCG worker, the userspace is responsible for waking its +* server (before or after calling sys_umcg_ctl). +* +* Return: +* 0 - success +* -EFAULT - failed to read @self +* -EINVAL - some other error occurred +*/ +SYSCALL_DEFINE2(umcg_ctl, u32, flags, struct umcg_task __user *, self) +{ +struct umcg_task ut; + +if (flags ==UMCG_CTL_UNREGISTER ) { +if (self || !current->umcg_task) +return -EINVAL ; + +if (current->flags &PF_UMCG_WORKER ) +umcg_handle_exiting_worker (); +else +umcg_clear_task (current); + +return 0 ; + } + +if (!(flags &UMCG_CTL_REGISTER )) +return -EINVAL ; + + flags &= ~UMCG_CTL_REGISTER ; +if (flags && flags !=UMCG_CTL_WORKER ) +return -EINVAL ; + +if (current->umcg_task || !self) +return -EINVAL ; + +if (copy_from_user (&ut, self,sizeof (ut))) +return -EFAULT ;Quoted 8 lines
kernel/sched/umcg.c line 230
Quoted 6 lines
kernel/sched/umcg.c new file +6
-0+ +if (ut.next_tid) +return -EINVAL ; + +if (flags ==UMCG_CTL_WORKER ) { +if ((ut.state_ts &UMCG_TASK_STATE_MASK_FULL ) !=UMCG_TASK_BLOCKED )Or use
UMCG_TASK_STATE_MASKthat is enough.
Quoted 4 lines
Do you have a use case for this (i.e. when state flags can be legitimately set here)? At the moment I can't think of it, and I'd rather keep things more strict to avoid dealing with unexpected use cases in the future.
When read through this thread, I am not realize that this time the state flags should not be set. But I need to go other round to be more clear like I'm now reading the doc again..
Quoted 28 lines
Quoted 11 lines
kernel/sched/umcg.c line 239
Quoted 9 lines
kernel/sched/umcg.c new file +9
-0+return -EINVAL ; + +WRITE_ONCE (current->umcg_task, self); + current->flags |=PF_UMCG_WORKER ; + +/* Trigger umcg_handle_resuming_worker() */ +set_tsk_thread_flag (current,TIF_NOTIFY_RESUME ); + }else { +if ((ut.state_ts &UMCG_TASK_STATE_MASK_FULL ) !=UMCG_TASK_RUNNING )The same here.
Yes, the same here - why do you think task state flags should be allowed here?
Quoted 13 lines
kernel/sched/umcg.c line 247
Quoted 9 lines
kernel/sched/umcg.c new file +8
-0+return -EINVAL ; + +WRITE_ONCE (current->umcg_task, self); + } + +return 0 ; +} +Thanks,
Tao
Re: [PATCH v0.8 4/6] sched/umcg, lib/umcg: implement libumcg
In reply to Peter OskolkovQuoted 74 lines · Peter Oskolkov
Quoted 21 lines · Tao Zhou
Quoted 18 lines · Peter Oskolkov
tools/lib/umcg/libumcg.c new file +18
-0+/* Update the state variable, set new timestamp. */ +static bool umcg_update_state (uint64_t *state,uint64_t *prev,uint64_t next) +{ +uint64_t prev_ts = (*prev) >> (64 -UMCG_STATE_TIMESTAMP_BITS ); +struct timespec now; +uint64_t next_ts; +int res; + +/* +* clock_gettime(CLOCK_MONOTONIC, ...) takes less than 20ns on a +* typical Intel processor on average, even when run concurrently, +* so the overhead is low enough for most applications. +* +* If this is still too high, `next_ts = prev_ts + 1` should work +* as well. The only real requirement is that the "timestamps" are +* uniqueue per thread within a reasonable time frame. +*/ + res =clock_gettime (CLOCK_MONOTONIC , &now);Quoted 8 lines
tools/lib/umcg/libumcg.c line 179
Quoted 6 lines
tools/lib/umcg/libumcg.c new file +6
-0+assert (!res); + next_ts = (now.tv_sec *NSEC_PER_SEC + now.tv_nsec) >> +UMCG_STATE_TIMESTAMP_GRANULARITY ; + +/* Cut higher order bits. */ + next_ts &= ((1ULL <<UMCG_STATE_TIMESTAMP_BITS ) -1 );This is the right cut.. The same to the kernel side.
Yes, thanks!
Quoted 29 lines
Quoted 28 lines
tools/lib/umcg/libumcg.c new file +27
-0+ +if (next_ts == prev_ts) + ++next_ts; + +#ifndef NDEBUG +if (prev_ts > next_ts) { +fprintf (stderr,"%s: time goes back: prev_ts: %lu " +"next_ts: %lu diff: %lu\n" , __func__, + prev_ts, next_ts, prev_ts - next_ts); + } +#endif + +/* Remove old timestamp, if any. */ + next &= ((1ULL << (64 -UMCG_STATE_TIMESTAMP_BITS )) -1 ); + +/* Set the new timestamp. */ + next |= (next_ts << (64 -UMCG_STATE_TIMESTAMP_BITS )); + +/* +* TODO: review whether memory order below can be weakened to +* memory_order_acq_rel for success and memory_order_acquire for +* failure. +*/ +return atomic_compare_exchange_strong_explicit (state, prev, next, + memory_order_seq_cst, memory_order_seq_cst); +} +Quoted 11 lines
tools/lib/umcg/libumcg.c line 263
Quoted 9 lines
tools/lib/umcg/libumcg.c new file +9
-0+static void task_unlock (struct umcg_task_tls *task,uint64_t expected_state, +uint64_t new_state) +{ +bool ok; +uint64_t next; +uint64_t prev =atomic_load_explicit (&task->umcg_task.state_ts, + memory_order_acquire); + + next = ((prev & ~UMCG_TASK_STATE_MASK_FULL ) | new_state) & ~UMCG_TF_LOCKED ;Use
UMCG_TASK_STATE_MASKinstead and the other state flag can be checked.
Quoted 2 lines
Why? We want to clear the
TF_LOCKEDflag and keep every other bit of state, including other state flags (but excluding timestamp).
This one is different because the task state flag is also masked by UMCG_TASK_STATE_MASK_FULL. But no effect I think. Document says that
'
PREEMPTED: the userspace indicates it wants the worker to be preempted; there are no situations when both LOCKED and PREEMPTED flags are set at the same time.
'
The task state flag this time only have UMCG_TF_LOCKED be set even if we cleared the task state flag.
Quoted 19 lines
Quoted 19 lines
All others places that use
UMCG_TASK_STATE_MASK_FULLto mask to check the task state may seems reasonable if the state flag not allowed to be set when we check that task state, otherwise useUMCG_TASK_STATE_MASKwill be enough.Not sure.
Thanks,
TaoQuoted 6 lines
tools/lib/umcg/libumcg.c new file +6
-0+assert (next != prev); +assert ((prev &UMCG_TASK_STATE_MASK_FULL & ~UMCG_TF_LOCKED ) == expected_state); + + ok =umcg_update_state (&task->umcg_task.state_ts, &prev, next); +assert (ok); +}
Re: [PATCH v0.8 2/6] mm, x86/uaccess: add userspace atomic helpers
In reply to Peter OskolkovQuoted 75 lines · Peter Oskolkov
In addition to futexes needing to do atomic operations in the userspace, a second use case is now in the works (UMCG, see
https://lore.kernel.org/all/[email protected]/),
so a generic facility to perform these operations has been called for (see https://lore.kernel.org/all/87ilyk9xc0.ffs@tglx/).Add a set of generic helpers to perform 32/64-bit xchg and cmpxchg operations in the userspace. Also implement the required architecture-specific support on
x86_64.Signed-off-by Peter Oskolkov <[email protected]>--- arch/x86/include/asm/uaccess_64.h | 93 +++++++++++ include/linux/uaccess.h | 46 ++++++ mm/maccess.c | 264 ++++++++++++++++++++++++++++++ 3 files changed, 403 insertions(+)arch/x86/include/asm/uaccess_64.h +50
-0@@ -79,4 +79,97 @@ __copy_from_user_flushcache(void *dst, const void __user *src, unsigned size)kasan_check_write (dst, size);return __copy_user_flushcache (dst, src, size); } + +#define ARCH_HAS_ATOMIC_UACCESS_HELPERS 1 + +static inline int __try_cmpxchg_user_32 (u32 *uval,u32 __user *uaddr, +u32 oldval,u32 newval) +{ +int ret =0 ; + + asmvolatile ("\n" +"1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" +"2:\n" +"\t.section .fixup, \"ax\"\n" +"3:\tmov %3, %0\n" +"\tjmp 2b\n" +"\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "+r" (ret), "=a" (oldval), "+m" (*uaddr) + : "i" (-EFAULT), "r" (newval), "1" (oldval) + : "memory" + ); + *uval = oldval; +return ret; +} + +static inline int __try_cmpxchg_user_64 (u64 *uval,u64 __user *uaddr, +u64 oldval,u64 newval) +{ +int ret =0 ; + + asmvolatile ("\n" +"1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" +"2:\n" +"\t.section .fixup, \"ax\"\n" +"3:\tmov %3, %0\n" +"\tjmp 2b\n" +"\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "+r" (ret), "=a" (oldval), "+m" (*uaddr) + : "i" (-EFAULT), "r" (newval), "1" (oldval) + : "memory" + ); + *uval = oldval; +return ret; +} + +static inline int __try_xchg_user_32 (u32 *oval,u32 __user *uaddr,u32 newval) +{ +u32 oldval =0 ; +int ret =0 ; +
arch/x86/include/asm/uaccess_64.h __copy_from_user_flushcache(void *dst, const void __user *src, unsigned size) · line 141
Quoted 10 lines
arch/x86/include/asm/uaccess_64.h +10
-0+ asmvolatile ("\n" +"1:\txchgl %0, %2\n" +"2:\n" +"\t.section .fixup, \"ax\"\n" +"3:\tmov %3, %1\n" +"\tjmp 2b\n" +"\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "=r" (oldval), "=r" (ret), "+m" (*uaddr) + : "i" (-EFAULT), "0" (newval), "1" (0)
"1"(0) can be omitted, that ret is initialized. And the initialization of oldval not need.
Quoted 14 lines
arch/x86/include/asm/uaccess_64.h +14
-0+ ); + +if (ret) +return ret; + + *oval = oldval; +return 0 ; +} + +static inline int __try_xchg_user_64 (u64 *oval,u64 __user *uaddr,u64 newval) +{ +u64 oldval =0 ; +int ret =0 ; +
arch/x86/include/asm/uaccess_64.h __copy_from_user_flushcache(void *dst, const void __user *src, unsigned size) · line 165
Quoted 10 lines
arch/x86/include/asm/uaccess_64.h +10
-0+ asmvolatile ("\n" +"1:\txchgq %0, %2\n" +"2:\n" +"\t.section .fixup, \"ax\"\n" +"3:\tmov %3, %1\n" +"\tjmp 2b\n" +"\t.previous\n" + _ASM_EXTABLE_UA(1b, 3b) + : "=r" (oldval), "=r" (ret), "+m" (*uaddr) + : "i" (-EFAULT), "0" (newval), "1" (0)
Same of above.
Quoted 26 lines
arch/x86/include/asm/uaccess_64.h +9
-0+ ); + +if (ret) +return ret; + + *oval = oldval; + return 0; +} +#endif /* _ASM_X86_UACCESS_64_H */ include/linux/uaccess.h +8
-0@@ -408,4 +408,50 @@ void __noreturn usercopy_abort(const char *name, const char *detail, unsigned long len);#endif +#ifdef ARCH_HAS_ATOMIC_UACCESS_HELPERS +/** +* cmpxchg_user_[32|64][_nofault|]() - compare_exchange 32/64-bit values +* @uaddr: Destination address, in user space; +* @curr_val: Source address, in kernel space; +* @new_val: The value to write to the destination address. +* +* This is the standard cmpxchg: atomically: compare *@uaddr to *@curr_val;
include/linux/uaccess.h void __noreturn usercopy_abort(const char *name, const char *detail, · line 428
Quoted 10 lines
include/linux/uaccess.h +10
-0+* if the values match, write @new_val to @uaddr, return 0; if the values +* do not match, write *@uaddr to @curr_val, return -EAGAIN. +* +* The _nofault versions don't fault and can be used in +* atomic/preempt-disabled contexts. +* +* Return: +* 0 : OK/success; +* -EINVAL: @uaddr is not properly aligned ('may fault' versions only); +* -EFAULT: memory access error (including mis-aligned @uaddr in _nofault);
(including mis-aligned @uaddr in _fault)
Quoted 11 lines
include/linux/uaccess.h +11
-0+* -EAGAIN: @old did not match. +*/ +int cmpxchg_user_32_nofault (u32 __user *uaddr,u32 *curr_val,u32 new_val); +int cmpxchg_user_64_nofault (u64 __user *uaddr,u64 *curr_val,u64 new_val); +int cmpxchg_user_32 (u32 __user *uaddr,u32 *curr_val,u32 new_val); +int cmpxchg_user_64 (u64 __user *uaddr,u64 *curr_val,u64 new_val); + +/** +* xchg_user_[32|64][_nofault|]() - exchange 32/64-bit values +* @uaddr: Destination address, in user space; +* @val: Source address, in kernel space.
include/linux/uaccess.h void __noreturn usercopy_abort(const char *name, const char *detail, · line 449
Quoted 10 lines
include/linux/uaccess.h +10
-0+* +* This is the standard atomic xchg: exchange values pointed to by @uaddr and @val. +* +* The _nofault versions don't fault and can be used in +* atomic/preempt-disabled contexts. +* +* Return: +* 0 : OK/success; +* -EINVAL: @uaddr is not properly aligned ('may fault' versions only); +* -EFAULT: memory access error (including mis-aligned @uaddr in _nofault).
(including mis-aligned @uaddr in _fault)
Quoted 43 lines
include/linux/uaccess.h +7
-0+*/ +int xchg_user_32_nofault (u32 __user *uaddr,u32 *val); +int xchg_user_64_nofault (u64 __user *uaddr,u64 *val); +int xchg_user_32 (u32 __user *uaddr,u32 *val); +int xchg_user_64 (u64 __user *uaddr,u64 *val); +#endif /* ARCH_HAS_ATOMIC_UACCESS_HELPERS */ +#endif /* __LINUX_UACCESS_H__ */ mm/maccess.c +27
-0@@ -335,3 +335,267 @@ long strnlen_user_nofault(const void __user *unsafe_addr, long count)return ret; } + +#ifdef ARCH_HAS_ATOMIC_UACCESS_HELPERS + +static int fix_pagefault (unsigned long uaddr,bool write_fault,int bytes) +{ +struct mm_struct *mm = current->mm; +int ret; + +mmap_read_lock (mm); + ret =fixup_user_fault (mm, uaddr, write_fault ?FAULT_FLAG_WRITE :0 , +NULL ); +mmap_read_unlock (mm); + +return ret <0 ? ret :0 ; +} + +int cmpxchg_user_32_nofault (u32 __user *uaddr,u32 *curr_val,u32 new_val) +{ +int ret = -EFAULT ; +u32 __old = *curr_val; + +if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +if (!user_access_begin (uaddr,sizeof (*uaddr))) {
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 374
Quoted 10 lines
mm/maccess.c +10
-0+pagefault_enable (); +return -EFAULT ; + } + ret =__try_cmpxchg_user_32 (curr_val, uaddr, __old, new_val); +user_access_end (); + +if (!ret) + ret = *curr_val == __old ?0 : -EAGAIN ; + +pagefault_enable ();
May this can be moved to be sibling to user_access_end() even do not know much about this to me.
Quoted 14 lines
mm/maccess.c +14
-0+return ret; +} + +int cmpxchg_user_64_nofault (u64 __user *uaddr,u64 *curr_val,u64 new_val) +{ +int ret = -EFAULT ; +u64 __old = *curr_val; + +if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +if (!user_access_begin (uaddr,sizeof (*uaddr))) {
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 398
Quoted 10 lines
mm/maccess.c +10
-0+pagefault_enable (); +return -EFAULT ; + } + ret =__try_cmpxchg_user_64 (curr_val, uaddr, __old, new_val); +user_access_end (); + +if (!ret) + ret = *curr_val == __old ?0 : -EAGAIN ; + +pagefault_enable ();
The same.
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 409
Quoted 10 lines
mm/maccess.c +10
-0+return ret; +} + +int cmpxchg_user_32 (u32 __user *uaddr,u32 *curr_val,u32 new_val) +{ +int ret = -EFAULT ; +u32 __old = *curr_val; + +/* Validate proper alignment. */ + if (unlikely(((unsigned long)uaddr % sizeof(*uaddr)) ||
See address. sizeof(*uaddr) --> sizeof(uaddr).
The size of address length.
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 409
Quoted 1 line
mm/maccess.c +1
-0+ ((unsigned long)curr_val % sizeof(*curr_val))))
Same. sizeof(*curr_val) --> sizeof(curr_val)
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 410
Quoted 1 line
mm/maccess.c +1
-0+return -EINVAL ;
This return should be -EFAULT accord to the comment above if not wrong to me.
Quoted 25 lines
mm/maccess.c +25
-0+if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +while (true) { + ret = -EFAULT ; +if (!user_access_begin (uaddr,sizeof (*uaddr))) +break ; + + ret =__try_cmpxchg_user_32 (curr_val, uaddr, __old, new_val); +user_access_end (); + +if (!ret) { + ret = *curr_val == __old ?0 : -EAGAIN ; +break ; + } + +if (fix_pagefault ((unsigned long )uaddr, true,sizeof (*uaddr)) <0 ) +break ; + } + +pagefault_enable (); +return ret; +}
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 447
Quoted 10 lines
mm/maccess.c +10
-0+ +int cmpxchg_user_64 (u64 __user *uaddr,u64 *curr_val,u64 new_val) +{ +int ret = -EFAULT ; +u64 __old = *curr_val; + +/* Validate proper alignment. */ +if (unlikely (((unsigned long )uaddr %sizeof (*uaddr)) || + ((unsigned long )curr_val %sizeof (*curr_val)))) +return -EINVAL ;
The same as above.. even the address size is equal to the value size. Not use value size here.
Quoted 83 lines
mm/maccess.c +83
-0+if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +while (true) { + ret = -EFAULT ; +if (!user_access_begin (uaddr,sizeof (*uaddr))) +break ; + + ret =__try_cmpxchg_user_64 (curr_val, uaddr, __old, new_val); +user_access_end (); + +if (!ret) { + ret = *curr_val == __old ?0 : -EAGAIN ; +break ; + } + +if (fix_pagefault ((unsigned long )uaddr, true,sizeof (*uaddr)) <0 ) +break ; + } + +pagefault_enable (); +return ret; +} + +/** +* xchg_user_[32|64][_nofault|]() - exchange 32/64-bit values +* @uaddr: Destination address, in user space; +* @val: Source address, in kernel space. +* +* This is the standard atomic xchg: exchange values pointed to by @uaddr and @val. +* +* The _nofault versions don't fault and can be used in +* atomic/preempt-disabled contexts. +* +* Return: +* 0 : OK/success; +* -EINVAL: @uaddr is not properly aligned ('may fault' versions only); +* -EFAULT: memory access error (including mis-aligned @uaddr in _nofault). +*/ +int xchg_user_32_nofault (u32 __user *uaddr,u32 *val) +{ +int ret; + +if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +if (!user_access_begin (uaddr,sizeof (*uaddr))) { +pagefault_enable (); +return -EFAULT ; + } + + ret =__try_xchg_user_32 (val, uaddr, *val); +user_access_end (); + +pagefault_enable (); + +return ret; +} + +int xchg_user_64_nofault (u64 __user *uaddr,u64 *val) +{ +int ret; + +if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +if (!user_access_begin (uaddr,sizeof (*uaddr))) { +pagefault_enable (); +return -EFAULT ; + } + + ret =__try_xchg_user_64 (val, uaddr, *val); +user_access_end (); + +pagefault_enable (); + +return ret;
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 541
Quoted 10 lines
mm/maccess.c +10
-0+} + +int xchg_user_32 (u32 __user *uaddr,u32 *val) +{ +int ret = -EFAULT ; + +/* Validate proper alignment. */ +if (unlikely (((unsigned long )uaddr %sizeof (*uaddr)) || + ((unsigned long )val %sizeof (*val)))) +return -EINVAL ;
The same as above.
Quoted 23 lines
mm/maccess.c +23
-0+if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +while (true) { + ret = -EFAULT ; +if (!user_access_begin (uaddr,sizeof (*uaddr))) +break ; + + ret =__try_xchg_user_32 (val, uaddr, *val); +user_access_end (); + +if (!ret) +break ; + +if (fix_pagefault ((unsigned long )uaddr, true,sizeof (*uaddr)) <0 ) +break ; + } + +pagefault_enable (); + +return ret;
mm/maccess.c long strnlen_user_nofault(const void __user *unsafe_addr, long count) · line 575
Quoted 10 lines
mm/maccess.c +10
-0+} + +int xchg_user_64 (u64 __user *uaddr,u64 *val) +{ +int ret = -EFAULT ; + +/* Validate proper alignment. */ +if (unlikely (((unsigned long )uaddr %sizeof (*uaddr)) || + ((unsigned long )val %sizeof (*val)))) +return -EINVAL ;
The same as above..
Quoted 28 lines
mm/maccess.c +25
-1+if (unlikely (!access_ok (uaddr,sizeof (*uaddr)))) +return -EFAULT ; + +pagefault_disable (); + +while (true) { + ret = -EFAULT ; +if (!user_access_begin (uaddr,sizeof (*uaddr))) +break ; + + ret =__try_xchg_user_64 (val, uaddr, *val); +user_access_end (); + +if (!ret) +break ; + +if (fix_pagefault ((unsigned long )uaddr, true,sizeof (*uaddr)) <0 ) +break ; + } + +pagefault_enable (); + + return ret; +} +#endif /* ARCH_HAS_ATOMIC_UACCESS_HELPERS */ --2.25.1
Quoted 22 lines · Peter Oskolkov
User Managed Concurrency Groups (UMCG) is an M:N threading subsystem/toolkit that lets user space application developers implement in-process user space schedulers.
Key changes from the previous patchset
https://lore.kernel.org/all/[email protected]/:- added libumcg
tools/lib/umcg;
- worker "wakeup" is reworked so that it is now purely a userspace op, instead of waking the thread in order for it to block on return to the userspace immediately;
- a couple of minor fixes and refactorings.These big things remain to be addressed (in no particular order):
- support tracing/debugging
- make context switches faster (seeumcg_do_context_switchinumcg.c)
- support other architectures
- cleanup and post selftests intools/testing/selftests/umcg/
- allow cross-mm wakeups (securely)
Quoted 7 lines
Peter Oskolkov (6):
sched/umcg: addWF_CURRENT_CPUand externise ttwu mm, x86/uaccess: add userspace atomic helpers sched/umcg: implement UMCG syscalls sched/umcg, lib/umcg: implement libumcg sched/umcg: addDocumentation/userspace-api/umcg.txtsched/umcg, lib/umcg: addtools/lib/umcg/libumcg.txt
Hi Peter,
Do you have a real workload or an example application using UMCG?
Quoted 36 lines
Documentation/userspace-api/umcg.txt | 598 ++++++++++++ arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/x86/include/asm/uaccess_64.h | 93 ++ fs/exec.c | 1 + include/linux/sched.h | 71 ++ include/linux/syscalls.h | 3 + include/linux/uaccess.h | 46 + include/uapi/asm-generic/unistd.h | 6 +- include/uapi/linux/umcg.h | 137 +++ init/Kconfig | 10 + kernel/entry/common.c | 4 +- kernel/exit.c | 5 + kernel/sched/Makefile | 1 + kernel/sched/core.c | 12 +- kernel/sched/fair.c | 4 + kernel/sched/sched.h | 15 +- kernel/sched/umcg.c | 949 +++++++++++++++++++ kernel/sys_ni.c | 4 + mm/maccess.c | 264 ++++++ tools/lib/umcg/.gitignore | 4 + tools/lib/umcg/Makefile | 11 + tools/lib/umcg/libumcg.c | 1201 ++++++++++++++++++++++++ tools/lib/umcg/libumcg.h | 299 ++++++ tools/lib/umcg/libumcg.txt | 438 +++++++++ 24 files changed, 4166 insertions(+), 12 deletions(-) create mode 100644 Documentation/userspace-api/umcg.txt create mode 100644 include/uapi/linux/umcg.h create mode 100644 kernel/sched/umcg.c create mode 100644 tools/lib/umcg/.gitignore create mode 100644 tools/lib/umcg/Makefile create mode 100644 tools/lib/umcg/libumcg.c create mode 100644 tools/lib/umcg/libumcg.h create mode 100644 tools/lib/umcg/libumcg.txt
Quoted 4 lines
base-commit:
8ea9183db4ad8afbcb7089a77c23eaf965b0cacd--
2.25.1
Thanks
Barry
Hi Barry,
[...]
Quoted 3 lines
Do you have a real workload or an example application using UMCG?
[...]
A google-internal variant of UMCG kernel patches is used extensively to enable user-space scheduling of heterogeneous work items. The main use case is services that need to ensure user isolation; in addition, latency vs throughput workloads served by the same service are also well addressed by user-space schedulers.
For example, a DBMS needs to ensure that one "hungry" user does not adversely affect other well-behaved users; but at the same time if the overall load is relatively low, users are allowed to go ahead and consume as much CPU as possible, as long as this does not affect other users negatively.
Services that treat their work uniformly, and care only about raw throughput, usually do not benefit from custom user-space scheduling that UMCG, or similar, enables.
Thanks,
Peter
kernel test robot
build botRe: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
In reply to Peter OskolkovThank you for the patch! Yet something to improve:
Hi Peter,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd]
url: https://github.com/0day-ci/linux/commits/Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 base: 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd config: i386-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/93e6110356346b226e3a41044aafe3d3b0906d10
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 git checkout 93e6110356346b226e3a41044aafe3d3b0906d10
# save the attached .config to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from <command-line>:32:
>> ./usr/include/linux/umcg.h:80:2: error: unknown type name 'u64'
80 | u64 state_ts; /* r/w */
| ^~~
>> ./usr/include/linux/umcg.h:91:2: error: unknown type name 'u32'
91 | u32 next_tid; /* r */
| ^~~
./usr/include/linux/umcg.h:93:2: error: unknown type name 'u32'
93 | u32 flags; /* Reserved; must be zero. */
| ^~~
./usr/include/linux/umcg.h:101:2: error: unknown type name 'u64'
101 | u64 idle_workers_ptr; /* r/w */
| ^~~
./usr/include/linux/umcg.h:107:2: error: unknown type name 'u64'
107 | u64 idle_server_tid_ptr; /* r */
| ^~~---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls
Quoted 20 lines · kernel test robot
Hi Peter,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on
8ea9183db4ad8afbcb7089a77c23eaf965b0cacd]url: https://github.com/0day-ci/linux/commits/Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 base: 8ea9183db4ad8afbcb7089a77c23eaf965b0cacd config: i386-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/93e6110356346b226e3a41044aafe3d3b0906d10
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Peter-Oskolkov/sched-mm-x86-uaccess-implement-User-Managed-Concurrency-Groups/20211105-035945 git checkout93e6110356346b226e3a41044aafe3d3b0906d10
# save the attached .config to linux build tree
mkdirbuild_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
Quoted 4 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
I cannot reproduce this. Both in my tree on top of tip, and the one referenced above, I can compile i386 ok:
$ make ARCH=i386 allyesconfig $ make ARCH=i386 -j16
succeeds.
$ gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Quoted 21 lines
In file included from <command-line>:32:
Quoted 1 line
Quoted 1 line
./usr/include/linux/umcg.h:80:2: error: unknown type name 'u64'80 | u64 state_ts; /* r/w */ | ^~~Quoted 1 line
Quoted 1 line
./usr/include/linux/umcg.h:91:2: error: unknown type name 'u32'91 | u32 next_tid; /* r */ | ^~~ ./usr/include/linux/umcg.h:93:2: error: unknown type name 'u32' 93 | u32 flags; /* Reserved; must be zero. */ | ^~~ ./usr/include/linux/umcg.h:101:2: error: unknown type name 'u64' 101 | u64 idle_workers_ptr; /* r/w */ | ^~~ ./usr/include/linux/umcg.h:107:2: error: unknown type name 'u64' 107 | u64 idle_server_tid_ptr; /* r */ | ^~~---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org