Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9373849rwl; Wed, 11 Jan 2023 05:04:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXsbKWrveH/YAsSbg/Ro4UpJlOb+S/7LXqOgvXtPgC0e65ixSYH9QgH9WGn2x2NTI6g79TGr X-Received: by 2002:a17:902:dad0:b0:191:3ec0:9166 with SMTP id q16-20020a170902dad000b001913ec09166mr111822887plx.6.1673442286641; Wed, 11 Jan 2023 05:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673442286; cv=none; d=google.com; s=arc-20160816; b=JTKLKTPqWehhJFK7vTCHc+6V5VyUrbdY5YLOpvghJPhFwKnTHFfutwDVsvTHvQ/54y nBtuWKJ0Lqp3X3ubDi8K+NDiWAk/ZfyzULsf6XSY4nvH0+xE1qde1PPANYKHSXPnPFge YWNBnUl7NwkLFUQhQXEoRLqqnW8/JqZ4/P/K88K2lG1VE/Wnd8zo9xW7MLp6HPxVVMZP TyNG277K/zjtWWhd0bovma5TSCkfz6T1qBsEbU75VSwVZr+oky7blxrQ7Of0UB1xKPwg Fpzi41FgnD0fROLl+qrkPA1qP0TfA7SgzdZVVqV8TIhdkwrC0UKwwkc6JI3tZAtIkA7p jvbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VKsur9CfmJqd7RUyGBR9q++t3bYeorhbrnyT99ptMKU=; b=XQzVM/sDwXqKCiQO9Q2xWrZNVZ8RlutWOLIHn2T43ixD8gLeYwsmf7go7KiNrv9qDZ NnN07edD4og1jb33zuZSFIG4kvFuTrwZsbteKWBCQFgGYWuw5Ub0XHf1cVYYXQI9DW4T 13N0phfbrSW2yQs5bR+eIdXpCV6SDIBk/t+GFwHpb23ixTgHFk+M95WJYXUn6n/+QGb7 EseTWFRDJZX02dAX+TYFlAWcfLUpm/7408UDrbL3N7YmerJi6oNOWnFpKOobfco7fHXm VBqu6/RvK55KzMCnKdJyanpOsW62znwmvWfhveMfk+pjuq3shYH08g4fBrL0JtNElU9K ++fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=gVROtrLB; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a170902eac500b00189d1d721c4si13088425pld.584.2023.01.11.05.04.39; Wed, 11 Jan 2023 05:04:46 -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=@infradead.org header.s=desiato.20200630 header.b=gVROtrLB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232027AbjAKMzu (ORCPT + 55 others); Wed, 11 Jan 2023 07:55:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238823AbjAKMz0 (ORCPT ); Wed, 11 Jan 2023 07:55:26 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EADC819285; Wed, 11 Jan 2023 04:55:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=VKsur9CfmJqd7RUyGBR9q++t3bYeorhbrnyT99ptMKU=; b=gVROtrLBNj1yG8sCxjN9JxNi4e C9VB0rnlQ1k5fVCeA+nQ6FfyjaSOsRXlsRbOZ/Je/JlPZH+x+zZ5JcUy3epn/kPCP56GGmesEFS78 X1lY/6W0wZ2fqf7ihnUyqwuaMfvqlhK3WWwRF8gSFVWLoESF8L0cVzRy3auzjG6l1n7LKKqn0L3RT yDIRAzkOOHrqJx9MBpDae7IY/Q5zXTlThhaahQ5Z+ocWKTuPuGJbTuC06PWDoFZZZOTBhupesObT4 54p3OGyHtdFHkS4h1SRWye6GNFWI+0WaJmFI2GfpuDRfWegdhhHQok6tLAWhq6N6FZUa5YVGhmdvo lq9nsCYQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pFacy-003gFb-2p; Wed, 11 Jan 2023 12:54:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 63BDF3001F7; Wed, 11 Jan 2023 13:54:54 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 466A42C9F6B72; Wed, 11 Jan 2023 13:54:54 +0100 (CET) Date: Wed, 11 Jan 2023 13:54:54 +0100 From: Peter Zijlstra To: Namhyung Kim Cc: Ingo Molnar , LKML , Arnaldo Carvalho de Melo , Jiri Olsa , Kan Liang , Ravi Bangoria , bpf@vger.kernel.org Subject: Re: [PATCH 2/3] perf/core: Set data->sample_flags in perf_prepare_sample() Message-ID: References: <20221229204101.1099430-1-namhyung@kernel.org> <20221229204101.1099430-2-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 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; This way we express the implicit conditions by setting the required sample data flags, then we mask those we already have set. After the above something like: if (fst & PERF_SAMPLE_ADDR) { data->addr = 0; data->sample_flags |= PERF_SAMPLE_ADDR; } if (fst & PERF_SAMPLE_PHYS_ADDR) { data->phys_addr = perf_virt_to_phys(data->addr); data->sample_flags |= PERF_SAMPLE_PHYS_ADDR; } if (fst & PERF_SAMPLE_DATA_PAGE_SIZE) { data->data_page_size = perf_get_page_size(data->addr); data->sample_flags |= PERF_SAMPLE_DATA_PAGE_SIZE; } And maybe something like: #define __IF_SAMPLE_DATA(f_) ({ \ bool __f = fst & PERF_SAMPLE_##f_; \ if (__f) data->sample_flags |= PERF_SAMPLE_##f_;\ __f; }) #define IF_SAMPLE_DATA(f_) if (__IF_SAMPLE_DATA(f_)) Then we can write: IF_SAMPLE_DATA(ADDR) data->addr = 0; IF_SAMPLE_DATA(PHYS_ADDR) data->phys_addr = perf_virt_to_phys(data->addr); IF_SAMPLE_DATA(DATA_PAGE_SIZE) data->data_page_size = perf_get_page_size(data->addr); But I didn't check code-gen for this last suggestion.