On Tue, 13 Sep 2005, Mark Hounschell wrote:
> I need to know the kernels value of HZ in a userland app.
>
> getconf CLK_TCK
> and
> hz = sysconf (_SC_CLK_TCK)
>
> both seem to return CLOCKS_PER_SEC which is defined as USER_HZ which is
> defined as 100.
>
> include/asm/param.h:
>
> #ifdef __KERNEL__
> # define HZ 1000 /* Internal kernel timer frequency */
> # define USER_HZ 100 /* .. some user interfaces are in "ticks" */
> # define CLOCKS_PER_SEC (USER_HZ) /* like times() */
> #endif
>
> Thanks in advance for any help
> Mark
You are not supposed to 'tear apart' user-mode headers. In particular
you are not supposed to use anything in /usr/include/bits, /usr/include/asm,
or /usr/include/linux in user-mode programs. These are not POSIX headers.
Therefore, HZ is not something that is defined for user-mode programs.
the ANSI spec requires that things like clock() return a value that
can be divided by CLOCKS_PER_SEC to get CPU time. Nothing in user-mode
uses HZ. That's the reason why later versions of the kernel are
able to use dynamic HZ.
You will not find HZ in /usr/include/time.h or /usr/include/sys/time.h
because it's not supposed to be there, but these headers may reference
something that you are not supposed to look at in your programs.
If a user-mode program needs to know HZ, it is very, very, broken.
HZ is some kernel timeout tick which doesn't relate to anything
a user program needs to know.
If you are making a program that accesses /proc (therefore non-
standard and non portable), to obtain some kernel information,
some of which may be in HZ, you need to access the kernel headers
for the kernel that is running at the time that /proc is accessed.
This is a problem and is why we should have a kernel system-call
that returns the HZ value. I asked about this several years ago
and its inclusion was flatly refused because of what I quoted
above. Perhaps now that HZ are dynamic, it would be posasible to
add that system call.
Note, that on this particular kernel, at this phase of the moon...
This program returns the HZ value.
#include <stdio.h>
#include <unistd.h>
int main()
{
printf("%d\n", sysconf(_SC_CLK_TCK));
return 0;
}
Cheers,
Dick Johnson
Penguin : Linux version 2.6.13 on an i686 machine (5589.53 BogoMips).
Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
|
|