Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1721136pxb; Sun, 17 Jan 2021 20:23:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+1aaWblR+E8mRe3eSClnanEEKCw8xmS7CkcRB+gX2RZ8gxs2nGDY7bnmi6E72dUBerXII X-Received: by 2002:a17:907:961c:: with SMTP id gb28mr15511452ejc.393.1610943811746; Sun, 17 Jan 2021 20:23:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610943811; cv=none; d=google.com; s=arc-20160816; b=fXUALIaO4zlzxVfqowbExp7XC3UlaOmUlJd6jcsDg3NDtvHGtqFsG7yY28gjV4EH5m GkJN9D5PTLMWVvSOBelz6U+tGuubT4Wv+854Lu6McFS79Q71Y/u+9CXeOnOUXKp2APbx 8jak1Nc6F6RB1T414DWFjLFghPZGyepmx9f98Irqd0w0xfEmAqnu+r7LETTj2OlVEzww mWgEyydzHlxzoc8Cm5bpdTj2XsDShal54wV5lpjc3XM2me3nxtAQxyyiJzSvFAbgqpkY l+w0SjUpvrfdTG5HAr7DKwSzOfg5QUX8fuOvg5I37uZKHtBwQnuGlp1GFQMmmPSPjvqj QbLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=QLcD1KsLMyFBd6UHMlBHWAx5VWQMXZTljJhkoezxzl8=; b=qQL75qw5120TCLsMxHiGnlRsmruszSOuq1LMsT/KbHjEX1yQip8nBP1AvLX5TQbE16 bPtc+DsltxqhXkzqoM4SF//0qJwr9mXv7L0uqMArzzKAwvicveGnWYsnE7/TDdMhV0PA KjFum3QeAarTz5pOnuD/s+STmR7dJl6Cbxz/hhb3RRuto3fpdBG0nyUAwnlVXtFgnECn pllnclL7Gy5qXFVdJ03XyZSJ/P3bNSiOghkE5OpTh7SFiArK0sLTVR+YNjXQCQS1uUys xuKqu9Ya6SlmNO0s3I1p74wxesFVb8OUSjaRLm0VDojf+1e7p8+AnvL6pZHboGIALoIh 4iWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q5WaNaCq; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si7188639edv.418.2021.01.17.20.23.09; Sun, 17 Jan 2021 20:23:31 -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=@gmail.com header.s=20161025 header.b=q5WaNaCq; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730816AbhARDoL (ORCPT + 99 others); Sun, 17 Jan 2021 22:44:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729588AbhARDoK (ORCPT ); Sun, 17 Jan 2021 22:44:10 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3844C061573 for ; Sun, 17 Jan 2021 19:43:29 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id v1so8600874pjr.2 for ; Sun, 17 Jan 2021 19:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QLcD1KsLMyFBd6UHMlBHWAx5VWQMXZTljJhkoezxzl8=; b=q5WaNaCqvCm4ogcoKOyiIAjCjA9JwOvrGrtehIVqzJRrLngSXhKrB/RdwXjOaHaQRw QbLIkOyl+IZbFEYDJ+Rf+yu5lUVKJxSg76AmI63C73ArO4Egf4IClxCSzDd6yODmm4Dr 5jbOBEkyRWiak3M9i5Gj/Hm52sGrdzHoGZ2FhxVbYUnkNV9tYsh2gMt8DEQ4djse+p4N gOqAj4UfZMggsXlkrOd/QgoOfoj9uv+vaLo0IvQ9EE6YtmZylrA7laAqcMvIuALb8ndg /yYEL/v/O92EYB+Vc2O6QriwUEeq95nzCOdQfYoabUGr19PXnwiwwmc2G8TDUVxXJimA yY8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=QLcD1KsLMyFBd6UHMlBHWAx5VWQMXZTljJhkoezxzl8=; b=jRBiz2c7YuGmXF3SpQW2PtvlH9Ty+4feJ6J5I8ddbb09xU+cIhIY0qAOi8+FtHTAg0 0oIaSoa4zuIcO3woWwrQMydh2M79vycyq3qC/6j6/h0REKajtcfRg/2Butj1MTt/wlcN KyX5QzaVvYuvG/WOZqh4uVG5aP+uyMiPKR/ojap6wBvXRNSNP5VFqtaOrDRJq2Wq0yS3 nEUlWUFhWoeTm5llGWzGuD6ny13oKYfpRFyiBmxVGohmRmj8WxBPm8mRubgGGcco1PG3 n4JdXdSx+vqhEyxf8oiWz29H+QYsXPHgJq16tZUALplu9NzvtUq7ZqDPadP0Quv07Qwq iNdw== X-Gm-Message-State: AOAM532zZTH0cF6VWY7RC2RNbOV2A38gW06tXiOiABrkEfb9d/hZNQnE ZfDERwyG0nhlwbBSTL6CkmU= X-Received: by 2002:a17:90a:708b:: with SMTP id g11mr23498675pjk.23.1610941409458; Sun, 17 Jan 2021 19:43:29 -0800 (PST) Received: from balhae.roam.corp.google.com ([114.129.115.223]) by smtp.gmail.com with ESMTPSA id i62sm7979978pfc.150.2021.01.17.19.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 19:43:28 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra Cc: Ingo Molnar , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Andi Kleen , Ian Rogers , Alexey Alexandrov Subject: [PATCH] perf/core: Emit PERF_RECORD_LOST for pinned events Date: Mon, 18 Jan 2021 12:43:23 +0900 Message-Id: <20210118034323.427029-1-namhyung@kernel.org> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As of now we silently ignore pinned events when it's failed to be scheduled and make it error state not try to schedule it again. That means we won't get any samples for the event. But there's no way for users to notice and respond to it. Let's emit a lost event with a new misc bit to indicate this situation. Signed-off-by: Namhyung Kim --- include/uapi/linux/perf_event.h | 2 ++ kernel/events/core.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index b15e3447cd9f..3c0e115dd8b7 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -679,11 +679,13 @@ struct perf_event_mmap_page { * PERF_RECORD_MISC_COMM_EXEC - PERF_RECORD_COMM event * PERF_RECORD_MISC_FORK_EXEC - PERF_RECORD_FORK event (perf internal) * PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events + * PERF_RECORD_MISC_LOST_PINNED- PERF_RECORD_LOST event */ #define PERF_RECORD_MISC_MMAP_DATA (1 << 13) #define PERF_RECORD_MISC_COMM_EXEC (1 << 13) #define PERF_RECORD_MISC_FORK_EXEC (1 << 13) #define PERF_RECORD_MISC_SWITCH_OUT (1 << 13) +#define PERF_RECORD_MISC_LOST_PINNED (1 << 13) /* * These PERF_RECORD_MISC_* flags below are safely reused * for the following events: diff --git a/kernel/events/core.c b/kernel/events/core.c index 55d18791a72d..523927575434 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3654,6 +3654,8 @@ static noinline int visit_groups_merge(struct perf_cpu_context *cpuctx, return 0; } +static void perf_log_lost_event(struct perf_event *event); + static int merge_sched_in(struct perf_event *event, void *data) { struct perf_event_context *ctx = event->ctx; @@ -3675,6 +3677,7 @@ static int merge_sched_in(struct perf_event *event, void *data) if (event->attr.pinned) { perf_cgroup_event_disable(event, ctx); perf_event_set_state(event, PERF_EVENT_STATE_ERROR); + perf_log_lost_event(event); } *can_add_hw = 0; @@ -8414,6 +8417,39 @@ void perf_event_aux_event(struct perf_event *event, unsigned long head, perf_output_end(&handle); } +/* + * failed/errored events logging + */ +static void perf_log_lost_event(struct perf_event *event) +{ + struct perf_output_handle handle; + struct perf_sample_data sample; + int ret; + struct { + struct perf_event_header header; + u64 id; + u64 lost; + } lost_event = { + .header = { + .type = PERF_RECORD_LOST, + .misc = PERF_RECORD_MISC_LOST_PINNED, + .size = sizeof(lost_event), + }, + .id = event->id, + }; + + perf_event_header__init_id(&lost_event.header, &sample, event); + + ret = perf_output_begin(&handle, &sample, event, + lost_event.header.size); + if (ret) + return; + + perf_output_put(&handle, lost_event); + perf_event__output_id_sample(event, &handle, &sample); + perf_output_end(&handle); +} + /* * Lost/dropped samples logging */ -- 2.30.0.284.gd98b1dd5eaa7-goog