Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp921505pxf; Wed, 7 Apr 2021 15:07:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkVtPjFKPetvo0GVbg8AcThcVBKw/EhVVqXAjoiOvAbwYdNDfJxLc7zqCjWgXi8v2mCZmy X-Received: by 2002:a62:2742:0:b029:222:b711:3324 with SMTP id n63-20020a6227420000b0290222b7113324mr4719158pfn.7.1617833245109; Wed, 07 Apr 2021 15:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617833245; cv=none; d=google.com; s=arc-20160816; b=T+NAe86bKg3BZEIbACwFKObf2asmk7T91smyrHJ8+5Ym3K4fP1BEw/8MVnp6M3qigj i42rchSIkgeSaJ0xETGlUH5TxpIuQIF4Z9SJjVDaHuMr72LmFKxfAuPfZmesXJatrDLy wkzlBk7XSovD2zGil29HyvwcYnxluU7uJ64TFSKi0uQq29dx2H79B5slSy2rodUadxqy S7Vo6KuT78MnzUQvXc7CZ/sudfwxwo3HROkk57Bmr+raYZrBM68YdvLieonozwIvOTyZ FhCQL7e4ZtsKVD7ONMk6dI9a4P19rt8G+Il6OaTo3fduzQL2mMMju57uigOmQ3pPPNW7 Adtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=t32TPFN7dNcai01TfPFUtOMBnlxLIFARiDUKaGnE5/w=; b=I4iDX0JY23QdTOV4agkbbUf/4Jde7mJEOiWU61uCpTtxJTePyX//J02jHlsLtd6jZ8 nhOI+paPQbVCk915C2ryX4EXWQbZVrZOwJIwe0Vv14AU7Him+rgVz/5YOrCgNT3oWdiL QbSNlg5jtB2mK4RmueL6VLc06j6yCGvMDaQ+1xxv3c9aADkcrZUWBh+W1vFob69pKWO/ 0UEAU+/oE1lWmX2/fckraqXg5Pl8K354M8zD/iXUgi4TkmJ+jCodOizrlcxj6XNnUGcA 30h6GLW255U7Db+VULsQRNv+e3ez/pJz2k4bTCbIwwpHYYBYC+KlKcBbxweGNV2ZUW1y /LdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=En0QuuXp; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si26067211pgf.338.2021.04.07.15.07.13; Wed, 07 Apr 2021 15:07:25 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=En0QuuXp; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234138AbhDGVpE (ORCPT + 99 others); Wed, 7 Apr 2021 17:45:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233811AbhDGVpE (ORCPT ); Wed, 7 Apr 2021 17:45:04 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7855AC061761 for ; Wed, 7 Apr 2021 14:44:54 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id g15so305058pfq.3 for ; Wed, 07 Apr 2021 14:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=t32TPFN7dNcai01TfPFUtOMBnlxLIFARiDUKaGnE5/w=; b=En0QuuXpjbv30VQDDu/QYB+aN5fxgnlMmq9zD16uWOEI1XHDszQUYXkUsH7Rpah4sc CgZwX4Qw6Q+VF3DyKS5NuEg3I0ytCnFHtTXWtkEp2qcQXdIN0S+xre7zXOUq1gS/AEC4 Y0jV1OKpHFI9Zxuc8mlWGYdVzJLdg7Ehn/sT8QHFuJlNYac15Snd+OGlaFn3G61tSVd0 JpRfi+cRUO808quk1L/9jfHZi7pgCZ0OiaY8c24ZiSPdEIgewMBfBG//imnHUcwTUB1Q um0fzy7BWxKnaoVWzGBFylq9/5YW1/gpeKMGy6yBl4dbNpCLp6hFXfhs4mVWOlWg4bPU pSQA== 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=t32TPFN7dNcai01TfPFUtOMBnlxLIFARiDUKaGnE5/w=; b=QXXCPWq2wvI+KfkHrfX+H91WMwHCJ9IDhnerQj0hf2mq6kymH/2o0wNPiazEadMfMq crDoC4VtHPl1V5qmHqqvOAwf0LjYNl7GEocMC9deJWiwQ0TPfjIgeN39G7n9YXZU8irF u8RQhORD5Mm31Yc2M+p74hbWfxDIhVxLIjw9hMsONiQ6yfquDqcyv+H/OkzIty89rp1T b4iDzoCAPovmTO2eQR0YxDBCBv6U/TQ9PmcOH+YIEX6Wzq59UDncGFobmqWVtKsntkE5 t+2IpOJsI2WS423NyJ8lrphDamDykv/VCqBlTJ44AbCL+5t9JYj8pEK8zCYZmN2J5Qjy GM6A== X-Gm-Message-State: AOAM531KIDvdDdU3GHuzX7q8evMitQg1AbCC5r8oz/gjETV4RCuj/IhC OXgE45vK5FPBtcRLOvze4YoapwK9fzhhaFl5R+JabA== X-Received: by 2002:a62:6451:0:b029:23f:6ea1:293f with SMTP id y78-20020a6264510000b029023f6ea1293fmr4670336pfb.53.1617831893704; Wed, 07 Apr 2021 14:44:53 -0700 (PDT) MIME-Version: 1.0 References: <20210111081821.3041587-1-morbo@google.com> <20210407211704.367039-1-morbo@google.com> <202104071419.AA35EEAF@keescook> In-Reply-To: <202104071419.AA35EEAF@keescook> From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Wed, 7 Apr 2021 14:44:41 -0700 Message-ID: Subject: Re: [PATCH v9] pgo: add clang's Profile Guided Optimization infrastructure To: Kees Cook , Bill Wendling Cc: Masahiro Yamada , Jonathan Corbet , Linux Doc Mailing List , LKML , Linux Kbuild mailing list , clang-built-linux , Andrew Morton , Nathan Chancellor , Nick Desaulniers , Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 7, 2021 at 2:22 PM Kees Cook wrote: > > On Wed, Apr 07, 2021 at 02:17:04PM -0700, 'Bill Wendling' via Clang Built= Linux wrote: > > From: Sami Tolvanen > > > > Enable the use of clang's Profile-Guided Optimization[1]. To generate a > > profile, the kernel is instrumented with PGO counters, a representative > > workload is run, and the raw profile data is collected from > > /sys/kernel/debug/pgo/profraw. > > > > The raw profile data must be processed by clang's "llvm-profdata" tool > > before it can be used during recompilation: > > > > $ cp /sys/kernel/debug/pgo/profraw vmlinux.profraw > > $ llvm-profdata merge --output=3Dvmlinux.profdata vmlinux.profraw > > > > Multiple raw profiles may be merged during this step. > > > > The data can now be used by the compiler: > > > > $ make LLVM=3D1 KCFLAGS=3D-fprofile-use=3Dvmlinux.profdata ... > > > > This initial submission is restricted to x86, as that's the platform we > > know works. This restriction can be lifted once other platforms have > > been verified to work with PGO. > > > > Note that this method of profiling the kernel is clang-native, unlike > > the clang support in kernel/gcov. > > > > [1] https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimiz= ation > > > > Signed-off-by: Sami Tolvanen > > Co-developed-by: Bill Wendling > > Signed-off-by: Bill Wendling > > Tested-by: Nick Desaulniers > > Reviewed-by: Nick Desaulniers > > Reviewed-by: Fangrui Song > > Thanks for sending this again! I'm looking forward to using it. Yay. Quite excited about that:) > Masahiro and Andrew, unless one of you would prefer to take this in your > tree, I figure I can snag it to send to Linus. > > Anyone else have feedback? I have carefully compared the implementation and the original implementation in llvm-project/compiler-rt. This looks great. Also very happy about the cleaner include/asm-generic/vmlinux.lds.h now. Just adding a note here for folks who may want to help test the not-yet-common option LD_DEAD_CODE_DATA_ELIMINATION. --gc-sections may not work perfectly with some advanced PGO features before Clang 13 (not broken but probably just in an inferior state). There were some upstream changes in this area recently and I think as of my https://reviews.llvm.org/D97649 things should be perfect with GC now. This does not deserve any comment without more testing, though. Thanks for already carrying my Reviewed-by tag. > Thanks! > > -Kees > > -- > Kees Cook --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF