LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-28-2009, 01:13 PM   #1
JimHughen
Member
 
Registered: Jun 2009
Location: Austin, Texas
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 16
Arrow rtc_interrupt() code ... "+ HZ/rtc_freq +"


In the file: "linux-2.6.30/drivers/char/rtc.c"
in the interrupt handler at:

static irqreturn_t rtc_interrupt(int irq, void *dev_id)
{
...
if (rtc_status & RTC_TIMER_ON)
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);
...
return IRQ_HANDLED;
}

In particular "+ HZ/rtc_freq +".

Notice this expression has a non-constant divide, which begs
close inspection because this is in an important interrupt handler.

So...
HZ is a constant with apparent values of
100, 1000, 1024, or CONFIG_HZ.
(I can't find a definition of CONFIG_HZ in a *.h file)
rtc_freq is a "static unsigned long rtc_freq;"
defined in this module.
rtc_freq gets its value from
static int rtc_do_ioctl(RTC_IRQP_SET,unsigned long arg,...)

If 'unsigned long' is more a single 'div' instruction
(seems possible in some configurations), a multiple precision divide
routine might be called from this interrupt handler,
which would not be good.

If a single precision divide is used (more likely), something like
40 instruction cycles could be used.

Since this quotient (and subsequent constant addition
in this expression) does not change, wouldn't the performance
of this ISR be significantly improved if this math is done
outside of the ISR?

Maybe the correct terminology is to move these instructions to the
'Bottom Half' or equivalent.
 
Old 06-29-2009, 07:15 AM   #2
JimHughen
Member
 
Registered: Jun 2009
Location: Austin, Texas
Distribution: Ubuntu
Posts: 44

Original Poster
Rep: Reputation: 16
I hope replying to one's own thread is allowed...

You may guess that I am learning Linux Kernel Development and
reading Robert Love's book by that name.

Quote:
Maybe the correct terminology is to move these instructions to the
'Bottom Half' or equivalent.
The previous 'Bottom Half' reference was, of course, not used correctly.

These little math expressions would be calculated/reduced at
(or just prior to) the interrupt handler being enabled.

This Bottom Half mechanism looks really nice, especially in networking
where message processing has a tendency to get into an interrupt handler.
With BH mechanisms, the interrupt handler can detect a special event
(say an inquire message to this terminal on a large network), respond
quickly to that event, without creating additional interrupt latency.

... good stuff this ...
 
Old 06-29-2009, 12:54 PM   #3
lmaza
LQ Newbie
 
Registered: Dec 2008
Posts: 12

Rep: Reputation: 1
Re-CONFIG_HZ

Hello

I am a Linux Device Drivers 3rd Edition (LDD3) reader
In that book on chapter 7 Time, Delays, and Deferred Work says:

"Measuring Time Lapses
...
Timer interrupts are generated by the system's timing hardware at regular intervals; this interval is programmed at boot time by the kernel according to the value of HZ, which is an architecture-dependent value defined in <linux/param.h> or a subplataform file included by it."

The variable CONFIG_HZ does not seem to be included in the LDD3 book.
Maybe this could help.



Quote:
Originally Posted by JimHughen View Post
In the file: "linux-2.6.30/drivers/char/rtc.c"
in the interrupt handler at:

static irqreturn_t rtc_interrupt(int irq, void *dev_id)
{
...
if (rtc_status & RTC_TIMER_ON)
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);
...
return IRQ_HANDLED;
}

In particular "+ HZ/rtc_freq +".

Notice this expression has a non-constant divide, which begs
close inspection because this is in an important interrupt handler.

So...
HZ is a constant with apparent values of
100, 1000, 1024, or CONFIG_HZ.
(I can't find a definition of CONFIG_HZ in a *.h file)
rtc_freq is a "static unsigned long rtc_freq;"
defined in this module.
rtc_freq gets its value from
static int rtc_do_ioctl(RTC_IRQP_SET,unsigned long arg,...)

If 'unsigned long' is more a single 'div' instruction
(seems possible in some configurations), a multiple precision divide
routine might be called from this interrupt handler,
which would not be good.

If a single precision divide is used (more likely), something like
40 instruction cycles could be used.

Since this quotient (and subsequent constant addition
in this expression) does not change, wouldn't the performance
of this ISR be significantly improved if this math is done
outside of the ISR?

Maybe the correct terminology is to move these instructions to the
'Bottom Half' or equivalent.
 
Old 06-29-2009, 02:08 PM   #4
JimHughen
Member
 
Registered: Jun 2009
Location: Austin, Texas
Distribution: Ubuntu
Posts: 44

Original Poster
Rep: Reputation: 16
Thanks lmaza for responding.

I am very excited about learning this Linux kernel.
The Linux initiative is very important (even historically)
at this time. The ability to collaborate on such a scale is
tremendous.

Code:
  mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);
The analysis of this expression is not primarily to detail
the 2nd parameter of the mod_timer() call. It is to predict
what code the compiler might generate. Of course, this type
of analysis is normally somewhat bizarre. However, consider
the side effect of an unnecessary multi-precision or
floating point expression in this interrupt handler.
Any reasonable optimization is advisable, if it improves the
system wide interrupt latency.

The term "+ HZ/rtc_freq +" appears to be a constant divided
by an 'unsigned long'. It looks like the preprocessor will
not be able to perform this division, so run time execution
will result.

I am in the habit of holding my interrupt handlers to very
tight scrutiny for execution cycles.
 
  


Reply



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
Do i need "RPM Packages" or "SuSe Source code packages" Donati Linux - Software 3 03-19-2009 07:32 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
How to convert Assembly code to "C" source code ssg14j Programming 2 08-01-2005 12:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:51 AM.

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