Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1554658rwb; Fri, 13 Jan 2023 14:05:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXvssoz2zCvhgX/ex85Lf8/LPEZhBisKeSVeyOaPenF8kzR8s0OING8jBXTDr+NCHWxZ66IA X-Received: by 2002:a17:906:34db:b0:842:3920:df75 with SMTP id h27-20020a17090634db00b008423920df75mr72421802ejb.33.1673647526577; Fri, 13 Jan 2023 14:05:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673647526; cv=none; d=google.com; s=arc-20160816; b=OnX11YrSUAxM3u+G0n6GqMxSMj3F5PLJCDYOonYj6jFWZXmZAkhGvvz910YEqMIGmi kCaUsGFfDv3XKFUXDVclU1SnyDwaaXOChNzjaEbjOdH9WOw1V5ETp5kHfbej/vMEmeUA MkpOqUOE+3Q3il51BBn97s7mwCgRtrXWQEMWRsBbzOh1AkL7edmEN0t2f0YaG5L6ju0i pGojTowih8FLeKKn1w1XSCowPcUWkd2KbkxhEexVnuh3KG6usbhE228ZFPuF61+cHcAa xtmOaCoYnIGDSxsSq/ov7fR442Y0hks0HGPNUQEcD9ox5S8o/Kj5aiBXByZrBebtv0sO TCQQ== 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; bh=Cn5WaIR2kYHfvSAn6aGjThopDJINdcdLaEEO7lYUz7s=; b=vHURmqvpFqCIpJKKPxWALZzIFhpLuT5eVGG3GivwFQYBNfJ4Gg9M3fggiY5yJQeu/X NrbwtmEAN9dWbA/xAe0pGbs9+Clq2gOjAOWrjrQz3Biv5/ptIaOHkTLqtxDjq9gd0hUD xiiT6VA8TRxdgEjZ1WCQXLd4j/TLi4vD1NkGieTonFlb2XztntNT5dMjRLdMvWAVOpYF SlIWXZZHRdwdbCOKBTxVgDza9++Y7kivWXNv7hPNY+EJ7tIxlfi0p0Pl0o82UFzlFqjk 4ru/A9RvzMo8C5r8SFGSuC/sCjymCDnYrh0a/W93blgbrG0KJjgj2Exw5FcFKNBtAu+3 mvJw== ARC-Authentication-Results: i=1; mx.google.com; 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 oz6-20020a1709077d8600b0085fea84a453si9106443ejc.402.2023.01.13.14.05.14; Fri, 13 Jan 2023 14:05:26 -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; 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 S231312AbjAMV4v (ORCPT + 52 others); Fri, 13 Jan 2023 16:56:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjAMV4t (ORCPT ); Fri, 13 Jan 2023 16:56:49 -0500 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21798892CD; Fri, 13 Jan 2023 13:56:49 -0800 (PST) Received: by mail-vk1-f180.google.com with SMTP id q141so8201821vkb.13; Fri, 13 Jan 2023 13:56:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Cn5WaIR2kYHfvSAn6aGjThopDJINdcdLaEEO7lYUz7s=; b=jt3l9jzeq4haX5c4B8Vtb7v7kpt2w3BctPHaRmBcSCqTdwF2h7ZilY696eylJx0Rr8 o3SOOgmAjWnGtJij2Q9aEmERh656Liz2UYVxM0hHkSVoRm/VYnOEW5A2JpMRc7ajkEuc YIlFevLxxUnEUr3hnygom6EziZUX16lDj687SlSdrJnmF9oE6FSqrqVyZFw167N2kWtu KMc+wluMwt3aDeY/wmmIiluO7nK+Vf54T1MQ35qjsWOU/zVlrFaPkvRmqvghmOgDPbVy HdewqsS+u9zIOHgqxVw41FOO8zkPDB+fMDE+oukXJA4UrvO0J3RiIhEEka2Nd08ZNls0 SrSw== X-Gm-Message-State: AFqh2kqfewquwT0J+AtyW+WXNpcii1DOwoqitYFxMj0UH4UsK+Dref0d PJR6vlZIbcW3qmpUVfZ/+lALfrxvNiC21MWFmoF+pDwg X-Received: by 2002:a05:6122:d9e:b0:3d5:3ee8:6603 with SMTP id bc30-20020a0561220d9e00b003d53ee86603mr9014889vkb.7.1673647008141; Fri, 13 Jan 2023 13:56:48 -0800 (PST) MIME-Version: 1.0 References: <20230112214015.1014857-1-namhyung@kernel.org> <20230112214015.1014857-4-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Fri, 13 Jan 2023 13:56:36 -0800 Message-ID: Subject: Re: [PATCH 3/8] perf/core: Add perf_sample_save_raw_data() helper To: Song Liu 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=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 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. Thanks, Namhyung