From nobody Fri Apr 10 20:17:13 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 B5720C25B0E for ; Fri, 19 Aug 2022 00:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244840AbiHSAgu (ORCPT ); Thu, 18 Aug 2022 20:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242755AbiHSAgt (ORCPT ); Thu, 18 Aug 2022 20:36:49 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9EF8DEA7F; Thu, 18 Aug 2022 17:36:48 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 202so2526813pgc.8; Thu, 18 Aug 2022 17:36:48 -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=X4JKtGGQOwyyDoEC+VjchavxLOpFCxVxZQ0CCAZ7ACmwPRkTvgUONVgjP3rC1he8K0 7hKw5+oE8a1OmPwaTVVyL+qktbAuXlzkb7vC7Ul4Kusr2fnmIZVL+HoL/uSpEnjWuguE NKxj/NogYkNlG1IeOxq61SxDQKdXf1BDS5PX8aquzO5V+EhdXyMaIwaEVUg9oHMQv6OH bd83XVnJFLm+sHAQVFfuEhBGKRRCEFSeOvMRVbjMpUJIupMJ5azWO/8XVws2aJ3mY75m TMGpfTYRw2HU0NuahqwxO4cAeu32caQVBzFTayJlof6nWY1QVhX0SJgRGQClblSvtfv3 hEJQ== 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=bJ7sz9rJIog2LjRGQPEPWu4pvxrn/mUKD8yg4hX/yYINjeB/Ia4LZh9+hgz4pnApPN 7hDX3D52qveRevWxIlJOnkaar2R/I5nX3o7N0qPNM5v073t9mDdHFJwS3i2Ggt5kGJz0 AVu+eGA6o3o0O6q5gnouJMdmx2jykXsgje4ELdCzrACfO7SfEeREDWmue7T7fXdqq2kF cUTWFwgcHh1WqRzm5Up59aUEuOHsoGfauNCwfl33lel1h/aniZLg2wuhwtGCJkKqm6Vk GjB31JUyOs/kBgvhGY6+5de9GBfU4uStb0iWnle/r0JgST1G9FxlMnjrx/oyuq5EvPaw QaBA== X-Gm-Message-State: ACgBeo21RePOxROogOLLAtLvg7d/eY7l+DUW76dP7loxcbJYJMuosk6m WXnh5vEzeG6QbxmK0Wuo7FY= X-Google-Smtp-Source: AA6agR7dHikG9IfUHMQRRWFsLO3xfKjnnMD8fKhAVwzmi6Mc9ill7Io6mAvEK1mjqDDSreQDebQmRg== X-Received: by 2002:aa7:96d5:0:b0:52e:e2a:9c79 with SMTP id h21-20020aa796d5000000b0052e0e2a9c79mr5338582pfq.55.1660869408017; Thu, 18 Aug 2022 17:36:48 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:436c:3fa9:2b77:a856]) by smtp.gmail.com with ESMTPSA id e5-20020a17090a4a0500b001f303d149casm2057567pjh.50.2022.08.18.17.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 17:36:47 -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: Thu, 18 Aug 2022 17:36:41 -0700 Message-Id: <20220819003644.508916-2-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220819003644.508916-1-namhyung@kernel.org> References: <20220819003644.508916-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 Acked-by: Jiri Olsa --- 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 Fri Apr 10 20:17:13 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 C373AC00140 for ; Fri, 19 Aug 2022 00:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240015AbiHSAg7 (ORCPT ); Thu, 18 Aug 2022 20:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243261AbiHSAgu (ORCPT ); Thu, 18 Aug 2022 20:36:50 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB28DEA78; Thu, 18 Aug 2022 17:36:49 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id x19so204899pfq.1; Thu, 18 Aug 2022 17:36:49 -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=CraHROS+NJtL9SDztOre+0LV3k2cwcFvVDvpbMu+G5jpBWjogKNH90GAYIc18Aahxc 63LxIuF5eZ0DLYq5BLvZKTePK/kNoYBhvUS1tCkpCQTqGk0J50qznbNkHyypeUxFjWAG 4OIi+3wRMDOV82uwc0C4wg+PJQEZlzNpCoupgEjNBmYJLH2GqegJFjyNiWWiMmzr1wQg Q6jvMfoDSySu/gFWKB6ndFQ1Qu4xthMGs9F63iwCmDwtDPgN1KsL87WISz1XZK+1gRED m9Y6b4mN+T++RSsipMPkNIMeBVH8S2sBLWNOZlyhm3N9pNJ101VUVC8DrWEZq+NMLhf7 3QgA== 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=w289hpWwH8+4/z5pZqb+BhW7FAwJEM4G6ceq7+59bi4OgED35Mm81LXu5PHw89+FZA Pmcg55+aQYPstBnNBDOmWgAeX0O0sASv84VRnAb/MBRbmsxhemdspZ57qUniRrFm8BVU PBDdQ1rz6MXr4+R/PkRya9NWJx7YkwBdi377IOrAd1tPbx/6iaAMHvtQYXs9edsEAxCk ikidb+pYlkpWT3aks3ZfTvlUufIiYO4F8GiTP7oVXxUqmA8yUxjJwJq9KgfrrGpvZ+Jq DUY+wqvNHG0kK5gD9+6r6ptFm33yJTKhUWT7XBEN3cXXqMm4+UUedf99x/dTGCgUiOEH QmLQ== X-Gm-Message-State: ACgBeo0kxfmQp03Po4ivjESxLDxGVKsvtVCuGYdsn0HbqTonl6tyIgIJ sRfpAlz6ZvAKXaSunp4tUhv1Rd0wfEOc/Q== X-Google-Smtp-Source: AA6agR7jbzEls61dp0C+sz/vuCAt0Fo6xmASdDDEnzuR5s2axkwcpWNx+poX9JZL908ldPDxmiMgqw== X-Received: by 2002:a05:6a00:14d3:b0:52f:918f:c3b8 with SMTP id w19-20020a056a0014d300b0052f918fc3b8mr5391066pfu.1.1660869409160; Thu, 18 Aug 2022 17:36:49 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:436c:3fa9:2b77:a856]) by smtp.gmail.com with ESMTPSA id e5-20020a17090a4a0500b001f303d149casm2057567pjh.50.2022.08.18.17.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 17:36:48 -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: Thu, 18 Aug 2022 17:36:42 -0700 Message-Id: <20220819003644.508916-3-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220819003644.508916-1-namhyung@kernel.org> References: <20220819003644.508916-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 Acked-by: Jiri Olsa --- 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 Fri Apr 10 20:17:13 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 2D682C00140 for ; Fri, 19 Aug 2022 00:37:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244968AbiHSAhE (ORCPT ); Thu, 18 Aug 2022 20:37:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243317AbiHSAgw (ORCPT ); Thu, 18 Aug 2022 20:36:52 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04F47D758B; Thu, 18 Aug 2022 17:36:51 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id c2so2862008plo.3; Thu, 18 Aug 2022 17:36: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=aFH5O6viJ6NTA25wi2Aiw0FQRIeUfCBP+ZrmMXU/R8U=; b=UTqo95W5sFEGm/9q+KSY2LR4JqUs07dpgbh7hpFuDmbzAKCMEs4XwEgeQHpDeeUCoT n00p/IQBTIJKG2YDW+8/Qc9ZPGPF9nL3T3zGalSEmPX+k6j6S94heO8kAAVxjmiJQpDk 25rugz+4wWjqfQ/zduySx69w+eDJLsYiFuBYnIw4fHZyuwRMiQ3TWvKDY9UAnal0AOO4 026Xo9Fn4pypDWO6GIUiHgpSmTY5yqN0Lbb66+FPPoRFobHIU2PqQfZNXBJLpZlGhUj3 8T/yb1ivSlbSrm4q7NiAPMRbImf1wHiwC1ETjzDk00jmepT4Pqu1CjrcuS1qd7ilEia/ SZeQ== 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=v7p6iJIMEJ+wu+eaVnPHBGOCccjAClZWG7AMkokhInbMXjAWVLH91O0W5wI1ZgiJko GQXQDeETc7K1qSLzFnfnYw27Z5blKckb793khOJII+miNXJsKTHm55gGH0ubiL6zIskU 1YYGnDSJY63Z8acl3fgKh+nmhp8W+TFin/GS0Bt3noofR0fmkPnnlcDZrlOdhR6DtP22 Z8mN1UvFHArkCUcLxOHWyHVNUdAcRZFI4Iof1UDzvJ8hFinEPpwbWLs72dTc8IHBS91W eri9YpnuD+iwJzXSedsTNOIJEjpdZph8SuMpHQI+QfEJnMDrhtTSI5e8VrNZTYEvCvd2 rXDg== X-Gm-Message-State: ACgBeo2JuP/a8zmcxe/E+PCKA8w1QKd1kG9sFHsxO1sLQK2Ve382PpeQ +YKQCrFDZE9rZ7JGs3TAG9g= X-Google-Smtp-Source: AA6agR4vJY63i3QMAtr3pWndk1kgYzx6VfMmP1iLYxbkheNdQijcOndbFavj+1bYsuUFJbYiw6BelA== X-Received: by 2002:a17:903:1c7:b0:16f:1228:f632 with SMTP id e7-20020a17090301c700b0016f1228f632mr4968982plh.65.1660869410452; Thu, 18 Aug 2022 17:36:50 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:436c:3fa9:2b77:a856]) by smtp.gmail.com with ESMTPSA id e5-20020a17090a4a0500b001f303d149casm2057567pjh.50.2022.08.18.17.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 17:36:49 -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: Thu, 18 Aug 2022 17:36:43 -0700 Message-Id: <20220819003644.508916-4-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220819003644.508916-1-namhyung@kernel.org> References: <20220819003644.508916-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 Acked-by: Jiri Olsa --- 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 Fri Apr 10 20:17:13 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 C9E3BC00140 for ; Fri, 19 Aug 2022 00:37:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238384AbiHSAhO (ORCPT ); Thu, 18 Aug 2022 20:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244397AbiHSAg7 (ORCPT ); Thu, 18 Aug 2022 20:36:59 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BFD1DEA57; Thu, 18 Aug 2022 17:36:52 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id s31-20020a17090a2f2200b001faaf9d92easo6143144pjd.3; Thu, 18 Aug 2022 17:36: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=04mrbdeAlasHwvT3Fh9Z1ZRe3mssxYDaUL9Qw3iJ218=; b=W67ugkdGRf0QFsI7qCuz7kAaniBXo08JQsE+T0990WjQpCPoatY6g6RzcvXEevKV8e m5Kow55avUG2gvSP+t0M3O+IGDfrp+WRJ4UkHB/08Z5/LAysqR0MXnck/BPfB6IaADJi ByCud6oazyltIyfKQpCojCeF0/26OUvHqd92Q2MCk0wcRWP1czUuof2jH2UwhBRteomK rMU1ysaPIk2enyeM9yXo5JTG6y9wUNjeCRM7dv1bw/NQ2BXf2Qju73TaVUcdY0jJjqcj c/3gikL8w8Y0+Y/1nS2aoA0pLcIAD77jCYpnCxwElId+sd7nebL0A4B7UOXZ0wm/AwX5 Ybaw== 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=04mrbdeAlasHwvT3Fh9Z1ZRe3mssxYDaUL9Qw3iJ218=; b=LZTbAFegImgoXi8PUg1XVbfVcdD0Tc9yc3tRLABE9tA2Dh13l2Dj0WG12AzjCAKxiI QGbGKXUutue+6TY3CO0NCC5Lk71/IewVmpHgv3lqHzZBHKS8+p4xn9v5zVk9wK0UZUai NgO0RUIPAGflprGeMZkjvFF49gRot/Ha5Xx9utsuJPqJckAdSYM7ShtuIZIu5ioQmi8J dcGCus7fbinnvTbGCy3VL8fbxeVNzlR2gKYpgqBCDHE9DOFKylsB1WNhIZTjq1LQ8bFt sL4C4DC9aghXQy1LDF5skYgKTnmYqgnlhfqmZYXIYWbmXSD6H0lIAjIHfm/uQ/it+68n eG5w== X-Gm-Message-State: ACgBeo2iDSF7r03oRrHiQWuhxVR0pmXUMAEiUAsvkMMtLPLXC5MJLkdu 3Ece7cijA/bijIcSLKz2N4sJhABKTEXiyg== X-Google-Smtp-Source: AA6agR6hBL12ERR9NACDSfitNt3h81d91kkilJsGr0aC9QzGPirXScD1LcBdrOpJq5wcZDhIlYk3Ng== X-Received: by 2002:a17:902:ba96:b0:170:9f15:b997 with SMTP id k22-20020a170902ba9600b001709f15b997mr4693786pls.34.1660869411608; Thu, 18 Aug 2022 17:36:51 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:436c:3fa9:2b77:a856]) by smtp.gmail.com with ESMTPSA id e5-20020a17090a4a0500b001f303d149casm2057567pjh.50.2022.08.18.17.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 17:36: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 4/4] perf tools: Support reading PERF_FORMAT_LOST Date: Thu, 18 Aug 2022 17:36:44 -0700 Message-Id: <20220819003644.508916-5-namhyung@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220819003644.508916-1-namhyung@kernel.org> References: <20220819003644.508916-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 Acked-by: Jiri Olsa --- tools/perf/tests/sample-parsing.c | 14 +++++--- tools/perf/util/event.h | 21 ++++++++++- tools/perf/util/evsel.c | 29 +++++++++------ .../scripting-engines/trace-event-python.c | 19 +++++++--- tools/perf/util/session.c | 35 +++++++++++-------- tools/perf/util/synthetic-events.c | 32 +++++++++++++---- 6 files changed, 108 insertions(+), 42 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..058d07923f04 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,24 @@ 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); +} + +#define sample_read_group__for_each(v, nr, rf) \ + for (int __i =3D 0; __i < (int)nr; v =3D next_sample_read_value(v, rf), _= _i++) + struct ip_callchain { u64 nr; u64 ips[]; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4852089e1d79..18c3eb864d55 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; =20 nr =3D *data++; =20 @@ -1571,18 +1572,18 @@ static int evsel__process_group_data(struct evsel *= leader, int cpu_map_idx, int if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) run =3D *data++; =20 - v =3D (struct sample_read_value *) data; - - evsel__set_count(leader, cpu_map_idx, thread, v[0].value, ena, run); - - for (i =3D 1; i < nr; i++) { + v =3D (void *)data; + sample_read_group__for_each(v, nr, read_format) { 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); } =20 return 0; @@ -2475,8 +2476,8 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_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; @@ -2485,6 +2486,12 @@ int evsel__parse_sample(struct evsel *evsel, union p= erf_event *event, 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..1f2040f36d4e 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,17 @@ 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) { - for (i =3D 0; i < sample->read.group.nr; i++) { - PyObject *t =3D get_sample_value_as_tuple(&sample->read.group.values[i]= ); + struct sample_read_value *v =3D sample->read.group.values; + + i =3D 0; + sample_read_group__for_each(v, sample->read.group.nr, read_format) { + PyObject *t =3D get_sample_value_as_tuple(v, read_format); PyList_SET_ITEM(values, i, t); + i++; } } 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..40a907d95639 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1283,21 +1283,25 @@ static void sample_read__printf(struct perf_sample = *sample, u64 read_format) sample->read.time_running); =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]; + sample_read_group__for_each(value, sample->read.group.nr, read_format) { 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"); } - } 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 +1415,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,14 +1486,14 @@ 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], + sample_read_group__for_each(v, sample->read.group.nr, read_format) { + ret =3D deliver_sample_value(evlist, tool, event, sample, v, machine); if (ret) break; @@ -1510,7 +1517,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..24df0d9755e4 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,20 @@ 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 sz =3D sample_read_value_size(read_format); + struct sample_read_value *v =3D sample->read.group.values; + + sample_read_group__for_each(v, sample->read.group.nr, read_format) { + /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ + memcpy(array, v, 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 +1617,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