El Tue, Aug 18, 2009 at 11:13:59PM -0400 Mayuresh Kulkarni ha dit: > I read this thread : > http://article.gmane.org/gmane.linux.kernel.kernelnewbies/31239 and > have a question about it that I hope somebody will answer :) > > 1) What exactly does it mean to say that "User space sees value x for > HZ?" I mean, for kernel space, I can understand that if I do things > like nanosleep() etc then the resolution with which I can sleep is > determined by the value of HZ inside the kernel. (or so I think). not necessarily if your kernel has hrtimer support enabled these will be used for nanosleep and can provide a higher resolution: http://lxr.linux.no/#linux+v2.6.30/kernel/posix-timers.c#L954 HZ is the frequency at which the periodic system timer tick is generated (if you don't have a tickless system). it defines the precision for time *accounting* (process time, ...) and the length of a jiffy. > But what does the value of HZ in user space mean? "In kernels earlier than 2.6, changing the value of HZ resulted in user-space anomalies. This happened because values were exported to user-space in units of ticks-per-second. As these interfaces became permanent, applications grew to rely on a specific value of HZ. Consequently, changing HZ would scale various exported values by some constantwithout user-space knowing! Uptime would read 20 hours when it was in fact two! To prevent such problems, the kernel needs to scale all exported jiffies values. It does this by definingUSER_HZ, which is the HZ value that user-space expects. On x86, because HZ was historically 100,USER_HZ is 100. The macro jiffies_to_clock_t() is then used to scalea tick count in terms of HZ to a tick count in terms of USER_HZ." (excerpt from Robert Loves' "Linux Kernel Development") > 2) I tried the following program at the end of the above message I get > the following values : > > #include <unistd.h> > #include <time.h> > #include <stdio.h> > > int main() > { > struct timespec res; > double resolution; > > printf("UserHZ %ld\n", sysconf(_SC_CLK_TCK)); > > clock_getres(CLOCK_REALTIME, &res); > resolution = res.tv_sec + (((double)res.tv_nsec)/1.0e9); > > printf("SystemHZ %ld\n", (unsigned long)(1/resolution + 0.5)); > return 0; > } > > I get the values: > > UserHZ 100 > SystemHZ 1000000000 > > This looks a bit too high to me? > (My kernel version is 2.6.27/fedora core 10 , /usr/include/asm/param.h > says that HZ is 100 ) i think CLOCK_REALTIME doesn't rely on the system timer tick, but is tied to a physical clock which can provide the resolution you see -- Matthias Kaehlcke Embedded Linux Engineer Barcelona If sharing a thing in no way diminishes it, it is not rightly owned if it is not shared .''`. using free software / Debian GNU/Linux | http://debian.org : :' : `. `'` gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `- -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ