From owner-svn-src-all@FreeBSD.ORG Sat Oct 30 13:58:03 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E646F1065672; Sat, 30 Oct 2010 13:58:03 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id C651A8FC08; Sat, 30 Oct 2010 13:58:02 +0000 (UTC) Received: by wwi17 with SMTP id 17so2845811wwi.31 for ; Sat, 30 Oct 2010 06:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=ZT4QpLXxLvhROeCGwGSN+znNgaSaN6Qr5iJyYbojMi0=; b=KupCRTR0nFnYjB60e1se+c0LSee5ap3T6BTqofDs5LDwX3AhpQEEz4lTTLN7Ad1Gnn LwU3/0NzBAWh0jcbrDpw+0RiFSrzq7ExWWKD3Ra0x8nQnDlb8wp/B+YEVPDSrnOeq1yq 4LmFCxn59a4BfRhHVYBOpThfX+nvFxvxQ34tM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=my1BykgFtyV5N7uNVkn6qjXZnhv26NcbNn0NpvOQ1cx5yZEzUklj1mmFsEunYzbSum KpGjgulrotJ30nfAQwfN7CKrwvzCIzzan50McXVUFs0H517gBepry7D1vMHo27uqyWmZ K6PJBhFssdqveoxfVQYAUW7rhsbUro05D9ELA= MIME-Version: 1.0 Received: by 10.216.58.209 with SMTP id q59mr545691wec.41.1288447081194; Sat, 30 Oct 2010 06:58:01 -0700 (PDT) Sender: yanegomi@gmail.com Received: by 10.216.10.198 with HTTP; Sat, 30 Oct 2010 06:58:01 -0700 (PDT) In-Reply-To: <20101030203424.M1007@besplex.bde.org> References: <201010291331.o9TDVAtm027022@svn.freebsd.org> <20101029222159.GA2160@garage.freebsd.pl> <20101030203424.M1007@besplex.bde.org> Date: Sat, 30 Oct 2010 06:58:01 -0700 X-Google-Sender-Auth: e3eVA1vUX1aS3nv1u3ywGwvow1A Message-ID: From: Garrett Cooper To: Bruce Evans Content-Type: multipart/mixed; boundary=000e0ce02a0a96247c0493d5f6ad Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Pawel Jakub Dawidek , David Xu Subject: Re: svn commit: r214510 - in head: include lib/libc/gen sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Oct 2010 13:58:04 -0000 --000e0ce02a0a96247c0493d5f6ad Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sat, Oct 30, 2010 at 3:08 AM, Bruce Evans wrote: > On Sat, 30 Oct 2010, Pawel Jakub Dawidek wrote: > >> On Fri, Oct 29, 2010 at 01:31:10PM +0000, David Xu wrote: >>> >>> Log: >>> =A0Add sysctl kern.sched.cpusetsize to export the size of kernel cpuset= , >>> =A0also add sysconf() key _SC_CPUSET_SIZE to get sysctl value. >>> >>> =A0Submitted by: gcooper >> >> [...] >>> >>> +#ifdef _SC_CPUSET_SIZE >>> + =A0 =A0 =A0 case _SC_CPUSET_SIZE: >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D sizeof(lvalue); >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (sysctlbyname("kern.sched.cpusetsize",= &lvalue, &len, >>> NULL, >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 0) =3D=3D -1) >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (-1); >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (lvalue); >>> +#endif >> >> [...] >>> >>> +static size_t _kern_cpuset_size =3D sizeof(cpuset_t); > > No need for this or its bogus type, since it is a small compile-time > constant value. > >> [...] >>> >>> +/* >>> + * Return the size of cpuset_t at the kernel level >>> + * >>> + * XXX (gcooper): replace ULONG with SIZE once CTLTYPE_SIZE is >>> implemented. >>> + */ >>> +SYSCTL_ULONG(_kern_sched, OID_AUTO, cpusetsize, CTLFLAG_RD, >>> + =A0 =A0&_kern_cpuset_size, 0, "Kernel-level cpuset_t struct size"); >>> + > > Just use: > > SYSCTL_INT(_kern_sched, OID_AUTO, cpusetsize, CTLFLAG_RD, > =A0 =A00, sizeof(cpuset_t), "sizeof(cpuset_t) in the kernel"); > > the same as for all debugging sizeofs in kern_mib.c. =A0(I also changed t= he > style of the message to be more like the ones there. =A0(sysctl -ad | gre= o > sizeof on ref9-i386 shows only 1 other inconsistency: the banal descripti= on > is missing for debug.sizeof.namecache.)) Yeah... it was silly of me to do it that way, in hindsight :(... >> Because it is used via sysconf(3), I don't think it should be converted >> to CTLTYPE_SIZE at all. I even think it would be safer to make >> _kern_cpuset_size a long (sysconf's lvalue is long) and (just for >> consistency) use SYSCTL_LONG(). >> >> Also note, that on i386 long is 32bit and on amd64 long is 64bit, so >> 32bit process running on 64bit system won't be able to read this sysctl. >> Or do we detect 32bit processes on 64bit systems and convert such types >> in the kernel? > > Just use int. =A016-bit ints are only large enough for 8*32767 CPUs, but > 32-bit ints are large enough for 8*2147482647 CPUs, which should be > enough for anyone. =A0Also use 'int value' instead of 'long lvalue' in > sysconf.c. That won't really do much good, otherwise it would oppose the POSIX API definition :/... > Using u_long is also bogus. =A0Because the value is returned by sysconf(3= ), > u_long won't actually work if it is actually needed, because if the > value exceeds LONG_MAX then `return (lvalue)' will blindly overflow. > But the value is very far from exeeding even INT_MAX, so there is no > problem. =A0(Overflow would actually occur earlier, via the type pun of > using sysctl for a u_long variable to read the variable into a plain > long. =A0It is unclear that this type pun is safe even when there is no > overflow.) > > The kernel isn't going to be having any data structures larger than > 2147482647 bytes any time soon, so 32-bit ints are plenty large enough > for returning the size of any data structure in the kernel. =A0However, > 16-bit ints wouldn't be. =A0Careful code might use size_t to avoid > assuming anything about sizeof(int), but with 32-bit ints this mainly > gives bloat when size_t is 64 bits. Ok. Thanks! -Garrett --000e0ce02a0a96247c0493d5f6ad Content-Type: text/x-patch; charset=US-ASCII; name="cpuset_t-less_suckage.patch" Content-Disposition: attachment; filename="cpuset_t-less_suckage.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gfwk3lu30 SW5kZXg6IHN5cy9rZXJuL3NjaGVkX3VsZS5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIHN5cy9rZXJuL3NjaGVk X3VsZS5jCShyZXZpc2lvbiAyMTQ1NTQpCisrKyBzeXMva2Vybi9zY2hlZF91bGUuYwkod29ya2lu ZyBjb3B5KQpAQCAtMjcxMiw4ICsyNzEyLDYgQEAKIAlzYnVmX2RlbGV0ZSh0b3BvKTsKIAlyZXR1 cm4gKGVycik7CiB9Ci0KLXN0YXRpYyBzaXplX3QgX2tlcm5fY3B1c2V0X3NpemUgPSBzaXplb2Yo Y3B1c2V0X3QpOwogI2VuZGlmCiAKIFNZU0NUTF9OT0RFKF9rZXJuLCBPSURfQVVUTywgc2NoZWQs IENUTEZMQUdfUlcsIDAsICJTY2hlZHVsZXIiKTsKQEAgLTI3NTEsMTMgKzI3NDksOSBAQAogICAg IENUTEZMQUdfUkQsIE5VTEwsIDAsIHN5c2N0bF9rZXJuX3NjaGVkX3RvcG9sb2d5X3NwZWMsICJB IiwgCiAgICAgIlhNTCBkdW1wIG9mIGRldGVjdGVkIENQVSB0b3BvbG9neSIpOwogCi0vKiAKLSAq IFJldHVybiB0aGUgc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