Skip to contentSkip to conversation

sysctl: Document that sys_sysctl will be removed.

PATCH In review Eric W. Biederman 14 participants 38 messages Jul 10, 2006 – Jul 14, 2006 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysctl: Document that sys_sysctl will be removed.

---
 Documentation/feature-removal-schedule.txt |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Documentation/feature-removal-schedule.txt +11 -0
index e978943..bef1bf0 100644
@@ -250,3 +250,14 @@ Why:	These drivers never compiled since 
 Who:	Jean Delvare <[email protected]>
 
 ---------------------------
+
+What:	sys_sysctl
+When:	January 2007
+Why:	The same information is available through /proc/sys and that is the
+	interface user space prefers to use. And there do not appear to be
+	any existing user in user space of sys_sysctl.  The additional
+	maintenance overhead of keeping a set of binary names gets
+	in the way of doing a good job of maintaining this interface.
+
+Who:	Eric Biederman <[email protected]>
+
Signature · 1 line
1.4.1.gac83a
#1 lore raw
Quoted 14 lines · On Mon, 10 Jul 2006 16:39:47 -0600 Eric W. Biederman wrote:
---
 Documentation/feature-removal-schedule.txt |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Documentation/feature-removal-schedule.txt +0 -0
index e978943..bef1bf0 100644
@@ -250,3 +250,14 @@ Why:	These drivers never compiled since 
 Who:	Jean Delvare <[email protected]>
 
 ---------------------------

Documentation/feature-removal-schedule.txt Why: These drivers never compiled since · line 262

Quoted 10 lines
Documentation/feature-removal-schedule.txt +10 -0
+
+What:	sys_sysctl
+When:	January 2007
+Why:	The same information is available through /proc/sys and that is the
+	interface user space prefers to use. And there do not appear to be
+	any existing user in user space of sys_sysctl.  The additional
+	maintenance overhead of keeping a set of binary names gets
+	in the way of doing a good job of maintaining this interface.
+
+Who:	Eric Biederman <[email protected]>

aha, patch 1/2 and patch 2/2 would have helped that. :)

---
~Randy

#2 lore raw
Quoted 2 lines · Randy.Dunlap

aha, patch 1/2 and patch 2/2 would have helped that. :)

Sorry. I finally have found the original deprecation commit.

Quoted 15 lines

commit 073cd7b5515a7f5b74dbb4917c717e3c390013e7

Author: ak <ak>
Date:   Sat Jul 12 16:45:55 2003 +0000

[PATCH] Deprecate numerical sysctl

Deprecate the numerical sysctl name space. People can use /proc/sys instead.

The numeric name space was never well maintained and especially in distribution kernels is not very consistent (everybody has their own extensions, conflicting with others). It's also a great source of rejects when merging patches. The name-based /proc/sys is a much better interface for this, which people should use instead.

Quoted 8 lines

Discussion of this on l-k found no advocate for it, so it seems to not be very popular anyways.

This patch deprecates numerical name space accesses to make it possible to remove them in the future. The only exception is kernel.version, which is used by glibc (this one has to be maintained forever)

BKrev: 3f103b43JQH2fwSWpRLoTKziIiqH1w

The comment about kernel.version is odd. That information is available in uname so I can't imagine why sys_sysctl would be an interesting source. Also kernel.version is the compile string so it is pretty uninteresting to glibc.

I guess if it is really needed someone will scream before the code gets deleted completely.

Eric

#3 lore raw
Quoted 3 lines

The comment about kernel.version is odd. That information is available in uname so I can't imagine why sys_sysctl would be an interesting source.

glibc used it (pass tense); sometimes it's better to not ask why ;)

#4 lore raw

PATCH 1/1 Use uname not sysctl to get the kernel revision

Currently it is felt but at least a subset of the kernel maintainers that the binary sysctl interface is not maintainable, and the /proc /sys interface should be used instead. In investigating this it turns out that the pthread code in glibc for detecting a SMP kernel appears to be the primary user.

The information that we are asking for is available from the uname system call so I don't understand why the code is using sysctl.

To understand the cost of the various approaches I put together a little test program. Using time for timing and running 100000 repetitions of the various system calls I get about

sysctl: 0.3s to 0.2s
uname:  0.1s to 0.07s
proc:   7.5 to  4.1s

proc is significantly slower which puzzles me.
But uname is noticeably faster than sysctl and uname is more portable across linux flavors. So updating the glibc pthread code to use uname looks like the right way to implement is_smp_system.

I do think detecting a SMP kernel to enable busy waiting on contended mutexes is a very peculiar thing to be doing.

My test performance test program:

Quoted 53 lines

#include <string.h>
#include <stdio.h>
#include <sys/utsname.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#include <fcntl.h>
#include <unistd.h>

static void uname_test(void)

{
	struct utsname uts;
	uname(&uts);
}

static void proc_test(void)

{
	int fd;
	char buf[512];
	fd = open("/proc/sys/kernel/version", O_RDONLY);
	read(fd, buf, sizeof(buf));
	close(fd);
}

static void sysctl_test(void)

{
	static int sysctl_args[] = { CTL_KERN, KERN_VERSION };
	char buf[512];
	size_t reslen = sizeof(buf);

	sysctl(sysctl_args, sizeof(sysctl_args)/sizeof(sysctl_args[0]),
		buf, &reslen, NULL, 0);
}

int main(int argc, char *argv[])

{
	void (*test)(void) = NULL;
	int reps = -1;
	int i;

	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--sysctl") == 0)
			test = sysctl_test;
		else if (strcmp(argv[i], "--uname") == 0)
			test = uname_test;
		else if (strcmp(argv[i], "--proc") == 0)
			test = proc_test;
		else 
			reps = atol(argv[i]);
	}
	if ((reps == -1) || (test == NULL)) {
		fprintf(stderr, "usage: [--sysctl | --uname | --proc] <reps>\n");
Quoted 8 lines
		return 1;
	}

	for (i = 0; i < reps; i++) {
		test();
	}
	return 0;
}

My patch to use uname instead of proc or sysctl to get the

nptl/sysdeps/unix/sysv/linux/smp.h renamed from nptl/sysdeps/unix/sysv/linux/smp.h-sysctl +5 -24
@@ -17,11 +17,8 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <errno.h>
-#include <fcntl.h>
 #include <string.h>
-#include <sys/sysctl.h>
-#include <not-cancel.h>
+#include <sys/utsname>
 
 /* Test whether the machine has more than one processor.  This is not the
    best test but good enough.  More complicated tests would require `malloc'
@@ -29,24 +26,8 @@
 static inline int
 is_smp_system (void)
 {
-  static const int sysctl_args[] = { CTL_KERN, KERN_VERSION };
-  char buf[512];
-  size_t reslen = sizeof (buf);
-
-  /* Try reading the number using `sysctl' first.  */
-  if (__sysctl ((int *) sysctl_args,
-		sizeof (sysctl_args) / sizeof (sysctl_args[0]),
-		buf, &reslen, NULL, 0) < 0)
-    {
-      /* This was not successful.  Now try reading the /proc filesystem.  */
-      int fd = open_not_cancel_2 ("/proc/sys/kernel/version", O_RDONLY);
-      if (__builtin_expect (fd, 0) == -1
-	  || (reslen = read_not_cancel (fd, buf, sizeof (buf))) <= 0)
-	/* This also didn't work.  We give up and say it's a UP machine.  */
-	buf[0] = '\0';
-
-      close_not_cancel_no_status (fd);
-    }
-
-  return strstr (buf, "SMP") != NULL;
+  struct utsname uts;
+  if (uname(&uts) < 0)
+	  uts.version[0] = '\0';
+  return strstr (uts.version, "SMP") != NULL;
 }
#5 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 3 lines · Eric W. Biederman

But uname is noticeably faster than sysctl and uname is more portable across linux flavors. So updating the glibc pthread code to use uname looks like the right way to implement is_smp_system.

This is (was?) not the universal through. We used uname at some point but then I did some profiling and sysctl turned out to be faster.

If the reverse is true now I can certainly look into changing this but the evidence and ideally has to be there. The simplicity of the uname code should mean that it's faster.

In a year or two I'll remove the test anyway. By then there will likely not be any UP kernels on reasonable machines anymore and I can drop all the conditional code.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#6 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 7 lines · Ulrich Drepper
Quoted 3 lines · Eric W. Biederman

But uname is noticeably faster than sysctl and uname is more portable across linux flavors. So updating the glibc pthread code to use uname looks like the right way to implement is_smp_system.

This is (was?) not the universal through. We used uname at some point but then I did some profiling and sysctl turned out to be faster.

I track the code bask as far as I could and back to about 2000 in pthread.c when the code was introduced it always used sys_sysctl.

Quoted 3 lines

If the reverse is true now I can certainly look into changing this but the evidence and ideally has to be there. The simplicity of the uname code should mean that it's faster.

The evidence and ideally what has to be there?

Quoted 3 lines

In a year or two I'll remove the test anyway. By then there will likely not be any UP kernels on reasonable machines anymore and I can drop all the conditional code.

Well there are embedded targets but I guess uclibc takes care of them.

Unless a darn good reason for keeping it is found, sys_sysctl won't be in the kernel several months from now. And uname is faster by a large margin than /proc.

Right now because there has been a deprecated note in "include/linux/sysctl.h" since 2003 people currently feel fine with letting sys_sysctl code bit rot. I am trying to resolve that situation most likely by just updating the few stray pieces of user space that care and then cutting out that chunk of kernel code.

Eric

#7 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 3 lines · Eric W. Biederman

Unless a darn good reason for keeping it is found, sys_sysctl won't be in the kernel several months from now. And uname is faster by a large margin than /proc.

Um, if glibc is using sys_sysctl, then that's a pretty good reason. Once we remove it from the kernel, then people will be forced to upgrade glibc's before they can install a newer kernel. Can we please give people some time for an version of glibc with this change to make it out to most deployed systems, first? It's really annoying when it's not possible to install a stock kernel.org kernel on a system, and often upgrading glibc is not a trivial thing to do on a distribution userspace, especially if there is a concern for ISV compatibility. (Especially if C++ code is involved, unfortunately.)

Quoted 5 lines

Right now because there has been a deprecated note in "include/linux/sysctl.h" since 2003 people currently feel fine with letting sys_sysctl code bit rot. I am trying to resolve that situation most likely by just updating the few stray pieces of user space that care and then cutting out that chunk of kernel code.

What we should do is what we've done in the past before removing a system call like this. printk a deprecation warning no more than n times an hours with the process name using the deprecated interface. A deprecated note in a header isn't necessarily something which will be noticed by userspace programmers. Heck, it isn't even in Documentation/feature-removal-schedule.txt yet.

If people want to remove it, let's please do this in an orderly fashion, and with ample warning that people besides kernel developers will actually *notice*.

- Ted

P.S. I happen to be one those developers who think the binary interface is not so bad, and for compared to reading from /proc/sys, the sysctl syscall *is* faster. But at the same there, there really isn't anything where really does require that kind of speed, so that point is moot. But at the same time, what is the cost of leaving sys_sysctl in the kernel for an extra 6-12 months, or even longer, starting from now?

Or if we going to remove parts of sysctl, can we at least keep enough there so that existing glibc systems don't break?

#8 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 9 lines · Theodore Tso

Um, if glibc is using sys_sysctl, then that's a pretty good reason. Once we remove it from the kernel, then people will be forced to upgrade glibc's before they can install a newer kernel. Can we please give people some time for an version of glibc with this change to make it out to most deployed systems, first? It's really annoying when it's not possible to install a stock kernel.org kernel on a system, and often upgrading glibc is not a trivial thing to do on a distribution userspace, especially if there is a concern for ISV compatibility. (Especially if C++ code is involved, unfortunately.)

glibc still works, just slower. But I think the best strategy is just to emulate the single sysctl glibc is using and printk for the rest.

Quoted 3 lines

What we should do is what we've done in the past before removing a system call like this. printk a deprecation warning no more than n times an hours with the process name using the deprecated interface.

We did this some time ago, but Andrew took it out (partly because the original code was somewhat broken and the printk tended to trigger too often in crashme)

Hopefully he puts it back in now.

Quoted 7 lines

P.S. I happen to be one those developers who think the binary interface is not so bad, and for compared to reading from /proc/sys, the sysctl syscall *is* faster. But at the same there, there really isn't anything where really does require that kind of speed, so that point is moot. But at the same time, what is the cost of leaving sys_sysctl in the kernel for an extra 6-12 months, or even longer, starting from now?

The numerical namespace for sysctl is unsalvagable imho. e.g. distributions regularly break it because there is no central repository of numbers so it's not very usable anyways in practice.

-Andi

#9 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 5 lines · Andi Kleen

glibc still works, just slower. But I think the best strategy is just to emulate the single sysctl glibc is using and printk for the rest.

That sounds reasonable, yes.

Quoted 7 lines
Quoted 3 lines

point is moot. But at the same time, what is the cost of leaving sys_sysctl in the kernel for an extra 6-12 months, or even longer, starting from now?

The numerical namespace for sysctl is unsalvagable imho. e.g. distributions regularly break it because there is no central repository of numbers so it's not very usable anyways in practice.

That may be true, but it doesn't answer the question, what's the cost of leaving in sys_sysctl in there for now?

In any case, if we really do want to get rid of it, the next step should be a working deprecation printk and adding something to Documentation/feature-removal-schedule.txt.

- Ted

#10 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 2 lines · Theodore Tso

That may be true, but it doesn't answer the question, what's the cost of leaving in sys_sysctl in there for now?

Among other things the implementation of all of:
CTL_KERN, {KERN_OSTYPE, KERN_OSRELEASE, KERN_OSREV, KERN_VERSION,

          KERN_SECUREMASK,KERN_PROF,KERN_NODENAME,KERN_DOMAINNAME }

are broken in kernel/sysctl.c because the locking is missing.

Eric

#11 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Theodore Tso
Quoted 11 lines · Theodore Tso
Quoted 3 lines · Andi Kleen

glibc still works, just slower. But I think the best strategy is just to emulate the single sysctl glibc is using and printk for the rest.

That sounds reasonable, yes.

Quoted 4 lines
Quoted 3 lines

point is moot. But at the same time, what is the cost of leaving sys_sysctl in the kernel for an extra 6-12 months, or even longer, starting from now?

Quoted 6 lines
Quoted 3 lines

The numerical namespace for sysctl is unsalvagable imho. e.g. distributions regularly break it because there is no central repository of numbers so it's not very usable anyways in practice.

That may be true, but it doesn't answer the question, what's the cost of leaving in sys_sysctl in there for now?

For once linux/sysctl.h is one of the biggest source of patch rejects. The sooner it goes the better.

Quoted 3 lines

In any case, if we really do want to get rid of it, the next step should be a working deprecation printk

It was in there for months already.

Quoted 2 lines

and adding something to
Documentation/feature-removal-schedule.txt.

That is what Eric's patch did.

-Andi

#12 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Theodore Tso

Theodore Tso <[email protected]> wrote on 07/12/2006 06:24:14 PM:

Quoted 5 lines · Eric W. Biederman
Quoted 3 lines

Unless a darn good reason for keeping it is found, sys_sysctl won't be in the kernel several months from now. And uname is faster by a large margin than /proc.

Quoted 10 lines

Um, if glibc is using sys_sysctl, then that's a pretty good reason. Once we remove it from the kernel, then people will be forced to upgrade glibc's before they can install a newer kernel. Can we please give people some time for an version of glibc with this change to make it out to most deployed systems, first? It's really annoying when it's not possible to install a stock kernel.org kernel on a system, and often upgrading glibc is not a trivial thing to do on a distribution userspace, especially if there is a concern for ISV compatibility. (Especially if C++ code is involved, unfortunately.)

We will need an implementation that will fall back to sys_sysctl for older kernels. This is already common practice in glibc. I don't really understand the performance concern because it seems to me that _is_smp_system() is only called once per process.

But isn't this the kind of thing that the Aux Vector is for? I like vDSO too, but I think it is best deployed for information of a more dynamic nature and performance sensitive.

#13 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 8 lines

We will need an implementation that will fall back to sys_sysctl for older kernels. This is already common practice in glibc. I don't really understand the performance concern because it seems to me that _is_smp_system() is only called once per process.

But isn't this the kind of thing that the Aux Vector is for? I like vDSO too, but I think it is best deployed for information of a more dynamic nature and performance sensitive.

For a simple "is_smp" kind of flag, I would tend to agree with the above... for more complex NUMA topology and/or cache characteristics, which is quite a bigger amount of information, I'm not sure it's worth copying all of that data on every process exec (and making the initial AT_ parsing slower). Especially since very few processes actually care about those.

Ben.

#14 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines

We will need an implementation that will fall back to sys_sysctl for older kernels. This is already common practice in glibc. I don't really understand the performance concern because it seems to me that _is_smp_system() is only called once per process.

But isn't this the kind of thing that the Aux Vector is for? I like vDSO too, but I think it is best deployed for information of a more dynamic nature and performance sensitive.

Quoted 6 lines

For a simple "is_smp" kind of flag, I would tend to agree with the above... for more complex NUMA topology and/or cache characteristics, which is quite a bigger amount of information, I'm not sure it's worth copying all of that data on every process exec (and making the initial AT_ parsing slower). Especially since very few processes actually care about those.

I've actually spent some thought on that recently. The motivation came from someone who wanted the number of CPUs in a fast way to tune AMD64 memcpy etc. better.

My proposal was to supply four new count:
number of cores, number of siblings, number of sockets, number of nodes

These all fit easily in 16bit so it would be 2 new entries in the aux vector (128 bit total). Shouldn't be much overhead to write this.

If you need more exact topology you can probably eat the overhead of parsing /proc/cpuinfo or read it from sysfs (or just use libnuma which supplies most of this in an easy way)

Doing it in a vDSO would be in theory ok for me too, except that x86-64 doesn't have one so far. Even in vDSO I wouldn't add much more than this (like bitmaps and similar) because otherwise cpu/node hotplug could be racy. Also I'm reluctant to redo /proc/cpuinfo and /sys for this.

-Andi

#15 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Theodore Tso
Quoted 5 lines · Theodore Tso
Quoted 3 lines · Eric W. Biederman

Unless a darn good reason for keeping it is found, sys_sysctl won't be in the kernel several months from now. And uname is faster by a large margin than /proc.

Quoted 9 lines

Um, if glibc is using sys_sysctl, then that's a pretty good reason. Once we remove it from the kernel, then people will be forced to upgrade glibc's before they can install a newer kernel. Can we please give people some time for an version of glibc with this change to make it out to most deployed systems, first? It's really annoying when it's not possible to install a stock kernel.org kernel on a system, and often upgrading glibc is not a trivial thing to do on a distribution userspace, especially if there is a concern for ISV compatibility. (Especially if C++ code is involved, unfortunately.)

I agree.

The reason for stopping this is that sys_sysctl at that location in glibc is unnecessary, we can use uname now.

Currently that usage by glibc gives false positives if we want to warn users.

Quoted 6 lines
Quoted 5 lines

Right now because there has been a deprecated note in "include/linux/sysctl.h" since 2003 people currently feel fine with letting sys_sysctl code bit rot. I am trying to resolve that situation most likely by just updating the few stray pieces of user space that care and then cutting out that chunk of kernel code.

Quoted 6 lines

What we should do is what we've done in the past before removing a system call like this. printk a deprecation warning no more than n times an hours with the process name using the deprecated interface. A deprecated note in a header isn't necessarily something which will be noticed by userspace programmers. Heck, it isn't even in Documentation/feature-removal-schedule.txt yet.

I sent Andrew patches yesterday to put it in Documentation/feature-remove-schedule.txt, and to print a warning, and to optionally compile out sys_sysctl.

Quoted 3 lines

If people want to remove it, let's please do this in an orderly fashion, and with ample warning that people besides kernel developers will actually *notice*.

I agree. Part of that beyond the deprecated message is sending patches to fixup the few remaining users and talking about it a lot so even if someone doesn't run the kernels with deprecated message they might notice something.

Quoted 9 lines

- Ted

P.S. I happen to be one those developers who think the binary interface is not so bad, and for compared to reading from /proc/sys, the sysctl syscall *is* faster. But at the same there, there really isn't anything where really does require that kind of speed, so that point is moot. But at the same time, what is the cost of leaving sys_sysctl in the kernel for an extra 6-12 months, or even longer, starting from now?

The core problem is enough people have read that depreciated warning that the binary interface of kernel/sysctl.c is not being maintained seriously. So the code must move out of this half deprecated state. Either to all of the way gone (preferably) or reinstated as an interface that we are serious about maintaining. Code that bit rots and people don't care is a problem.

Quoted 2 lines

Or if we going to remove parts of sysctl, can we at least keep enough there so that existing glibc systems don't break?

That is not a problem. glibc will happily fall back to reading the values from /proc/sys/kernel/version if sysctl fails. It just makes more sense (to me at least) to use uname for getting uname data.

Eric

#17 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#18 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 4 lines · Ulrich Drepper
Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

AND rather than OR would be even better. So glibc could find kernel version, etc. and topology in the vDSO cheaply.

Jakub

#19 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 7 lines · Jakub Jelinek
Quoted 3 lines · Ulrich Drepper
Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

AND rather than OR would be even better. So glibc could find kernel version, etc. and topology in the vDSO cheaply.

Wouldn't it make more sense for this to be in ELF tags, rather than the vdso? Another alternative, I guess, would be to put a pointer in the ELF tags, which may point into the vdso.

-hpa

#20 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 11 lines · H. Peter Anvin
Quoted 6 lines · Jakub Jelinek
Quoted 3 lines · Ulrich Drepper
Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

AND rather than OR would be even better. So glibc could find kernel version, etc. and topology in the vDSO cheaply.

Wouldn't it make more sense for this to be in ELF tags, rather than the vdso? Another alternative, I guess, would be to put a pointer in the ELF tags, which may point into the vdso.

Cheap and simple access to topology information would be interesting.

Glibc just wants to know if our kernel is SMP so it can know if it is ok to busy wait for a bit waiting for a mutex. Or if busy waiting is a complete loss.

The practical challenge is that topology information is not fixed but potentially varies at runtime.

Ulrich what would be interesting besides the possibility of having multiple cpus?

Eric

#21 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 14 lines · Eric W. Biederman
Quoted 11 lines · H. Peter Anvin
Quoted 6 lines · Jakub Jelinek
Quoted 3 lines · Ulrich Drepper
Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

AND rather than OR would be even better. So glibc could find kernel version, etc. and topology in the vDSO cheaply.

Wouldn't it make more sense for this to be in ELF tags, rather than the vdso? Another alternative, I guess, would be to put a pointer in the ELF tags, which may point into the vdso.

Quoted 5 lines

Cheap and simple access to topology information would be interesting.

Glibc just wants to know if our kernel is SMP so it can know if it is ok to busy wait for a bit waiting for a mutex. Or if busy waiting is a complete loss.

with current power management... busy waiting pretty much is a loss even on UP

#22 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 19 lines · Arjan van de Ven
Quoted 11 lines · Eric W. Biederman
Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Jakub Jelinek
Quoted 3 lines · Ulrich Drepper
Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

AND rather than OR would be even better. So glibc could find kernel version, etc. and topology in the vDSO cheaply.

Wouldn't it make more sense for this to be in ELF tags, rather than the

vdso?

Quoted 1 line
Quoted 1 line

Another alternative, I guess, would be to put a pointer in the ELF tags,

which

Quoted 4 lines
Quoted 1 line

may point into the vdso.

Cheap and simple access to topology information would be interesting.

Quoted 7 lines
Quoted 3 lines

Glibc just wants to know if our kernel is SMP so it can know if it is ok to busy wait for a bit waiting for a mutex. Or if busy waiting is a complete loss.

with current power management... busy waiting pretty much is a loss even on UP

It is a short busy wait before falling asleep. I assume you mean busy wait is a loss even on SMP?

Eric

#23 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 3 lines

It is a short busy wait before falling asleep. I assume you mean busy wait is a loss even on SMP?

eh yeah I forgot to think for a second. But yes even for SMP busy wait is pretty bad power wise nowadays.. at least if you wait more than a few hundred cycles. (and if you wait less... then it's almost unlikely that it'll be useful as well)

#24 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 8 lines · Arjan van de Ven
Quoted 2 lines

It is a short busy wait before falling asleep. I assume you mean busy wait is a loss even on SMP?

eh yeah I forgot to think for a second. But yes even for SMP busy wait is pretty bad power wise nowadays.. at least if you wait more than a few hundred cycles. (and if you wait less... then it's almost unlikely that it'll be useful as well)

It depends greatly; if a lock is likely to get released by the user after a few memory accesses, spinning is likely to be a win.

-hpa

#25 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 11 lines · H. Peter Anvin
Quoted 7 lines · Arjan van de Ven
Quoted 2 lines

It is a short busy wait before falling asleep. I assume you mean busy wait is a loss even on SMP?

eh yeah I forgot to think for a second. But yes even for SMP busy wait is pretty bad power wise nowadays.. at least if you wait more than a few hundred cycles. (and if you wait less... then it's almost unlikely that it'll be useful as well)

It depends greatly; if a lock is likely to get released by the user after a few memory accesses, spinning is likely to be a win.

But this requires that the lock be short lived, and highly contended.

If the lock is not short lived then the release is like to be a long ways off. If the lock is not highly contended then you are not likely to hit the window when someone else as the contended lock.

How frequent are highly contended short lived locks in user space?

Eric

#26 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 6 lines · Eric W. Biederman
Quoted 3 lines
Quoted 1 line

It depends greatly; if a lock is likely to get released by the user after a few memory accesses, spinning is likely to be a win.

But this requires that the lock be short lived, and highly contended.

Correct, and incorrect, in that order.

The contention level of the lock determines how likely you are to fail to acquire it immediately, not how long it takes until it can be acquired *after you know a failure has already happened.*

Quoted 3 lines

If the lock is not short lived then the release is like to be a long ways off. If the lock is not highly contended then you are not likely to hit the window when someone else as the contended lock.

The last sentence makes no sense either grammatically or technically. Sorry.

Quoted 1 line

How frequent are highly contended short lived locks in user space?

Short-lived locks (which may be significantly contended) are very common to protect data structures.

-hpa

#27 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Eric W. Biederman

Ar Mer, 2006-07-12 am 16:26 -0600, ysgrifennodd Eric W. Biederman:

Quoted 5 lines

If the lock is not short lived then the release is like to be a long ways off. If the lock is not highly contended then you are not likely to hit the window when someone else as the contended lock.

How frequent are highly contended short lived locks in user space?

I'm not sure it matters.

If you want to do the job right then do this

- Stick an indicator of how much else wants to run on this CPU in the vsyscall page or similar location

In your locks you can now do

              while(try_and_grab_lock() == FAILED) {
                       if (kernelpage->waiting > 0)
                              sys_somelockwaitthing()
              }

Furthermore the kernel can be intelligent about the waiting indicator for power or other global scheduling reasons

[Disclaimer: There is a patent issue around this technique but its not one that will impact GPL code as permissions are given for GPL use.]

Alan

#28 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 4 lines · Alan Cox

[Disclaimer: There is a patent issue around this technique but its not one that will impact GPL code as permissions are given for GPL use.]

glibc is (and has to be) LGPL.

Anyway, it seems absolutely insane that having a programmable threshold for spinning is patented...

-hpa

#29 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Ar Mer, 2006-07-12 am 16:19 -0700, ysgrifennodd H. Peter Anvin:

Quoted 4 lines

glibc is (and has to be) LGPL.

Anyway, it seems absolutely insane that having a programmable threshold for spinning is patented...

I'm not aware programmable thresholds are patented/patent-pending, just having the kernel indicate through a shared variable whether other tasks are waiting so that it avoids syscalls and latency costs.

#30 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Alan Cox
Quoted 5 lines · Alan Cox

Ar Mer, 2006-07-12 am 16:26 -0600, ysgrifennodd Eric W. Biederman:

Quoted 4 lines

If the lock is not short lived then the release is like to be a long ways off. If the lock is not highly contended then you are not likely to hit the window when someone else as the contended lock.

Quoted 8 lines
Quoted 1 line

How frequent are highly contended short lived locks in user space?

I'm not sure it matters.

If you want to do the job right then do this

- Stick an indicator of how much else wants to run on this CPU in the vsyscall page or similar location

Except that "this cpu" doesn't really mean anything in userspace, and while I think Andi has some tricks to get some sort of CPU number to userspace (though it's really only valid during the execution of the instruction that reads it :) I haven't yet found an equivalent for powerpc (and possibly other architectures will have the same problem).

Quoted 14 lines

In your locks you can now do

              while(try_and_grab_lock() == FAILED) {
                       if (kernelpage->waiting > 0)
                              sys_somelockwaitthing()
              }

Furthermore the kernel can be intelligent about the waiting indicator for power or other global scheduling reasons

[Disclaimer: There is a patent issue around this technique but its not one that will impact GPL code as permissions are given for GPL use.]

Alan

#31 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 12 lines · Benjamin Herrenschmidt
Quoted 5 lines

If you want to do the job right then do this

- Stick an indicator of how much else wants to run on this CPU in the vsyscall page or similar location

Except that "this cpu" doesn't really mean anything in userspace, and while I think Andi has some tricks to get some sort of CPU number to userspace (though it's really only valid during the execution of the instruction that reads it :) I haven't yet found an equivalent for powerpc (and possibly other architectures will have the same problem).

Sure it does... although its validity in terms of a locality metric decays with time.

-hpa

#32 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Eric W. Biederman
Quoted 19 lines · Eric W. Biederman
Quoted 10 lines · H. Peter Anvin
Quoted 6 lines · Jakub Jelinek
Quoted 3 lines · Ulrich Drepper
Quoted 1 line · Roland McGrath

We could also put the uname info (modulo nodename) into the vDSO.

Or even better: real topology information.

AND rather than OR would be even better. So glibc could find kernel version, etc. and topology in the vDSO cheaply.

Wouldn't it make more sense for this to be in ELF tags, rather than the vdso? Another alternative, I guess, would be to put a pointer in the ELF tags, which may point into the vdso.

Cheap and simple access to topology information would be interesting.

Glibc just wants to know if our kernel is SMP so it can know if it is ok to busy wait for a bit waiting for a mutex. Or if busy waiting is a complete loss.

Quoted 6 lines

The practical challenge is that topology information is not fixed but potentially varies at runtime.

Ulrich what would be interesting besides the possibility of having multiple cpus?

Something that might make sense to ask CPU vendors for in the future: an instruction that can either trap or be a noop (or better, cpu_relax) based on a control register.

Not that that solves any problem any time soon.

-hpa

#33 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Eric W. Biederman

Eric W. Biederman wrote:
[]

Quoted 3 lines

Glibc just wants to know if our kernel is SMP so it can know if it is ok to busy wait for a bit waiting for a mutex. Or if busy waiting is a complete loss.

BTW, with smp-alternatives thing merged, "SMP or not" may not be that simple question anymore.

I for one stopped compiling UP and SMP kernels for x86 since 2.6.17, because SMP kernel works just fine on UP, including benchmarks (as opposed to SMP kernel w/o smp-alternatives). But I don't remember if uname shows SMP in this case or not (don't have any running UP machine with that kernel right now).

But the thing is: smp-alternatives + cpu-hotplug changes things at runtime...

/mjt

#34 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Eric W. Biederman
Quoted 2 lines · Eric W. Biederman

Ulrich what would be interesting besides the possibility of having multiple cpus?

What is needed for various things like memory handling etc is all topology information. Somebody might remember the numa library proposal I had in April 2004 which was cast aside because people were only looking for a "quick fix". Well, the problem still isn't solved.

IMO the vdso should export information about:

- processors and their relationship (hyperthreads, cores)

- the CPU caches and how they relate to the cores (e.g., dual core with shared L2)

- local main memory for each processor

- relative costs of the memory access of the various memory regions (for numa local memory to a node, intra-node costs)

- ideally, relative costs main memory and CPU caches

All this information can be steadily updated by the kernel as new CPUs/memory get added/removed. The vdso should have functions to access this information. It's easy enough to make this access race free.

I guess I should try to come up with a representation for this knowledge. Collecting the information (except the costs) should be easy. Determining the costs also shouldn't be that hard but it can be very useful. Some of this information could be determined at userlevel but you really don't want every process to compute all this from scratch. And stored data in a file is stale if the system changes.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#36 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

In reply to Ulrich Drepper
Quoted 28 lines · Ulrich Drepper
Quoted 2 lines · Eric W. Biederman

Ulrich what would be interesting besides the possibility of having multiple cpus?

What is needed for various things like memory handling etc is all topology information. Somebody might remember the numa library proposal I had in April 2004 which was cast aside because people were only looking for a "quick fix". Well, the problem still isn't solved.

IMO the vdso should export information about:

- processors and their relationship (hyperthreads, cores)

- the CPU caches and how they relate to the cores (e.g., dual core with shared L2)

- local main memory for each processor

- relative costs of the memory access of the various memory regions (for numa local memory to a node, intra-node costs)

- ideally, relative costs main memory and CPU caches

All this information can be steadily updated by the kernel as new CPUs/memory get added/removed. The vdso should have functions to access this information. It's easy enough to make this access race free.

Quoted 6 lines

I guess I should try to come up with a representation for this knowledge. Collecting the information (except the costs) should be easy. Determining the costs also shouldn't be that hard but it can be very useful. Some of this information could be determined at userlevel but you really don't want every process to compute all this from scratch. And stored data in a file is stale if the system changes.

The history of Linux shows that auto-tuning while not always perfect is much more effective than manual tuning. How are you envisioning using this information?

I find it really easy to see how topology information can be used to manually tune a system. I don't currently see how it can be used to automatically tune a system.

My fear is that we will end up making things brittle with user space over specifying things.

I have another related concern about what rules need to be in place so I can upgrade the kernel vdso while a user space program is running. That make me seriously wonder how sane the vdso concept is, but that is a completely different issue.

Eric

#37 lore raw

Re: [PATCH] Use uname not sysctl to get the kernel revision

Quoted 23 lines · Eric W. Biederman
Quoted 21 lines · Ulrich Drepper
Quoted 2 lines · Eric W. Biederman

Ulrich what would be interesting besides the possibility of having multiple cpus?

What is needed for various things like memory handling etc is all topology information. Somebody might remember the numa library proposal I had in April 2004 which was cast aside because people were only looking for a "quick fix". Well, the problem still isn't solved.

IMO the vdso should export information about:

- processors and their relationship (hyperthreads, cores)

- the CPU caches and how they relate to the cores (e.g., dual core with shared L2)

- local main memory for each processor

- relative costs of the memory access of the various memory regions (for numa local memory to a node, intra-node costs)

Quoted 7 lines
Quoted 7 lines

- ideally, relative costs main memory and CPU caches

All this information can be steadily updated by the kernel as new CPUs/memory get added/removed. The vdso should have functions to access this information. It's easy enough to make this access race free.

why does this have to be in the vdso? It's not like the code can be a regular userspace lib/daemon that gets all the hotplug events and that processes the info from /proc and /sys once during boot. A bit like how nscd works I suppose..