Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp784273pxj; Tue, 18 May 2021 14:09:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhu3NZb3uYI0hc+TSfU9VA/4o9Y9W4uwMtDb/Uxf9Jalxkr/IUuVq/zMwEpcQaITyYn7Mp X-Received: by 2002:a05:6402:3098:: with SMTP id de24mr9167871edb.339.1621372196219; Tue, 18 May 2021 14:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621372196; cv=none; d=google.com; s=arc-20160816; b=PI78fvAztt45Dglk2BSdT/wYsN01H8zUNWvDMyUfJzK8Ca/ZaDVsY0oipYkPI/tkVr a+fDC/zp1DR8Dy5aq0KbnVnWqv1RWiDSjoaSZODR3TZTUCnwDbuhtwNAcjwXhwbKYQEr F5zWI+8NPWx8FthBvsCp6zYOf1zqHbmm1l212gZp8Jq4YCTCKha2eW/qEBtizNVqfqnT JIVHry2+cLe3kuTz08EXw5EEWWqDcBS8Egam9USy29uZURj6XmVZp/DgwOatYFnc01hz mmMBJor9JT3PPd5d0dRocLk0brxjFhUPImfeyqPxzoIEIFgrH4ODFOHHhLsO8ykNmdUi /IzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=0xXGg47v6DZsDlaOvLYi6M02v9ny8K+pnAPv065jups=; b=aUcVl/+BbljHRNBuoGSvgd1qMXBpaLlg+LPbi0m1YPo5ceKFjlJCR8qGQXRGo6z8P5 SRbK4+/J0+HebW/t1ODzt8UE+h3ZxL4i7gFxFTBLj59z32hyUV6voBauogN2J/T8R09H 3AYGTzyFOhnzRqU5FLTLF3Y3tKfa0OVv4bFvVul92Dxa4QykYj/AtD3vBjOz9KTqPIX7 uWv1wl8Tzbq3WuaqVrO8sjcO/KX97ULkQnkqgYDTnG9z3/rbMeoWErNK9+yL8O/lZrcE xnS2OpmrLutnS32G4oAhbfEMsnKXrUF+3fimr1f3ulYg9incaGsWnJkP6aQBBr6hm66A /akg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qt5si15364780ejb.360.2021.05.18.14.09.33; Tue, 18 May 2021 14:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240312AbhEQR20 (ORCPT + 99 others); Mon, 17 May 2021 13:28:26 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:44932 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbhEQR2Z (ORCPT ); Mon, 17 May 2021 13:28:25 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lih1I-008g3Z-Gy; Mon, 17 May 2021 11:27:08 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=fess.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1ligwn-0007iG-0m; Mon, 17 May 2021 11:22:29 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Pavel Begunkov Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Jens Axboe References: Date: Mon, 17 May 2021 12:22:13 -0500 In-Reply-To: (Pavel Begunkov's message of "Mon, 17 May 2021 11:18:07 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1ligwn-0007iG-0m;;;mid=;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/uHyMU4FoXCJfugdXBJnxPvncafg9cjoo= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa02.xmission.com X-Spam-Level: X-Spam-Status: No, score=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_TooManySym_02 autolearn=disabled version=3.4.2 X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4985] * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Pavel Begunkov X-Spam-Relay-Country: X-Spam-Timing: total 281 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 4.0 (1.4%), b_tie_ro: 2.9 (1.0%), parse: 0.57 (0.2%), extract_message_metadata: 2.4 (0.8%), get_uri_detail_list: 1.01 (0.4%), tests_pri_-1000: 1.89 (0.7%), tests_pri_-950: 0.99 (0.4%), tests_pri_-900: 0.74 (0.3%), tests_pri_-90: 72 (25.4%), check_bayes: 70 (25.1%), b_tokenize: 4.3 (1.5%), b_tok_get_all: 6 (2.0%), b_comp_prob: 1.36 (0.5%), b_tok_touch_all: 57 (20.2%), b_finish: 0.58 (0.2%), tests_pri_0: 187 (66.5%), check_dkim_signature: 0.35 (0.1%), check_dkim_adsp: 2.3 (0.8%), poll_dns_idle: 0.22 (0.1%), tests_pri_10: 1.62 (0.6%), tests_pri_500: 5 (1.9%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] signal: optimise signal_pending() X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pavel Begunkov writes: > Optimise signal_pending() by checking both TIF_SIGPENDING and > TIF_NOTIFY_SIGNAL at once. Saves quite a bit of generated instructions, > e.g. sheds 240B from io_uring alone, some including ones in hot paths. > > text data bss dec hex filename > 84087 12414 8 96509 178fd ./fs/io_uring.o > 83847 12414 8 96269 1780d ./fs/io_uring.o I believe the atomic test_bit is pretty fundamental, especially with it's implied barriers. I believe you are optimizing out the code that will makes signal_pending work in a loop. I have tried looking and I really don't understand why TIF_NOTIFY_SIGNAL was added. Perhaps instead of trying to optimize the test, you should optimize by combining TIF_NOTIFY_SIGNAL with TIF_SIGPENDING. Perhaps set_notify_signal could be optimized to set both. I think I only see 4 calls in the tree. > Signed-off-by: Pavel Begunkov > --- > > Suggestions on how to make it less disruptive to abstractions are most > welcome, as even the one below fails to generated anything sane because > of test_bit() > > return unlikely(test_ti_thread_flag(ti, TIF_SIGPENDING) | > test_ti_thread_flag(ti, TIF_SIGPENDING)); > > include/linux/sched/signal.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h > index 3f6a0fcaa10c..97e1963a13fc 100644 > --- a/include/linux/sched/signal.h > +++ b/include/linux/sched/signal.h > @@ -361,14 +361,14 @@ static inline int task_sigpending(struct task_struct *p) > > static inline int signal_pending(struct task_struct *p) > { > + struct thread_info *ti = task_thread_info(p); > + > /* > * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same > * behavior in terms of ensuring that we break out of wait loops > * so that notify signal callbacks can be processed. > */ > - if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL))) > - return 1; > - return task_sigpending(p); > + return unlikely(ti->flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)); > } > > static inline int __fatal_signal_pending(struct task_struct *p)