Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9830477rwl; Wed, 11 Jan 2023 10:31:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXsCKJJbSkNTdqp2hewj9sHRWBSN3TlG1xYGG/XtEJbGwO5pW+JBh9r5WrDe1jRfUQRuqpzD X-Received: by 2002:a17:907:c242:b0:7c1:453f:1aae with SMTP id tj2-20020a170907c24200b007c1453f1aaemr80100032ejc.37.1673461896808; Wed, 11 Jan 2023 10:31:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673461896; cv=none; d=google.com; s=arc-20160816; b=iYdjzJVGQpTWOTVeAoDdqFZXZiGuTLLKpmC1W7F2lGDRzPGl3ntOl9EBFMx0izd4b5 2G/r7vLzfiiE+GquNEf5k9YPq5HV4mnCaSlQu4E9oyBhB/PdPbHQpRIsF+uP9c3qlnti vse7tjvlWQSG56o9tcbl3BerQtL5/8LFVkOSJq4V8oMuFwazE+5Iz/tO1uwtwxwsWeyX XlnmAGodfqKHZCjhXuhum/2w+7C4/bKZODj24MSGFlH7eP062zKZOscXNTx1/BZt+vVn /aLzcofMX3AwnD/8bxpukvQt+km91RPDZKRa6oSaGmMN+ZK/nJejRV/aZ1q8ntNUclNq 5WQg== 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=ns9qgbZZDM0cRBwnUDXXAKWNmRdk/HbHXOFx6BEC0M8=; b=EJ+yiqVZNR6ColIpUgil4oTe26tqOAIjNYJJ6tLR2p4Ksra/syEO/45+EX1Jjxaow2 CALwQMvkiyI3X80q2CqYX2jj9/1zmGgp1guIJtiTZiA648QtaRgNi8LILzl7pdDxHdgw hvaj0NHcxc2kNvjmlou6a7kuipUKl9QbaIXv7hmOOSX2ZTtyPYXtMttycgprc2D5b6lp XTMrgzXN3QP6uL0/auEGGEjgXxguPSViuIzSDQOfcotjzVMzVnSaE/6WTiQMP39nZ1t3 eebShQOL+3uMKLI6iPvXRVI9balVncAo8kSnMLOvtIwKXdJB7+tZCWxe4R+7VoAGvkHA bK4g== 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 g16-20020a1709065d1000b0084ca32731dcsi16446235ejt.675.2023.01.11.10.31.24; Wed, 11 Jan 2023 10:31:36 -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 S233923AbjAKR7m (ORCPT + 51 others); Wed, 11 Jan 2023 12:59:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbjAKR70 (ORCPT ); Wed, 11 Jan 2023 12:59:26 -0500 Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFCE014D24; Wed, 11 Jan 2023 09:59:25 -0800 (PST) Received: by mail-il1-f175.google.com with SMTP id m15so8273221ilq.2; Wed, 11 Jan 2023 09:59:25 -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=ns9qgbZZDM0cRBwnUDXXAKWNmRdk/HbHXOFx6BEC0M8=; b=Udznus0+05ocgOYtYseFqL9ktwoX/2rg99XjOTQaoOGTjZmysKvcmMKzXZUdZJISyn 99tIfixYBPPz+kdqrtLmRu6YhzB6Bd9iGnVpP6R4VYJmDEH8zcVOL5N1AdICnit+uPPf sdKt/ddMJjWZDIqoESH6CUzdTLy3cAtEBNEPYutia2CqPbhZwvtUCfTvEoZEU/6fmj8X fFo/luqxcLBo4371dzPr96GmomU4jex9FnmphrCI5rm4kDcaxfWH0mFt3H226maOwQJZ DhwHrWn64TfEgMOCYdZjzjq0jjNsGFRlhvQ+JzRI6XwJCijlroBXxiCB5e3lny+XmCL9 1FZg== X-Gm-Message-State: AFqh2kpbAaz8xLITCHpCQz3AfCZNuYqW5a14YMFgSckNzYIvXldYevPx EhEiG1R26eYggLOtnMlHGMyypZeta2K87XLlpI9JOkNi X-Received: by 2002:a05:6e02:f10:b0:30d:e353:8613 with SMTP id x16-20020a056e020f1000b0030de3538613mr106170ilj.250.1673459965081; Wed, 11 Jan 2023 09:59:25 -0800 (PST) MIME-Version: 1.0 References: <20221229204101.1099430-1-namhyung@kernel.org> <20221229204101.1099430-2-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Wed, 11 Jan 2023 09:59:13 -0800 Message-ID: Subject: Re: [PATCH 2/3] perf/core: Set data->sample_flags in perf_prepare_sample() To: Peter Zijlstra Cc: Ingo Molnar , LKML , Arnaldo Carvalho de Melo , Jiri Olsa , Kan Liang , Ravi Bangoria , 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 On Wed, Jan 11, 2023 at 8:45 AM Peter Zijlstra wrote: > > On Wed, Jan 11, 2023 at 01:54:54PM +0100, Peter Zijlstra wrote: > > On Tue, Jan 10, 2023 at 12:06:00PM -0800, Namhyung Kim wrote: > > > > > Another example, but in this case it's real, is ADDR. We cannot update > > > the data->addr just because filtered_sample_type has PHYS_ADDR or > > > DATA_PAGE_SIZE as it'd lose the original value. > > > > Hmm, how about something like so? > > > > /* > > * if (flags & s) flags |= d; // without branches > > */ > > static __always_inline unsigned long > > __cond_set(unsigned long flags, unsigned long s, unsigned long d) > > { > > return flags | (d * !!(flags & s)); > > } > > > > Then: > > > > fst = sample_type; > > fst = __cond_set(fst, PERF_SAMPLE_CODE_PAGE_SIZE, PERF_SAMPLE_IP); > > fst = __cond_set(fst, PERF_SAMPLE_DATA_PAGE_SIZE | > > PERF_SAMPLE_PHYS_ADDR, PERF_SAMPLE_ADDR); > > fst = __cond_set(fst, PERF_SAMPLE_STACK_USER, PERF_SAMPLE_REGS_USER); > > fst &= ~data->sample_flags; > > > > Hmm, I think it's better to write this like: > > static __always_inline unsigned long > __cond_set(unsigned long flags, unsigned long s, unsigned long d) > { > return d * !!(flags & s); > } > > fst = sample_type; > fst |= __cond_set(sample_type, PERF_SAMPLE_CODE_PAGE_SIZE, PERF_SAMPLE_IP); > fst |= __cond_set(sample_type, PERF_SAMPLE_DATA_PAGE_SIZE | > PERF_SAMPLE_PHYS_ADDR, PERF_SAMPLE_ADDR); > fst |= __cond_set(sample_type, PERF_SAMPLE_STACK_USER, PERF_SAMPLE_REGS_USER); > fst &= ~data->sample_flags; > > Which should be identical but has less data dependencies and thus gives > an OoO CPU more leaway to paralleize things. Looks good. Let me try this. Thanks, Namhyung