Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp846712pxb; Fri, 22 Apr 2022 12:28:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhQEVwxG4xRvL4qEQm1oklv2m4MM6LI8UyGapMNDjVlEO+W7XSgsTCOEgtt4RPUAk5e2zo X-Received: by 2002:a63:9203:0:b0:386:3b37:76b5 with SMTP id o3-20020a639203000000b003863b3776b5mr5319108pgd.234.1650655697035; Fri, 22 Apr 2022 12:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650655697; cv=none; d=google.com; s=arc-20160816; b=tp3GFXJSLS+g6Bssl8DoDX3HVBvIXCcXQQCBx1ukRk+mHqgdoIDE4CqoVfV91BhxkZ rudROgn5S4LitLhHrZDjzD61aQ0WJmAlFlie2GmCygKfdAd06Qi5ipQ5mUl4SVPfw1cF /oDKHsj8GL3sQTuqgGmRaITgH0s9tQl78eVEeR/dOsO/Jnr5TQJ5S1/JShMHyv0FNbRF VRC5M+QcUKQIp3TbcRApiXEkEmv0AgFhRCt+lweTt4AiSaUB0HZKYgyuSSTEB9m7B/nl BsDUO+bUSN17TSM9+JsD0EWY1R0j5n4YOxe+Xbmp/SKZSV763L1Ch6k88KaIDjQy/dsw tILA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:to :content-language:user-agent:mime-version:date:message-id :dkim-signature; bh=oH3leSqKDga9NZO+bBSqAcrROxxIXZVikqhqPeAfS1Q=; b=ETst78t5HV9/7qV37i3nDdThrp1DMdSCyGerGebkDKdbsgd0eK3bIWb/Oaf959GQ8+ S5Wm4Sr6cd0ATzNr0INNO8dl9x522tpp4r77k+yb9NuIzZnY+bM0oZ6MmOSUOH0t4sHJ 54HwgOo9ev+ZRuonmiLUugOXu/UZVsZKq3UgYZR/Bt/qj6ClUSlrUm+kx4BuCd5wWeJz rCXhowCIaQaRyWpzVlEJgR/hMPWo1wE46AdB1ufE2fogWN+9xrsLJ3XLS9RKjew1LB0D Mqu9eZCWy3Ss4v+a9DxAnkP/GDkrwKcpl9jMIEACt18gM7KBtVu5EEvoFqlx/oEBVTtC xPCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=K1gIMEIf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f29-20020a63101d000000b00382192930cdsi9363481pgl.349.2022.04.22.12.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:28:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=K1gIMEIf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 89AAD15F583; Fri, 22 Apr 2022 11:39:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1448711AbiDVOhI (ORCPT + 99 others); Fri, 22 Apr 2022 10:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1448707AbiDVOhF (ORCPT ); Fri, 22 Apr 2022 10:37:05 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A60855B3DA for ; Fri, 22 Apr 2022 07:34:11 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id h83so8755266iof.8 for ; Fri, 22 Apr 2022 07:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:to:from :subject:content-transfer-encoding; bh=oH3leSqKDga9NZO+bBSqAcrROxxIXZVikqhqPeAfS1Q=; b=K1gIMEIfLl85rfD2GqcuCIyX229fRksXEenYNCb3Xa50L1SN5M0fJEn5nyuVoZmaHm ahtOwuUI7bloePgpydDuYVQ3HWjwHiZqsUh61ZbccJP2fRPNL5hhhx9Du09Hs/DpDqqX UDrmSnwbOD3KZbIhnEju7pWhDNoXyywJ8om/9UHhceyAiaUBumNcBuOH2LCarTHo96wg 54c7bzp0tAQTddtEQaJ2dccXOZTAuRQDZq2fJyX6l6VobYP2hKpOjhISgVaAwZcwv1e/ o3AFCJ0J8ult4wQW5ZX+dAKo7Oicd3laeiGQyH5GFP3xa2RtQmBZqqXc2Q+Nfyg+jehO tqLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:from:subject:content-transfer-encoding; bh=oH3leSqKDga9NZO+bBSqAcrROxxIXZVikqhqPeAfS1Q=; b=dg+npftN/y7l5frPx3tkgJ3XCPA8FqGPdcrwwxrJaAzVZjvy4JMvRUnjZxnU8tzQHH 45oGCPREIceJfo/8LB5iUn03eSQhUsN8GpnaNzSj+PFLRQN18TCny81eFC1uNooQGNGm Ly0vJXGPWAk0a1WTjCkn2/ocAr3AiNmhG2ckxACu+1ohl5Sd/5/BhgXRkYILx0eb+VFm UozCMVo56QulJR9MiwAXo9ASCsG7Cdu2CczQp5AngpLR/i1CWE9MT1/IJ/OXMZXJIHEo Ts0n21VJxFmKGlNqiboz9lZP4aEfCJgdJyvw8VInyRShMHD8czpPngf8m/3NLfBuHEKr r2vQ== X-Gm-Message-State: AOAM533KTHotcTEFGXuhWP64Ee6DBBfzY/7gH8roONYRy8WFud+ksF5v ypIPkfchTgcDYmHlxyrAMVzvqJPCxJSoDQ== X-Received: by 2002:a02:7f4f:0:b0:326:760d:8ec0 with SMTP id r76-20020a027f4f000000b00326760d8ec0mr2287590jac.3.1650638050510; Fri, 22 Apr 2022 07:34:10 -0700 (PDT) Received: from [192.168.1.172] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id i9-20020a056e02054900b002cc1959aa6fsm1408236ils.87.2022.04.22.07.34.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Apr 2022 07:34:09 -0700 (PDT) Message-ID: <543452ca-f82e-4f00-cd51-88bb9723a975@kernel.dk> Date: Fri, 22 Apr 2022 08:34:07 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-US To: LKML From: Jens Axboe Subject: [PATCH] task_work: allow TWA_SIGNAL without a rescheduling IPI Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some use cases don't always need an IPI when sending a TWA_SIGNAL notification. Add TWA_SIGNAL_NO_IPI, which is just like TWA_SIGNAL, except it doesn't send an IPI to the target task. It merely sets TIF_NOTIFY_SIGNAL and wakes up the task. Signed-off-by: Jens Axboe --- This is a prep patch for an io_uring change where we don't need the IPI, and skipping it can reduce rescheduling/IPI rate by tens to hundreds of thousands per second. diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 3c8b34876744..66b689f6cfcb 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -355,14 +355,23 @@ static inline void clear_notify_signal(void) smp_mb__after_atomic(); } +/* + * Returns 'true' if kick_process() is needed to force a transition from + * user -> kernel to guarantee expedient run of TWA_SIGNAL based task_work. + */ +static inline bool __set_notify_signal(struct task_struct *task) +{ + return !test_and_set_tsk_thread_flag(task, TIF_NOTIFY_SIGNAL) && + !wake_up_state(task, TASK_INTERRUPTIBLE); +} + /* * Called to break out of interruptible wait loops, and enter the * exit_to_user_mode_loop(). */ static inline void set_notify_signal(struct task_struct *task) { - if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_SIGNAL) && - !wake_up_state(task, TASK_INTERRUPTIBLE)) + if (__set_notify_signal(task)) kick_process(task); } diff --git a/include/linux/task_work.h b/include/linux/task_work.h index 897494b597ba..795ef5a68429 100644 --- a/include/linux/task_work.h +++ b/include/linux/task_work.h @@ -17,6 +17,7 @@ enum task_work_notify_mode { TWA_NONE, TWA_RESUME, TWA_SIGNAL, + TWA_SIGNAL_NO_IPI, }; static inline bool task_work_pending(struct task_struct *task) diff --git a/kernel/task_work.c b/kernel/task_work.c index c59e1a49bc40..fa8fdd04aa17 100644 --- a/kernel/task_work.c +++ b/kernel/task_work.c @@ -13,11 +13,13 @@ static struct callback_head work_exited; /* all we need is ->next == NULL */ * * Queue @work for task_work_run() below and notify the @task if @notify * is @TWA_RESUME or @TWA_SIGNAL. @TWA_SIGNAL works like signals, in that the - * it will interrupt the targeted task and run the task_work. @TWA_RESUME - * work is run only when the task exits the kernel and returns to user mode, - * or before entering guest mode. Fails if the @task is exiting/exited and thus - * it can't process this @work. Otherwise @work->func() will be called when the - * @task goes through one of the aforementioned transitions, or exits. + * it will interrupt the targeted task and run the task_work. @TWA_SIGNAL_NO_IPI + * works like @TWA_SIGNAL, except it doesn't send a reschedule IPI to force the + * targeted task to reschedule and run task_work. @TWA_RESUME work is run only + * when the task exits the kernel and returns to user mode, or before entering + * guest mode. Fails if the @task is exiting/exited and thus it can't process + * this @work. Otherwise @work->func() will be called when the @task goes + * through one of the aforementioned transitions, or exits. * * If the targeted task is exiting, then an error is returned and the work item * is not queued. It's up to the caller to arrange for an alternative mechanism @@ -53,6 +55,9 @@ int task_work_add(struct task_struct *task, struct callback_head *work, case TWA_SIGNAL: set_notify_signal(task); break; + case TWA_SIGNAL_NO_IPI: + __set_notify_signal(task); + break; default: WARN_ON_ONCE(1); break; -- Jens Axboe