LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-01-2007, 01:20 PM   #1
RedOctober45
Member
 
Registered: Aug 2007
Distribution: OFFICE: Solaris, RedHawk
Posts: 65

Rep: Reputation: 15
Linux Coding - TSC Register


Hi guys!

I have an assginment in which code is given to me and I have to modify some errors injected by the professor on purpose, sort of like a warm-up exercise for the course. Anywho, this project involves comparing changes from gettimeofday() function with changes taken from the TSC register. The TSC register differences are converted to microseconds and compared to the gettimeofday() microsecond values, and to see the difference bewteen the exact same time differences (delta) from two different sources and to explain why, yada yada yada.

Part of this assignment is to correct the wrap-around effect of the TSC register, which is 64 bits. Unless I am doing something wrong, this register never wraps around, well it does, just not for a very very long time. I mean, it is 2^64 long. Even a 3GHZ processor would take forever to wrap that register around. My professor is annoyed with me bugging him about it and keeps saying that it wraps around and I am not understanding this right. Can someone clear this up for me? Can the TSC register wrap around, what am I doing wrong?

Here is a snipet of the main code:

Code:
main()
{
  struct timespec dt;
  struct timeval  bt, et;
  tsc_t       tsc_bt, tsc_et;
  double      delta_t, tsc_delta_t;
  int        i;

  printf("CPU clock: %.2f MHz\n", Init_TSC() / 1000000.0);

  for (i = 100; i < 500000; i += 100) {

    dt.tv_sec = 0;
    dt.tv_nsec =i  * 1000;

    gettimeofday( &bt, NULL );
    Read_TSC( tsc_bt );
    nanosleep( &dt, NULL );
    Read_TSC( tsc_et );
    gettimeofday( &et, NULL );

    delta_t  =  (et.tv_sec - bt.tv_sec) ;
    delta_t += (et.tv_usec - bt.tv_usec);
    tsc_delta_t = Convert_TSC( tsc_et - tsc_bt, TSC_Microseconds );

    printf("Requested %6d uS sleep:  actual %8.3f, tsc %8.3f, delta %.6f, %.3f%% err\n",
      i, delta_t, tsc_delta_t, delta_t - tsc_delta_t,
      (fabs(delta_t - tsc_delta_t) / delta_t) * 100.0);

  }
}
Convert_TSC() just converts the value from the TSC register into the modifier specified (TSC_Microseconds), which is microseconds. (Ingore any obvious math errors, I see them, just haven't changed them yet. I am most concerned about the wrap-around issue.)

Thank you so much guys!
 
Old 10-01-2007, 09:58 PM   #2
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
perhaps the code was written for a 32 bit tsc ??
a 32 bit counter wrapps around in under a minute.

other wise i guess you just have to work the problem in "theory"
i guess you culd try to manually zero the counter to test your thoeretical solution.
 
  


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
Clocksource tsc unstable punt Fedora 11 12-29-2008 03:16 AM
Losing too many ticks! TSC cannot be used as a timesource. V Naveen Linux - Software 4 06-26-2007 10:27 PM
Problem with Exceed and multiple users logged via TSC Michele Spinolo Linux - General 0 02-01-2005 04:48 PM
coding linux services bytebrowser Linux - Software 4 01-16-2005 11:56 PM
Need linux coding help iqbal Programming 1 07-21-2004 02:28 PM

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

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