Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2573699pxb; Mon, 11 Jan 2021 13:20:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnRMjUNDMkupKNeg8GjBaBp2ADts/2u8U9jcZhrpnqWYgNp3qzWGvDfcvcb7Bgb6Ux+zGi X-Received: by 2002:a50:d4d9:: with SMTP id e25mr921303edj.243.1610400045001; Mon, 11 Jan 2021 13:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610400044; cv=none; d=google.com; s=arc-20160816; b=KHE1jIuFFOF2FEHFqFuV/bLOt/3BjoKYLkyZRjEN9e+op0IfndK1pG3S5ClU8I2l4V zp8n3Q9SIGFiu2MpXglrg4EZsNx36SW5i7pjP73QNpyHhWKlwIUcwasxqhUOxX+kSbJ/ b9qPzZTLtENNGKw9WR1bf7BNSvAxbgo28R+p0ID6H4K/vvn30uNi/cnsfk57UvnDZ+ig PjRD0miFjx9aAtlw8SBNZNhSNs5JFF32UXQefM6VsIPY6XD6hRzPAWPRfvQHe2HNQJx8 j3AEPNi0qg+bCFz9nUR/PAEb3soeNR7jkILgjDUB8NG5QEQz4bZBOnXvFB7s7v6PyuqR vDqA== 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=0qOSbOIoHdN2DZPTqNutcK6F4X/pENnDZjQfdlW5H0c=; b=GPDTUTBugGfLYhXUe4aIcm3YEomEZA+PNk8YPZUbntdwixmDKzc3hdlm1uWDk1IB9T +WvvOPjNx4ZXLXX9vV5UC1qIuLkn161bPB6EWdpqwwHVfwhEKSKoAOxzveYsiotgJwGv 8o8HKsAChnb5EnM/yik2/A8P6xqoS64J5Pw7oexbpIKBUvm0mDmiq3sI3diX6kG2MbNM X6BvxqlQ5VUl4GoD+E0ZRypUl4A/kmU62CDjacUgQ9OiHJ7e1WZQEaRvEtEqyFbEN6XF 6FYi1oU1iTEHmgZdsIiQC+hej1L9RVDb0woDQSISJAnT5Lzu0GZjZsAUo8KSHiAReYQ1 PYfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="j2/sB7/R"; 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 v13si354751edx.218.2021.01.11.13.20.20; Mon, 11 Jan 2021 13:20:44 -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="j2/sB7/R"; 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 S1730145AbhAKVSr (ORCPT + 99 others); Mon, 11 Jan 2021 16:18:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727150AbhAKVSp (ORCPT ); Mon, 11 Jan 2021 16:18:45 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD5F3C061795 for ; Mon, 11 Jan 2021 13:18:04 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id w1so493242pjc.0 for ; Mon, 11 Jan 2021 13:18:04 -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=0qOSbOIoHdN2DZPTqNutcK6F4X/pENnDZjQfdlW5H0c=; b=j2/sB7/RU5nL76Pa1L1dp1gCmPW9RtgnhlOkU9CiPL/vgEu0AzN3MnegQM25nqbFZO GdzCzXY3KfqY40y9YoRy4JUZ/j60yRTN/7zwg7Uo3PdHlEJS7blWtkjbjnUjohiO+2i5 HxQ6qaRIV8v12rY/kSwUVK9q2Vd9+FdUTrxewc2nzJ0P1GV2EVo+ansDYxAFpMBtk14/ NwBf5ewSGbABgg5tXfSizs6Hsx00LlHf8+58gz3epX9LGeFudhkSvXxU59RoDpeIowwK uKu61pD7h2broKNQKMpLvxQqdRr4+avLzxtK4epTmhvB//XOnXGXuNuwFI8WOewkw7hy OLRA== 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=0qOSbOIoHdN2DZPTqNutcK6F4X/pENnDZjQfdlW5H0c=; b=GP0SybdcN4cmUG9scnmWc0z3VaraYGe433AJLK3EPxx9Ckto7iJxOGV2HTeVrvrDWw dLw2N+vAGpJPpqbzBcff5713wOPsu2gHaJaBxlQ2OGeIIQYknPmxy1hyPoRu9d5+M+yz Mw6TR8lEaqZGi+4AsUTZEWLKGiLOHl8Jp8J94316DFYZymQXV5JjqfDPw5QpYzJu9TK7 gvtYiHUpfcDMHLsdarKwjXh5RexPvl0KjSa8dhvTsSJWSSGHpxp+1iIcC6/29YSkROle YQuuc4Myma34AKCsKxd319rRLhMWX3nwypNi6iJdb1b0ZWdYZ+fOdDh/Vqn2MOerqKzA 4yIw== X-Gm-Message-State: AOAM530S4OOazLWHERtFhmFxNHgwZ8u6SLViTwzmSmQv8d5TdtV2Vij7 hO/5vrxHqdudXSixFSdtt/YHezqRvChIZainoiB/6g== X-Received: by 2002:a17:90a:cb0b:: with SMTP id z11mr786374pjt.101.1610399884135; Mon, 11 Jan 2021 13:18:04 -0800 (PST) MIME-Version: 1.0 References: <20210111081821.3041587-1-morbo@google.com> <20210111210418.GA3660906@ubuntu-m3-large-x86> In-Reply-To: <20210111210418.GA3660906@ubuntu-m3-large-x86> From: Nick Desaulniers Date: Mon, 11 Jan 2021 13:17:52 -0800 Message-ID: Subject: Re: [PATCH] pgo: add clang's Profile Guided Optimization infrastructure To: Nathan Chancellor Cc: Bill Wendling , Jonathan Corbet , Masahiro Yamada , Linux Doc Mailing List , LKML , Linux Kbuild mailing list , clang-built-linux , Andrew Morton , 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 1:04 PM Nathan Chancellor wrote: > > On Mon, Jan 11, 2021 at 12:18:21AM -0800, Bill Wendling 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 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 and isn't > > compatible with clang's gcov support in kernel/gcov. > > > > [1] https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization > > > > Signed-off-by: Sami Tolvanen > > Co-developed-by: Bill Wendling > > Signed-off-by: Bill Wendling > > I took this for a spin against x86_64_defconfig and ran into two issues: > > 1. https://github.com/ClangBuiltLinux/linux/issues/1252 "Cannot split an edge from a CallBrInst" Looks like that should be fixed first, then we should gate this feature on clang-12. > > There is also one in drivers/gpu/drm/i915/i915_query.c. For the time > being, I added PGO_PROFILE_... := n for those two files. > > 2. After doing that, I run into an undefined function error with ld.lld. > > How I tested: > > $ make -skj"$(nproc)" LLVM=1 defconfig > > $ scripts/config -e PGO_CLANG > > $ make -skj"$(nproc)" LLVM=1 olddefconfig vmlinux all > ld.lld: error: undefined symbol: __llvm_profile_instrument_memop Err...that seems like it should be implemented in kernel/pgo/instrument.c in this patch in a v2? > >>> referenced by head64.c > >>> arch/x86/kernel/head64.o:(__early_make_pgtable) > >>> referenced by head64.c > >>> arch/x86/kernel/head64.o:(x86_64_start_kernel) > >>> referenced by head64.c > >>> arch/x86/kernel/head64.o:(copy_bootdata) > >>> referenced 2259 more times > > Local diff: > > diff --git a/drivers/char/Makefile b/drivers/char/Makefile > index ffce287ef415..4b2f238770b5 100644 > --- a/drivers/char/Makefile > +++ b/drivers/char/Makefile > @@ -4,6 +4,7 @@ > # > > obj-y += mem.o random.o > +PGO_PROFILE_random.o := n > obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o > obj-y += misc.o > obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o > diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile > index e5574e506a5c..d83cacc79b1a 100644 > --- a/drivers/gpu/drm/i915/Makefile > +++ b/drivers/gpu/drm/i915/Makefile > @@ -168,6 +168,7 @@ i915-y += \ > i915_vma.o \ > intel_region_lmem.o \ > intel_wopcm.o > +PGO_PROFILE_i915_query.o := n > > # general-purpose microcontroller (GuC) support > i915-y += gt/uc/intel_uc.o \ I'd rather have these both sorted out before landing with PGO disabled on these files. -- Thanks, ~Nick Desaulniers