[glibc] Fix Linux sysconf(_SC_NPROCESSORS_[CONF|ONLN]) performance problem

Linus Torvalds torvalds@linux-foundation.org
Thu Jun 16 21:00:00 GMT 2011


On Thu, Jun 16, 2011 at 12:07 PM, Ulrich Drepper <drepper@gmail.com> wrote:
>
> I'm not opposed to any improvements.  Do you think I like this
> implementation while every other OS which has these interfaces
> implement sysconf() using a simple syscall?

The thing is, I'd be more impressed by your statement if I actually
believed it. Every time I report a problem with glibc, it does seem
like you're actually against improvements, and instead of improving
glibc code, you _invariably_ blame other things instead.

It might be the kernel interfaces, or it might be "broken programs"
like adobe flash. But never is it glibc itself that is the problem.

So I sent a simple patch that I actually think will improve
performance enormously, and nobody will ever complain. But no, not
acceptable.

We can do it other ways. You already parse /sys/devices/system/cpu for
_SC_NPROCESSORS_CONF, although you do it in an odd way (by iterating
over directory entries). You could just open
/sys/devices/system/cpu/online, and parse the result from there
instead. If that file doesn't exist, the system doesn't support
hotplug, so you can do the caching.

The fact is, the kernel interfaces are ALREADY much better than the
ones you actually use.

Here's a new patch. The code worked when it was a test-program, I
haven't actually tested it within the confines of the glibc thing.
There may be special magical internal glibc names it should use for
fopen/fscanf etc.

                                Linus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-patch
Size: 2475 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20110616/7e700b4f/attachment.bin>


More information about the Libc-alpha mailing list