Received: by 10.223.164.221 with SMTP id h29csp2462303wrb; Thu, 2 Nov 2017 11:17:59 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RMiQz0Vi9VQbFb+l+vw4csznE8SyRzoBmp6qOQ3DYNzQxt7LDfI1Glw6UeMW8o8Wu2JAdG X-Received: by 10.98.34.131 with SMTP id p3mr4811842pfj.1.1509646679540; Thu, 02 Nov 2017 11:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509646679; cv=none; d=google.com; s=arc-20160816; b=09qaGvHBuzDh9XZtMNCJnmnIODqq1BDuC/9zdaTkIFF2smss0mStEXysIz+IqmM+RS F29WUKhnZcjQWQ5MPJ2J8Rh6v+ofkg8zj/+f4ARyy+qB/DFGa6rrL0nCbgjLN8k+XqrT EUZhWVMITEFpWCLHs29vzIsNBzdNC5/tIyNgFNgW0cssTPKs1hozMGIzfSGrMlmcEi/+ gYQ+MA9VhSNbWAstCSGRLd9uz+Rexd3tB+MgLxgzNrExCyI/1FwXUpQTNq4nBfecauPz OQokqF2ZPux8sNUaQA7IDiwrjmtA9QU6XrLoOJ3fE7ViPs6pnuWiyUBv2+dKxKsrdQcQ /Ddg== 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=Nq2MbL33eMbXMwryNCvzwJFYK/pqFZVtDjy/NYEIIV8=; b=e+KVT0Zjl/WQWO3EEPTxlzz59424VTuJeK3Y7GNylKzViUSCaBTHyZ8wSQ0Q6l1VpU dLpWreovamtoPzhomkel94XgfynMDb3E7ER1D49akuWfBZtFPdxiUdw6JT2y6h/HujUn 9ZWC9HsAmwIlqjvEzN696fUu2wor1G4Ym2Jofort9T/XCDeqAFblZeC/qrB+Xe5Zq+QZ Zwd+Kda2yGvlxVetwDjqa3ACQvyltwkDdYyo2Y93aVRr7409vzPbR7gqJPKBGaCl5P6W srfe4Zf13TujjAzqAR0EAi/AgbhCuuHQyRztdx+kAgBCW7+xUqPO00qc0KbK8YYBiBm+ VB2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WrXGShGB; 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 d63si2927978pld.450.2017.11.02.11.17.46; Thu, 02 Nov 2017 11:17:59 -0700 (PDT) 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=WrXGShGB; 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 S933748AbdKBSQH (ORCPT + 97 others); Thu, 2 Nov 2017 14:16:07 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:50279 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932438AbdKBSQE (ORCPT ); Thu, 2 Nov 2017 14:16:04 -0400 Received: by mail-pf0-f195.google.com with SMTP id b6so275287pfh.7 for ; Thu, 02 Nov 2017 11:16:04 -0700 (PDT) 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=Nq2MbL33eMbXMwryNCvzwJFYK/pqFZVtDjy/NYEIIV8=; b=WrXGShGBf9l9S14ryUdre4sDT/1UyzfN5wUa/3lTLc27tn48a+y+R8fRPTjssph0YN 7TGuGc5+7BmErBfu8zmxDAK+VoHZpGtn2MPHMrkNl0BH/TvtGLtAoaZInHH0K5pX2b7g 2cDx0CCgxZeECU7T/jtcu2/QKQ6yDOgMJC22rDwYHGBnE2eAIdXwkKl5Qzug+25T5bmL fJzKweZ/MgVn6U7KdbB32WdntXWVJzqncVditAPOsyEm0rnhW4ZPfw7hPBsueaagre7Z svlDBek5pNqXg87oRi1FL6DSrOnMniIfWZ7zO+falf0J09TmXr7b0WAR5BU+mq5HSG23 yBFg== 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=Nq2MbL33eMbXMwryNCvzwJFYK/pqFZVtDjy/NYEIIV8=; b=WmBittGgUs5TX8m+07PllZCn0vRzTuK2IQbgwTh+Jkv1OBDdm0jjirOZMjexFxp8uQ uISfracf4Brseg0IyaiEWzkEpCMKDcshJs2AKvxEFb5/x6pfN8hxo1VWqciajD5eHR+D 93pTg0NNOyTi3NxqY4zZaYRtsaJWRSxnrfEJwBdGu4lVnrbQlyG36QwovZgexJEeCIe1 lgo7AIRiVAy4OHpTYnvFY59gfa1twvXSKaebw3a8Xv6K7KQLNFkHZK6cGGF+GVkQ23g9 2Ehd1MOfdRYDdGvqVdTWEkT0R1J/zYTA5cGybZVKwTqAIqFtPApHsBLNFoyD2clXZzRj hbfw== X-Gm-Message-State: AMCzsaVoACeeOtaIp9RoTzKiX2bc8SAZ1+YKBwObHXe4b82/HGBt5wTu lWBT7Vu0yGhFO0ZEiTNTait9WYjrHIw= X-Received: by 10.159.218.73 with SMTP id x9mr4125163plv.259.1509646563010; Thu, 02 Nov 2017 11:16:03 -0700 (PDT) Received: from localhost (c-67-169-55-77.hsd1.ca.comcast.net. [67.169.55.77]) by smtp.gmail.com with ESMTPSA id g24sm8242167pfk.0.2017.11.02.11.16.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 11:16:02 -0700 (PDT) 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, Stephane Eranian Subject: [PATCH v2 1/5] perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type Date: Thu, 2 Nov 2017 11:15:55 -0700 Message-Id: <1509646559-919-2-git-send-email-eranian@google.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509646559-919-1-git-send-email-eranian@google.com> References: <1509646559-919-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 From: Stephane Eranian 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 140ae638cfd6..93e1970e9421 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -140,8 +140,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 */ }; /* @@ -816,6 +817,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 1582934082623750952@xxx Thu Nov 02 06:19:39 +0000 2017 X-GM-THRID: 1581147142217357430 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread