Received: by 10.223.164.202 with SMTP id h10csp1200305wrb; Wed, 8 Nov 2017 00:00:24 -0800 (PST) X-Google-Smtp-Source: ABhQp+Tl1AtYUSDkuUzlMrYUfI0K3l9rWseH0BjkfWaky89NLQPlHJiKwXs2X2BqkGpYdOtNgiWB X-Received: by 10.99.9.130 with SMTP id 124mr1521983pgj.324.1510128024622; Wed, 08 Nov 2017 00:00:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510128024; cv=none; d=google.com; s=arc-20160816; b=EdVwMFtSWdPC1O4BpVY41Fiap5HhbjA1YpE6UiH3wKjdSD/eAMjk+uwdvgWGk/gcSt 7wKfG4TiL9SeWh6JyyAlco9QgCsbyY+5B9LOPnViHOVoEzskCO2RAb/na+faQpyc9tuF TK25JIdYSeRFjZbl7V9rz+pQUr3388p6/5DIDzgSX8Rf6oOQ03HPQCW4EYu51SVt0IU3 5/QU1Ivu4z69UPJGXJSwc9m44ocSiHNp1Em6aXce7kESi/JJNg60bCnnVXZ3yV0ksrqr 9uvR+s4SjH0kpofKWO1wH/0r7pfA/+xEK7gPAQDmtOMklvhJ1neh/4Q94B/0DYyzE4B5 jykQ== 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=Vdpgw13jA80UzLkTxn4kHdSJxEhISRogMX8n0AUwEc9EdKEJAx23heYawir6ZzUtGP gihZgqySYzsmKaejOyCReQBe2DKNGY1CnSNfY5suq/BniclubHL2soVuMWRnAGt8rfiC 9VP4ivOk9WXry6yTNn/2jITBwrVqkX4QlmFCnOFtxukUNmSJLeFnis7NxR6Zh3ws1XRq oM55DXQYOyn0APl2fL/J4aPZDnyivKaCj9cWX84g41trCkFY24GB+0VANzE3QuD33h/8 gBZlgltSFRVysTnSqNZEqfpq2/AALLEATStBIatAbbYzTEGtqCfNuN9nVG7rF2KKrASB JasQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QR929p50; 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 n13si638112pgc.825.2017.11.08.00.00.12; Wed, 08 Nov 2017 00:00:24 -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=QR929p50; 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 S1751090AbdKHH4u (ORCPT + 89 others); Wed, 8 Nov 2017 02:56:50 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:52813 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750964AbdKHH4r (ORCPT ); Wed, 8 Nov 2017 02:56:47 -0500 Received: by mail-pg0-f65.google.com with SMTP id a192so1261063pge.9 for ; Tue, 07 Nov 2017 23:56:47 -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=QR929p50SWGCRl3HoLkGKwlaFfnQorBSqtpkR0u45aczC83s4KXnyzHaLaN7qn36OE Ec94Jfy0XOoX+kgfkY5QzpbWKJt8O2H+tyz1nHRzYp/4rMSx+2xwNuZ237it1LGodjs5 FL91b2LYAfvKYmv2vYVu0LGOWbbL5JABC0JW2226utiFwjaseWvEhI/f/frpDjrvpGem R+pjWBoW+LNJkLaSMwSl9KDeU1L/jRn3/xJ6bPDXNORxfoKGnM/O4g0Nhh/WouoI7nqF TpHUG5vpiI2bbVxaEX1GC6XuZ65bF9nUgoi7sn0Z/bxQD05PV85GBW7xK15iVKBkL4x0 lEWQ== 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=RQXIloGwg90zokR6OAVq8ohZ9tikNOeA4lN1+PCQfjDTot+DWvt1SkDw0eG9pVlBE3 T2rO4gWRs4K3lsKrMtbRGg0Er0CUZZog6L1SRdaRNWOSTE5V8dJxspfPracMmcy7t2lc 66aouiZaKeuOXbgwNoBR/AZOweGppNOHWbHciKKEdRCEPmX5/TqqoOYFlNz4+IR3QM+T mzKBCLBT3qMmXu/ybUNIpGs+FvfB01L5Zl6LpJpvfIJlwtEM8Hlg/1R4nxPM30MUCBFX MG0HOUXb4TJkMOpmwSkcbynwJ4qn7Jw9YARTm1Ak6lTnlyr/6Rc7plF4OY0a4f9YywsE G+fg== X-Gm-Message-State: AJaThX5Vhl8pAr0ZGlkDEo6/Cia5O6KVKymVUbXM8rg4cDBDrZQEcew5 qiZpmUwkJXUJir4Ns3LajEd2/Bb0src= X-Received: by 10.98.73.134 with SMTP id r6mr1620003pfi.145.1510127806739; Tue, 07 Nov 2017 23:56:46 -0800 (PST) Received: from localhost (c-67-169-55-77.hsd1.ca.comcast.net. [67.169.55.77]) by smtp.gmail.com with ESMTPSA id u8sm5450310pgp.17.2017.11.07.23.56.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 23:56:46 -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 v3 1/5] perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type Date: Tue, 7 Nov 2017 23:56:33 -0800 Message-Id: <1510127797-22483-2-git-send-email-eranian@google.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510127797-22483-1-git-send-email-eranian@google.com> References: <1510127797-22483-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 1583578242513651290@xxx Thu Nov 09 08:58:17 +0000 2017 X-GM-THRID: 1583578242513651290 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread