Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3242501pxb; Tue, 12 Jan 2021 09:40:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJJTvRxvkdkHTUS3lm3FAJw1GLVxB5vqUnHEQgBtgh8VqCl5TbYEX+86UKQXpE9LVWGMUD X-Received: by 2002:aa7:c64e:: with SMTP id z14mr201336edr.69.1610473206775; Tue, 12 Jan 2021 09:40:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610473206; cv=none; d=google.com; s=arc-20160816; b=nKJtwZ1Xb6pxs6q13gONR57+mFAqPIl7UNiFwj1TVMzVMcAMrgrCoSShwmhknM4mAX yCt4SzallFTsY5DZMx2k3EaWnPYn6pL2S2YzTxNhxVa/MU0yhKz2XvjxG03OlJcvMrrY Z3UsHt8AE+cnLNwtZTNoQrMqs/Pr0nPlXAeWK3Nsq5y5ZijV9OgleXzUbxXi8o3Rrb5X YD7R4/NIrkKo54YgQrRXYMULX+qhigM4paZ+I0k2dP2veqiXUGnHiNwCOoEWC9gTCPij wHSAmXgvz/G2BmqYRavPbf+qsgBn0oyl0H+d1Mg6yjBf+cfBgleXf1p6gG4rmFouE3+7 3sEw== 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=RmYwXjpSpSGJIaBI6nXMPcfre/G2OFN7SFzhgu7QxWw=; b=oUutk+NStqW3e62LN/MAkeGqneFNHTEsPCdSY97AcH64OLzxyGiHqf28NeJbefzq6W n9enmCpJjqXgl33lwLDOUtOHKhw6+t4k88Y0N5Eb5GvLHfB0lPWGbkd8Ql8e4nFVsfdb rvVWzaNNBlfog8M1U9FPUA08y37durf5lQxqI1YaOHL5mLgfu4d8p95V3dbHVrIl4i0B i+HCY1KfzXXiin86aJAMSfa+skgIfArjbROphGStoomjBewuUxw/wvI15Pz79weLCsnY JW8VhbyAbIbMIzbZxVosA8Nf6VCQ0FkhoruSjfWSA2veDpi6teAE8DLsX/qaBtNGmkwB 732g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=a2RPjzDN; 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 s11si1548316edw.280.2021.01.12.09.39.43; Tue, 12 Jan 2021 09:40:06 -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=a2RPjzDN; 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 S1727021AbhALRhy (ORCPT + 99 others); Tue, 12 Jan 2021 12:37:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbhALRhx (ORCPT ); Tue, 12 Jan 2021 12:37:53 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82CAFC061795 for ; Tue, 12 Jan 2021 09:37:13 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id cq1so1851368pjb.4 for ; Tue, 12 Jan 2021 09:37:13 -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=RmYwXjpSpSGJIaBI6nXMPcfre/G2OFN7SFzhgu7QxWw=; b=a2RPjzDNhO8HodYXLbDa3bberc83Qk9BDEkIp/TLIvN9CDQNWmkgfktCTAGNqUegMk M4OYxj1CNE+s9lezxe9nSsk/oHP0K6ZieMYbU/IP79dqY1Gdi3Obdu8WvUe8sx6IExWs 4/D0P4EXagL2fgNP9DY3Ua9h4Me5MQT1dPAO/y2zwcwt8PvCLB18hSJjTEBLIdaCeLuY 0n6VC/xTSY7jOuhSF++Syldf/QvI/zSrvQMRZcATD0oCp3CGIeb0shYFH8y67v4vnbKj oZ37YoGufFmaH50CBJiFMua8GLd1gknoMbC7dewfpS5aCmxjd4uA/oRcPZEHIeKkVRp3 aSuw== 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=RmYwXjpSpSGJIaBI6nXMPcfre/G2OFN7SFzhgu7QxWw=; b=N24GsyX3kRlHMN4nigoMLIRzgstbWaEdi+E0bQBRwZcYwXDRWRtJHQNLqlDh4AZvR4 j5T7iet6NM3Ywe5HqYuQPvdYZR4Qp6JsnTDZO827+09ZLw6lno7f1InYar+hq+C+b8ec 6iQyQRam9xlTHHt26Rl4YM+FLTJFfk8XcBXZf3zIGX0LYThPBGexTbERnJoN0oSSCzCx UT/gs4pqy2zCSO5xj9KPv65F8TKBbGFh5kmtKGM8vyRzx+H13bTqwWeHXBnDX1a43wIW Yw0YmGahzRBSlM+lOpqMAd2a/1z+eBKowxe4ivaLWFIYQ9qrInwjUKDSPCFSCPR0cqZO Iumw== X-Gm-Message-State: AOAM531yLPRWSBqPsQmswsreVynSaCD+7iiYHEnnt6dN5FN8QR6loprm ddIPbIkdRe/Quke4qug7GrGA9N1D4oY3ThjYp7ZlHg== X-Received: by 2002:a17:90a:cb0b:: with SMTP id z11mr170236pjt.101.1610473032865; Tue, 12 Jan 2021 09:37:12 -0800 (PST) MIME-Version: 1.0 References: <20210111081821.3041587-1-morbo@google.com> <20210112051428.4175583-1-morbo@google.com> In-Reply-To: <20210112051428.4175583-1-morbo@google.com> From: Nick Desaulniers Date: Tue, 12 Jan 2021 09:37:01 -0800 Message-ID: Subject: Re: [PATCH v2] pgo: add clang's Profile Guided Optimization infrastructure To: Bill Wendling Cc: Jonathan Corbet , Masahiro Yamada , Linux Doc Mailing List , LKML , Linux Kbuild mailing list , clang-built-linux , Andrew Morton , Nathan Chancellor , Sami Tolvanen , Alistair Delva 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 9:14 PM 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 Please drop all changes to arch/* that are not to arch/x86/ then; we can cross that bridge when we get to each arch. For example, there's no point disabling PGO for architectures LLVM doesn't even have a backend for. > 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. Then the Kconfig option should depend on !GCOV so that they are mutually exclusive and can't be selected together accidentally; such as by bots doing randconfig tests. > +static inline int inst_prof_popcount(unsigned long long value) > +{ > + value = value - ((value >> 1) & 0x5555555555555555ULL); > + value = (value & 0x3333333333333333ULL) + > + ((value >> 2) & 0x3333333333333333ULL); > + value = (value + (value >> 4)) & 0x0F0F0F0F0F0F0F0FULL; > + > + return (int)((unsigned long long)(value * 0x0101010101010101ULL) >> 56); > +} The kernel has a portable popcnt implementation called hweight64 if you #include ; does that work here? https://en.wikipedia.org/wiki/Hamming_weight -- Thanks, ~Nick Desaulniers