Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2547994pxb; Mon, 11 Jan 2021 12:36:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxAamLWC7/aHpucWpDvleufsaDcU9UTRj6hdCSaXczJz5QK2LEBhXqY1/Sl6evz4dC6sf4 X-Received: by 2002:a17:906:1ed6:: with SMTP id m22mr845926ejj.231.1610397386786; Mon, 11 Jan 2021 12:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610397386; cv=none; d=google.com; s=arc-20160816; b=bU9/ievKy4WPsAneAeXisHMUAFvJdlAuRwIQWlhPI1c7mTf1VnBWdEfTkqisYw45MY 6YeMPdNRiGnuXzh+/WEtNF4tPMY/YEFOs6PjQPoRWWIZucek530X/KBxs3X0jkynu/BY mMr6204aRhCkf07nPsFUh36sinhYiWrvgDaCdoTj3af4NDs2eV+L4vVsZW6O9LtDM8kx GnSAmJCM1ss9tn/FmU622AaeDgu40nRxDn7z0+O+Ki4xQptm8oWPV4sWnCSsHwe+Bc3i a99BJ2AR/bK4TmdeB+QhtQpdf30LNquXZwWcs7R6uCOK9dxudblQtuXr7niBuAuNSMdM CeDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BZbWJMckP7KnFzgMzYjv6b0GUK1slDkOJ3IpYhCUuJM=; b=w78ynwL6Hj6dd5oQ5s5O02HFCEZu9A0qOwpb2av+qTgfISzjjfOkO9AaeuOyMrjur6 GDZcI82XGgnXnvJmSZcYb8lkbEMwS0hv90h6WhwhN1I//V3lyDlhaOYFRe6NmJZAcdhl OuPYAFpdw2yUveRVvhA+uM4VUpbozHU0HStYJ5yXk9CaH1OvzIEN7PwObkJJpfrdjK2p JzXR7zMfXZl+VjICz4uhT2fA0Y+uxVaATARTqiQpa/h+GpIdwswHARoblah7VaNSKevp rUIDESCFH49BkrUaX2tTVgVlS+94oDzpgwG39Ws20NFGzv4yVrzswW2kNN+zQFwIHKnu AKJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZmSjWT7f; 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 z23si319368edx.444.2021.01.11.12.36.01; Mon, 11 Jan 2021 12:36:26 -0800 (PST) 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=ZmSjWT7f; 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 S1731050AbhAKUcG (ORCPT + 99 others); Mon, 11 Jan 2021 15:32:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728813AbhAKUcF (ORCPT ); Mon, 11 Jan 2021 15:32:05 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08EA5C06179F for ; Mon, 11 Jan 2021 12:31:25 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id j13so249286pjz.3 for ; Mon, 11 Jan 2021 12:31:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BZbWJMckP7KnFzgMzYjv6b0GUK1slDkOJ3IpYhCUuJM=; b=ZmSjWT7fgSd1h2QCqYkfefvC7EBMF1WXYaFlU/v6xYDyebfJ3A4MtqB5B9R9QoJZdr zwOkX46YznqaaTwRUsjKhbu/FTJce0XchX3Dg38w4d2PJ78QBFiXRDYnLVddUQPZXii6 w1MIlAW7XLcq/wIvIcumiEkGdcHd1/N4oQg63J9ONYBGGCvtmkdgYKdY9EivNstrRP6C UcXE7ajSI/3Z4OVHWC4dl4c9Vfila5c9BIabdkWEkgYCM7Ti8QeQDSM2DJBievQ1Efwu HMMhPtCEikIiUF7Yx4UrhQK+CrOLwJUyjvTrJYRZJmxR9tmkl9AGvjbIcU86JCWmlfdM J+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BZbWJMckP7KnFzgMzYjv6b0GUK1slDkOJ3IpYhCUuJM=; b=hzrICPmpNxLJmxSNeEC8bw6JLM5Z3WeJVPJ38N0sTTl6a/dSDGSJlC5uJxqOYsKsNi 6n8qerwvqKdhLTLORbE0GX56Q2Rt1NFlrfb/GSAqQuLJsA4p9Iu/uqa2izWfXRr1RYlo mnWKBaqDnVQ5JQKUGfyB2m8B/DxjchV8qlHVTODXSZ8D6GWVy6kSXW6PTPS+3yw8Cv3m bjJjigpyfRX/XVQ3ynbEy0O7HFw/+RDLolQdb28DSNoLRkVCXXAlgFJnciGCt2qDT9Y3 IhZpO1WI1B3Iwe2lH9HW+ZpkvGQj05T9OGHmDVg+KGXUFKYF3iSI811CG1aQzcruQwJ4 L0/w== X-Gm-Message-State: AOAM533zwu6HjvbIrpnzoHarJVLZKGtCrceKHA7FcHAXzLaCZU6eoGip Y/l5/QOM9pwQSC/IgftUL19zww== X-Received: by 2002:a17:90b:23d6:: with SMTP id md22mr638840pjb.206.1610397084289; Mon, 11 Jan 2021 12:31:24 -0800 (PST) Received: from google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) by smtp.gmail.com with ESMTPSA id t23sm538631pfc.0.2021.01.11.12.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 12:31:23 -0800 (PST) Date: Mon, 11 Jan 2021 12:31:20 -0800 From: Fangrui Song To: Bill Wendling Cc: Jonathan Corbet , Masahiro Yamada , linux-doc@vger.kernel.org, LKML , Linux Kbuild mailing list , clang-built-linux , Andrew Morton , Nathan Chancellor , Nick Desaulniers , Sami Tolvanen Subject: Re: [PATCH] pgo: add clang's Profile Guided Optimization infrastructure Message-ID: <20210111203120.daeef4yuwgmk5em4@google.com> References: <20210111081821.3041587-1-morbo@google.com> <20210111201224.l5r2zxuyd7ayszke@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-11, Bill Wendling wrote: >On Mon, Jan 11, 2021 at 12:12 PM Fangrui Song wrote: >> >> On 2021-01-11, '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=vmlinux.profdata vmlinux.profraw >> > >> >Multiple raw profiles may be merged during this step. >> > >> >The data can be used either by the compiler if LTO isn't enabled: >> > >> > ... -fprofile-use=vmlinux.profdata ... >> > >> >or by LLD if LTO is enabled: >> > >> > ... -lto-cs-profile-file=vmlinux.profdata ... >> >> This LLD option does not exist. >> LLD does have some `--lto-*` options but the `-lto-*` form is not supported >> (it clashes with -l) https://reviews.llvm.org/D79371 >> >That's strange. I've been using that option for years now. :-) Is this >a recent change? The more frequently used options (specifyed by the clang driver) are -plugin-opt=... (options implemented by LLVMgold.so). `-lto-*` is rare. >> (There is an earlier -fprofile-instr-generate which does >> instrumentation in Clang, but the option does not have broad usage. >> It is used more for code coverage, not for optimization. >> Noticeably, it does not even implement the Kirchhoff's current law >> optimization) >> >Right. I've been told outside of this email that -fprofile-generate is >the prefered flag to use. > >> -fprofile-use= is used by both regular PGO and context-sensitive PGO (CSPGO). >> >> clang -flto=thin -fprofile-use= passes -plugin-opt=cs-profile-path= to the linker. >> For regular PGO, this option is effectively a no-op (confirmed with CSPGO main developer). >> >> So I think the "or by LLD if LTO is enabled:" part should be removed. > >But what if you specify the linking step explicitly? Linux doesn't >call "clang" when linking, but "ld.lld". Regular PGO+LTO does not need -plugin-opt=cs-profile-path= CSPGO+LTO needs it. Because -fprofile-use= may be used by both, Clang driver adds it. CSPGO is relevant in this this patch, so the linker option does not need to be mentioned.