Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1095428ybl; Thu, 23 Jan 2020 13:29:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxR2VzjF3NOYRGt9AJyuDndWx1kxAJTy6Fcs411o+Z9xMrQequr2YQxq/c8OHbEWsISc1nm X-Received: by 2002:aca:1713:: with SMTP id j19mr11755198oii.160.1579814998045; Thu, 23 Jan 2020 13:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579814998; cv=none; d=google.com; s=arc-20160816; b=LSNXktC8fhZHLFIU82zdufCT1skiWB4AkslNiUPkBwTQeJ+pU+/QtRnLQ1UXo5jmMq YuRnhsZP8V1CV6RYBLItd4HFDZOFvD/t77PXiqp9s9hJlvksr7cwpi82u7FGstWWtCZd DSptpBinw782nroakslBi6rLgvfviKUwZex07Qx0DGfSchafGu/vUgC4VKaGpZbD0Itq qOrJ9gePkUss1i7J8fQKGxwp2edd/Lk+NN0neKDNmP1vWBfeAK5GRYsLFLwAdeqdxKdV 7nxcFSWCTv3D/F1CoClJqcIv5/x2Z4oHNvO/nd3bg4dIu74/wnrx3WNB6QcsHQqoVIMd YmcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=P9qYDjaalIojOyrJspA6Do0Z3KUXZSgzocMNFgoWdUg=; b=EsoZORjCul7tX56/wVT71yy82HMCsNFO3xagiLuRl2/gv/stQ0ZvUxaLMx/YxL8BP1 RQJxprdAG9TrdeTtQKpGyP18X05HcwjNLg0V/qfEelIMllVbqjLh9f2L65ieGsc9egEF as7nurhD95Bo/XAuIko5i7gGpeEiII/vHEPgVckT1fh19NBjdfKNAz65zPKP5Y045UiD mkOMSMEig5o25SpyfEM+1SXtlIdTpaoNl4jduOnEK+qBDcsXvFzYUI4VPyW7I0+ZnLu8 9mRs+C3a6YAe1qkQ29GQgYUq7vO2DXBlKlFvbNzGM9eNgz55lKR4gbFu6Zi5NQM5CHjw QQhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm2 header.b=XjYqqzbb; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=HvVl6qdS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t74si1425985oih.155.2020.01.23.13.29.45; Thu, 23 Jan 2020 13:29:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm2 header.b=XjYqqzbb; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=HvVl6qdS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729527AbgAWVXk (ORCPT + 99 others); Thu, 23 Jan 2020 16:23:40 -0500 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:41041 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728765AbgAWVXj (ORCPT ); Thu, 23 Jan 2020 16:23:39 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 785E75F4B; Thu, 23 Jan 2020 16:23:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 23 Jan 2020 16:23:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm2; bh=P9qYDjaalIojOyrJspA6Do0Z3K UXZSgzocMNFgoWdUg=; b=XjYqqzbbPIF4MJrNVCCX0UVqD0LDJ+azHGZx2x6Mpt qfHQm0rz36j16A7K5QJtF9BMADnEzTXAEa6Tpmr+pzgZB/mXfgi7RvQ8YXWI/2pO HsRKkBPVH0Q31LDk1dgiR46XI9EuI+SVbvPw1zn1BcT6bmC21AcalIWc5Zb6pMgm 2NY5PxSxjacHXOwL64/x5PCpEy9O+3yN3ITMrH3te+5K3eSk4Jax+tOAqPvvKliy 9bPgBtOJMObi+gGEpqS0XRtHb0fEkmYTwyGYf2/fKEMwnkpHyUjBeXlOzeiEZobn QS+jh2E5mkFUQYWzoBjere1X8DTolXynx8WhUGHH3DvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=P9qYDjaalIojOyrJs pA6Do0Z3KUXZSgzocMNFgoWdUg=; b=HvVl6qdS5APVwXY3SOPPjKBKfiSzl0y5I bAeH1Q4LE610BhILw/+/MynnDhIU7N8eexHwF3IOUPJFL0RKokHK9BJEnSSC4HLW sgui44EI1Nv9fYko7D1S3R6P+vuhCTk8ONBjNolUCvQb4/skzWWw6lPKMoYklJBo WefOls0QXLjcGyeYGzEeZyhjUcT+PybjMgAtFuNHA9UJXe8BNPjIMbhcdwJberPc 8PD+7fXxBZKOmlsaF3EpFsLYySwHvlMk+fZnN4uFQQhfgiSVItuO1Yz+i9+7eQJo vWou7Wrj6HkOBqvO+n9RN8SiEPXMS4dIinbxawNtmWpZQDRjYYaEw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrvddvgdelvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvuf ffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougiguhes ugiguhhuuhdrgiihiieqnecukfhppeduleelrddvtddurdeigedrudefheenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhu rdighiii X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.64.135]) by mail.messagingengine.com (Postfix) with ESMTPA id 3D3133060AA8; Thu, 23 Jan 2020 16:23:36 -0500 (EST) From: Daniel Xu To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, songliubraving@fb.com, yhs@fb.com, andriin@fb.com Cc: Daniel Xu , linux-kernel@vger.kernel.org, kernel-team@fb.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Subject: [PATCH v3 bpf-next 0/3] Add bpf_perf_prog_read_branches() helper Date: Thu, 23 Jan 2020 13:23:09 -0800 Message-Id: <20200123212312.3963-1-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Branch records are a CPU feature that can be configured to record certain branches that are taken during code execution. This data is particularly interesting for profile guided optimizations. perf has had branch record support for a while but the data collection can be a bit coarse grained. We (Facebook) have seen in experiments that associating metadata with branch records can improve results (after postprocessing). We generally use bpf_probe_read_*() to get metadata out of userspace. That's why bpf support for branch records is useful. Aside from this particular use case, having branch data available to bpf progs can be useful to get stack traces out of userspace applications that omit frame pointers. Changes in v3: - Document filling unused buffer with zero - Formatting fixes - Rebase Changes in v2: - Change to a bpf helper instead of context access - Avoid mentioning Intel specific things Daniel Xu (3): bpf: Add bpf_perf_prog_read_branches() helper tools/bpf: Sync uapi header bpf.h selftests/bpf: add bpf_perf_prog_read_branches() selftest include/uapi/linux/bpf.h | 15 ++- kernel/trace/bpf_trace.c | 31 +++++ tools/include/uapi/linux/bpf.h | 15 ++- .../selftests/bpf/prog_tests/perf_branches.c | 106 ++++++++++++++++++ .../selftests/bpf/progs/test_perf_branches.c | 39 +++++++ 5 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/perf_branches.c create mode 100644 tools/testing/selftests/bpf/progs/test_perf_branches.c -- 2.21.1