Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp672227pxb; Thu, 21 Jan 2021 17:31:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwc0ioVF4iAJ0s/TiZCl232sbZGItxOEMt1+jFYl3N+Uc0cTUxOTVvfauQ6djvgD5o0d5Bm X-Received: by 2002:a05:6402:17a2:: with SMTP id j2mr1398087edy.15.1611279116757; Thu, 21 Jan 2021 17:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611279116; cv=none; d=google.com; s=arc-20160816; b=VX/QN5gW3EyCEtz/2vZ3IyhVKXrQYZQhgXGzoVpFaoBFXqmfAACR9xHJqlEGbSGSAV J2rsDYmeChvWW0gBIgMjFDgN9Mupnul9i+uQhRAkumZm9sCz/f361k9QdWjAK28wz6vf +/fqi33SsV8EkQ6yXOHZSrW0N6RD3TDPSpr3NQNLD/qrIMdIuu0tjHPwz0rHA6ES2WMZ V66HnXK7vl/Y6aBBfvMw+/iuL5dO6p2Q7FCtIFY7uGTwgjrE1NZIYelZ1pdC1JVs3VDM FCP8Ldrr2pJt5LkpGD0jxRqUFCookWJ+Ln+We/TJP4PEm3rYE+js7HvnCbKEKyS93dwM vNWw== 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=xevnePlqkoJPc/gVx/RFwj12UYNRMR5SpPrBczxYlwU=; b=BUTK4CqJSekXYBXL4+8aVlbHYERDNibZ+N4JBBRWY0zbWzPmkqc/U42gvkPPR7HV5u 4+V/GATpMXtFjNtMtHBsuJSI+RbZmqBMLl24znjt101FqPewIWL/aVHV38jDYluajPgQ lfyTHk5PEE3bA7NGz7+Nbf//pZ9HBOftqqC/cP5tg9eNTa+wUqsdIct7bjhfOSlSS/Ej xPQ4vsp/8mEGzXYZdM7aLUhycU0RdvjJ/x/s7QmAO84mpAZmEvUDe6Yw19uo3z6r+Iwt W/4PCazB3B4DVTrRylutYg32ztd0mhgO0fqFx8QUcDIe6aUYDYpoQtExQ4k2mKgIe2Hq T6jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FAaMN6Ay; 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 cs9si2383849ejc.113.2021.01.21.17.31.32; Thu, 21 Jan 2021 17:31:56 -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=FAaMN6Ay; 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 S1725946AbhAVBaj (ORCPT + 99 others); Thu, 21 Jan 2021 20:30:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726110AbhAVBaf (ORCPT ); Thu, 21 Jan 2021 20:30:35 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8491C061756 for ; Thu, 21 Jan 2021 17:29:52 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id o20so2671873pfu.0 for ; Thu, 21 Jan 2021 17:29:52 -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=xevnePlqkoJPc/gVx/RFwj12UYNRMR5SpPrBczxYlwU=; b=FAaMN6AyqXOw4wBmmhNtwxoT6KGu6JihNZn+M+CLJmuNa/lpE8D88XnxfKOLemwyHz TI5aKcgt1SVzfkXaJs/3nWef0FXiHqTH70dPrea3jrhHlNnnI5380+pLqgQN+d8AFjGz ZyIHY70PZX052b4pCrh19ltUyBOszpEr5+ocfkRMZ/mV1a6Cx2MyXMG1wDEFkfm2rLvn 8LsP51l5ke7HdGwWcRlanQ2FPrAPNyt1E2l664oclu4QV/nAhkkJBkVav18vjoZa4jk9 dXZNVYxEWXhgxwuZrbF7yZIlGYcqVVbkbQg0J3Ck36wlk07OaYx+GO5Ry5J0kB7ngJ5g XQFQ== 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=xevnePlqkoJPc/gVx/RFwj12UYNRMR5SpPrBczxYlwU=; b=AEj88+c/+jsYQ2wSqie8CReOvp3/SEZwVJH7qoZCNONxh754RrhBssT9CYo+tW5jLJ poTiF4KA7aHnffXB5bgniB1YVQNgy2bmxKhrN6CKfx1tbG+J2kXy4At2z2w2W2Ap2r+0 lF7PgX00JOW2miQBzdxW8NPGZURTKDNq8yybVmi2qMBLLR/0XJa2DNw4G6WJmjQQq9yQ kxsBULrgfGqY0HDXSqB6Z6uw6M4ANrYvrt3/3FjaZjuLNpbQ7szuLsV5NjsVBSaUdnMP BVHgPjKCFgIbFg9TMM+PfwHi503Ro7qfi/lrqJ6CAuDwQnTAbH0YcmXbIZvKU+UBZzI0 mMrg== X-Gm-Message-State: AOAM530fnkGix7FSIF+SCyV8xE1kIao+U1cZIMXXi0I2a6yDTwOUquDx vOFYvAs9HIDSR+auz9V/GEk/3yiAOvJXhdMzMxgfJg== X-Received: by 2002:a62:838d:0:b029:1ba:9b85:2eac with SMTP id h135-20020a62838d0000b02901ba9b852eacmr2251542pfe.36.1611278991948; Thu, 21 Jan 2021 17:29:51 -0800 (PST) MIME-Version: 1.0 References: <20210116094357.3620352-1-morbo@google.com> <20210121082451.2240540-1-morbo@google.com> In-Reply-To: <20210121082451.2240540-1-morbo@google.com> From: Nick Desaulniers Date: Thu, 21 Jan 2021 17:29:40 -0800 Message-ID: Subject: Re: [PATCH v6] 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 21, 2021 at 12:24 AM 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. > > Note that this method of profiling the kernel is clang-native, unlike > the clang 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 > Tested-by: Nick Desaulniers > --- > v2: - Added "__llvm_profile_instrument_memop" based on Nathan Chancellor's > testing. > - Corrected documentation, re PGO flags when using LTO, based on Fangrui > Song's comments. > v3: - Added change log section based on Sedat Dilek's comments. > v4: - Remove non-x86 Makfile changes and se "hweight64" instead of using our > own popcount implementation, based on Nick Desaulniers's comment. > v5: - Correct padding calculation, discovered by Nathan Chancellor. > v6: - Add better documentation about the locking scheme and other things. > - Rename macros to better match the same macros in LLVM's source code. This is a major win for readability and comparing it against LLVM's compiler-rt implementation! Thank you for doing that. It looks like it addresses most of my concerns. I'm not against following up on little details in subsequent patches on top. However Sedat is right about the small issue that v6 doesn't compile. If you were to roll his fixup into a v7 I'd be happy to sign off on it at this point. -- Thanks, ~Nick Desaulniers