Re: CONFIG_* and user-visible #defines

Mitchell Blank Jr (mitch@execpc.com)
Tue, 25 Aug 1998 17:37:04 -0500


I made the following point on the -m68k list before, but it probably bears
repeating on the -kernel list.

Alan Cox wrote:
> > Is there a clean way to have dependencies on a CONFIG_* option in parts of
> > the kernel headers that aren't #ifdef __KERNEL__ ?
> >
> > I need to set (at least) HZ and PAGE_SIZE depending on CONFIG_SUN3X, but
> > those definitions appear to be visible outside the kernel so including
> > linux/config.h seems like a bad idea..
>
> Put a machine type in the gcc spec file for your target and do
>
> #ifdef __sun3__

... which means that any user programs that use HZ and PAGE_SIZE are now
incompatible within the same architecture.

The fix that eventually needs to happen is that these values must be replaced
with calls to sysconf:

#ifdef __KERNEL__
#define HZ CONFIG_HZ
#define PAGE_SIZE ARCH_PAGESIZE
#else
#define HZ (sysconf(_SC_CLK_TCK))
#define PAGE_SIZE (sysconf(_SC_PAGE_SIZE))
#endif

Unfortunately, even this won't currently work, because there is currently
no hook for libc to get this data out of the kernel. The way this is usually
handled is a sys_sysconf system call so the kernel can provide the values
only it knows about (those two , _SC_ARG_MAX, _SC_CHILD_MAX, _SC_NGROUPS_MAX,
_SC_OPEN_MAX, _SC_IOV_MAX, _SC_NPROCESSORS_CONF, _SC_NPROCESSORS_ONLN,
_SC_PHYS_PAGES, _SC_AVPHYS_PAGES, _SC_AIO_*, ...). Some of these can be
fetched from the kernel through other means, but often libc is left to
guess or respond with a compiled-in default (see
glibc-2.0.6:sysdeps/posix/sysconf.c)

On a similar note, the kernel also needs pathconf and fpathconf (see the
files pathconf.c and fpathconf.c in the same directory). This one is
particularly ugly because it needs a new hook into VFS and (trivial)
modifications to filesystems.

> HZ is a bad one as it leaks everywhere. Andi Kleen had a patch that makes
> HZ visible (not settable) via sysctl and /proc/sys

That would be a start. Ditto for PAGE_SIZE, at least. In fact, if we
commit to doing this for all the kernel things that sysconf handles,
we can use sysctl for that purpose. This may be the cleanest fix and
is certainly the quickest. Of course, that doesn't fix {f,}pathconf.

-Mitch

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html