From nobody Sat Apr 11 02:17:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2DB9C32792 for ; Tue, 16 Aug 2022 22:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237911AbiHPWSD (ORCPT ); Tue, 16 Aug 2022 18:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237999AbiHPWRx (ORCPT ); Tue, 16 Aug 2022 18:17:53 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7296A901B7; Tue, 16 Aug 2022 15:17:51 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id l64so10482704pge.0; Tue, 16 Aug 2022 15:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc; bh=84gL6qYXoIL91eAhUH7dgvAezoFgyrY4+iuV6650YZc=; b=cYK3wI6YLLfLwF08C0BXRx0SjLpb5jVdFgPwFiFNGD7iqYTo8GOVDvWG7Jmb/7WXKj LZqDhlcFpn1xH3Rt+OkY8yAesdoU+LiRMTqkoFuxLQ3RqgA/b9Yk/uzjHTId2jQ9OOWR 0CAzm282cGgT6on95ZFkONfXjLnxT2yWLDFx+0JrPUQjyFIE9wrMllZel1FMDJVV+yVF NmDUSrT/6W04x3S5qm5drBTu/mXHtmn65n5P1J4kKVufEF2Xrvgr4rH1DZ04QUdkZi/n EkiovqyPY+bDGmO41dlaUlvTJreyii310HhegiZDWOUHyZnWSVM8qyCr0/lS8GQyXald Smew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc; bh=84gL6qYXoIL91eAhUH7dgvAezoFgyrY4+iuV6650YZc=; b=vBVjC4V9sEmJ/RMcSvNbv7dil+988uamzcKJFJKpkktrXqDlSyNN6ltIvGjwsye05A yhM5usYh964xje0vMAN/S2NCtGgckanrOYQzNdCsLdh3bimvdszO1Ub3tksor88F/Qmz ivW61qmtHCyGTDymdjA39BdsPE3OIlGGjn3G3MKRifNh97TVknW3ewiX4iOvffIaoeOY 2TXW48mb1Or/6N79DD7yozA+tF+JJHLVRxjWnzoPrnw1xPSs55o7H6akwB+BudNH8ZpV 57cSTekNegynBwFoCggng825sO93pU+aO0JI/qNTpfa2IQQfkSpQawhyVKTHMM2tXwP4 9AKg== X-Gm-Message-State: ACgBeo2CIO9xXShY/vQaIzX5RHj1IAaikFCdPTK3QxxuxT3Jnv/Aw9Ca BZ5Ia+jMUdz9AR1EGtZzc/U= X-Google-Smtp-Source: AA6agR65u1hPTOpZiganCVlM6hJi4TdQ8cu//l+GzkFJSC517cP01lba9WOpusrLCNOakdJIhLZdHQ== X-Received: by 2002:a05:6a00:1a4f:b0:52e:33bf:f3d with SMTP id h15-20020a056a001a4f00b0052e33bf0f3dmr22914951pfv.61.1660688270902; Tue, 16 Aug 2022 15:17:50 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:d539:e967:9fd8:5c81]) by smtp.gmail.com with ESMTPSA id 3-20020a620603000000b0052b7f0ff197sm8965943pfg.49.2022.08.16.15.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 15:17:50 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org Subject: [PATCH 1/4] tools headers UAPI: Sync linux/perf_event.h with the kernel sources Date: Tue, 16 Aug 2022 15:17:44 -0700 Message-Id: <20220816221747.275828-2-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220816221747.275828-1-namhyung@kernel.org> References: <20220816221747.275828-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To pick the trivial change in: 119a784c8127 ("perf/core: Add a new read format to get a number of lost s= amples") Signed-off-by: Namhyung Kim --- tools/include/uapi/linux/perf_event.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/lin= ux/perf_event.h index e2b77fbca91e..581ed4bdc062 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -301,6 +301,7 @@ enum { * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING * { u64 id; } && PERF_FORMAT_ID + * { u64 lost; } && PERF_FORMAT_LOST * } && !PERF_FORMAT_GROUP * * { u64 nr; @@ -308,6 +309,7 @@ enum { * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING * { u64 value; * { u64 id; } && PERF_FORMAT_ID + * { u64 lost; } && PERF_FORMAT_LOST * } cntr[nr]; * } && PERF_FORMAT_GROUP * }; @@ -317,8 +319,9 @@ enum perf_event_read_format { PERF_FORMAT_TOTAL_TIME_RUNNING =3D 1U << 1, PERF_FORMAT_ID =3D 1U << 2, PERF_FORMAT_GROUP =3D 1U << 3, + PERF_FORMAT_LOST =3D 1U << 4, =20 - PERF_FORMAT_MAX =3D 1U << 4, /* non-ABI */ + PERF_FORMAT_MAX =3D 1U << 5, /* non-ABI */ }; =20 #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */ --=20 2.37.1.595.g718a3a8f04-goog From nobody Sat Apr 11 02:17:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1155FC32789 for ; Tue, 16 Aug 2022 22:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237944AbiHPWSH (ORCPT ); Tue, 16 Aug 2022 18:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238000AbiHPWRx (ORCPT ); Tue, 16 Aug 2022 18:17:53 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA838901AD; Tue, 16 Aug 2022 15:17:52 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id 17so10473340pli.0; Tue, 16 Aug 2022 15:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc; bh=JozqI5HGaTqIqUqt2jBuKrvzFFJykmSG4D6AZASqs+k=; b=VtebnvoeSwqIJoYSMWLDIqk72k0WBw9KRGwVuMkxBTV+kVJbz382YZcC1Bh4PeJKDi jVGpjeDqA+UN/hY57cSxT9cV94aByX0LSqfjKGkRG0D+E+RaC2eXi89mO6wzmkBLXlCp b+/4p7ixrkyj9alGoPisGY3uDxAUC7MMy5ZDrbXZtMM9Zqd3Fh+ymQjX/aZzywr2EmrC n78P/0Eo/xnGZubCBZ2k5KxoQgrh5kNPZm/fBd+pABXr721HKEPYfPRk1kmH7VjiP02V JhBrNxF1I7RKLY26Q6M5tjtBCW6eU5IY4k3ZmQiydKqQ7JA92nSxMt57cALmYDB1pq0/ dLEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc; bh=JozqI5HGaTqIqUqt2jBuKrvzFFJykmSG4D6AZASqs+k=; b=X8INFlMme+ccvZIXQc/wopQRlacSL11jUY2QoRaz0P1LO4zp80te040ompZhNo5szq jXRGef0AGdEH+57MWulC3QSOBrfx1EEaPXQdEUcSd0P9frRLgWaYCsybVJxrox1gh3DN pSL9Zm2dowQSzdYXulAXvXi9oS7qXxqjuxD36ebDUvbhlntoTHSeQvXh4r8wvluxXi8+ +5voS+noj6smcs0dFLTmgT7sZSElA06sVyhSYicNDcNgbM+JXGGbp1eBLXlgTT4q64cZ URQ6PHRMuNMWn64Hvgo6mkkfoLqP9XqTydW0EjwOJwIpR6MpY8bFF3M0EMqFJrYZyqu8 89hQ== X-Gm-Message-State: ACgBeo1UlzAMuS5iuWZS64+8dgzk6J3gUBw9927UVhQrE4VWBKW+Z3X9 dqzGDlIGrLwaidlPhirGNc8= X-Google-Smtp-Source: AA6agR4+XvQZ7aOAhSU041b+KS5YR/g0e4WbsOo9eIXerUgE/wmCqsWxyvnBw57wAivJWNsE+n2YoA== X-Received: by 2002:a17:90b:4a06:b0:1f4:e4fc:91ed with SMTP id kk6-20020a17090b4a0600b001f4e4fc91edmr720840pjb.152.1660688272055; Tue, 16 Aug 2022 15:17:52 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:d539:e967:9fd8:5c81]) by smtp.gmail.com with ESMTPSA id 3-20020a620603000000b0052b7f0ff197sm8965943pfg.49.2022.08.16.15.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 15:17:51 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org Subject: [PATCH 2/4] tools lib perf: Handle read format in perf_evsel__read() Date: Tue, 16 Aug 2022 15:17:45 -0700 Message-Id: <20220816221747.275828-3-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220816221747.275828-1-namhyung@kernel.org> References: <20220816221747.275828-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The perf_counts_values should be increased to read the new lost data. Also adjust values after read according the read format. This supports PERF_FORMAT_GROUP which has a different data format but it's only available for leader events. Currently it doesn't have an API to read sibling (member) events in the group. But users may read the sibling event directly. Also reading from mmap would be disabled when the read format has ID or LOST bit as it's not exposed via mmap. Signed-off-by: Namhyung Kim --- tools/lib/perf/evsel.c | 79 ++++++++++++++++++++++++++++- tools/lib/perf/include/perf/event.h | 3 +- tools/lib/perf/include/perf/evsel.h | 4 +- 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 952f3520d5c2..8ce5bbd09666 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -305,6 +305,9 @@ int perf_evsel__read_size(struct perf_evsel *evsel) if (read_format & PERF_FORMAT_ID) entry +=3D sizeof(u64); =20 + if (read_format & PERF_FORMAT_LOST) + entry +=3D sizeof(u64); + if (read_format & PERF_FORMAT_GROUP) { nr =3D evsel->nr_members; size +=3D sizeof(u64); @@ -314,24 +317,98 @@ int perf_evsel__read_size(struct perf_evsel *evsel) return size; } =20 +/* This only reads values for the leader */ +static int perf_evsel__read_group(struct perf_evsel *evsel, int cpu_map_id= x, + int thread, struct perf_counts_values *count) +{ + size_t size =3D perf_evsel__read_size(evsel); + int *fd =3D FD(evsel, cpu_map_idx, thread); + u64 read_format =3D evsel->attr.read_format; + u64 *data; + int idx =3D 1; + + if (fd =3D=3D NULL || *fd < 0) + return -EINVAL; + + data =3D calloc(1, size); + if (data =3D=3D NULL) + return -ENOMEM; + + if (readn(*fd, data, size) <=3D 0) { + free(data); + return -errno; + } + + /* + * This reads only the leader event intentionally since we don't have + * perf counts values for sibling events. + */ + if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) + count->ena =3D data[idx++]; + if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) + count->run =3D data[idx++]; + + /* value is always available */ + count->val =3D data[idx++]; + if (read_format & PERF_FORMAT_ID) + count->id =3D data[idx++]; + if (read_format & PERF_FORMAT_LOST) + count->lost =3D data[idx++]; + + free(data); + return 0; +} + +/* + * The perf read format is very flexible. It needs to set the proper + * values according to the read format. + */ +static void perf_evsel__adjust_values(struct perf_evsel *evsel, u64 *buf, + struct perf_counts_values *count) +{ + u64 read_format =3D evsel->attr.read_format; + int n =3D 0; + + count->val =3D buf[n++]; + + if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) + count->ena =3D buf[n++]; + + if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) + count->run =3D buf[n++]; + + if (read_format & PERF_FORMAT_ID) + count->id =3D buf[n++]; + + if (read_format & PERF_FORMAT_LOST) + count->lost =3D buf[n++]; +} + int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread, struct perf_counts_values *count) { size_t size =3D perf_evsel__read_size(evsel); int *fd =3D FD(evsel, cpu_map_idx, thread); + u64 read_format =3D evsel->attr.read_format; + struct perf_counts_values buf; =20 memset(count, 0, sizeof(*count)); =20 if (fd =3D=3D NULL || *fd < 0) return -EINVAL; =20 + if (read_format & PERF_FORMAT_GROUP) + return perf_evsel__read_group(evsel, cpu_map_idx, thread, count); + if (MMAP(evsel, cpu_map_idx, thread) && + !(read_format & (PERF_FORMAT_ID | PERF_FORMAT_LOST)) && !perf_mmap__read_self(MMAP(evsel, cpu_map_idx, thread), count)) return 0; =20 - if (readn(*fd, count->values, size) <=3D 0) + if (readn(*fd, buf.values, size) <=3D 0) return -errno; =20 + perf_evsel__adjust_values(evsel, buf.values, count); return 0; } =20 diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/p= erf/event.h index 556bb06798f2..38dd35cbca71 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -76,7 +76,7 @@ struct perf_record_lost_samples { }; =20 /* - * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID + * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMA= T_LOST */ struct perf_record_read { struct perf_event_header header; @@ -85,6 +85,7 @@ struct perf_record_read { __u64 time_enabled; __u64 time_running; __u64 id; + __u64 lost; }; =20 struct perf_record_throttle { diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index 699c0ed97d34..6f92204075c2 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -18,8 +18,10 @@ struct perf_counts_values { uint64_t val; uint64_t ena; uint64_t run; + uint64_t id; + uint64_t lost; }; - uint64_t values[3]; + uint64_t values[5]; }; }; =20 --=20 2.37.1.595.g718a3a8f04-goog From nobody Sat Apr 11 02:17:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0EF2C32774 for ; Tue, 16 Aug 2022 22:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237890AbiHPWSB (ORCPT ); Tue, 16 Aug 2022 18:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238003AbiHPWRy (ORCPT ); Tue, 16 Aug 2022 18:17:54 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5310901B9; Tue, 16 Aug 2022 15:17:53 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id g18so1947298pju.0; Tue, 16 Aug 2022 15:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc; bh=aFH5O6viJ6NTA25wi2Aiw0FQRIeUfCBP+ZrmMXU/R8U=; b=IZh+6RGZ+6/V/QYTPdN/5U4FDgEYkPcMJDOUV2EmmEXgKPXLlVK2/5ujAB0BprUSAh kS3hmzJBEDhqPF1pDHPOROXRnWzB1etxHmCR0BX59Ams/S0reNxuw0s6gsRhYfwcoOEO Kvl+5oFOwSqtuzbd0vHKvJOYnd42utdtqiXarnNmh2Pyr6/Ka9aB0oNVlLn3mIf6L7L1 UrMPxzrNb9ctol1tllzwNJBWyPPZIv545b/u95j0Mn11MZXj8iyScaQgAwyisSAbuNRu UoOzpmyQGT/Dga7jdhs+0kIlUpLwXHM4ixsFZQ7IK75E3crIq+EXdNfsK5lw930/pZ6P kwgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc; bh=aFH5O6viJ6NTA25wi2Aiw0FQRIeUfCBP+ZrmMXU/R8U=; b=IGXy5owsAqtOrPBrZVS+uRkJ3gsD2z8D29kbpfwN1RfK/w5Q3dtzl+vssDAg3JNDXe UhcM6VRZ161myKFcGjdaHsu1S5PolQGTLNjRYOI6IChlzcWd+TbgMG4OBaGSG1NnR38L l7sa7ehYHMPYEOP3kPC1e8GbuYoDvLtKQ7pMWbqcI/h1Th3ThT0Sj1wRy0mHALl+Eomd DwVPF0U1/qtWhDlqBCd5KdH+eE7B7n6Dn4AFrXieKCl6lL73ZCiRjbTAW2BdfuIC9uiq R7SKFaCAZCIDGrq2q3MPpTGd0BfRyCfcHjaU8PfJNbL4/9hp3BapXXPpMk4q/FUKr4kY 1pJA== X-Gm-Message-State: ACgBeo2DGVTRNKZkYNzUFqqUq/0cLqkKPvuP4wXS4Cifvt1QVq5Ft616 jO900FyvIoKnr+OT/diTEyw= X-Google-Smtp-Source: AA6agR6xS9AmAxMz40IF10AMCHPiCXnkDEH1nJq+aTMlKqYSNTEjnotjcqx2/4z0zTC+1K/QwdMyMA== X-Received: by 2002:a17:902:d48d:b0:16f:5ce:1d08 with SMTP id c13-20020a170902d48d00b0016f05ce1d08mr23525965plg.49.1660688273183; Tue, 16 Aug 2022 15:17:53 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:d539:e967:9fd8:5c81]) by smtp.gmail.com with ESMTPSA id 3-20020a620603000000b0052b7f0ff197sm8965943pfg.49.2022.08.16.15.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 15:17:52 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org Subject: [PATCH 3/4] tools lib perf: Add a test case for read formats Date: Tue, 16 Aug 2022 15:17:46 -0700 Message-Id: <20220816221747.275828-4-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220816221747.275828-1-namhyung@kernel.org> References: <20220816221747.275828-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It checks a various combination of the read format settings and verify it return the value in a proper position. The test uses task-clock software events to guarantee it's always active and sets enabled/running time. Signed-off-by: Namhyung Kim --- tools/lib/perf/tests/test-evsel.c | 161 ++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/tools/lib/perf/tests/test-evsel.c b/tools/lib/perf/tests/test-= evsel.c index 89be89afb24d..a11fc51bfb68 100644 --- a/tools/lib/perf/tests/test-evsel.c +++ b/tools/lib/perf/tests/test-evsel.c @@ -1,10 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include +#include #include #include #include +#include #include #include "tests.h" =20 @@ -189,6 +192,163 @@ static int test_stat_user_read(int event) return 0; } =20 +static int test_stat_read_format_single(struct perf_event_attr *attr, stru= ct perf_thread_map *threads) +{ + struct perf_evsel *evsel; + struct perf_counts_values counts; + volatile int count =3D 0x100000; + int err; + + evsel =3D perf_evsel__new(attr); + __T("failed to create evsel", evsel); + + /* skip old kernels that don't support the format */ + err =3D perf_evsel__open(evsel, NULL, threads); + if (err < 0) + return 0; + + while (count--) ; + + memset(&counts, -1, sizeof(counts)); + perf_evsel__read(evsel, 0, 0, &counts); + + __T("failed to read value", counts.val); + if (attr->read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) + __T("failed to read TOTAL_TIME_ENABLED", counts.ena); + if (attr->read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) + __T("failed to read TOTAL_TIME_RUNNING", counts.run); + if (attr->read_format & PERF_FORMAT_ID) + __T("failed to read ID", counts.id); + if (attr->read_format & PERF_FORMAT_LOST) + __T("failed to read LOST", counts.lost =3D=3D 0); + + perf_evsel__close(evsel); + perf_evsel__delete(evsel); + return 0; +} + +static int test_stat_read_format_group(struct perf_event_attr *attr, struc= t perf_thread_map *threads) +{ + struct perf_evsel *leader, *member; + struct perf_counts_values counts; + volatile int count =3D 0x100000; + int err; + + attr->read_format |=3D PERF_FORMAT_GROUP; + leader =3D perf_evsel__new(attr); + __T("failed to create leader", leader); + + attr->read_format &=3D ~PERF_FORMAT_GROUP; + member =3D perf_evsel__new(attr); + __T("failed to create member", member); + + member->leader =3D leader; + leader->nr_members =3D 2; + + /* skip old kernels that don't support the format */ + err =3D perf_evsel__open(leader, NULL, threads); + if (err < 0) + return 0; + err =3D perf_evsel__open(member, NULL, threads); + if (err < 0) + return 0; + + while (count--) ; + + memset(&counts, -1, sizeof(counts)); + perf_evsel__read(leader, 0, 0, &counts); + + __T("failed to read leader value", counts.val); + if (attr->read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) + __T("failed to read leader TOTAL_TIME_ENABLED", counts.ena); + if (attr->read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) + __T("failed to read leader TOTAL_TIME_RUNNING", counts.run); + if (attr->read_format & PERF_FORMAT_ID) + __T("failed to read leader ID", counts.id); + if (attr->read_format & PERF_FORMAT_LOST) + __T("failed to read leader LOST", counts.lost =3D=3D 0); + + memset(&counts, -1, sizeof(counts)); + perf_evsel__read(member, 0, 0, &counts); + + __T("failed to read member value", counts.val); + if (attr->read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) + __T("failed to read member TOTAL_TIME_ENABLED", counts.ena); + if (attr->read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) + __T("failed to read member TOTAL_TIME_RUNNING", counts.run); + if (attr->read_format & PERF_FORMAT_ID) + __T("failed to read member ID", counts.id); + if (attr->read_format & PERF_FORMAT_LOST) + __T("failed to read member LOST", counts.lost =3D=3D 0); + + perf_evsel__close(member); + perf_evsel__close(leader); + perf_evsel__delete(member); + perf_evsel__delete(leader); + return 0; +} + +static int test_stat_read_format(void) +{ + struct perf_thread_map *threads; + struct perf_event_attr attr =3D { + .type =3D PERF_TYPE_SOFTWARE, + .config =3D PERF_COUNT_SW_TASK_CLOCK, + }; + int err, i; + +#define FMT(_fmt) PERF_FORMAT_ ## _fmt +#define FMT_TIME (FMT(TOTAL_TIME_ENABLED) | FMT(TOTAL_TIME_RUNNING)) + + uint64_t test_formats [] =3D { + 0, + FMT_TIME, + FMT(ID), + FMT(LOST), + FMT_TIME | FMT(ID), + FMT_TIME | FMT(LOST), + FMT_TIME | FMT(ID) | FMT(LOST), + FMT(ID) | FMT(LOST), + }; + +#undef FMT +#undef FMT_TIME + + threads =3D perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + for (i =3D 0; i < (int)ARRAY_SIZE(test_formats); i++) { + attr.read_format =3D test_formats[i]; + __T_VERBOSE("testing single read with read_format: %lx\n", + (unsigned long)test_formats[i]); + + err =3D test_stat_read_format_single(&attr, threads); + __T("failed to read single format", err =3D=3D 0); + } + + perf_thread_map__put(threads); + + threads =3D perf_thread_map__new_array(2, NULL); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + perf_thread_map__set_pid(threads, 1, 0); + + for (i =3D 0; i < (int)ARRAY_SIZE(test_formats); i++) { + attr.read_format =3D test_formats[i]; + __T_VERBOSE("testing group read with read_format: %lx\n", + (unsigned long)test_formats[i]); + + err =3D test_stat_read_format_group(&attr, threads); + __T("failed to read group format", err =3D=3D 0); + } + + perf_thread_map__put(threads); + return 0; +} + int test_evsel(int argc, char **argv) { __T_START; @@ -200,6 +360,7 @@ int test_evsel(int argc, char **argv) test_stat_thread_enable(); test_stat_user_read(PERF_COUNT_HW_INSTRUCTIONS); test_stat_user_read(PERF_COUNT_HW_CPU_CYCLES); + test_stat_read_format(); =20 __T_END; return tests_failed =3D=3D 0 ? 0 : -1; --=20 2.37.1.595.g718a3a8f04-goog From nobody Sat Apr 11 02:17:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A7F0C48BE4 for ; Tue, 16 Aug 2022 22:19:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237908AbiHPWSg (ORCPT ); Tue, 16 Aug 2022 18:18:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237893AbiHPWSC (ORCPT ); Tue, 16 Aug 2022 18:18:02 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D30A901AB; Tue, 16 Aug 2022 15:17:55 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id w11-20020a17090a380b00b001f73f75a1feso168416pjb.2; Tue, 16 Aug 2022 15:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc; bh=eGwWLAV+VmdnzL2DzlRl4cqZkvkUk0pyXNIXElL51oM=; b=e5KS+WSqyv1FUewEscpcVWTtwcL5j+IZ6oKh2O6aug8w69jX7WFp+7hSZ9qvjwV8nO AqMK0cnG6OAYc8eTG+D0CHzpWRBz5DyRInMMgK/K0BbJnCJI/57N4dGjRdsqXlRngE6B hxIG32e3L3294LfrhWqQIazAr6DuBjnqu2ocETR2EUt7der1Fhltx4e83k0qFQ/x7yUz O1qmtl+L5lJMijwp6QZkVgg5zuP3prRkDI5esWf3T4vlhf3+/7biRjPYaOk/vXt0MdiJ W1cdu8CPYW/FFaHtIwUkArjwmS2AUC830s0F5h9THwVPX6RdhR+BUpTQ8TFSD3RbcGAp knIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc; bh=eGwWLAV+VmdnzL2DzlRl4cqZkvkUk0pyXNIXElL51oM=; b=myuCsbrqDPYwgdwwlfAjgW/xyp2pzY0sLy9FHmPkRAADqui+iPlsJOtQgrBo3hB39k Rd/48cBZ3dRsos9CG2ohTexJt1DkA4nIhp+R0HjZjJNKsQvVQot7unWFKhzpSau3XjTi soalryvhZKHP/RrFwjOBTSd5GFW57zkw6n2Up6nQjVt3SWxS4tcOVzSUX9C7rsAijAv2 8Vfsiw9TRAIZD18npZPtrhQOgkfj2U6c1U4Hx69Njwvrzi/buqU5fGflKxaCZ8ch0CJN o6RD28mtbS5nvnM53kZFNhXEMtZ2tXn7gwQ8oZi05/+3jOJg/wtWi5gNuhEKggRCX81n dlfQ== X-Gm-Message-State: ACgBeo19Rvi7KVAxFqghabKE7yvnZ0WaMnKzHu6R//BS7eo9nX1pEKr2 m98qohj0DZLs/SwxrpmpgD0= X-Google-Smtp-Source: AA6agR4ZoWsg5l7OBXdSw2ObCkzYygR1O06rsL9Ov91xW5kvssXPo2iwupGrQvfKfHiwYSMbgi4ELw== X-Received: by 2002:a17:90b:4f44:b0:1f5:1310:9e7f with SMTP id pj4-20020a17090b4f4400b001f513109e7fmr656706pjb.235.1660688274472; Tue, 16 Aug 2022 15:17:54 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:d539:e967:9fd8:5c81]) by smtp.gmail.com with ESMTPSA id 3-20020a620603000000b0052b7f0ff197sm8965943pfg.49.2022.08.16.15.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 15:17:53 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org Subject: [PATCH 4/4] perf tools: Support reading PERF_FORMAT_LOST Date: Tue, 16 Aug 2022 15:17:47 -0700 Message-Id: <20220816221747.275828-5-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220816221747.275828-1-namhyung@kernel.org> References: <20220816221747.275828-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The recent kernel added lost count can be read from either read(2) or ring buffer data with PERF_SAMPLE_READ. As it's a variable length data we need to access it according to the format info. But for perf tools use cases, PERF_FORMAT_ID is always set. So we can only check PERF_FORMAT_LOST bit to determine the data format. Add sample_read_value_size() and next_sample_read_value() helpers to make it a bit easier to access. Use them in all places where it reads the struct sample_read_value. Signed-off-by: Namhyung Kim --- tools/perf/tests/sample-parsing.c | 14 +++++--- tools/perf/util/event.h | 18 +++++++++- tools/perf/util/evsel.c | 33 +++++++++++++----- .../scripting-engines/trace-event-python.c | 16 ++++++--- tools/perf/util/session.c | 32 +++++++++++------ tools/perf/util/synthetic-events.c | 34 +++++++++++++++---- 6 files changed, 112 insertions(+), 35 deletions(-) diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-pa= rsing.c index 07f2411b0ad4..20930dd48ee0 100644 --- a/tools/perf/tests/sample-parsing.c +++ b/tools/perf/tests/sample-parsing.c @@ -86,10 +86,15 @@ static bool samples_same(const struct perf_sample *s1, COMP(read.time_running); /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ if (read_format & PERF_FORMAT_GROUP) { - for (i =3D 0; i < s1->read.group.nr; i++) - MCOMP(read.group.values[i]); + for (i =3D 0; i < s1->read.group.nr; i++) { + /* FIXME: check values without LOST */ + if (read_format & PERF_FORMAT_LOST) + MCOMP(read.group.values[i]); + } } else { COMP(read.one.id); + if (read_format & PERF_FORMAT_LOST) + COMP(read.one.lost); } } =20 @@ -263,7 +268,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u6= 4 read_format) .data =3D (void *)aux_data, }, }; - struct sample_read_value values[] =3D {{1, 5}, {9, 3}, {2, 7}, {6, 4},}; + struct sample_read_value values[] =3D {{1, 5, 0}, {9, 3, 0}, {2, 7, 0}, {= 6, 4, 1},}; struct perf_sample sample_out, sample_out_endian; size_t i, sz, bufsz; int err, ret =3D -1; @@ -286,6 +291,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u6= 4 read_format) } else { sample.read.one.value =3D 0x08789faeb786aa87ULL; sample.read.one.id =3D 99; + sample.read.one.lost =3D 1; } =20 sz =3D perf_event__sample_event_size(&sample, sample_type, read_format); @@ -370,7 +376,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u6= 4 read_format) */ static int test__sample_parsing(struct test_suite *test __maybe_unused, in= t subtest __maybe_unused) { - const u64 rf[] =3D {4, 5, 6, 7, 12, 13, 14, 15}; + const u64 rf[] =3D {4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 28, 29, 30, 3= 1}; u64 sample_type; u64 sample_regs; size_t i; diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index a7b0931d5137..7753368d70d6 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -65,7 +65,8 @@ struct stack_dump { =20 struct sample_read_value { u64 value; - u64 id; + u64 id; /* only if PERF_FORMAT_ID */ + u64 lost; /* only if PERF_FORMAT_LOST */ }; =20 struct sample_read { @@ -80,6 +81,21 @@ struct sample_read { }; }; =20 +static inline size_t sample_read_value_size(u64 read_format) +{ + /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ + if (read_format & PERF_FORMAT_LOST) + return sizeof(struct sample_read_value); + else + return offsetof(struct sample_read_value, lost); +} + +static inline struct sample_read_value * +next_sample_read_value(struct sample_read_value *v, u64 read_format) +{ + return (void *)v + sample_read_value_size(read_format); +} + struct ip_callchain { u64 nr; u64 ips[]; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4852089e1d79..781367ccdb84 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1541,7 +1541,7 @@ static int evsel__read_one(struct evsel *evsel, int c= pu_map_idx, int thread) } =20 static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int t= hread, - u64 val, u64 ena, u64 run) + u64 val, u64 ena, u64 run, u64 lost) { struct perf_counts_values *count; =20 @@ -1550,6 +1550,7 @@ static void evsel__set_count(struct evsel *counter, i= nt cpu_map_idx, int thread, count->val =3D val; count->ena =3D ena; count->run =3D run; + count->lost =3D lost; =20 perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, true); } @@ -1558,7 +1559,7 @@ static int evsel__process_group_data(struct evsel *le= ader, int cpu_map_idx, int { u64 read_format =3D leader->core.attr.read_format; struct sample_read_value *v; - u64 nr, ena =3D 0, run =3D 0, i; + u64 nr, ena =3D 0, run =3D 0, lost =3D 0, i; =20 nr =3D *data++; =20 @@ -1573,16 +1574,25 @@ static int evsel__process_group_data(struct evsel *= leader, int cpu_map_idx, int =20 v =3D (struct sample_read_value *) data; =20 - evsel__set_count(leader, cpu_map_idx, thread, v[0].value, ena, run); + if (read_format & PERF_FORMAT_LOST) + lost =3D v->lost; + + evsel__set_count(leader, cpu_map_idx, thread, v[0].value, ena, run, lost); + + v =3D next_sample_read_value(v, read_format); =20 for (i =3D 1; i < nr; i++) { struct evsel *counter; =20 - counter =3D evlist__id2evsel(leader->evlist, v[i].id); + counter =3D evlist__id2evsel(leader->evlist, v->id); if (!counter) return -EINVAL; =20 - evsel__set_count(counter, cpu_map_idx, thread, v[i].value, ena, run); + if (read_format & PERF_FORMAT_LOST) + lost =3D v->lost; + + evsel__set_count(counter, cpu_map_idx, thread, v->value, ena, run, lost); + v =3D next_sample_read_value(v, read_format); } =20 return 0; @@ -2475,16 +2485,21 @@ int evsel__parse_sample(struct evsel *evsel, union = perf_event *event, =20 if (data->read.group.nr > max_group_nr) return -EFAULT; - sz =3D data->read.group.nr * - sizeof(struct sample_read_value); + + sz =3D data->read.group.nr * sample_read_value_size(read_format); OVERFLOW_CHECK(array, sz, max_size); - data->read.group.values =3D - (struct sample_read_value *)array; + data->read.group.values =3D (void *)array; array =3D (void *)array + sz; } else { OVERFLOW_CHECK_u64(array); data->read.one.id =3D *array; array++; + + if (read_format & PERF_FORMAT_LOST) { + OVERFLOW_CHECK_u64(array); + data->read.one.lost =3D *array; + array++; + } } } =20 diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 9ef2406e0ede..7e15e64f311b 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -642,15 +642,19 @@ static PyObject *python_process_brstacksym(struct per= f_sample *sample, return pylist; } =20 -static PyObject *get_sample_value_as_tuple(struct sample_read_value *value) +static PyObject *get_sample_value_as_tuple(struct sample_read_value *value, + u64 read_format) { PyObject *t; =20 - t =3D PyTuple_New(2); + t =3D PyTuple_New(3); if (!t) Py_FatalError("couldn't create Python tuple"); PyTuple_SetItem(t, 0, PyLong_FromUnsignedLongLong(value->id)); PyTuple_SetItem(t, 1, PyLong_FromUnsignedLongLong(value->value)); + if (read_format & PERF_FORMAT_LOST) + PyTuple_SetItem(t, 2, PyLong_FromUnsignedLongLong(value->lost)); + return t; } =20 @@ -681,12 +685,16 @@ static void set_sample_read_in_dict(PyObject *dict_sa= mple, Py_FatalError("couldn't create Python list"); =20 if (read_format & PERF_FORMAT_GROUP) { + struct sample_read_value *v =3D sample->read.group.values; + for (i =3D 0; i < sample->read.group.nr; i++) { - PyObject *t =3D get_sample_value_as_tuple(&sample->read.group.values[i]= ); + PyObject *t =3D get_sample_value_as_tuple(v, read_format); PyList_SET_ITEM(values, i, t); + v =3D next_sample_read_value(v, read_format); } } else { - PyObject *t =3D get_sample_value_as_tuple(&sample->read.one); + PyObject *t =3D get_sample_value_as_tuple(&sample->read.one, + read_format); PyList_SET_ITEM(values, 0, t); } pydict_set_item_string_decref(dict_sample, "values", values); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 98e16659a149..dd818764bd4d 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1284,20 +1284,26 @@ static void sample_read__printf(struct perf_sample = *sample, u64 read_format) =20 if (read_format & PERF_FORMAT_GROUP) { u64 i; + struct sample_read_value *value =3D sample->read.group.values; =20 printf(".... group nr %" PRIu64 "\n", sample->read.group.nr); =20 for (i =3D 0; i < sample->read.group.nr; i++) { - struct sample_read_value *value; - - value =3D &sample->read.group.values[i]; printf("..... id %016" PRIx64 - ", value %016" PRIx64 "\n", + ", value %016" PRIx64, value->id, value->value); + if (read_format & PERF_FORMAT_LOST) + printf(", lost %" PRIu64, value->lost); + printf("\n"); + value =3D next_sample_read_value(value, read_format); } - } else - printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n", + } else { + printf("..... id %016" PRIx64 ", value %016" PRIx64, sample->read.one.id, sample->read.one.value); + if (read_format & PERF_FORMAT_LOST) + printf(", lost %" PRIu64, sample->read.one.lost); + printf("\n"); + } } =20 static void dump_event(struct evlist *evlist, union perf_event *event, @@ -1411,6 +1417,9 @@ static void dump_read(struct evsel *evsel, union perf= _event *event) =20 if (read_format & PERF_FORMAT_ID) printf("... id : %" PRI_lu64 "\n", read_event->id); + + if (read_format & PERF_FORMAT_LOST) + printf("... lost : %" PRI_lu64 "\n", read_event->lost); } =20 static struct machine *machines__find_for_cpumode(struct machines *machine= s, @@ -1479,17 +1488,20 @@ static int deliver_sample_group(struct evlist *evli= st, struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, - struct machine *machine) + struct machine *machine, + u64 read_format) { int ret =3D -EINVAL; u64 i; + struct sample_read_value *v =3D sample->read.group.values; =20 for (i =3D 0; i < sample->read.group.nr; i++) { - ret =3D deliver_sample_value(evlist, tool, event, sample, - &sample->read.group.values[i], + ret =3D deliver_sample_value(evlist, tool, event, sample, v, machine); if (ret) break; + + v =3D next_sample_read_value(v, read_format); } =20 return ret; @@ -1510,7 +1522,7 @@ static int evlist__deliver_sample(struct evlist *evli= st, struct perf_tool *tool, /* For PERF_SAMPLE_READ we have either single or group mode. */ if (read_format & PERF_FORMAT_GROUP) return deliver_sample_group(evlist, tool, event, sample, - machine); + machine, read_format); else return deliver_sample_value(evlist, tool, event, sample, &sample->read.one, machine); diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 2ae59c03ae77..9b8dc7633a02 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1432,11 +1432,12 @@ size_t perf_event__sample_event_size(const struct p= erf_sample *sample, u64 type, result +=3D sizeof(u64); /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ if (read_format & PERF_FORMAT_GROUP) { - sz =3D sample->read.group.nr * - sizeof(struct sample_read_value); - result +=3D sz; + sz =3D sample_read_value_size(read_format); + result +=3D sz * sample->read.group.nr; } else { result +=3D sizeof(u64); + if (read_format & PERF_FORMAT_LOST) + result +=3D sizeof(u64); } } =20 @@ -1521,6 +1522,22 @@ void __weak arch_perf_synthesize_sample_weight(const= struct perf_sample *data, *array =3D data->weight; } =20 +static __u64 *copy_read_group_values(__u64 *array, __u64 read_format, + const struct perf_sample *sample) +{ + size_t i, sz; + void *data =3D sample->read.group.values; + + sz =3D sample_read_value_size(read_format); + for (i =3D 0; i < sample->read.group.nr; i++) { + memcpy(array, data, sz); + + data +=3D sz; + array =3D (void *)array + sz; + } + return array; +} + int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 r= ead_format, const struct perf_sample *sample) { @@ -1602,13 +1619,16 @@ int perf_event__synthesize_sample(union perf_event = *event, u64 type, u64 read_fo =20 /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ if (read_format & PERF_FORMAT_GROUP) { - sz =3D sample->read.group.nr * - sizeof(struct sample_read_value); - memcpy(array, sample->read.group.values, sz); - array =3D (void *)array + sz; + array =3D copy_read_group_values(array, read_format, + sample); } else { *array =3D sample->read.one.id; array++; + + if (read_format & PERF_FORMAT_LOST) { + *array =3D sample->read.one.lost; + array++; + } } } =20 --=20 2.37.1.595.g718a3a8f04-goog