Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp10790pxb; Tue, 12 Jan 2021 18:23:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2hvzdTVk6jsM/e5uHMD36NtZNjkLTEziYK18qgrqxT/7VFLTto3pmEoIchfOeg0MOFEwb X-Received: by 2002:a17:906:a857:: with SMTP id dx23mr1212448ejb.189.1610504635521; Tue, 12 Jan 2021 18:23:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610504635; cv=none; d=google.com; s=arc-20160816; b=jJzHHN/emW6faw4bmiq/4+89HiKmYwKqQbcolhe/0a5ZZX0D3EVoIDi6S4AETjuDI7 KMjfFGEvxqGaHw/mZqrMUAwmIRwJ+og2P+0OZt/3IQ9itk6DfRmd4MJ3x5+4TL0hfcHO h/BqIYgNbNqWFreLbmSqAZLy7J9GbwTtnjcJ+s50WT3b5d8Gc7EAxxQYqjIMLj4U9Ebl BeRFJu2p+ODb3DqvCUZ9ExcrRWLgrIBQZFmZ3UjHguRqJjErPyKnzlYT9XG0LsWlp+gR 9apThnQq0J4o0tEgK2NGABDJ+7x1CAsonWqdVgZec8P8DIZa4f3fqdrV1y+PWaD+i7iC 8iXA== 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=kp8U52XQRpl24mM7G2RDldHnlK7yV2a+H4JiRS6waC0=; b=iWQhaHnNwGN7ht4INztjQNKfvh96GbsfPMAcVD+/oG1b3ZbaghNHZOD5aPK9WRqTrH 5N0bWj2YTWV+sfLAUW0gcUa+azCq/K4p+Yg8Zw+v+5cTDDilv1YCVX5ZH1I0x/kr9Jp8 Tse7Dazp3TA3SbLFKYd53HN8zaV4JNXwZGW2i3AgzfPVXMZl7UD1TmhD6dS3JgP74hiU nxxiAJzVUdIYGS72LiyS1X7A055eTdV1TWf7HOfVoDXfyNFeFcpF+koJ234+axHqON3Q IlBpxBv1JZyNO/8EXw13eUvR2ikzrh0V8wRxodO5fHMdD8yPBXQAqsMyUOjpxXSYhNj8 FjiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s1TmDllN; 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 c22si253810ejx.290.2021.01.12.18.23.31; Tue, 12 Jan 2021 18:23:55 -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=s1TmDllN; 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 S2389380AbhALRqL (ORCPT + 99 others); Tue, 12 Jan 2021 12:46:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728425AbhALRqK (ORCPT ); Tue, 12 Jan 2021 12:46:10 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57B34C061795 for ; Tue, 12 Jan 2021 09:45:30 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id 11so1822423pfu.4 for ; Tue, 12 Jan 2021 09:45:30 -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=kp8U52XQRpl24mM7G2RDldHnlK7yV2a+H4JiRS6waC0=; b=s1TmDllNcfHa8938jvmhvPAjJZWqwEjtTyoDnQZPsMSJznW7XTmhxVP5QdM+VgFQfg GX4fndU3z6c3ACC6H4qbwKDzKyqZAhxRUrFNFDQKv0jWwSJmzyAWn6zDf3S0k1PxzE+f zPPPtxqBgqLvQILOQcmZ1vLXO2wQOK+JHC67fhNpUOjFsdRZP+oG/CqUd407IoMSYKlO V6dgnHUKIDSi7JGpq8exTW/MIFI65W1O4bc/DtreEikPrmXag2mYo57+lEMg+xln9z75 FTwQfrHHHTqAFde7sPnMaD61o3HSCMHTFC5fbqgZdzK9WUpMEmtM5iPH7CbaeMnLAjCe rhog== 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=kp8U52XQRpl24mM7G2RDldHnlK7yV2a+H4JiRS6waC0=; b=N/kZQH0BnbczJCkh22lhmYPcMlRLh1RmgWMMe/Zw94iCPmXGQ4gDxcrU/cFjoMBoMA ik7RzYZgBywhwj9AKFdqKAV77LKdwGc1KrxD5AgvMQD+NqY88cFa6etQ6J9eWVvg/DsU jTvdg0Gj7lsoXT+ZxxHDAaA5yeuW9kCGeIrkYK+BIjVEFXc142F0FA02mciGQ2mc6EoB gzq43aaelfgxpfxCiLjirfFZsX6SZPXmh0TaOfyKXB2vHMXxpY8BMMpEBO6nZYil4eD3 pMcyuKYcnCiaAmHJIhPjXUrIRg/IWz7/dInXO8g6IvIIcuC+O19sJtiH68vfYqsgXg9b Vl7g== X-Gm-Message-State: AOAM533GC2RB05x+VfRhI737DHol3XMt70gYY/D3qdj8ltHNhhWa7QC1 rAprclpNHiGANnDBzz4/lrgtX0QDiBHchWG1p0vJYw== X-Received: by 2002:a65:48cb:: with SMTP id o11mr164747pgs.121.1610473529429; Tue, 12 Jan 2021 09:45:29 -0800 (PST) MIME-Version: 1.0 References: <20210111081821.3041587-1-morbo@google.com> <20210112051428.4175583-1-morbo@google.com> In-Reply-To: From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Tue, 12 Jan 2021 09:45:17 -0800 Message-ID: Subject: Re: [PATCH v2] pgo: add clang's Profile Guided Optimization infrastructure To: Nick Desaulniers Cc: Bill Wendling , 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 Tue, Jan 12, 2021 at 9:37 AM 'Nick Desaulniers' via Clang Built Linux wrote: > > 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. The profile formats (Clang PGO, Clang gcov, GCC gcov/PGO) are different but Clang PGO can be used with Clang's gcov implementation: clang -fprofile-generate --coverage a.cc; ./a.out => default*.profraw + a.gcda > > > > +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 > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAKwvOdk%2BNqhzC_4wFbQMJmLMQWoDSjQiRJyCGe5dsWkqK_NJJQ%40mail.gmail.com.