-----BEGIN PGP SIGNATURE----- iQJEBAABCAAuFiEEwPw5LcreJtl1+l5K99NY+ylx4KYFAl/YJxsQHGF4Ym9lQGtl cm5lbC5kawAKCRD301j7KXHgpjpyEACBdW+YjenjTbkUPeEXzQgkBkTZUYw3g007 DPcUT1g8PQZXYXlQvBKCvGhhIr7/KVcjepKoowiNQfBNGcIPJTVopW58nzpqAfTQ goI2WYGn5EKFFKBPvtH04cJD/Wo8muXdxynKtqyZbnGGgZjQxPrE259b8dpHjBSR 6L7HHkk0D1oU/5b6h6Ocpg9mc/0iIUCZylySAYY3eGO0JaVPJaXgZSJZYgHxCHll Lb+/y/fXdtm/0PmQ3ko0ev54g3yEWqZIX0NsZW1asrButIy+KLzQ2Mz1xFLFDMag prtIfwb8tzgc4dFPY090C/azjCh5CPpxqYS6FkRwS0p86n6OhkyXrqfily5Hs4/B NC7CBPBSH/j+NKUK7CYZcpTzTpxPjUr9p0anUdlvMJz8FhTb/3YEEZ1UTeWOeHmk Yo5SxnFghLeZZeZ1ok6rdymnVa7WEX12SCLGQX31BB2mld0tNbKb4b+FsBF6OUMk IUaX6OjwDFVRaysC88BQ4hjcIP1HxsViG4/VZDX15gjAAH2Pvb+7tev+lcDcOhjz TCD4GNFspTFzRhh9nT7oxQ679qCh9G9zHbzuIRewnrS6iqvo5SJQB3dR2yrWZRRH ySkQFiHpYOlnLJYv0jg9COlGwo2FUdcvKhCvkjQKKBz48rzW/IC0LwKdRQWZDFk3 FKGzP/NBig== =cadT -----END PGP SIGNATURE----- Merge tag 'tif-task_work.arch-2020-12-14' of git://git.kernel.dk/linux-block Pull TIF_NOTIFY_SIGNAL updates from Jens Axboe: "This sits on top of of the core entry/exit and x86 entry branch from the tip tree, which contains the generic and x86 parts of this work. Here we convert the rest of the archs to support TIF_NOTIFY_SIGNAL. With that done, we can get rid of JOBCTL_TASK_WORK from task_work and signal.c, and also remove a deadlock work-around in io_uring around knowing that signal based task_work waking is invoked with the sighand wait queue head lock. The motivation for this work is to decouple signal notify based task_work, of which io_uring is a heavy user of, from sighand. The sighand lock becomes a huge contention point, particularly for threaded workloads where it's shared between threads. Even outside of threaded applications it's slower than it needs to be. Roman Gershman <romger@amazon.com> reported that his networked workload dropped from 1.6M QPS at 80% CPU to 1.0M QPS at 100% CPU after io_uring was changed to use TIF_NOTIFY_SIGNAL. The time was all spent hammering on the sighand lock, showing 57% of the CPU time there [1]. There are further cleanups possible on top of this. One example is TIF_PATCH_PENDING, where a patch already exists to use TIF_NOTIFY_SIGNAL instead. Hopefully this will also lead to more consolidation, but the work stands on its own as well" [1] https://github.com/axboe/liburing/issues/215 * tag 'tif-task_work.arch-2020-12-14' of git://git.kernel.dk/linux-block: (28 commits) io_uring: remove 'twa_signal_ok' deadlock work-around kernel: remove checking for TIF_NOTIFY_SIGNAL signal: kill JOBCTL_TASK_WORK io_uring: JOBCTL_TASK_WORK is no longer used by task_work task_work: remove legacy TWA_SIGNAL path sparc: add support for TIF_NOTIFY_SIGNAL riscv: add support for TIF_NOTIFY_SIGNAL nds32: add support for TIF_NOTIFY_SIGNAL ia64: add support for TIF_NOTIFY_SIGNAL h8300: add support for TIF_NOTIFY_SIGNAL c6x: add support for TIF_NOTIFY_SIGNAL alpha: add support for TIF_NOTIFY_SIGNAL xtensa: add support for TIF_NOTIFY_SIGNAL arm: add support for TIF_NOTIFY_SIGNAL microblaze: add support for TIF_NOTIFY_SIGNAL hexagon: add support for TIF_NOTIFY_SIGNAL csky: add support for TIF_NOTIFY_SIGNAL openrisc: add support for TIF_NOTIFY_SIGNAL sh: add support for TIF_NOTIFY_SIGNAL um: add support for TIF_NOTIFY_SIGNAL ...
191 lines
4.8 KiB
C
191 lines
4.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Process creation support for Hexagon
|
|
*
|
|
* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/sched/debug.h>
|
|
#include <linux/sched/task.h>
|
|
#include <linux/sched/task_stack.h>
|
|
#include <linux/types.h>
|
|
#include <linux/module.h>
|
|
#include <linux/tick.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/tracehook.h>
|
|
|
|
/*
|
|
* Program thread launch. Often defined as a macro in processor.h,
|
|
* but we're shooting for a small footprint and it's not an inner-loop
|
|
* performance-critical operation.
|
|
*
|
|
* The Hexagon ABI specifies that R28 is zero'ed before program launch,
|
|
* so that gets automatically done here. If we ever stop doing that here,
|
|
* we'll probably want to define the ELF_PLAT_INIT macro.
|
|
*/
|
|
void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
|
|
{
|
|
/* We want to zero all data-containing registers. Is this overkill? */
|
|
memset(regs, 0, sizeof(*regs));
|
|
/* We might want to also zero all Processor registers here */
|
|
pt_set_usermode(regs);
|
|
pt_set_elr(regs, pc);
|
|
pt_set_rte_sp(regs, sp);
|
|
}
|
|
|
|
/*
|
|
* Spin, or better still, do a hardware or VM wait instruction
|
|
* If hardware or VM offer wait termination even though interrupts
|
|
* are disabled.
|
|
*/
|
|
void arch_cpu_idle(void)
|
|
{
|
|
__vmwait();
|
|
/* interrupts wake us up, but irqs are still disabled */
|
|
raw_local_irq_enable();
|
|
}
|
|
|
|
/*
|
|
* Copy architecture-specific thread state
|
|
*/
|
|
int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
|
|
struct task_struct *p, unsigned long tls)
|
|
{
|
|
struct thread_info *ti = task_thread_info(p);
|
|
struct hexagon_switch_stack *ss;
|
|
struct pt_regs *childregs;
|
|
asmlinkage void ret_from_fork(void);
|
|
|
|
childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
|
|
sizeof(*childregs));
|
|
|
|
ti->regs = childregs;
|
|
|
|
/*
|
|
* Establish kernel stack pointer and initial PC for new thread
|
|
* Note that unlike the usual situation, we do not copy the
|
|
* parent's callee-saved here; those are in pt_regs and whatever
|
|
* we leave here will be overridden on return to userland.
|
|
*/
|
|
ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
|
|
sizeof(*ss));
|
|
ss->lr = (unsigned long)ret_from_fork;
|
|
p->thread.switch_sp = ss;
|
|
if (unlikely(p->flags & PF_KTHREAD)) {
|
|
memset(childregs, 0, sizeof(struct pt_regs));
|
|
/* r24 <- fn, r25 <- arg */
|
|
ss->r24 = usp;
|
|
ss->r25 = arg;
|
|
pt_set_kmode(childregs);
|
|
return 0;
|
|
}
|
|
memcpy(childregs, current_pt_regs(), sizeof(*childregs));
|
|
ss->r2524 = 0;
|
|
|
|
if (usp)
|
|
pt_set_rte_sp(childregs, usp);
|
|
|
|
/* Child sees zero return value */
|
|
childregs->r00 = 0;
|
|
|
|
/*
|
|
* The clone syscall has the C signature:
|
|
* int [r0] clone(int flags [r0],
|
|
* void *child_frame [r1],
|
|
* void *parent_tid [r2],
|
|
* void *child_tid [r3],
|
|
* void *thread_control_block [r4]);
|
|
* ugp is used to provide TLS support.
|
|
*/
|
|
if (clone_flags & CLONE_SETTLS)
|
|
childregs->ugp = tls;
|
|
|
|
/*
|
|
* Parent sees new pid -- not necessary, not even possible at
|
|
* this point in the fork process
|
|
* Might also want to set things like ti->addr_limit
|
|
*/
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Release any architecture-specific resources locked by thread
|
|
*/
|
|
void release_thread(struct task_struct *dead_task)
|
|
{
|
|
}
|
|
|
|
/*
|
|
* Some archs flush debug and FPU info here
|
|
*/
|
|
void flush_thread(void)
|
|
{
|
|
}
|
|
|
|
/*
|
|
* The "wait channel" terminology is archaic, but what we want
|
|
* is an identification of the point at which the scheduler
|
|
* was invoked by a blocked thread.
|
|
*/
|
|
unsigned long get_wchan(struct task_struct *p)
|
|
{
|
|
unsigned long fp, pc;
|
|
unsigned long stack_page;
|
|
int count = 0;
|
|
if (!p || p == current || p->state == TASK_RUNNING)
|
|
return 0;
|
|
|
|
stack_page = (unsigned long)task_stack_page(p);
|
|
fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
|
|
do {
|
|
if (fp < (stack_page + sizeof(struct thread_info)) ||
|
|
fp >= (THREAD_SIZE - 8 + stack_page))
|
|
return 0;
|
|
pc = ((unsigned long *)fp)[1];
|
|
if (!in_sched_functions(pc))
|
|
return pc;
|
|
fp = *(unsigned long *) fp;
|
|
} while (count++ < 16);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Called on the exit path of event entry; see vm_entry.S
|
|
*
|
|
* Interrupts will already be disabled.
|
|
*
|
|
* Returns 0 if there's no need to re-check for more work.
|
|
*/
|
|
|
|
int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
|
|
{
|
|
if (!(thread_info_flags & _TIF_WORK_MASK)) {
|
|
return 0;
|
|
} /* shortcut -- no work to be done */
|
|
|
|
local_irq_enable();
|
|
|
|
if (thread_info_flags & _TIF_NEED_RESCHED) {
|
|
schedule();
|
|
return 1;
|
|
}
|
|
|
|
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
|
|
do_signal(regs);
|
|
return 1;
|
|
}
|
|
|
|
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
|
|
tracehook_notify_resume(regs);
|
|
return 1;
|
|
}
|
|
|
|
/* Should not even reach here */
|
|
panic("%s: bad thread_info flags 0x%08x\n", __func__,
|
|
thread_info_flags);
|
|
}
|