Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1557713pxj; Sat, 12 Jun 2021 12:14:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGoNP8QcFL/hw+Xt3zF+5xhnMVDAwGmIxysliA/OQpJco1+Y4meC2E2tOwAt/VwTXnk0CM X-Received: by 2002:aa7:cc87:: with SMTP id p7mr9437078edt.82.1623525274422; Sat, 12 Jun 2021 12:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623525274; cv=none; d=google.com; s=arc-20160816; b=od0l+Srt4FFr028EP5vdVr0WfjYtk1PISvI3Z3fQPMBStp9NtmYMPCaOrn/BynNkFJ dD5eYF7T8ofXNxBAmTCwIU/8mv3XwODtt4wXa29wKLvCQr/KlPfI2t2NvljEOcFRrUGv J36kBfhUh7vQN6cjws8yytz7HGaQlbt+OJ/Lozx5ftbcbOk/Gsefr6USNJXlKHBq+AZO 77UFU6Nc82IrKDsGbQUFuU8t529M720pZYQZeH8/k7T6cjqNJfiETPqptMHjKRBODqJL p1LkHLjdu1vaHXrGt+mN/PjoO/7+3c/n3F8R8bQmuR4MtnZjPpZVDNIKqs0Bu/KQAKwg DBHg== 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=BF4KTa2Agq0jbJMydgzuSSPg/d4XEACgY0H+fIBjXaw=; b=ME/KwaNr6OI1PxQWBtq/vdKmam215/RJKKv0/2Ou/ddHtWVk45B8tIKVsvCzWpXSPM wh42Z2uljqdfcVNLQaMCqFd1WEoSI9GzEWJJM53zDzzctM53jRKxZBsgou6aMlgCRsMG 0azzNlYBXuPl+Ls4al1u1NBtKHsQsS96tPv8ByA06oHtD2YJOAdHZk59MIQSz8yL7bko /6fQ2CmNYZd1IOakkbumiCFRUkdbiEXKCRZi98TpHF+AJxGYIxCb6TSCWdnv7P8B5CLw Ujx8uB/ifE+U25LVEtseanTeunjn7eUVwR6KnQ808Xrib1TMzFz30zV4IYYqif7XHFB+ YeYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=srFpC0Se; 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 z1si7887044edd.156.2021.06.12.12.14.10; Sat, 12 Jun 2021 12:14:34 -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=srFpC0Se; 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 S229985AbhFLTNP (ORCPT + 99 others); Sat, 12 Jun 2021 15:13:15 -0400 Received: from mail-ed1-f43.google.com ([209.85.208.43]:39843 "EHLO mail-ed1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbhFLTNP (ORCPT ); Sat, 12 Jun 2021 15:13:15 -0400 Received: by mail-ed1-f43.google.com with SMTP id dj8so41089642edb.6 for ; Sat, 12 Jun 2021 12:11:15 -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; bh=BF4KTa2Agq0jbJMydgzuSSPg/d4XEACgY0H+fIBjXaw=; b=srFpC0SeLeMkVrDjlzK1DW3HKDXhgIITNsH1dfNDZIW98UQGzwOjxIsfL4oL/Par+m c325BPpRkPl+4uPJznfiMMw7K2cnTPKKPhxMmSpG37iPrSA1T3WHK7bXik4gzuEu/wyc 31SiUM5cp8kGuZyoC6TJ0E5SNnylKtM6oIFXlVXhuZT2abo/g0jaqNy3BTW1QSgdkGTr 3nXeZaipGtuuyWN5IeOMXVRivOnUS5ld7q0xAPSQJVTVIR56tvaL63vVUVxpxyDtqqBP mXFfee3XX/86wOJFUUlgn/QkWD3yH2i09HfpVWOYukEUPsl32LVj2mBotqEd7mNaEOhF ZCkA== 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=BF4KTa2Agq0jbJMydgzuSSPg/d4XEACgY0H+fIBjXaw=; b=DRIIcnG9i8wFEN1lpUQnRueROZUh1wJV2KYW/XTSox8NYhLFiMGG0nN88nT35pwzqQ jbRMPwAXCeTh8kcKInIQkApUVTVzLPchZsBEcJ1++xfGvckhlCb122MSV9HSosD0276d 2/bFtorD1UIcYs/svYyvnfpmYEEP0RlWPikW9qXwnSHKmvK4vAv0s5MUO9lO/uBEgUe7 yJCWXSeupo+8pQHNvnqHlwnG82z1hIct7lHSPWv7RmNRjGbJlhEsVf2/CJz3+DNhbuSo +yZ7RevesopMvomXdc5FqRk8PZLyvEOmpAlNvPDh8sbBiBQE+G/fY4/fxVwUrCmAAe1m BE+g== X-Gm-Message-State: AOAM530GjG6krXaLEHZkSRV9794MFk/4HCxrsxapgrOZ9ug5WpPLs/RW 6NceEQZrDF951GioNOZwJcUKzcoSl4W+5rXZKGTb X-Received: by 2002:aa7:c782:: with SMTP id n2mr9796203eds.77.1623525014362; Sat, 12 Jun 2021 12:10:14 -0700 (PDT) MIME-Version: 1.0 References: <20210111081821.3041587-1-morbo@google.com> <20210407211704.367039-1-morbo@google.com> In-Reply-To: From: Bill Wendling Date: Sat, 12 Jun 2021 12:10:03 -0700 Message-ID: Subject: Re: [PATCH v9] pgo: add clang's Profile Guided Optimization infrastructure To: Peter Zijlstra Cc: Kees Cook , Jonathan Corbet , Masahiro Yamada , Linux Doc Mailing List , LKML , Linux Kbuild mailing list , clang-built-linux , Andrew Morton , Nathan Chancellor , Nick Desaulniers , Sami Tolvanen , Fangrui Song , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ")On Sat, Jun 12, 2021 at 11:15 AM Peter Zijlstra wrote: > > On Sat, Jun 12, 2021 at 10:25:57AM -0700, Bill Wendling wrote: > > On Sat, Jun 12, 2021 at 9:59 AM Peter Zijlstra wrote: > > > > > > On Wed, Apr 07, 2021 at 02:17:04PM -0700, 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 now be used by the compiler: > > > > > > > > $ make LLVM=1 KCFLAGS=-fprofile-use=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. > > > > > > *sigh*, and not a single x86 person on Cc, how nice :-/ > > > > > This tool is generic and, despite the fact that it's first enabled for > > x86, it contains no x86-specific code. The reason we're restricting it > > to x86 is because it's the platform we tested on. > > You're modifying a lot of x86 files, you don't think it's good to let us > know? Worse, afaict this -fprofile-generate changes code generation, > and we definitely want to know about that. > I got the list of people to add from the scripts/get_maintainer.pl. The files you list below are mostly changes in Makefile, so it added the kbuild maintainers and list. There's a small change to the linker script to add the clang PGO data section, which is defined in "include/asm-generic/vmlinux.lds.h". Using the "kernel/gcov" initial implementation as a guildlline (2521f2c228ad750701ba4702484e31d876dbc386), there's one intel people CC'ed, but he didn't sign off on it. These patches were available for review for months now, and posted to all of the lists and CC'ed to the people from scripts/get_maintainers.pl. Perhaps that program should be improved? > > > > arch/x86/Kconfig | 1 + > > > > arch/x86/boot/Makefile | 1 + > > > > arch/x86/boot/compressed/Makefile | 1 + > > > > arch/x86/crypto/Makefile | 4 + > > > > arch/x86/entry/vdso/Makefile | 1 + > > > > arch/x86/kernel/vmlinux.lds.S | 2 + > > > > arch/x86/platform/efi/Makefile | 1 + > > > > arch/x86/purgatory/Makefile | 1 + > > > > arch/x86/realmode/rm/Makefile | 1 + > > > > arch/x86/um/vdso/Makefile | 1 + > > > > > > +CFLAGS_PGO_CLANG := -fprofile-generate > > > > +export CFLAGS_PGO_CLANG > > > > And which of the many flags in noinstr disables this? > > > > > These flags aren't used with PGO. So there's no need to disable them. > > Supposedly -fprofile-generate adds instrumentation to the generated > code. noinstr *MUST* disable that. If not, this is a complete > non-starter for x86. "noinstr" has "notrace", which is defined as "__attribute__((__no_instrument_function__))", which is honored by both gcc and clang. > > > Also, and I don't see this answered *anywhere*, why are you not using > > > perf for this? Your link even mentions Sampling Profilers (and I happen > > > to know there's been significant effort to make perf output work as > > > input for the PGO passes of the various compilers). > > > > > Instruction-based (non-sampling) profiling gives us a better > > context-sensitive profile, making PGO more impactful. It's also useful > > for coverage whereas sampling profiles cannot. > > We've got KCOV and GCOV support already. Coverage is also not an > argument mentioned anywhere else. Coverage can go pound sand, we really > don't need a third means of getting that. > Those aren't useful for clang-based implementations. And I like to look forward to potential improvements. > Do you have actual numbers that back up the sampling vs instrumented > argument? Having the instrumentation will affect performance which can > scew the profile just the same. > Instrumentation counts the number of times a branch is taken. Sampling is at a gross level, where if the sampling time is fine enough, you can get an idea of where the hot spots are, but it won't give you the fine-grained information that clang finds useful. Essentially, while sampling can "capture the hot spots very well", relying solely on sampling is basically leaving optimization on the floor. Our optimizations experts here have determined, through data of course, that instrumentation is the best option for PGO. > Also, sampling tends to capture the hot spots very well. -bw