Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1626634rwb; Fri, 13 Jan 2023 15:16:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXsjQwuiQwrxnGeVRwG+XWOTQW25+75HpnBvr+k/TjE3o2x9ng4fGAQRYtTC53izUbsGyrbp X-Received: by 2002:a05:6402:25c6:b0:46c:d2a3:76b3 with SMTP id x6-20020a05640225c600b0046cd2a376b3mr76332978edb.14.1673651777704; Fri, 13 Jan 2023 15:16:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673651777; cv=none; d=google.com; s=arc-20160816; b=CVi6dnaLq2PdVxpgeqTsMX6Pom0sRzhmJBg2bdrLy/WY5mKciY5DRwlC/hpY++0Bix 9T9jYNQhlWc7Z4ugOaTfPvit7gy1xo2Cas3bHJ3UERNdfD7qSSjff29fDrIWrUOwZFmA zH8j7MkUVS2GjrASHCP1TDPZxdvMA/xeBA8Dptf+8ikeeZJNWpv2PU78Ey79egEJN0Ag 6fGPyTh+p56wHSk9iXr59AHXqImUJo5OWEJqPR6rnqwZLRcU+ZRSDcC02QDPusbsVCKH Xr4bzn2cLPpPwk5H3kjFV8yJBa9gjH30TgnxnsrnYXmi+K0fTfwufjQZ+8aaS4HG0TYy Devg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fzLppoZoN37Cklb1U/BkgwK1+ABA2lzhxUgHzRKPWXc=; b=j3yG1LgYKW6ePWKrTOjiF5k9NGVaw44ZwLwghOrHi1RlNYYs956rcTjz4tyq1FZvNt 0iVHeivx1gXujjSUKP97AiPthYnMBl5aXYwdCnVxLzw63qT3egUsImEP/qeRFEM4zKGa W7Yz6+BuTGNsbB07LpYE4+IzZe7rg0d3+WR2UmyIuWZkexreN0ZOa7Gagycd4gQbHTWC cF5ry3CYyXf3GKUUmeskrlXI4u6qEf2rX62M4613RQ/8KYzwp8C5D9UsL0QntJUvu6ga FDe1iZ6y8URr5DVT2hIkudH3uyBbf24AAw/ruU8aKZBlNNutoaGWOk419FmCb3pWLgtk mk8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DGjGwvtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a056402514900b00490df3bd87fsi20613262edd.219.2023.01.13.15.16.05; Fri, 13 Jan 2023 15:16:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DGjGwvtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230138AbjAMW6K (ORCPT + 52 others); Fri, 13 Jan 2023 17:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbjAMW5o (ORCPT ); Fri, 13 Jan 2023 17:57:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D760784F82; Fri, 13 Jan 2023 14:57:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7474962263; Fri, 13 Jan 2023 22:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8027C433F1; Fri, 13 Jan 2023 22:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673650651; bh=s/4KHihd3TlUX2HOfaEEQ08QQuS7t1/ev0yRVowTt6k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DGjGwvtJaN5G7uhUFsJvOaNGmWV7xGVt1twaufKt9hqaVwISHvOuY1A1YQ8ujSHPP is7SOE+vUwAbCEDEp0uVXbFprJkWJ16wYVprF1KOURLesYTyTLvWB42F5DvWw5Ta5g 0MUKvI8Z/tsa3/o6q7M6sQOzHegNntuteeM6ARpsLdwzGjPSVvXWRkSzGFHdMHgf0a I49KTiEr1cj4DlpNokQdMjP5J8Z5he/YAfA4wdFc/3CPVOJfEQY9rZt0UII1LVvNhk sfj9jDx0NjtZoDo/MIPEjEXHfF0FA4mQaJ9iS2za1+2yOBeNLgHmilAGtDb6JgjLP9 +LCBDlFrlAUgQ== Received: by mail-lj1-f175.google.com with SMTP id n5so23406718ljc.9; Fri, 13 Jan 2023 14:57:31 -0800 (PST) X-Gm-Message-State: AFqh2kpi33jfWLsIAzTgpfXKlFxpuHKSIV4Ia5ZjcBXV+TNg0zXYA9SC gOWOfmMc73BcCirUu67pSqMhGCuMghFtJRZ3i0w= X-Received: by 2002:a2e:9382:0:b0:284:b05a:9e82 with SMTP id g2-20020a2e9382000000b00284b05a9e82mr1394658ljh.479.1673650649893; Fri, 13 Jan 2023 14:57:29 -0800 (PST) MIME-Version: 1.0 References: <20230112214015.1014857-1-namhyung@kernel.org> <20230112214015.1014857-4-namhyung@kernel.org> In-Reply-To: From: Song Liu Date: Fri, 13 Jan 2023 14:57:17 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/8] perf/core: Add perf_sample_save_raw_data() helper To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , LKML , linux-s390@vger.kernel.org, x86@kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 13, 2023 at 1:56 PM Namhyung Kim wrote: > > Hi Song, > > On Fri, Jan 13, 2023 at 1:01 PM Song Liu wrote: > > > > On Thu, Jan 12, 2023 at 1:40 PM Namhyung Kim wrote: > > > > > > When it saves the raw_data to the perf sample data, it needs to update > > > the sample flags and the dynamic size. To make sure this, add the > > > perf_sample_save_raw_data() helper and convert all call sites. > > > > > > Cc: linux-s390@vger.kernel.org > > > Cc: x86@kernel.org > > > Cc: bpf@vger.kernel.org > > > Suggested-by: Peter Zijlstra > > > Signed-off-by: Namhyung Kim > > > --- > > [SNIP] > > > diff --git a/kernel/events/core.c b/kernel/events/core.c > > > index 0fba98b9cd65..133894ae5e30 100644 > > > --- a/kernel/events/core.c > > > +++ b/kernel/events/core.c > > > @@ -7588,30 +7588,10 @@ void perf_prepare_sample(struct perf_event_header *header, > > > if (filtered_sample_type & PERF_SAMPLE_CALLCHAIN) > > > perf_sample_save_callchain(data, event, regs); > > > > > > - if (sample_type & PERF_SAMPLE_RAW) { > > > - struct perf_raw_record *raw = data->raw; > > > - int size; > > > - > > > - if (raw && (data->sample_flags & PERF_SAMPLE_RAW)) { > > > - struct perf_raw_frag *frag = &raw->frag; > > > - u32 sum = 0; > > > - > > > - do { > > > - sum += frag->size; > > > - if (perf_raw_frag_last(frag)) > > > - break; > > > - frag = frag->next; > > > - } while (1); > > > - > > > - size = round_up(sum + sizeof(u32), sizeof(u64)); > > > - raw->size = size - sizeof(u32); > > > - frag->pad = raw->size - sum; > > > - } else { > > > - size = sizeof(u64); > > > - data->raw = NULL; > > > - } > > > - > > > - data->dyn_size += size; > > > + if (filtered_sample_type & PERF_SAMPLE_RAW) { > > > + data->raw = NULL; > > > + data->dyn_size += sizeof(u64); > > > + data->sample_flags |= PERF_SAMPLE_RAW; > > > } > > > > I don't quite follow this change, and the commit log doesn't seem > > to cover this part. > > It's for when the user requested RAW but no actual data. > It assumes PMU drivers call perf_sample_save_raw_data() > before perf_prepare_sample() if there's RAW data. > So we can only handle the 'else' part in the original code. Got it. Thanks for the explanation. Song