LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2015, 05:01 PM   #1
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 75

Rep: Reputation: Disabled
clocksource, clockevent, jiffies


Hi all,

What are the relations between clocksourcem clockevent and jiffies? I looked at the kernel source code but it's hard to understand. Can someone gives a brief to top level explanation?

Thanks,
Wei Xu
 
Old 11-19-2015, 05:09 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by david_8274 View Post
Hi all,

What are the relations between clocksourcem clockevent and jiffies? I looked at the kernel source code but it's hard to understand. Can someone gives a brief to top level explanation?

Thanks,
Wei Xu
Jiffies are the easiest - they are the shortest measurable time given a particular clock. The jiffy counter is used when no other scheduling clock is available.

The following should be included with the kernel source, but it provides an overview of how timekeeping is used.

https://www.kernel.org/doc/Documenta...imekeeping.txt
 
Old 11-19-2015, 06:44 PM   #3
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 75

Original Poster
Rep: Reputation: Disabled
Hi,

So is jiffies based on clocksource or clockevent?

Thanks,
Wei Xu


Quote:
Originally Posted by jpollard View Post
Jiffies are the easiest - they are the shortest measurable time given a particular clock. The jiffy counter is used when no other scheduling clock is available.

The following should be included with the kernel source, but it provides an overview of how timekeeping is used.

https://www.kernel.org/doc/Documenta...imekeeping.txt
 
Old 11-19-2015, 07:01 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by david_8274 View Post
Hi,

So is jiffies based on clocksource or clockevent?

Thanks,
Wei Xu
It all depends on the local clock. Some clocks don't have an interrupt - they just count. A jiffy is just a conversion unit that allows for a common notation. I've worked on systems where a jiffy is 1/60 second - but not rigidly as the clock was based on the local 60hz power line... which varied +- 5 percent. On a 50Hz power line, that would be 1/50 second instead.

Since it depends on the environment, the "bogomips" values got used to create a fictitious speed that could be used for very low level spinwaits. A request for a millisecond (or less) would go into a loop for a fixed count - computed from the bogomips speed for the given CPU. Not perfect, but it allows things to work where there are no interrupts.

Last edited by jpollard; 11-19-2015 at 07:06 PM.
 
Old 11-19-2015, 08:15 PM   #5
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 75

Original Poster
Rep: Reputation: Disabled
Hi,

When I look at how jiffies is implemented, i saw the following code:

# define jiffies raid6_jiffies()

static inline uint32_t raid6_jiffies(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec*1000 + tv.tv_usec/1000;
}

Looks like it call gettimeofday() to get the elapsed time then return the second *1000 and micor_second/1000.
My question is, why multiply the second by 1000 is hard coded? doesn't jiffies depends on
#define HZ xxx

in other words, if I redefine HZ to other value, could than not make the factor 1000 invalid?

Thanks,
Wei Xu





Quote:
Originally Posted by jpollard View Post
It all depends on the local clock. Some clocks don't have an interrupt - they just count. A jiffy is just a conversion unit that allows for a common notation. I've worked on systems where a jiffy is 1/60 second - but not rigidly as the clock was based on the local 60hz power line... which varied +- 5 percent. On a 50Hz power line, that would be 1/50 second instead.

Since it depends on the environment, the "bogomips" values got used to create a fictitious speed that could be used for very low level spinwaits. A request for a millisecond (or less) would go into a loop for a fixed count - computed from the bogomips speed for the given CPU. Not perfect, but it allows things to work where there are no interrupts.
 
Old 11-20-2015, 07:51 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by david_8274 View Post
Hi,

When I look at how jiffies is implemented, i saw the following code:
Quote:
# define jiffies raid6_jiffies()

static inline uint32_t raid6_jiffies(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec*1000 + tv.tv_usec/1000;
}
Looks like it call gettimeofday() to get the elapsed time then return the second *1000 and micor_second/1000.
My question is, why multiply the second by 1000 is hard coded? doesn't jiffies depends on
#define HZ xxx

in other words, if I redefine HZ to other value, could than not make the factor 1000 invalid?

Thanks,
Wei Xu
No. If you notice, this is only defined if things are NOT the kernel.

Here, a jiffy is being defined from the timeval structure (manpage gettimeofday):
Code:
struct timeval {
       time_t      tv_sec;     /* seconds */
       suseconds_t tv_usec;    /* microseconds */
};
So divide the microseconds by 1000, and multiply the seconds by 1000 and add. This is done to get a 32 bit number. (1 second = 1e6 microseconds... so scale one up and one down to keep the units straight).

The result is a monotonically increasing count. It just happens that the 1000 is the same value as the Hz value - but is not related. The units being computed are milliseconds, so changing the values by 1000.

I believe in this case the count is used to set generations of the raid 6 data structures to identify out-of-date data blocks that are in error, and a millisecond is judged to be short enough to make that determination.

The "jiffy" in this case is the minimum time between generations of data blocks before an error has occured, which happens to be units of 1 millisecond.

As before, a "jiffy" is just a minimum amount of time a given clock can detect. In this case, 1 millisecond.

Last edited by jpollard; 11-20-2015 at 07:57 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] hdsp9652 clocksource lambo69 Slackware 2 04-24-2014 01:21 PM
How to set TSC as a clocksource begroup Linux - Newbie 2 01-24-2011 08:43 AM
[SOLVED] How to add a new clocksource? Rushis Linux - Embedded & Single-board computer 1 08-20-2010 02:03 PM
Check available clocksource? kushalkoolwal Linux - Kernel 2 02-22-2010 02:56 PM
What is user mode jiffies and kernel mode jiffies of a process iamjayanth Linux - Software 2 09-14-2009 11:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration