Date: Wed, 27 Oct 2010 09:07:37 -0700 From: Garrett Cooper <gcooper@freebsd.org> To: Kostik Belousov <kostikbel@gmail.com> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Pawel Jakub Dawidek <pjd@freebsd.org>, David Xu <davidxu@freebsd.org> Subject: Re: svn commit: r214409 - head/sys/kern Message-ID: <AANLkTinzP%2Btj3y%2B-r4-%2BgHgCzg6BJ-ZpWru365zysSEF@mail.gmail.com> In-Reply-To: <20101027133307.GQ2392@deviant.kiev.zoral.com.ua> References: <201010270232.o9R2Wsu3084553@svn.freebsd.org> <AANLkTi=2dTVmB8Goj%2BNXq4F6SmZBNS3bxn8gLjmQ%2BdfV@mail.gmail.com> <4CC803A8.3040602@freebsd.org> <20101027082122.GD1848@garage.freebsd.pl> <4CC85552.2020100@freebsd.org> <20101027133307.GQ2392@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Wed, Oct 27, 2010 at 6:33 AM, Kostik Belousov <kostikbel@gmail.com> wrote:
> On Wed, Oct 27, 2010 at 04:37:38PM +0000, David Xu wrote:
>> Pawel Jakub Dawidek wrote:
>> >On Wed, Oct 27, 2010 at 10:49:12AM +0000, David Xu wrote:
>> >>I really hate to see such a problem that userland can not figure out
>> >>what kernel is using, I try hardly to guess, but still can not find
>> >>what it is using. yes, I think the doc may need to be fixed or
>> >>another syscall is needed.
>> >
>> >Maybe you could just add sysctl and eventually put it into sysconf(3)?
>> >
>>
>> I just found a dirty method, use sizeof(long) and kern.smp.maxcpus
>> 32 to figure out the size the kernel is using, because it is how
>> cpuset_t is constructed, wish it will never be changed. ;-)
>>
> I think that sysctl is the way forward, but you may add non-portable
> FreeBSD function to get the value, and use an ELF aux vector interface
> to avoid sysctl most of the time.
How about this patch? I implemented this as a readonly tunable and
sysconf tunable, because (AFAIK) the value that is being tested
shouldn't change during runtime after the system has been booted up,
and figuring that the value wasn't going to change it was better to
lose 4/8 bytes on the kernel stack instead of having to recompute the
value every time in a function call, with the associated lost heap /
stack memory in the process, as the assumption is that this libcall
was going to be called frequently by some programs.
Thanks!
-Garrett
[-- Attachment #2 --]
Index: include/unistd.h
===================================================================
--- include/unistd.h (revision 214413)
+++ include/unistd.h (working copy)
@@ -288,6 +288,7 @@
#if __BSD_VISIBLE
#define _SC_NPROCESSORS_CONF 57
#define _SC_NPROCESSORS_ONLN 58
+#define _SC_CPUSET_SIZE 122
#endif
/* Extensions found in Solaris and Linux. */
Index: lib/libc/gen/sysconf.c
===================================================================
--- lib/libc/gen/sysconf.c (revision 214413)
+++ lib/libc/gen/sysconf.c (working copy)
@@ -597,6 +597,15 @@
return (lvalue);
#endif
+#ifdef _SC_CPUSET_SIZE
+ case _SC_CPUSET_SIZE:
+ len = sizeof(lvalue);
+ if (sysctlbyname("kern.sched.cpusetsize", &lvalue, &len, NULL,
+ 0) == -1)
+ return (-1);
+ return (lvalue);
+#endif
+
default:
errno = EINVAL;
return (-1);
Index: sys/kern/sched_ule.c
===================================================================
--- sys/kern/sched_ule.c (revision 214413)
+++ sys/kern/sched_ule.c (working copy)
@@ -2712,6 +2712,8 @@
sbuf_delete(topo);
return (err);
}
+
+static size_t _kern_cpuset_size = sizeof(cpuset_t);
#endif
SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RW, 0, "Scheduler");
@@ -2748,6 +2750,15 @@
SYSCTL_PROC(_kern_sched, OID_AUTO, topology_spec, CTLTYPE_STRING |
CTLFLAG_RD, NULL, 0, sysctl_kern_sched_topology_spec, "A",
"XML dump of detected CPU topology");
+
+/*
+ * 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_RDTUN,
+ &_kern_cpuset_size, 0, "Kernel-level cpuset_t struct size");
+
#endif
/* ps compat. All cpu percentages from ULE are weighted. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTinzP%2Btj3y%2B-r4-%2BgHgCzg6BJ-ZpWru365zysSEF>
