Sponsored Content
Full Discussion: Accessing TSC Register
Top Forums Programming Accessing TSC Register Post 302394009 by snowbarr on Wednesday 10th of February 2010 08:23:16 AM
Old 02-10-2010
Accessing TSC Register

I'm accessing the TSC register, and using usleep() function to calculate my clock frequency. Basically, I check the current clock, delay for 1 second, and then check the clock again to discover how many clock ticks occur in a second.

The only problem is - my result turns out to be a ridiculous (and inconsistent) number. It always very close to one of the two following numbers.
18446744072127.2 Mhz or 2712.6 Mhz

My question - Is this a result of having a multi-core processor? Or is my code/logic just plain wrong? I included the relevant sections of the code below.


Code:
typedef unsigned long long int UINT64;

UINT64 startTSC = 0;
UINT64 stopTSC = 0;
UINT64 cycleCnt = 0;

// Access TSC register to get current value
__asm__ volatile(".byte 0x0f,0x31" : "=A" (startTSC));
// Delay for 1*10^6 us (1 second)
usleep(1000000);
// Access TSC register to get new value
__asm__ volatile(".byte 0x0f,0x31" : "=A" (stopTSC));

// Calculate cycles that happened over the full second
cycleCnt = stopTSC-startTSC;


Last edited by pludi; 02-10-2010 at 09:38 AM.. Reason: code tags, please...
 

8 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Can't register

I tried registering, but no matter what email address I provide, it says not a valid address and not the same in confirm. I tried many times, but no go. I thought I had already registered as Sully but even that didn't like my email address for password info. Of course, that could be someone else... (2 Replies)
Discussion started by: Not registered
2 Replies

2. Forum Support Area for Unregistered Users & Account Problems

Not able to register

I tried my best to register myself on unix.com but i am not lucky, can you pls give me instruction. (1 Reply)
Discussion started by: Kuldeep_Sngh333
1 Replies

3. Forum Support Area for Unregistered Users & Account Problems

Cant register

Registration denied. Sorry, The UNIX and Linux Forums runs an active policy of not allowing spammers. Please contact us via by posting in this forum if you believe this is in error What's with this? Tried 2 email accounts in case your forum blocks either. (1 Reply)
Discussion started by: Diagonal
1 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Can not register

I need help from the scripting threads and want to register. I tried it several times, but I was all the time rejected, because of your spam policy. I do what you have written, but I wasn't still able to register. (1 Reply)
Discussion started by: ScAr
1 Replies

5. Forum Support Area for Unregistered Users & Account Problems

I can't register

Hello admin, I come from Vietnam, it's in blocked country list. Can you help me to register I want to register with following information: Username: bojankikrick Email: <removed> Thanks very much! (1 Reply)
Discussion started by: Unregistered
1 Replies

6. Forum Support Area for Unregistered Users & Account Problems

I can't register

hi,admin: i come from china,my country is in the blocked list.i want to register a account,can you help me? infomation: username: zhengzfand email:<removed> (1 Reply)
Discussion started by: Unregistered
1 Replies

7. Forum Support Area for Unregistered Users & Account Problems

Can't register

I am in China. China is in the blocked country list. I can't register. And I don't have a static ip. Can u help me to fix it. I want to register with following information: Username:liuchengzhang email:<removed> Thanks! (1 Reply)
Discussion started by: liuchengzhang
1 Replies

8. Forum Support Area for Unregistered Users & Account Problems

Cannot able to Register!

Hi Admin, I am unable to register . Request you to help me in getting my registration done. Name: Raghavendra Kulkarni Mail id : <removed> Thanking you in advance for your support. (1 Reply)
Discussion started by: Unregistered
1 Replies
drv_usectohz(9F)					   Kernel Functions for Drivers 					  drv_usectohz(9F)

NAME
drv_usectohz - convert microseconds to clock ticks SYNOPSIS
#include <sys/types.h> #include <sys/ddi.h> clock_t drv_usectohz(clock_t microsecs); INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI). PARAMETERS
microsecs The number of microseconds to convert. DESCRIPTION
drv_usectohz() converts a length of time expressed in microseconds to a number of system clock ticks. The time arguments to timeout(9F) and delay(9F) are expressed in clock ticks. drv_usectohz() is a portable interface for drivers to make calls to timeout(9F) and delay(9F) and remain binary compatible should the driver object file be used on a system with a different clock speed (a different number of ticks in a second). RETURN VALUES
The value returned is the number of system clock ticks equivalent to the microsecs argument. No error value is returned. If the clock tick equivalent to microsecs is too large to be represented as a clock_t, then the maximum clock_t value will be returned. CONTEXT
drv_usectohz() can be called from user or interrupt context. SEE ALSO
delay(9F), drv_hztousec(9F), timeout(9F) Writing Device Drivers SunOS 5.10 12 Nov 1992 drv_usectohz(9F)
All times are GMT -4. The time now is 09:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy