[PATCH] HZ export was: Re: CONFIG_* and user-visible #defines

Andi Kleen (ak@muc.de)
26 Aug 1998 11:04:31 +0200


In article <19980825173704.25036@execpc.com>,
Mitchell Blank Jr <mitch@execpc.com> writes:
> 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.

Unfortunately Linus did not include my patch. Here is it again in case
anybody wants it. Linus, please consider it :)

It also needs a trivial change in glibc to take advantage of it.

diff -u -r1.60 include/linux/sysctl.h
--- include/linux/sysctl.h 1998/05/07 20:48:57 1.60
+++ include/linux/sysctl.h 1998/07/27 14:06:40
@@ -67,7 +67,8 @@
KERN_PPC_HTABRECLAIM, /* turn htab reclaimation on/off on PPC */
KERN_PPC_ZEROPAGED, /* turn idle page zeroing on/off on PPC */
KERN_MODPROBE,
- KERN_SG_BIG_BUFF
+ KERN_SG_BIG_BUFF,
+ KERN_HZ /* int: Readonly: export HZ to userspace */
};


diff -u -r1.45 kernel/sysctl.c
--- kernel/sysctl.c 1998/06/16 04:38:13 1.45
+++ kernel/sysctl.c 1998/07/27 14:06:57
@@ -55,6 +55,8 @@
extern unsigned long htab_reclaim_on, zero_paged_on;
#endif

+int hzrate = HZ; /* exported readonly */
+
extern int pgt_cache_water[];

static int parse_table(int *, int, void *, size_t *, void *, size_t,
@@ -184,6 +186,8 @@
{KERN_SG_BIG_BUFF, "sg-big-buff", &sg_big_buff, sizeof (int),
0444, NULL, &proc_dointvec},
#endif
+ {KERN_HZ, "clock-rate", &hzrate, sizeof(int), 0444, NULL,
+ &proc_dointvec},
{0}
};

-Andi

-
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