Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1629751rdb; Mon, 8 Jan 2024 05:41:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsMCWmFyb0HpsqMlBmbxNYod8ux/P9pmq1urBcIxEbn7RIjhhZ0PM7x/Ww73gJfhx3MZC1 X-Received: by 2002:a17:902:d2cb:b0:1d4:7e51:ff6c with SMTP id n11-20020a170902d2cb00b001d47e51ff6cmr1518464plc.121.1704721301485; Mon, 08 Jan 2024 05:41:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704721301; cv=none; d=google.com; s=arc-20160816; b=PZ7ILUSMHBzHQDF6M23icJgc0M6jRoVbcRrPobNtGgl30NMTP5nF2Nh1HqcwKuojEq RxGThqX/k4XUVCHl3J7Sk7UepJMt7JE+G81Q4ry+7NMTBqdzI5IA2JOpVCK4F3teQA41 Q192ceUwtfTaiWuqNE3vDJUyWJWp8rXAXKLwdODSI25Zh0lgEWqpOOMJCUOxDCmTsEr5 s+ykyBynC93TDuAgDIR25BY+nnUdcVf5SIsiS6Ii5wSzE8N/aSqdo2vevVb0UcEPgVL5 VrkHiWV9qlusY7GzNZj/MzswDoux9XvlFHYneTyj16NjmWgJDL3GcYuVPqKJ6BteArk8 9eQQ== ARC-Message-Signature: i=1; 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=eG9T8lTouYuHP4iTNggEDal9BKSEaIu9o9UHqgV4zmU=; fh=QVlrob+87Aa9C/zUUVfXbxBxkNRgWogAIscdHXhwk+w=; b=ftzO7A/1xF9laqxMYIUpZ1FCfc5RGEp1snfdEPJh2xsGsKvCjK9Fr9KovU92N6J6uw 24Z5KcGeScJDh9JJ+ep0m1OMbJvSQeFJmIlGSRwwSb8MGAAwep/5VGuBcDu2RVtMuH0A BbFP13/0LR/zXafTdxV7E5cMDR8ubEEGD9XSHiaPi+KdiykyQhI5SAfbVGwnWuwRy6qh OgFuox/B+3m8RMvCQx/CMsx1pphC3orS93dT+xpjlpg3XymZwU+gEOWvhhsAiPSKcI7v XrJ2SlMGMPKblPRgctzlyrdcc0YvM7hi+6+kBnUzWSdb47plKce7GkE7r7EaOyNwllhh LBNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="g/89ezCx"; spf=pass (google.com: domain of linux-kernel+bounces-19633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k11-20020a170902c40b00b001d40e1162ccsi6229767plk.352.2024.01.08.05.41.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:41:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19633-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=@lunn.ch header.s=20171124 header.b="g/89ezCx"; spf=pass (google.com: domain of linux-kernel+bounces-19633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch 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 F3A4D2840DF for ; Mon, 8 Jan 2024 13:41:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B25C34594A; Mon, 8 Jan 2024 13:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="g/89ezCx" X-Original-To: linux-kernel@vger.kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (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 858A145948; Mon, 8 Jan 2024 13:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=eG9T8lTouYuHP4iTNggEDal9BKSEaIu9o9UHqgV4zmU=; b=g/89ezCx8XKj8W9WmBVIIO1o2v Xrhg/GZiVeJL8+zT0PrmSbue3YHm45GvMqN34rXMHhRVjLn5ggcS5uLitaN9K3ZBf9LvpoTlX3G2l f1q+wmn+Iq76ScsWq6Apwf8I0AEZUWJTBs5u7YApblPFDXs5zD4uka8lxEKjQ+BwNpwc=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1rMpsM-004dvG-Sa; Mon, 08 Jan 2024 14:41:10 +0100 Date: Mon, 8 Jan 2024 14:41:10 +0100 From: Andrew Lunn To: David Laight Cc: Petr =?utf-8?B?VGVzYcWZw61r?= , Eric Dumazet , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , "open list:STMMAC ETHERNET DRIVER" , "moderated list:ARM/STM32 ARCHITECTURE" , "moderated list:ARM/STM32 ARCHITECTURE" , open list , "open list:ARM/Allwinner sunXi SoC support" , Jiri Pirko Subject: Re: [PATCH] net: stmmac: protect statistics updates with a spinlock Message-ID: <32c4095e-ec33-4059-a8d3-f85e18363c77@lunn.ch> References: <20240105113402.0f5f1232@meshulam.tesarici.cz> <20240105121447.11ae80d1@meshulam.tesarici.cz> <20240105142732.1903bc70@meshulam.tesarici.cz> <20240105154558.2ca38aca@meshulam.tesarici.cz> 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: > > You might want to consider per CPU statistics. Since each CPU has its > > own structure of statistics, you don't need atomic. > > > > The code actually using the statistics then needs to sum up the per > > CPU statistics, and using syncp should be sufficient for that. > > Doesn't that consume rather a lot of memory on systems with > 'silly numbers' of cpu? Systems with silly number of CPUS tend to also have silly amounts of memory. We are talking about maybe a dozen u64 here. So the memory usage goes from 144 bytes, to 144K for a 1024CPU system. Is 144K excessive for such a system? > Updating an atomic_t is (pretty much) the same as taking a lock. > unlock() is also likely to also contain an atomic operation. > So if you update more than two atomic_t it is likely that a lock > will be faster. True, but all those 1024 CPUs in your silly system get affected by a lock or an atomic. They all need to do something with there L1 and L2 cache when using atomics. Spending an extra 144K of RAM means the other 1023 CPUs don't notice anything at all during the increment phase, which could be happening 1M times a second. They only get involved when something in user space wants the statistics, so maybe once per second from the SNMP agent. Also, stmmac is not used on silly CPU systems. It used in embedded systems. I doubt its integrated into anything with more than 8 CPUs. Andrew