Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007

    how to modify and read the tick rate:HZ


    one of our customer is facing an issue with jiffies wrap up.
    on a 32 bit machine, the variable jiffies count upto 472 days.
    the customer's server was up for 472 days ('uptime') and to reproduce
    the same, i tried to change the variable HZ in linux-2.6..23.9/include/asm-i386/param.h
    from 100 to 10000.
    after which i rebuilt the kernel with following steps:
    # make oldconfig
    # make modules_install
    # make install

    Now when i boot from this newly built kernel, i wrote a small kernel module
    to read the jiffies and HZ global variable,which is as follows:

    [root@localhost drivers]# cat get_jiffies.c
    #include <linux/init.h>
    #include <linux/module.h>
    #include <asm/current.h>
    #include <linux/sched.h>
    #include <linux/time.h>
    #include <linux/jiffies.h>
    static int __init jiffies_init(void)
    unsigned long j,z;
    j = z = 0;
    j = jiffies;
    z = HZ;
    printk(KERN_ALERT "jiffies value is %lu\n",j);
    printk(KERN_ALERT "jiffies value in seconds %lu\n",(jiffies/HZ));
    printk(KERN_ALERT "HZ value is %lu\n",z);
    return 0;

    static void __exit jiffies_exit(void)
    printk(KERN_ALERT "Goodbye, world!\n");



    [root@localhost drivers]# insmod get_jiffies.ko
    [root@localhost drivers]# dmesg
    jiffies value is 372939
    jiffies value in seconds 1491
    HZ value is 250 <====

    why this HZ variable is shown as 250 ?
    i am a newbie in kernel programming and i might be doing something really stupid as well


  2. #2
    check this in kernel


  3. #3
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    [amit@localhost include]$ ls -l asm
    lrwxrwxrwx 1 amit amit 8 Nov 30 19:43 asm -> asm-i386

    [amit@localhost include]$ diff -q asm/param.h asm-i386/param.h
    [amit@localhost include]$ echo $?


  4. $spacer_open
  5. #4

    #ifndef _ASMi386_PARAM_H
    #define _ASMi386_PARAM_H
    #ifndef HZ
    #define HZ 100
    #define EXEC_PAGESIZE	4096
    #ifndef NGROUPS
    #define NGROUPS		32
    #ifndef NOGROUP
    #define NOGROUP		(-1)
    #define MAXHOSTNAMELEN	64	/* max length of hostname */
    #ifdef __KERNEL__
    # define CLOCKS_PER_SEC	100	/* frequency at which times() counts */

  6. #5
    I guess HZ value also depends on processor

  7. #6
    Linux Newbie dilbert's Avatar
    Join Date
    Sep 2006
    Lima, Peru
    Yes, if not on x86, then param.h files in directories asm-xxx different from asm-x86 can have different HZ values.

    (Only visible if someone looks into the file ... )
    Bus Error: Passengers dumped. Hech gap yo'q.

  8. #7
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Sorry for not updating on this for a long time.
    Here are some points which i gathered by asking the same thing on some other forums and through some reading :

    HZ is tick rate which is different for different processors,
    so if for a particular type of processor it is 250 then this means that processor will have 250 ticks in a second.
    this value is configurable,which is defined in include/asm/param.h

    Snip from my 2.6 linux kernel include/asm-i386/param.h file
    #define HZ CONFIG_HZ

    Now this CONFIG_HZ gets set to a value in arc/<asm-i386>/defconfig to a value after doing
    make {menuconfig|xconfig}

    Also uptime = jiffies * HZ
    hence just by looking at these things, i could think of configuring the HZ to a large value in order to get the jiffies wrapped as early as possible(forget about the performance for some moment).

    Now jiffies get reset at every reboot,but every time after reboot,when i insert my module to read jiffies,i get very large value for jiffies !!!(look at the code which i've pasted before),
    because even if i keep the HZ value to 1000,it should take about 47 days for jiffies wrap up,but this is happening withing minutes on my machine !!

    Later i was pointed to this code which explained this behaviour(getting a large value of jiffies after startup on 2.6 kernel):

    snip from linux-<version>/include/linux/jiffies.h:

    * Have the 32 bit jiffies value wrap 5 minutes after boot
    * so jiffies wrap bugs show up earlier.
    #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))

    So, in any recent kernels, the jiffies counter is initialized so that it *will* wrap around 5 minutes after boot, regardless of the HZ setting.

    changing the HZ value will automatically be compensated in the uptime calculation too. Therefore the uptime will never be too fast nor too slow: changing the HZ will not affect it.


  9. #8
    Your system HZ value is 100 only,
    jiffies is defined as unsigned long means range from 0 - 4294967295

    system startup time is jiffies/HZ seconds

    from above formulae calculated maximum startup time is 497 days.

    now recalcute with HZ 250 you'll get 198 days

    hope this helpful ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts