Received: by 10.223.164.202 with SMTP id h10csp609341wrb; Thu, 9 Nov 2017 00:00:22 -0800 (PST) X-Google-Smtp-Source: ABhQp+QCD8NpgNYA8XRQ2N5EC7drYi9L01hVLxpC+7zLe2F9G81IwC/eCxI0FsrDGvRqmC/zosyx X-Received: by 10.84.178.131 with SMTP id z3mr2971067plb.165.1510214422783; Thu, 09 Nov 2017 00:00:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510214422; cv=none; d=google.com; s=arc-20160816; b=q0d/+/YqmbZkVo7fFHv915BdEz8viQp66Q4iXgt7IOnZMI+CXH2wTI4C1szzHSQ874 IXak2znTzKY2gVSX9/b2qPCrBxdQ0XGFkygtEKt0/EodKqMA0HjMk3xk0QozHLmxWP+7 DKg3YL2H1AcPX9h8pyD1DCW5ftXi0PNE8L7mwYua4QV5GWu/8mnP02DARo7Z3+5xZPKP K21VHNIP9AnnljF+fpWxWl+WsSMy/epNanRxe9UyvdXvXDABlYXw65lSc9d2/gmQkUQZ 0F/md3koc4PVYbfED+H0ky/S829Wphr8TGBHVOIflF9v3Dm2ZwMfwiwW0JH0DE0WevQm D8Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=/MemK//g/GRoarK6uOFbqD+IVga3Q9QT756TYqv8ORw=; b=wli52Y5yrRHZLD/L1IuTIg2zz8rxxeXtbgGeNDRqnaPzlWP2mnVwcKqz/In41aeUa9 F/5WW/MgjW27br4WmhUf8wz3nVzy6xZv9yeOx6Xh7p7XhIDxSA7wuXv7CViIN7oB/EYy hkQhswJIYSxOfX3XTpuswjlNcqZsrqyC6SBtPpnN6cjQ0xAM0AoJzLG6vGlDyQcixgLH Lzio+a0sYf7uE1GSa8ORvMPDWSPuunc1ZZKhclS6vnTt9YiunGbqWmFUcUbIlZ3w+zKK +m69hyZsrGTM891Z0Fo8evRAeMg1Fugwhbxkqn0an2bEeVorMvabi8cT+Go4uk4qsyjl EUyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wUf9r4nO; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n187si5985865pfn.150.2017.11.09.00.00.11; Thu, 09 Nov 2017 00:00:22 -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=@google.com header.s=20161025 header.b=wUf9r4nO; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753170AbdKIH6d (ORCPT + 82 others); Thu, 9 Nov 2017 02:58:33 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:46025 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753096AbdKIH5W (ORCPT ); Thu, 9 Nov 2017 02:57:22 -0500 Received: by mail-pf0-f196.google.com with SMTP id d28so3730227pfe.2 for ; Wed, 08 Nov 2017 23:57:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/MemK//g/GRoarK6uOFbqD+IVga3Q9QT756TYqv8ORw=; b=wUf9r4nO13hODmi+jQiadSB402woEZ6pAy6HlBd2vQoWZqoL/5r3Py9WKCKWRhuZgu /M4O0M8z0vI4DpHesP+F7/z+u1A9JRMKR10cHQ2pSq/M/Y3UjuEc351nBCkUBYAHVHiJ 2RnrI5a/tC0kzk1PsdsdhDY6QKBdK/ftAf4JRy29MHmCGyTH0oh3s8MJIsNeEA372so6 +2ZYTBiKb2SrRJPr8AcG0sKZNET+xSK1G0bE+hnKa6gwnOdhZqeM9nx5BRNI21D9SP8j aAsfmvEfTVtkltKATQkrTHZ2nsMO72e2SAGgrzJ/YQ+b5fmSUs5CbO/ZjMfXbC3qHe2Y K8ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/MemK//g/GRoarK6uOFbqD+IVga3Q9QT756TYqv8ORw=; b=RfuDquBcZtC6+SgwcggzNSsRIQ910kJcFiXazYoaJkBh+fmIHLNvS3oIYyl13ouMTt ujaNQ3iPLylSqUVJ9OxKdTVV/8Puzdw6rW8ZfDScjewMVG6VikmHG5yV+eIJNontu4sX e8scn4vKg2q2sHG8Sqb7lJRWodw30gb+q2pjztbJn5kRL/1jMddRyRkbKQrvkr27SMnZ jKqA7SRKbjUROiSGGG5acds23CN4epDNAGS44RTohgRBfNkZcFsRlrcMWeQcRcqH7D8x 4T+0PW3xRSzVHPM1mipjYIP5R7PDlJkGwUSYz+RXpNb4FlzSRMbKDYuXH2z/szohnoU2 SfQw== X-Gm-Message-State: AJaThX4m7+JnQaJp8N0q5zR62MnwSCt68cjA/zz9+FYlCGRxNYZVAJM6 zVazBIUmkvkaZ2Y4XkR/v/GSd8BR6DU= X-Received: by 10.99.131.66 with SMTP id h63mr3053937pge.156.1510214241493; Wed, 08 Nov 2017 23:57:21 -0800 (PST) Received: from localhost ([172.56.39.30]) by smtp.gmail.com with ESMTPSA id j186sm12728294pfc.114.2017.11.08.23.57.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 23:57:20 -0800 (PST) From: Stephane Eranian To: linux-kernel@vger.kernel.org Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu, ak@linux.intel.com, kan.liang@intel.com, jolsa@redhat.com Subject: [PATCH v4 1/5] perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type Date: Wed, 8 Nov 2017 23:57:09 -0800 Message-Id: <1510214233-2074-2-git-send-email-eranian@google.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510214233-2074-1-git-send-email-eranian@google.com> References: <1510214233-2074-1-git-send-email-eranian@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patchs adds a new sample record type. The goal is to record the interrupted instruction pointer (IP) as seen by the kernel and reflected in the machine state (pt_regs). On some architectures, it is possible to avoid the IP skid using hardware support. For instance, on Intel x86, the use of PEBS helps eliminate the skid on Haswell and later processors. Without this patch, on Haswell processors, if you set: - attr.precise = 0, then you get the skid IP - attr.precise > 0, then you get the PEBS ip corrected for skid The IP normally comes when the event has PERF_RECORD_SAMPLE_IP set. However, there are certain measuremewnts where you need to have BOTH the corrected IP and the skid IP. For instance, when studying branches, the skid IP usually points to the target of the branch while the corrected IP point to the branch instruction itself. Today, it is not possible to retrieve both at the same time. This patch makes this possible by specifying PERF_SAMPLE_IP|PERF_SAMPLE_SKID_IP. Signed-off-by: Stephane Eranian --- include/linux/perf_event.h | 2 ++ include/uapi/linux/perf_event.h | 4 +++- kernel/events/core.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 874b71a70058..772530501025 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -917,6 +917,7 @@ struct perf_sample_data { u64 stack_user_size; u64 phys_addr; + u64 skid_ip; } ____cacheline_aligned; /* default value for data source */ @@ -937,6 +938,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data, data->weight = 0; data->data_src.val = PERF_MEM_NA; data->txn = 0; + data->skid_ip = 0; /* mark as uinitialized */ } extern void perf_output_sample(struct perf_output_handle *handle, diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 362493a2f950..48a65a90fcab 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -141,8 +141,9 @@ enum perf_event_sample_format { PERF_SAMPLE_TRANSACTION = 1U << 17, PERF_SAMPLE_REGS_INTR = 1U << 18, PERF_SAMPLE_PHYS_ADDR = 1U << 19, + PERF_SAMPLE_SKID_IP = 1U << 20, - PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */ + PERF_SAMPLE_MAX = 1U << 21, /* non-ABI */ }; /* @@ -817,6 +818,7 @@ enum perf_event_type { * { u64 abi; # enum perf_sample_regs_abi * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR * { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR + * { u64 skid_ip; } && PERF_SAMPLE_SKID_IP * }; */ PERF_RECORD_SAMPLE = 9, diff --git a/kernel/events/core.c b/kernel/events/core.c index 0649a84204e6..40f2839c8b94 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1565,6 +1565,9 @@ static void __perf_event_header_size(struct perf_event *event, u64 sample_type) if (sample_type & PERF_SAMPLE_PHYS_ADDR) size += sizeof(data->phys_addr); + if (sample_type & PERF_SAMPLE_SKID_IP) + size += sizeof(data->skid_ip); + event->header_size = size; } @@ -5934,6 +5937,9 @@ void perf_output_sample(struct perf_output_handle *handle, if (sample_type & PERF_SAMPLE_PHYS_ADDR) perf_output_put(handle, data->phys_addr); + if (sample_type & PERF_SAMPLE_SKID_IP) + perf_output_put(handle, data->skid_ip); + if (!event->attr.watermark) { int wakeup_events = event->attr.wakeup_events; @@ -5999,6 +6005,14 @@ void perf_prepare_sample(struct perf_event_header *header, if (sample_type & PERF_SAMPLE_IP) data->ip = perf_instruction_pointer(regs); + /* + * if skid_ip has not been set by arch specific code, then + * we initialize it to IP as interrupt-based sampling has + * skid + */ + if (!data->skid_ip && sample_type & PERF_SAMPLE_SKID_IP) + data->skid_ip = perf_instruction_pointer(regs); + if (sample_type & PERF_SAMPLE_CALLCHAIN) { int size = 1; -- 2.7.4 From 1583607739823458299@xxx Thu Nov 09 16:47:08 +0000 2017 X-GM-THRID: 1583459881696647787 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread