Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2951396pxb; Tue, 12 Jan 2021 02:40:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmtfBB+GlvJ8kruWshQkjyX7wtwI3CaYpOk6PxtpVDX6uOVVb2lasVhZ8EeKR83IhUzXj6 X-Received: by 2002:a17:906:af49:: with SMTP id ly9mr2659854ejb.38.1610448041994; Tue, 12 Jan 2021 02:40:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610448041; cv=none; d=google.com; s=arc-20160816; b=mG+DSbjt2Ehqqh3e1/rWexwaR7GVckthI5LLJ0xDWYA3H3AbU/EeDltYn0Sfb+6wEl x49GR6v8EeskpbQjBBkLVuROlMyizOM2xCWBppvMqC2LeppM/i4CbkSp3CMeyhN+QufS BqHOmkoAZshZ4yhipmo94b3Ju6TvU9o0p0eBBHxbVMbT9ZgYQAhekqDeAX1tEtxjwiZp PbXZ/Jptu7MICl1eD6rGBN+6NCOW2L9D1tGtCUdq2n7ULg7e5+8+grfAgs1+CmMJq8Cx jbSxef7aEni1+7mCtaZ9x+CpGPFjXxQ5LifWaXbLI8T3k1r3sJk4/6IFxjrSSlYZ7cZd 6evg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AAGK7QJnpAigixBsDwJOzFarQpa+uBn1LCtFQ6nqZOg=; b=CTEfMS3bgs2abiJ/HkMb1iGJDlzkCoYWr/crUbP1MhozVEoZJOK3ZXYZoN4rsEBYrf sdkqk25cRjwBWqtbnTVoXYFusCzBbsedr1sOHL3wDA7ipT+hMQWdabgIs0N5G4EtLd1R UErrxh0HXMnPe5mU/7frlwbmk9F04/ExmmMlVUuKLWsGy1oe8E6HchE/ugfxz2bxdUZj AdCPEa0pNE2/f0yYXj40eDlTKA6HkkF3yXwPbBubLFeOpZiiJX2oJ9WNYg8vgrLwTQ9J fo7ounO5n78WLHEbk/vBAaYU1KsR+bH+lOm5TyWyxyGk0uHm1mlYi2j5C6aXNbbJf8SZ E5ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Zj+qOLhH; 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 v5si928271eji.385.2021.01.12.02.40.17; Tue, 12 Jan 2021 02:40:41 -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=Zj+qOLhH; 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 S1728693AbhALAjc (ORCPT + 99 others); Mon, 11 Jan 2021 19:39:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728974AbhALAiq (ORCPT ); Mon, 11 Jan 2021 19:38:46 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41588C0617A4 for ; Mon, 11 Jan 2021 16:38:06 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id 6so1023064ejz.5 for ; Mon, 11 Jan 2021 16:38:06 -0800 (PST) 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; bh=AAGK7QJnpAigixBsDwJOzFarQpa+uBn1LCtFQ6nqZOg=; b=Zj+qOLhHhCXzhbKC6BIAew+AX4ps5bw/ov5suzZPwzPwiHyKHAlZpPGpfXEv10EV0C f+u28iptdt6p3p/fA/LMgRUvZ0kd2jfsUajM6UJUSBoPn2lAtcEaVibSRudyHVAG4Dsh 5wbu9vfoEfHtNNaSfcndmEfzD+b2I4KevWgCKhp795ZOltdJO0dx3nFQahcQtqyMYYOD C+m5v5SJZNDC8hJ4kQip8/63FIZVNzGX83A1ZZhSRmCpE6039rjwpXxqRHRMtjE9QYc0 9ucW1UVi0j32EE9Iam8Z1bs/Sa6LKBX/qLkboU4v1MA6+NRGJrzDgARi25KLBaPpYdf+ oFWQ== 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; bh=AAGK7QJnpAigixBsDwJOzFarQpa+uBn1LCtFQ6nqZOg=; b=pNT0CSama+mdAITspqK7lT2f0rN/5xIJ+eV/DIiI68LbAWp/8cL9LH4Kxunxo1Y5gF ASLTtOuww1n7HaZkkTlIfhl98qqhWour0foELTG/RI8ToJYEuy4hvCzJ6Qxzju/x2t5N DyMRgEnh3puIgJQNpmI3+eNZFh2i0cVU8tdQ3B4UqdSRAyWtEbof9gpBad+sgcIo+1/G N0mJaIcOsEcyqkYg21P/z0jhGbWUmePpmKrq/OZOD1qnMfDvkqXBi6vcJBlXWt2dSxCa NhDTb2PlpGvWsDJQzGO8maVK14Ntl3W3KKVWl7jryEoAr9DPcmMqinPPb2YvOz0jTmgX 2geg== X-Gm-Message-State: AOAM532eK74HSkKg6XGF8wywCOLC7QaT4lqmbd+TcM5HqXRg8fUUQ6uT 5PbcDMikNjxs7xITbedhebwB2PVf4dkyevbPSo44 X-Received: by 2002:a17:906:1194:: with SMTP id n20mr1301510eja.269.1610411884658; Mon, 11 Jan 2021 16:38:04 -0800 (PST) MIME-Version: 1.0 References: <20210111081821.3041587-1-morbo@google.com> <20210111201224.l5r2zxuyd7ayszke@google.com> <20210111203120.daeef4yuwgmk5em4@google.com> In-Reply-To: <20210111203120.daeef4yuwgmk5em4@google.com> From: Bill Wendling Date: Mon, 11 Jan 2021 16:37:53 -0800 Message-ID: Subject: Re: [PATCH] pgo: add clang's Profile Guided Optimization infrastructure To: Fangrui Song Cc: Jonathan Corbet , Masahiro Yamada , 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 11, 2021 at 12:31 PM Fangrui Song wrote: > 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. I'm still a bit confused. Are you saying that when clang uses `-flto=thin -fprofile-use=foo` that the profile file "foo" is embedded into the bitcode file so that when the linker's run it'll be used? This is the workflow: clang ... -fprofile-use=vmlinux.profdata ... -c -o foo.o foo.c clang ... -fprofile-use=vmlinux.profdata ... -c -o bar.o bar.c ld.lld ... foo.o bar.o Are you saying that we don't need to have "-plugin-opt=cs-profile-path=vmlinux.profdata" on the "ld.lld ..." line? -bw