Re: finding out the value of HZ from userspace

From: Jamie Lokier
Date: Thu Apr 01 2004 - 12:07:21 EST


Richard B. Johnson wrote:
> > Not to get irritatingly back to the subject of this thread or
> > anything, but... is the value of HZ reported to userspace anywhere?
>
> I may be naive, but what's the matter with:
>
> #include <sys/param.h> // Required to be here!
> int main()
> {
> printf("HZ=%d\n", HZ);
> return 0;
> }
> It works for me.

It gives the wrong answer for HZ on 2.6 kernels. Try it.

The value called "HZ" we are talking about in this thread is the timer
interrupt frequency. On 2.6 kernels, on x86, that is 1000. Your
program prints 100.

The reason that you are able to use "HZ" from userspace and get the
wrong answer is that the macros have different names when used from
userspace than from kernelspace.

The value your program reports is what we mean by USER_HZ in this
thread. That macro is renamed to HZ when the kernel header
<linux/param.h> is included from userspace, for backward
source compatibility with some programs.

Your method also perpetuates the problem that USER_HZ is hard-coded as
a constant into programs, so cannot ever be changed. Perhaps the
header files should redefine "HZ" to call sysconf(_SC_CLK_TCK)
nowadays, but presently they don't.

-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/