Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp968826img; Thu, 28 Feb 2019 10:44:08 -0800 (PST) X-Google-Smtp-Source: APXvYqyRkMenX1TgQQPAEzOxOLFZtSL72+dNJsC4WR7h9UK/criEPZLwUSbi+oKyilwdgbjecD/9 X-Received: by 2002:aa7:8497:: with SMTP id u23mr1003339pfn.253.1551379448837; Thu, 28 Feb 2019 10:44:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551379448; cv=none; d=google.com; s=arc-20160816; b=Cbq1N0pwC5vr8Tk78U4SGE3HW6VjL9YDnpq0h4NNK3+UcB16EWt0dsRH9STAJBBDIG hmKU7npcYqVf08crtE8A5qIPhVysxFcV3U7d5/0rS+07d8Iq99mXsSvta0gsEDkai8/o yx1pYvxJf9lPZ8mIeyHM9GUj3VGx5Jx50KaxI+wTT2wsh/AA36RkPg6J4WhT6t+f7Shn iG837Asa202wNLqzcPbWvCdttt7A6kyotjwsB4xCLG+9NXiQUK+X54AHNmnWSGgCRJ6w oKdNleR50+giifcEF2DNruZaavpbEGA7svX0CtCRlZSpqDPhqmm6HtKCImMWhpzO02w9 xIbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Q9cre5/Aq7q411RwATkV0IuqFgfbnApY5djU5qJvN3A=; b=o2XEh18+b2CuLiixaAX8v5UmZxHy5xiNXglnleMzxeguxtX7AMA6vWMblucnpDD86+ ArnY6nyb2iGv+lOIuJKv5xj5kDLKOUNE+3POaNkL1oru4peSR95zlD8Qf0pxffs8i36r A2b661sPvwg4Ya21WH8OXo+sTYt43fRE1HlZln7N2AXoEBD9yxmjyoxPe3ihLwbFRg0f yAE4goEu7gNbgJ1hLFxxewOhMuviGwZtEGSdGoY6xlqUzrXD8otdiec5znKuyFmeUprf M2auUb+QFUBmQuaE9dYo8+wME2VC/bxDcTkPr0ynzJhgNcdaS/zHttOpw9EZMLd/Rq7I 3i7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ayZO67lj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n20si18370724pfi.226.2019.02.28.10.43.52; Thu, 28 Feb 2019 10:44:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ayZO67lj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388570AbfB1SKW (ORCPT + 99 others); Thu, 28 Feb 2019 13:10:22 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:32823 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727499AbfB1SKV (ORCPT ); Thu, 28 Feb 2019 13:10:21 -0500 Received: by mail-oi1-f196.google.com with SMTP id z14so17299773oid.0; Thu, 28 Feb 2019 10:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Q9cre5/Aq7q411RwATkV0IuqFgfbnApY5djU5qJvN3A=; b=ayZO67ljJsjtlPuTZG+11HlQj1sn3rUYO/oOPb5KrlkuDfJIsR58qzUFj8TkVUzxbr Ee/fkN/7Lb8HCeFhguevuM0YmMLaJcJzRhs/gMkSzv+O6Gt06ob0Q6FEnqGHeeu/kE1l 084OO13O/A0k+LFasowMpxf6W7sdMm/j0w3ET0i7nkyWgtBV1KgT0S0ENpl8kEfHdubw VG4IGrz0qjXJwld6YeNuuaRFHzH7KW2msDTG8NL8WQKflvJhEogTbn9StABVYfbnXPN3 r9ZF9nX36NtZFJboFETarFfI2XTAZYJsZkcM0gpHDqrnYQ10m/6P+kTTO47+pSvg1nTF X+pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Q9cre5/Aq7q411RwATkV0IuqFgfbnApY5djU5qJvN3A=; b=t9oMdAUl/JMlOhQXdsCJ5IV+gd1OIgnc+6LMmhR0qhrEwZOTMUQ2w5mDBzAB2wFWuZ 8EyflCl10Pnut6GBABCM7DUNPPw+Mj/BniAXj2PA0KXCmhEl6Y0s3iSMY0H80Wabkh+u XUnH4asl5v/EkH1h1sr/307+Il0u82wz3I93jbpoTm+jbkcveGuhzLn3r1pwDImHgixm Vx9QL+a7xClClcIdHq8W3dIhf09v5FnBudqR1gT3AhZNf5afXAHA6xx1Ffj1PZiqoDnk zJXEB0qHL1K08J6XfcL2Ukf7lLCruiHXDk7rI420rqMQW27qeoHqdzbLw00v1njakSBU scxw== X-Gm-Message-State: APjAAAVcYatV8A9S16yMs4v3CJGJuIfA6+m3lsce830w/iwnCou11kVS RaQiaymt1jsR52SLP7l+Vpo4aSO4nCd1Q2fzBis= X-Received: by 2002:aca:c5d5:: with SMTP id v204mr675765oif.104.1551377420275; Thu, 28 Feb 2019 10:10:20 -0800 (PST) MIME-Version: 1.0 References: <20190221221941.29358-1-daniel@iogearbox.net> <33bf951448e7d916fd4a6ad41cd3d040e9d1f118.camel@infradead.org> <79add9a9-543b-a791-ecbe-79edd49f1bb3@iogearbox.net> <4604e680-7962-f1ee-5b79-711247f4e7d5@iogearbox.net> In-Reply-To: <4604e680-7962-f1ee-5b79-711247f4e7d5@iogearbox.net> From: "H.J. Lu" Date: Thu, 28 Feb 2019 10:09:43 -0800 Message-ID: Subject: Re: [tip:x86/build] x86, retpolines: Raise limit for generating indirect calls from switch-case To: Daniel Borkmann Cc: David Woodhouse , Ingo Molnar , bjorn.topel@intel.com, David Miller , brouer@redhat.com, magnus.karlsson@intel.com, Andy Lutomirski , "H. Peter Anvin" , Thomas Gleixner , Peter Zijlstra , Borislav Petkov , Linus Torvalds , LKML , ast@kernel.org, linux-tip-commits@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 28, 2019 at 9:58 AM Daniel Borkmann wrot= e: > > On 02/28/2019 05:25 PM, H.J. Lu wrote: > > On Thu, Feb 28, 2019 at 8:18 AM Daniel Borkmann = wrote: > >> On 02/28/2019 01:53 PM, H.J. Lu wrote: > >>> On Thu, Feb 28, 2019 at 3:27 AM David Woodhouse = wrote: > >>>> On Thu, 2019-02-28 at 03:12 -0800, tip-bot for Daniel Borkmann wrote= : > >>>>> Commit-ID: ce02ef06fcf7a399a6276adb83f37373d10cbbe1 > >>>>> Gitweb: https://git.kernel.org/tip/ce02ef06fcf7a399a6276adb83f3= 7373d10cbbe1 > >>>>> Author: Daniel Borkmann > >>>>> AuthorDate: Thu, 21 Feb 2019 23:19:41 +0100 > >>>>> Committer: Thomas Gleixner > >>>>> CommitDate: Thu, 28 Feb 2019 12:10:31 +0100 > >>>>> > >>>>> x86, retpolines: Raise limit for generating indirect calls from swi= tch-case > >>>>> > >>>>> From networking side, there are numerous attempts to get rid of ind= irect > >>>>> calls in fast-path wherever feasible in order to avoid the cost of > >>>>> retpolines, for example, just to name a few: > >>>>> > >>>>> * 283c16a2dfd3 ("indirect call wrappers: helpers to speed-up indi= rect calls of builtin") > >>>>> * aaa5d90b395a ("net: use indirect call wrappers at GRO network l= ayer") > >>>>> * 028e0a476684 ("net: use indirect call wrappers at GRO transport= layer") > >>>>> * 356da6d0cde3 ("dma-mapping: bypass indirect calls for dma-direc= t") > >>>>> * 09772d92cd5a ("bpf: avoid retpoline for lookup/update/delete ca= lls on maps") > >>>>> * 10870dd89e95 ("netfilter: nf_tables: add direct calls for all b= uiltin expressions") > >>>>> [...] > >>>>> > >>>>> Recent work on XDP from Bj=C3=B6rn and Magnus additionally found th= at manually > >>>>> transforming the XDP return code switch statement with more than 5 = cases > >>>>> into if-else combination would result in a considerable speedup in = XDP > >>>>> layer due to avoidance of indirect calls in CONFIG_RETPOLINE enable= d > >>>>> builds. > >>>> > >>>> +HJL > >>>> > >>>> This is a GCC bug, surely? It should know how expensive each > >>>> instruction is, and choose which to use accordingly. That should be > >>>> true even when the indirect branch "instruction" is a retpoline, and > >>>> thus enormously expensive. > >>>> > >>>> I believe this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D869= 52 so > >>>> please at least reference that bug, and be prepared to turn this hac= k > >>>> off when GCC is fixed. > >>> > >>> We couldn't find a testcase to show jump table with indirect branch > >>> is slower than direct branches. > >> > >> Ok, I've just checked https://github.com/marxin/microbenchmark/tree/re= tpoline-table > >> with the below on top. > >> > >> Makefile | 6 +++--- > >> switch.c | 2 +- > >> test.c | 6 ++++-- > >> 3 files changed, 8 insertions(+), 6 deletions(-) > >> > >> diff --git a/Makefile b/Makefile > >> index bd83233..ea81520 100644 > >> --- a/Makefile > >> +++ b/Makefile > >> @@ -1,16 +1,16 @@ > >> CC=3Dgcc > >> CFLAGS=3D-g -I. > >> -CFLAGS+=3D-O2 -mindirect-branch=3Dthunk > >> +CFLAGS+=3D-O2 -mindirect-branch=3Dthunk-inline -mindirect-branch-regi= ster > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > > Does slowdown show up only with -mindirect-branch=3Dthunk-inline? > > Not really, numbers are in similar range / outcome. Additionally, I also = tried > on a bit bigger machine (Xeon Gold 5120 this time). First is thunk-inline= , second > is thunk, and third is w/o raising limit for comparison; first test (from= last > mail) on that machine: Please re-open: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D86952 with new info. --=20 H.J.