LinuxQuestions.org
Visit Jeremy's Blog.
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 11-17-2009, 10:01 AM   #1
subhan222
LQ Newbie
 
Registered: Sep 2009
Posts: 6

Rep: Reputation: 0
Kernel 2.6.27.7-9 for Suse 11.1 help required with CPU Clock freq/speed/ticks


Problem Statement: High CPU clock speed/freq
Requirement: Obtain a stable CPU clock ticks/speed/freq on Suse 11.1 with kernel 2.6.27.7-9
Questions: Please refer to the bottom of this page


Artifacts in Use:
-----------------------------------
OS: Suse 11.1
GCC Version: 4.3.2 (Suse Linux) [gcc_4_3-brach revision 141291]
Kernel: 2.6.27.7-9
Kernel Mods:
* Un-check the Tickless option
* Timer Frequency - 1000Hz
* Preempt kernel

Others 1
-----------
OS: Suse 10.2
GCC Version: 4.1.2 20061115 (prerelease)(SUSE Linux)
Kernel: 2.6.18.2-34-default
Kernel Mods:
* Preemptible Kernel (Low-Latency Desktop) (NEW)
* Preempt The Big Kernel Lock (NEW)
* Timer frequency (NEW) - 1000 Hz (NEW)

Others 2
-----------
OS: Suse 9.3
GCC Version: 3.3.5 20050117 (prerelease)(SUSE Linux)
Kernel 2.6.11.4-20a-default
Kernel Mods: None

I executed the following c++ code on the above stated builds

CODE - file name test.cpp

<code>
Code:
#include <signal.h>
#include <sys/time.h>
#include <iostream>
#include <cstdlib>


using namespace std;

long long int counter = 0;
struct timeval last_time;
struct timeval curr_time;
double dif = 0.0;
double freq_sum = 0.0;
double reps = 0.0;
double freq_min = 99999.0;
double freq_max = 0.0;
long long int num_too_low = 0;

void time_check(int data)
{
    // work out the frequecy of the SIGALRMs
    ++counter;
    if (counter >= 1000)
    {

        // need to work out time since last 1000 ticks
	gettimeofday(&curr_time, NULL);
	dif = ((curr_time.tv_usec + curr_time.tv_sec * 1000000)
		- (last_time.tv_usec + last_time.tv_sec * 1000000));
        double freq = (counter / dif)  * 1000000;

        freq_sum = ((freq_sum * reps) + freq) / (reps + 1) ;

        ++reps;
        cout << "Frequency = " << freq << " reps= " << dif / 1000000 << endl;
        if (freq_min > freq) freq_min = freq;
        if (freq_max < freq) freq_max = freq;
        if (freq < 950) 
            ++num_too_low;
        last_time = curr_time;
        counter = 0;
    }
}

int main (int argc, char * argv[])
{
    cout << "go" /* << "\a \a \a" */ << endl;
	
    int res;
    gettimeofday(&last_time, NULL);
    struct sigaction action;

    struct itimerval timer_value;

    timer_value.it_value.tv_sec = 0;
    timer_value.it_value.tv_usec = 1;
    timer_value.it_interval.tv_sec = 0;
    timer_value.it_interval.tv_usec = 1;

    action.sa_handler = time_check;
    action.sa_flags = SA_NOMASK;
    sigemptyset(&action.sa_mask);

    sigaction( SIGALRM, &action, NULL);
    res = setitimer( ITIMER_REAL, &timer_value, NULL );
    if (res == -1)
        cout << "error in setitimer" << endl;

    cout << "Starting CPU Test program" << endl;
    // loop for a long time

    while (reps < 3000.0)
    {
        sleep(1);
    }
    cout << "average CPU frequency = " << freq_sum << endl;
    cout << "reps = " << reps << endl;
    cout << "Min = " << freq_min << "  Max = " << freq_max << endl;
    cout << "number of low = " << num_too_low << endl;
    return 0;
}

Compiled the above code with "g++ test.cpp -o test"
Run the above code with "./test"


Observations:
SUSE Version AVG. Frequency AVG. REPS
Suse 9.3 999.xxx to 990.xxx reps > 1 (on average)
Suse 10.2 999.xxx to 998.xxx reps (1 - 1.001)
Suse 10.3 1000.xxx to 912.xxx reps (1 - 1.090)
Suse 11.1 0 to 324263.xxx reps (-2e-0.6 upto 0.005112)

Suse 11.1 - Options:

- Turn off ACPI in options when booting with clock=tsc | clock=pit

Observations for suse 11.1 with options acpi=off and clock=tsc | clock=pit

SUSE Version AVG. Frequency AVG. REPS
Suse 11.1 710.xxx to 999.xxx reps (1.37xx to 1.0002)

Hardware used for Suse 11.1 - HP Pavilion Slimline s3821uk Desktop PC (NQ808AA) specifications - HP Home & Home Office products
http://h10010.www1.hp.com/wwpc/uk/en...t-xx-xx-/chev/

While testing no other application/s were running.

Question:

* Is my c++ code correct?
* Am I using the correct way to get the clock ticks or is there more reliable tchnique avaliable to do this?
* Is that a problem with new Kernel if so is it a known issue ?
* Do I need to modify the Kernel to obtain regular and stable clock tick at 1000 Hz ?
* Do I have to upgrade the Kernel ?
* Would be great, if pointed to the right direction for solution (e.g. another forum) if no solution at hand.

Thanks
 
Old 11-18-2009, 07:55 AM   #2
cladisch
Member
 
Registered: Oct 2008
Location: Earth
Distribution: Slackware
Posts: 228

Rep: Reputation: 54
Quote:
* Is my c++ code correct?
That depends on what it is supposed to do; your explanations are not very clear.

Quote:
* Am I using the correct way to get the clock ticks or is there more reliable tchnique avaliable to do this?
A Linux system can have more than one clock.
What your program does is trying to measure the maximum frequency of the POSIX interval timer; the result cannot be generalized to other timing mechanisms.

Quote:
* Is that a problem with new Kernel if so is it a known issue ?
* Do I need to modify the Kernel to obtain regular and stable clock tick at 1000 Hz ?
What problem? Recent kernels can use high-resolution timers that are programmed dynamically, so they do not have a fixed tick frequency.
If you want 1000 Hz, then program the timer with the correct value; 1 / 1000 Hz = 1000 µs.
 
Old 11-19-2009, 04:53 AM   #3
subhan222
LQ Newbie
 
Registered: Sep 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Hi, thanks for your reply.

I can explain what i want to achieve. My application requires a stable clock ticks through out life time of 1000Hz. My above code might not be correct way to obtain the stable 1000Hz clock ticks.

so could you please introduce the "OTHER TIMING MECHANISMs" you mentioned to obtain the stable clock speed.

I can understand the code i have posted works on measuring the maximum frequency of the POSIX interval timer and raising sig alarms. I accept it might not be the best way to do this.
+
Forgetting any changes to Kernel and code could you please advice me how to obtain 1000Hz (at least)

I want to run a specific code at 1/1000 th of every second regardless of any results from code executed.

Thanks for your help, i really appreciate it.

Last edited by subhan222; 11-19-2009 at 05:38 AM.
 
Old 11-19-2009, 06:26 AM   #4
cladisch
Member
 
Registered: Oct 2008
Location: Earth
Distribution: Slackware
Posts: 228

Rep: Reputation: 54
Quote:
I want to run a specific code at 1/1000 th of every second
setitimer() works for that.
You might also want to look into timer_create() or timerfd_create(), but these functions do not use a different clock, they just can report the timer expiration in different ways. A benefit compared to setitimer() is that they can report the number of overruns.

It might be possible to use different clocks with, e.g., snd_timer_open() or /dev/hpet, but none of these is guaranteed to be available on any system.
 
  


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
VMWare workstantion 6, virtual winXP, CPU clock speed to fast mrpc_cambodia Ubuntu 2 08-18-2008 06:50 PM
system clock runs at twice speed on dual core cpu samkraju Fedora 4 10-08-2007 06:09 PM
High clock freq. single core or lower clock freq, dual core? ferentix Linux - General 3 04-27-2006 02:35 PM
Processor clock speed vs. CPU speed moxieman99 Linux - General 4 06-24-2005 10:43 AM
difference between CPU speed and System clock frequency raees Linux - Software 1 04-26-2005 06:03 PM

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

All times are GMT -5. The time now is 03:19 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