From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82ED5C43460 for ; Tue, 18 May 2021 18:16:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 659CF61261 for ; Tue, 18 May 2021 18:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234187AbhERSRn (ORCPT ); Tue, 18 May 2021 14:17:43 -0400 Received: from mail.zx2c4.com ([104.131.123.232]:58458 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbhERSRl (ORCPT ); Tue, 18 May 2021 14:17:41 -0400 X-Greylist: delayed 397 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 May 2021 14:17:40 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1621361380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8rS8izsTLYXgTg5EMvpq46Wwtz/UgRyB75Drw18GbEc=; b=ordstdKxuroSvOenGkA5+S0n5Eaelw4XVAjEk8UkZ+3isrXKa/wmD2IPj5r0Kfvq1zfUvP CY+6i6WC3N7rlrm8aZt38e2edfNAMTLd+AO8SdHBhlEwi2KfGNHs1D7pQQWn5EZk5/Ft6s 3IM/CNVZLwMM7ldWaZFwTTdsthAFBJk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id dd3e8623 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 18 May 2021 18:09:40 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id g38so14466582ybi.12; Tue, 18 May 2021 11:09:40 -0700 (PDT) X-Gm-Message-State: AOAM533Fu+hAseTLmikalDAeO39oFaAUX/oBSRZs40DjskHEVMYuQuNd E+jEl+sU9jL/f36vhSipVszbjC+cFV2t6fZ0QrM= X-Google-Smtp-Source: ABdhPJzjL1VkURyiOt9hWVcfIhsJ4Fpd+evfXoJrwAsTV/P9d+CfD5cJgWw4InGE4VmuxwkJA2Pvdq6MOW/JGmXtt8w= X-Received: by 2002:a25:be09:: with SMTP id h9mr9533216ybk.239.1621361379012; Tue, 18 May 2021 11:09:39 -0700 (PDT) MIME-Version: 1.0 References: <20210514100106.3404011-1-arnd@kernel.org> <20210514100106.3404011-8-arnd@kernel.org> In-Reply-To: From: "Jason A. Donenfeld" Date: Tue, 18 May 2021 20:09:27 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 07/13] asm-generic: unaligned always use struct helpers To: Linus Torvalds Cc: Arnd Bergmann , Eric Biggers , linux-arch , Vineet Gupta , Russell King , Herbert Xu , "David S. Miller" , Thomas Bogendoerfer , Linux ARM , Linux Kernel Mailing List , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "open list:BROADCOM NVRAM DRIVER" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Linus, On Tue, May 18, 2021 at 6:12 PM Linus Torvalds wrote: > I'm actually surprised wireguard would use -O3. Yes, performance is > important. But for wireguard, correctness is certainly important too. > Maybe Jason isn't aware of just how bad gcc -O3 has historically been? > Jason? How big of a deal is that -O3 for wireguard wrt the normal -O2? > There are known buggy gcc versions that aren't ancient. My impression has always been that O3 might sometimes generate slower code, but not that it generates buggy code so commonly. Thanks for letting me know. I have a habit of compulsively run IDA Pro after making changes (brain damage from too many years as a "security person" or something), to see what the compiler did, and I've just been doing that with O3 since the beginning of the project, so that's what I wound up optimizing for. Or sometimes I'll work little things out in Godbolt's compiler explorer. It's not like it matters much most of the time, but sometimes I enjoy the golf. Anyway, I've never noticed it producing any clearly wrong code compared to O2. But I'm obviously not testing on all compilers or on all architectures. So if you think there's danger lurking somewhere, it seems reasonable to change that to O2. Comparing gcc 11's output between O2 and O3, it looks like the primary difference is that the constant propagation is much less aggressive with O2, and less inlining in general also means that some stores and loads to local variables across static function calls aren't being coalesced. A few null checks are removed too, where the compiler can prove them away. So while I've never seen issues with that code under O3, I don't see a super compelling speed up anywhere either, but rather a bunch of places that may or may not be theoretically faster or slower on some system, maybe. I can queue up a patch for the next wireguard series I send to Dave. Jason From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DF9FC433B4 for ; Tue, 18 May 2021 18:11:43 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5FA560FF1 for ; Tue, 18 May 2021 18:11:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5FA560FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=zx2c4.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/fLdq/NCLtvwkXfvWsDnd/W3KFXGRSpjxWukLGfAy8k=; b=F2fCjmKE4QmK2tGi8iYlXeh42 wPnrwsO42mGF6M2GgvYNTp4onp3tNKzBQ6XrtOLjzJTZZkoKxnpSHQtXaonbg5emjLNpXOvcqdOJy ip1fu6ri40yF2AMK/WzN43bIHNYCrvezVE7Zd/KTGgmBsGRq0e3+qlI1BryzN4cTD5uLjHO+dT/sd 5rUB1AnndYKUhPme8cLbYg3AtGk93BgxFYTvxRnOOgvv/tr/xxXaB/dhr0Lwv2R1ccTZOVxGryTWs qnPRuHVpOwOnY1wd0DdFwDgT8ONcsh1/98z5xQYqUdA44wXTP9gA1LlS8MrJW1kAt/YL8gsciWvmI lBv0n3fUg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lj4AB-001ZEP-V8; Tue, 18 May 2021 18:09:52 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lj4A8-001ZEF-PB for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 18:09:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8rS8izsTLYXgTg5EMvpq46Wwtz/UgRyB75Drw18GbEc=; b=Juj5JFvCUgwKdW6QjtUz2nWoiX /syNS8mLVERkxIvfTp9YH9L0BKVLhjzglENYIYR4lRq9ixphKdc0J1pg47JDhNKPINSoqEvserh6x CuZc6L3YHuHBvPdFgNQyigcI2blrPiQ7kLcJf9pA9QTJYJ0yptrGKtNy88XW1d9dPr/HZlb/icQ4C t5C+igJFVOItzeU6/eC1D5JfLWDPl//q/WOLE3gt1Dto3ZGlClbBx8Ed8hP2QBOkKmyroQhWPAIGe eaMLHdl71Xve3IuPvVyT06n2nkm8YuDni7UN4fVPEonKJ5mjqaOr9sTHHfpGC4PgA4HmSsAFSrnYy iO2TbHLQ==; Received: from mail.zx2c4.com ([104.131.123.232]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lj4A5-00Errj-AQ for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 18:09:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1621361380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8rS8izsTLYXgTg5EMvpq46Wwtz/UgRyB75Drw18GbEc=; b=ordstdKxuroSvOenGkA5+S0n5Eaelw4XVAjEk8UkZ+3isrXKa/wmD2IPj5r0Kfvq1zfUvP CY+6i6WC3N7rlrm8aZt38e2edfNAMTLd+AO8SdHBhlEwi2KfGNHs1D7pQQWn5EZk5/Ft6s 3IM/CNVZLwMM7ldWaZFwTTdsthAFBJk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id d4408f18 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Tue, 18 May 2021 18:09:40 +0000 (UTC) Received: by mail-yb1-f171.google.com with SMTP id b13so13134665ybk.4 for ; Tue, 18 May 2021 11:09:39 -0700 (PDT) X-Gm-Message-State: AOAM530IMY1x0LpxQ+gSPXxTHZhy1LWJujdgJCUCacgPLjXiMLPxcsaP DpZYW8fgqc52PWPXXO/IXGlub7dxwkXnW1JjXxw= X-Google-Smtp-Source: ABdhPJzjL1VkURyiOt9hWVcfIhsJ4Fpd+evfXoJrwAsTV/P9d+CfD5cJgWw4InGE4VmuxwkJA2Pvdq6MOW/JGmXtt8w= X-Received: by 2002:a25:be09:: with SMTP id h9mr9533216ybk.239.1621361379012; Tue, 18 May 2021 11:09:39 -0700 (PDT) MIME-Version: 1.0 References: <20210514100106.3404011-1-arnd@kernel.org> <20210514100106.3404011-8-arnd@kernel.org> In-Reply-To: From: "Jason A. Donenfeld" Date: Tue, 18 May 2021 20:09:27 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 07/13] asm-generic: unaligned always use struct helpers To: Linus Torvalds Cc: Arnd Bergmann , Eric Biggers , linux-arch , Vineet Gupta , Russell King , Herbert Xu , "David S. Miller" , Thomas Bogendoerfer , Linux ARM , Linux Kernel Mailing List , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "open list:BROADCOM NVRAM DRIVER" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_110945_574630_A220246C X-CRM114-Status: GOOD ( 19.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Linus, On Tue, May 18, 2021 at 6:12 PM Linus Torvalds wrote: > I'm actually surprised wireguard would use -O3. Yes, performance is > important. But for wireguard, correctness is certainly important too. > Maybe Jason isn't aware of just how bad gcc -O3 has historically been? > Jason? How big of a deal is that -O3 for wireguard wrt the normal -O2? > There are known buggy gcc versions that aren't ancient. My impression has always been that O3 might sometimes generate slower code, but not that it generates buggy code so commonly. Thanks for letting me know. I have a habit of compulsively run IDA Pro after making changes (brain damage from too many years as a "security person" or something), to see what the compiler did, and I've just been doing that with O3 since the beginning of the project, so that's what I wound up optimizing for. Or sometimes I'll work little things out in Godbolt's compiler explorer. It's not like it matters much most of the time, but sometimes I enjoy the golf. Anyway, I've never noticed it producing any clearly wrong code compared to O2. But I'm obviously not testing on all compilers or on all architectures. So if you think there's danger lurking somewhere, it seems reasonable to change that to O2. Comparing gcc 11's output between O2 and O3, it looks like the primary difference is that the constant propagation is much less aggressive with O2, and less inlining in general also means that some stores and loads to local variables across static function calls aren't being coalesced. A few null checks are removed too, where the compiler can prove them away. So while I've never seen issues with that code under O3, I don't see a super compelling speed up anywhere either, but rather a bunch of places that may or may not be theoretically faster or slower on some system, maybe. I can queue up a patch for the next wireguard series I send to Dave. Jason _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel