Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > The Linux Kernel
Reload this Page how to modify and read the tick rate:HZ
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

The Linux Kernel Compiling, theory, programming or other discussion about the linux kernel

Reply
 
Thread Tools Display Modes
Old 01-08-2008   #1 (permalink)
amit4g
Just Joined!
 
amit4g's Avatar
 
Join Date: Feb 2007
Location: Bangalore,India
Posts: 41
how to modify and read the tick rate:HZ

hi,

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");
}

module_init(jiffies_init);
module_exit(jiffies_exit);

MODULE_LICENSE("GPL");

[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


~amit
amit4g is offline   Reply With Quote
Old 01-08-2008   #2 (permalink)
ashok449
Just Joined!
 
Join Date: Jun 2006
Posts: 22
check this in kernel

include/asm-i386/param.h
ashok449 is offline   Reply With Quote
Old 01-08-2008   #3 (permalink)
amit4g
Just Joined!
 
amit4g's Avatar
 
Join Date: Feb 2007
Location: Bangalore,India
Posts: 41
[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 $?
0

~amit
amit4g is offline   Reply With Quote
Old 01-08-2008   #4 (permalink)
ashok449
Just Joined!
 
Join Date: Jun 2006
Posts: 22
linux-2.4.8-20/include/asm/param.h

Code:
#ifndef _ASMi386_PARAM_H
#define _ASMi386_PARAM_H

#ifndef HZ
#define HZ 100
#endif

#define EXEC_PAGESIZE	4096

#ifndef NGROUPS
#define NGROUPS		32
#endif

#ifndef NOGROUP
#define NOGROUP		(-1)
#endif

#define MAXHOSTNAMELEN	64	/* max length of hostname */

#ifdef __KERNEL__
# define CLOCKS_PER_SEC	100	/* frequency at which times() counts */
#endif

#endif
ashok449 is offline   Reply With Quote
Old 01-08-2008   #5 (permalink)
ashok449
Just Joined!
 
Join Date: Jun 2006
Posts: 22
I guess HZ value also depends on processor
ashok449 is offline   Reply With Quote
Old 01-10-2008   #6 (permalink)
dilbert
Linux Newbie
 
dilbert's Avatar
 
Join Date: Sep 2006
Location: Yorkshire, GB
Posts: 215
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.
dilbert is offline   Reply With Quote
Old 01-25-2008   #7 (permalink)
amit4g
Just Joined!
 
amit4g's Avatar
 
Join Date: Feb 2007
Location: Bangalore,India
Posts: 41
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:

<snip>
/*
* 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))


<snip>
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.

~amit
amit4g is offline   Reply With Quote
Old 01-29-2008   #8 (permalink)
ashok449
Just Joined!
 
Join Date: Jun 2006
Posts: 22
amit4g,
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 ...
ashok449 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
external HD (with enclosure) USB cannot be read by VL icedtea Other Distributions 0 10-10-2007 12:54 AM
Help for a menu that read the option from a txt file Lele Linux Programming & Scripting 4 06-13-2007 05:50 PM
Samba Read Only Error... azpyroguy Redhat / Fedora Linux Help 2 11-04-2005 04:33 AM
XF86Config-4 trying to modify, permission denied dhughes Debian Linux Help 8 06-28-2005 06:44 AM
Linux File Permissions GoldenEye Linux Tutorials, HOWTO's & Reference Material 0 07-16-2004 01:50 PM




All times are GMT. The time now is 05:26 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0