From owner-freebsd-current@FreeBSD.ORG Mon Sep 27 21:39:26 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E7181065673; Mon, 27 Sep 2010 21:39:26 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 4A2B58FC08; Mon, 27 Sep 2010 21:39:26 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id E249546B0D; Mon, 27 Sep 2010 17:39:25 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id E39A58A03C; Mon, 27 Sep 2010 17:39:24 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Date: Mon, 27 Sep 2010 17:38:19 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100819; KDE/4.4.5; amd64; ; ) References: <1285601161.7245.7.camel@home-yahoo> <1285604516.7245.16.camel@home-yahoo> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201009271738.19497.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 27 Sep 2010 17:39:24 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: "sbruno@freebsd.org" , Robert Watson , Sean Bruno , "current@freebsd.org" Subject: Re: MAXCPU preparations X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2010 21:39:26 -0000 On Monday, September 27, 2010 5:21:31 pm Robert Watson wrote: > > On Mon, 27 Sep 2010, Sean Bruno wrote: > > >> wouldn't it be better to do a sysctlbyname() and use the real value for the > >> system? > > libmemstat contains some useful sample code showing how this might be done. > > > That was my initial thought (as prodded by scottl and peter). > > > > If it is made dynamic, could this be opening a race condition where the call > > to sysctlbyname() returns a count of CPUS that is in turn changed by the > > offlining of a CPU? Or am I thinking to much about this? > > Yes, you are. MAXCPU is a compile-time constant for kernel builds, so (at > least a the world is today), that can't happen. > > I think there's a reasonable argument that MEMSTAT_MAXCPU should be phased out > and all internal structures in libmemstat should be dynamically sized. > However, core counts aren't growing that fast, and it's quite a bit of work, > and probably not worth it just yet. > > I'm somewhat averse to using MAXCPU in libmemstat, however, because MAXCPU is > actually not a constant in the general case: FreeBSD/i386, for example, > regularly uses two different values: 1 for !SMP kernels, and 32 for SMP > kernels. That's why libmemstat encodes its own value, for better or worse. > > A reasonable alternative would be to replace 32 with MAXCPU * 2, or if we're > feeling particularly optimistic, MAXCPU * 4. Or just another big number, like > 256. A prerequisite for this idea though is that MAXCPU needs to be fixed to export the SMP value to userland rather than the UP value. For example, this code in amd64/include/param.h: #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 32 #else #define MAXCPU 1 #endif would need to change so that !_KERNEL is in the conditional. I do think we should avoid using MAXCPU in userland as much as possible and use the existing sysctl for mp_maxid instead to dynamically allocate arrays. Also, I think we should either fix MAXCPU to export the SMP value to userland, or hide it from userland completely. Exporting the UP value is Just Wrong (tm). -- John Baldwin