Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4782307rdb; Tue, 12 Dec 2023 09:09:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpqLNPrdfEqQVfk26u0HzDY3WcbLHDwMfUwQ1tuEWBsg75k9EYTynYLs/2MbpNFQbNEprU X-Received: by 2002:a05:6a21:350d:b0:190:86b:ccf5 with SMTP id zc13-20020a056a21350d00b00190086bccf5mr4298287pzb.14.1702400954620; Tue, 12 Dec 2023 09:09:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702400954; cv=none; d=google.com; s=arc-20160816; b=lscah1S6EwS4gUsV+KXPriP7sfl5tzDjizzQFhDD8f/wZbAmpetbwbEBeh4+vYUjy0 s2Vgbb4Mxwc3sDusaK0ORulQVHR88tAehEe6AquX0tr6HIFLgCe/9hTBi1watbD1OdJZ be/mo9WjuT2j931PL+zqDBz+kjQdHEvCd2Hl0prcS1UstYXvntPl8K3d9W6O4fo9XLnX 0Ziy5vIF5rVUsb89adL7zplhQjVS7orBGrleZnjEAQWwKDVlIZzko6DxHI4trZEV2K3O PGFF8nsLpqRop337LFnKU6qHtFGFrtsj992yWpq4NSILIXbKxy3V4wx4Oorn5MGJVvFj owMg== 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:dkim-signature :dkim-signature:date; bh=QHd/GIvEuAFn2fDqEH8KZE4ZeOg4egPJvYnz2DkhrGo=; fh=5cMh8CKYPGN1F0fzuaj1xrlN5+dBfa6bPK4XIprQ5s0=; b=DpAju+OGAQ6JL4kyBiFMORsA3+wHSY4axNYsKFEKWWNsPV6w3t3dfr52x0lNxo0YjZ RUY/Z9MhqjSY+EHjT8OWgR8hwizkFIh1SGY99Xup3esbkMzOvb2z3LQqiruN9mpxPrM7 eTWTAEF2FvjWZMPv+yBkglqGwfDiLI0XCtrx+KO6nSxFOadwEPYe0bNqsnpdo/heRWDp 5rjV64YHtv4XIHI719U8dX3pPXqFKRIvEigQlrmXNtQ36gET6GlZkW6Y59MnyO1+wRRl 2HKXf9KVxZXikNjDRObs+yexM1wAITbKlhkURyOXSeJk1+LZOZa2JaMCsjGzYvVI0wpl VExA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="A2snbrL/"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id s42-20020a056a0017aa00b006cec77b95a3si7992614pfg.279.2023.12.12.09.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:09:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="A2snbrL/"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 834BF807C869; Tue, 12 Dec 2023 09:09:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232572AbjLLRIy (ORCPT + 99 others); Tue, 12 Dec 2023 12:08:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjLLRIx (ORCPT ); Tue, 12 Dec 2023 12:08:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4868999 for ; Tue, 12 Dec 2023 09:08:59 -0800 (PST) Date: Tue, 12 Dec 2023 18:08:55 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702400937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QHd/GIvEuAFn2fDqEH8KZE4ZeOg4egPJvYnz2DkhrGo=; b=A2snbrL/6oD6Pi26QkpMcd3c/txTX8r0SXA9vlJNAH/E2XeywD2Kb81NjIVJdWVzPBYukG XopQcBKbQZpNqsYAX1n/9U4z/8dSHTEVBaqDLk9Ms+kSn/hLuFgtv9KF3HLbvn3hcopY6C ovowidBdsPT+swOir25Iu6wX5RZRhJQLipK22UPHEjyB5KWxQJhvRv5X/6R7IxXZE3ui68 PRnRnoUWOZuDKZyWpuTdxgLAe6t2nAb+Nw8urVn+xSTahv5ier/Wvvwi+uznGNehsk5FH4 lcnoGlELWOlZdpGY6ZxW24g7SJlOi9XM6WLNHbNyscgUBsDxVgrkZ+xagpxsjQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702400937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QHd/GIvEuAFn2fDqEH8KZE4ZeOg4egPJvYnz2DkhrGo=; b=yjWflIRjqjIJkfSn94KCNfw18uIE9J/UKGXjOXaIBqLVg0R/VVQs83RwX22bSgzMp/8ns/ 9yGDhvQ+vGD37IAw== From: Sebastian Siewior To: Anna-Maria Behnsen Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Frederic Weisbecker , Rik van Riel , Steven Rostedt , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak Subject: Re: [PATCH v9 30/32] timers: Implement the hierarchical pull model Message-ID: <20231212170855.pxX3SZdS@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> <20231201092654.34614-31-anna-maria@linutronix.de> <20231212121404.C2R9VWj1@linutronix.de> <87y1dzlbh8.fsf@somnus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87y1dzlbh8.fsf@somnus> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Dec 2023 09:09:11 -0800 (PST) On 2023-12-12 15:52:19 [+0100], Anna-Maria Behnsen wrote: > Sebastian Siewior writes: > > >> +/* Per group capacity. Must be a power of 2! */ > >> +#define TMIGR_CHILDREN_PER_GROUP 8 > > > > BUILD_BUG_ON_NOT_POWER_OF_2(TMIGR_CHILDREN_PER_GROUP) > > > > Maybe in the .c file. > > > > in tmigr_init() ? Yeah why not. It is used there for the init of the structs. > >> +/** > >> + * struct tmigr_group - timer migration hierarchy group > >> + * @lock: Lock protecting the event information and group hierarchy > >> + * information during setup > >> + * @migr_state: State of the group (see union tmigr_state) > > > > So the lock does not protect migr_state? > > Right - this is not required due to the atomic cmpxchg and seqence > counter. > > > Mind moving it a little down the road? Not only would it be more > > obvious what is protected by the lock but it would also move > > migr_state in another/ later cache line. > > > > Where do you want me to move it? Switch places of lock and migr_state? > When I put it to another place, I would generate holes. A general > question: Is it required to have a look at the struct with pahole also > with LOCKDEP enabled? If yes, lock should stay at the first position. Maybe something like: | struct tmigr_group { | raw_spinlock_t lock; /* 0 4 */ | | /* XXX 4 bytes hole, try to pack */ | | struct tmigr_group * parent; /* 8 8 */ | struct tmigr_event groupevt __attribute__((__aligned__(8))); /* 16 40 */ | | /* XXX last struct has 3 bytes of padding */ | | u64 next_expiry; /* 56 8 */ | /* --- cacheline 1 boundary (64 bytes) --- */ | struct timerqueue_head events; /* 64 16 */ | atomic_t migr_state; /* 80 4 */ | unsigned int level; /* 84 4 */ | int numa_node; /* 88 4 */ | unsigned int num_children; /* 92 4 */ | u8 childmask; /* 96 1 */ | | /* XXX 7 bytes hole, try to pack */ | | struct list_head list; /* 104 16 */ Starting with lock isn't bad as you see everything from here is protected by lock. If it makes sense you could start with list so that the container_of() becomes a NOP. I wouldn't make lockdep a thing and assume it is off. Also, I would assume the architecture is 64bit. However with lockdep enabled it becomes: | struct tmigr_group { | raw_spinlock_t lock; /* 0 64 */ | /* --- cacheline 1 boundary (64 bytes) --- */ | struct tmigr_group * parent; /* 64 8 */ | struct tmigr_event groupevt __attribute__((__aligned__(8))); /* 72 40 */ | | /* XXX last struct has 3 bytes of padding */ | | u64 next_expiry; /* 112 8 */ | struct timerqueue_head events; /* 120 16 */ | /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */ | atomic_t migr_state; /* 136 4 */ | unsigned int level; /* 140 4 */ | int numa_node; /* 144 4 */ | unsigned int num_children; /* 148 4 */ | u8 childmask; /* 152 1 */ | | /* XXX 7 bytes hole, try to pack */ | | struct list_head list; /* 160 16 */ | } __attribute__((__aligned__(8))); so it didn't change much. I shuffled it a bit and everything after migr_state is read only. I don't think looking at pahole is required but in your case it makes sense to put the locked section into a separate cache line vs migr_state variable. It doesn't cost much. You can decide if it is worth to move childmask after the lock so you so you avoid the 7 byte hole at the end. I wouldn't do it to satisfy pahole here. If it makes sense, doesn't hurt/ confuse why not. You would consider the pahole output more on a structure like dentry which is used a _lot_. So saving 4 bytes would mean save a megabyte or ten in the end. > Thanks, > > Anna-Maria > Sebastian