Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp66247lql; Fri, 12 Apr 2024 04:06:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1/1jY6QuedCZsP7J9XfxpZ/u6gAaqsIlNg1K7hl+tB3T8B7G6qDu++PGjCnGMJX4BtjVecqytsa2aHL9meuHrvsl7mEIDz2AhWNGUPQ== X-Google-Smtp-Source: AGHT+IG0GXtuniQ0fc3KYCNkWgOmO3UajbHVByjCDBfS3t9thl50lPPsHUWpUTCfKYipYqKWujNT X-Received: by 2002:a17:90a:7c05:b0:2a6:664a:9c51 with SMTP id v5-20020a17090a7c0500b002a6664a9c51mr2085104pjf.17.1712920002169; Fri, 12 Apr 2024 04:06:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712920002; cv=pass; d=google.com; s=arc-20160816; b=MPyOY7HxdIwBJwmVs27HLEE1NI7Jg2hJaIgHHDQOkVg+HWcV6D8Syx6fBagVdSYrHM fNTMcbnJmJx3fhxeJ3e5dQNCpmDlQUZUR9otYRR8ULsgAIQNWuZbCjCurOhGThL3sOqf mhcxHoJHM9xLtf6GsWR5OmC7sC+u9QajSubKL0Y3VC2DPbcNRkoslCGTa4hiP9suGohK khj4XvTRq6oLYyKDWMLaF3Ek6HdH6Hf87hKSpJJsTtSEQq0B3+L3owq25if5OMwOn3Sx CMWoobJfAwd6vOGHUgUQfK0dG5dXcMhU6Tp0P8cMmxZ5xrLEytp0SWarqm9ICsd2U0MM Xvyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WqsHOb8ca3wTRadlCQz8Y2C98VyRQKabao20sZYMVuU=; fh=bLut86OR3jonTluX1u2hjC8BfgQuAgUsK94PaqYlHNc=; b=CMSlThNNwOSnsgsC70+EroM260bmnhYf98p1CTc6LnWloBMuQud3ykN2CRypQTn18s jck7INVud/lzDIIUfFF+qR9CaE4Lu3W6M/VixPxovV6Z8+che4+lHgjp+JZdm5mQJ78C rirklM3dO6dGzl/ARDw9H1zDct/zi/QLBIpmPSB0cxzpFf2lLahI6Hszw4/Ys/Lvdywe lQYQ2W49RX9vIun9o9738VD9hI4D0bTG3/brJW+te8G+OXwDa9N/q3au5BNdZNK5VsQN Wyh4g/DKVS3SxW+afHgjS757fMzN1naOheyQ2HMFeGIQvJo3drzVgo8a2Be52WgI3ZCK D3dQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eX4CZHVJ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-142143-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142143-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n21-20020a17090ac69500b002a545392a5fsi5234269pjt.1.2024.04.12.04.06.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 04:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142143-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eX4CZHVJ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-142143-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142143-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DE5062855AE for ; Fri, 12 Apr 2024 07:30:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 367EC4DA05; Fri, 12 Apr 2024 07:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eX4CZHVJ" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51D282C683; Fri, 12 Apr 2024 07:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712907029; cv=none; b=BymKsUHSf6h+v1qZ5o9ZBEj0GJykyosGsw4dKrwerl23RX5+pRC2nGEhhRn3Q4OSckbc8t7p3ykOU7i4X2ekbyiEl02VvVF2nDcn5crHj6Bb0QeaBFTvR4B+MlZlrSipOgex3H0LLjTs6PFoljFl0aKD8sS41+yOfcQiArw8uB8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712907029; c=relaxed/simple; bh=SMJxN39eSTs8bPxN1doXBcsVnwkQ15ZuSI+TQzwARyU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fDx/toZQ+4LZ2BmDAzDCFyzIsNfFDNfvlAWt13RMari9GiiP9Uxt/FgtlK0elae3f48HS8N1LQ87YTCDQVI+JHjqy3tRSxF/uc+VbcUgx6yPFXGG/RqtfrBBSRgfuw7X5pAe3PvQ8cyUw7GbyzFQKhX3N4DUUe013Jz/eN4BTlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=eX4CZHVJ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=WqsHOb8ca3wTRadlCQz8Y2C98VyRQKabao20sZYMVuU=; b=eX4CZHVJ3CoJuRj6xZ6ZoMY55b E4+cHxnKRhwlspEuPLkPOEMBgu62L57QQplzsmnmGOU1X/5uNFjzPdfUO2PsB+gHBIqcqlsApOVvS w0j47DZ6P36mawIWZi5pmYEEus/SkD8JgwMq6grItMkqZ948DCry5qcbupThkgcWrmkJ6dmvMRMc3 sgPanGppQemRKHkCd0b57PPzi6cFhYXZGz/I0dodBsrg49id0nMMEsQ1qvgunJZfvOqw0FnYbd3kM Ym1mlyAaQHZyhzXHPSM1ktyo1vLV6kYiHMYC1g+FS26tGu8xjub1jjlvPX/seM/9iG3HKuQzqZgtb m/G5bwCA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvBMY-00000008fV6-1VBb; Fri, 12 Apr 2024 07:30:18 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 0880E3004D5; Fri, 12 Apr 2024 09:30:18 +0200 (CEST) Date: Fri, 12 Apr 2024 09:30:17 +0200 From: Peter Zijlstra To: Kuan-Wei Chiu Cc: colyli@suse.de, kent.overstreet@linux.dev, msakai@redhat.com, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, akpm@linux-foundation.org, bfoster@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v3 04/17] lib min_heap: Add type safe interface Message-ID: <20240412073017.GE30852@noisy.programming.kicks-ass.net> References: <20240406164727.577914-1-visitorckw@gmail.com> <20240406164727.577914-5-visitorckw@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240406164727.577914-5-visitorckw@gmail.com> On Sun, Apr 07, 2024 at 12:47:14AM +0800, Kuan-Wei Chiu wrote: > -struct min_heap { > - void *data; > - int nr; > - int size; > -}; > +#define MIN_HEAP_PREALLOCATED(_type, _name, _nr) \ > +struct _name { \ > + int nr; \ > + int size; \ > + _type *data; \ > + _type preallocated[_nr]; \ > +} > @@ -3738,7 +3739,7 @@ static noinline int visit_groups_merge(struct perf_event_context *ctx, > struct perf_cpu_context *cpuctx = NULL; > /* Space for per CPU and/or any CPU event iterators. */ > struct perf_event *itrs[2]; > - struct min_heap event_heap; > + struct perf_event_min_heap event_heap; > struct perf_event **evt; > int ret; > > @@ -3747,11 +3748,9 @@ static noinline int visit_groups_merge(struct perf_event_context *ctx, > > if (!ctx->task) { > cpuctx = this_cpu_ptr(&perf_cpu_context); > - event_heap = (struct min_heap){ > - .data = cpuctx->heap, > - .nr = 0, > - .size = cpuctx->heap_size, > - }; > + event_heap.data = cpuctx->heap; > + event_heap.nr = 0; > + event_heap.size = cpuctx->heap_size; > > lockdep_assert_held(&cpuctx->ctx.lock); > > @@ -3760,11 +3759,9 @@ static noinline int visit_groups_merge(struct perf_event_context *ctx, > css = &cpuctx->cgrp->css; > #endif > } else { > - event_heap = (struct min_heap){ > - .data = itrs, > - .nr = 0, > - .size = ARRAY_SIZE(itrs), > - }; > + event_heap.data = itrs; > + event_heap.nr = 0; > + event_heap.size = ARRAY_SIZE(itrs); > /* Events not within a CPU context may be on any CPU. */ > __heap_add(&event_heap, perf_event_groups_first(groups, -1, pmu, NULL)); > } Not too happy about these. If you ever add more fields they will go uninitialized. Why not keep the existing form and fix the struct name?