Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jun 2012 10:53:03 +0800
From:      David Xu <listlog2011@gmail.com>
To:        Attilio Rao <attilio@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Konstantin Belousov <kib@freebsd.org>, davidxu@freebsd.org
Subject:   Re: svn commit: r237660 - head/lib/libc/gen
Message-ID:  <4FEBC70F.40408@gmail.com>
In-Reply-To: <CAJ-FndD9Hc_KvHe8vC3usVDZh7MYb51gtXsHgmins8dBC3mu_w@mail.gmail.com>
References:  <201206272032.q5RKWjvt031174@svn.freebsd.org> <4FEBB8C9.8070006@gmail.com> <CAJ-FndBdpP4hFPyqHaU6GucXeGi3WT4d%2Bpu-9hCNEpAPZAZQgg@mail.gmail.com> <4FEBC0A2.3010708@gmail.com> <CAJ-FndD9Hc_KvHe8vC3usVDZh7MYb51gtXsHgmins8dBC3mu_w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2012/6/28 10:32, Attilio Rao wrote:
> 2012/6/28, David Xu<listlog2011@gmail.com>:
>> On 2012/6/28 10:21, Attilio Rao wrote:
>>> 2012/6/28, David Xu<listlog2011@gmail.com>:
>>>> On 2012/6/28 4:32, Konstantin Belousov wrote:
>>>>> Author: kib
>>>>> Date: Wed Jun 27 20:32:45 2012
>>>>> New Revision: 237660
>>>>> URL: http://svn.freebsd.org/changeset/base/237660
>>>>>
>>>>> Log:
>>>>>      Optimize the handling of SC_NPROCESSORS_CONF, by using auxv AT_NCPU
>>>>>      value if present.
>>>>>
>>>>>      MFC after:	1 week
>>>>>
>>>>> Modified:
>>>>>      head/lib/libc/gen/sysconf.c
>>>>>
>>>>> Modified: head/lib/libc/gen/sysconf.c
>>>>> ==============================================================================
>>>>> --- head/lib/libc/gen/sysconf.c	Wed Jun 27 20:24:25 2012	(r237659)
>>>>> +++ head/lib/libc/gen/sysconf.c	Wed Jun 27 20:32:45 2012	(r237660)
>>>>> @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
>>>>>     #include<sys/resource.h>
>>>>>     #include<sys/socket.h>
>>>>>
>>>>> +#include<elf.h>
>>>>>     #include<errno.h>
>>>>>     #include<limits.h>
>>>>>     #include<paths.h>
>>>>> @@ -51,6 +52,7 @@ __FBSDID("$FreeBSD$");
>>>>>
>>>>>     #include "../stdlib/atexit.h"
>>>>>     #include "tzfile.h"		/* from ../../../contrib/tzcode/stdtime */
>>>>> +#include "libc_private.h"
>>>>>
>>>>>     #define	_PATH_ZONEINFO	TZDIR	/* from tzfile.h */
>>>>>
>>>>> @@ -585,6 +587,8 @@ yesno:
>>>>>
>>>>>     	case _SC_NPROCESSORS_CONF:
>>>>>     	case _SC_NPROCESSORS_ONLN:
>>>>> +		if (_elf_aux_info(AT_NCPUS,&value, sizeof(value)) == 0)
>>>>> +			return ((long)value);
>>>>>     		mib[0] = CTL_HW;
>>>>>     		mib[1] = HW_NCPU;
>>>>>     		break;
>>>>>
>>>> Will this make controlling the number of CPU online or CPU hotplug
>>>> be impossible on FreeBSD ?
>>> If I think about hotplug CPUs I can think of other 1000
>>> problems/races/bad situations to be fixed before this one, really.
>> These are problems only in kernel, but kib's change is about ABI
>> between userland and kernel, I hope we don't introduce an ABI which
>> is not extendable road stone.
> I'm not entirely sure I see the ABI breakage here.
It is not breakage, it is the ABI thinks number of online cpu is fixed,
obviously, it is not the case in future unless FreeBSD won't support
dynamic number of online cpus.


> If the AT_NCPUS
> becames unconvenient and not correct at some point we can just fix
> sysconf() to not look into the aux vector anymoe.
If you already know this will be a problem, why do you introduce it
and later need to fix it ?

>   Please note that
> AT_NCPUS is already exported nowadays. I think this is instead a
> clever optimization to avoid the sysctl() (usual way to retrieve the
> number of CPUs).
But why don't you cache it in libc ? following code is enough:

static int online_cpu;
if (online_cpu == 0)
     online_cpu = sysctl
return online_cpu;

> Attilio
>
>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4FEBC70F.40408>