How to measure the clock pulse of my computer manually?
My PC has two processors, and I know that each one runs at 1.86 GHz.
I want to measure the clock pulse of my PC processor/s manually, and my idea is just to compute the quotient between the number of assembler lines a program have, and the time my computer spends to execute it, so then I have the number of assembly instructions per time processed by the CPU (this is what I understood a 'clock cycle' is). I thought to do it in the following way:
- I write a C program and I convert it into assembly code.
- I do:
$gcc -S my_program.c
, which tells to gcc compiler to do the whole compiling process except the last step: to transform my_program.c into a binary object. Thus, I have a file named my_program.s that contains the source of my C program translated into assembler code.
I count the lines my program have (let's call this number N). I did:
$ nl -l my_program.s | tail -n 1
and I obtained the following:
1000015 .section .note.GNU-stack,"",@progbits
It is to say, the program has a million of lines of code.
- I do:
$gcc my_program.c
so that I can execute it.
I do:
$time ./a.out
("a.out" is the name of the binary object of my_program.c) for obtaining the time (let's call it T) it is spent for running the program and I obtain:
real 0m0.059s
user 0m0.000s
sys 0m0.004s
It is supposed that the time T I'm searching for is the first one represented in the list: the "real", because the other ones refer on other resources that are running in my system at the same right moment I execute ./a.out
.
So I have that N=1000015 lines and T=0.059 seconds. If I perform N/T division I obtain that the frequency is near to 17 MHz, which is obviously not correct.
Then I thought that maybe the fact that there are other programs running on my computer and consuming hardware resources (without going any further, the operating system itself) makes that the processor "splits" its "processing power" and it does the clock pulse goes slower, but I'm not sure.
But I thought that if this is right, I should also find the percentage of CPU resources (or memory) my program consumes, because then I could really aspire to obtain a (well) approximated result about my real CPU speed.
And this leads me to the issue of how to find out that 'resource consumption value' of my program. I thought about the $ top
command, but it's immediately discarded due to the short time my program spends to be executed (0.059 seconds); it's not possible to distinguish by simple sight any peak on the memory usage during this little time.
So what do you think about this? Or what do you recommend me to do? I know there are programs that do this work I try to do, but I prefer to do it by using the raw bash because I'm interested on doing it through the most "universal way" possible (seems like more reliable).
kernel memory cpu time cpu-frequency
add a comment |
My PC has two processors, and I know that each one runs at 1.86 GHz.
I want to measure the clock pulse of my PC processor/s manually, and my idea is just to compute the quotient between the number of assembler lines a program have, and the time my computer spends to execute it, so then I have the number of assembly instructions per time processed by the CPU (this is what I understood a 'clock cycle' is). I thought to do it in the following way:
- I write a C program and I convert it into assembly code.
- I do:
$gcc -S my_program.c
, which tells to gcc compiler to do the whole compiling process except the last step: to transform my_program.c into a binary object. Thus, I have a file named my_program.s that contains the source of my C program translated into assembler code.
I count the lines my program have (let's call this number N). I did:
$ nl -l my_program.s | tail -n 1
and I obtained the following:
1000015 .section .note.GNU-stack,"",@progbits
It is to say, the program has a million of lines of code.
- I do:
$gcc my_program.c
so that I can execute it.
I do:
$time ./a.out
("a.out" is the name of the binary object of my_program.c) for obtaining the time (let's call it T) it is spent for running the program and I obtain:
real 0m0.059s
user 0m0.000s
sys 0m0.004s
It is supposed that the time T I'm searching for is the first one represented in the list: the "real", because the other ones refer on other resources that are running in my system at the same right moment I execute ./a.out
.
So I have that N=1000015 lines and T=0.059 seconds. If I perform N/T division I obtain that the frequency is near to 17 MHz, which is obviously not correct.
Then I thought that maybe the fact that there are other programs running on my computer and consuming hardware resources (without going any further, the operating system itself) makes that the processor "splits" its "processing power" and it does the clock pulse goes slower, but I'm not sure.
But I thought that if this is right, I should also find the percentage of CPU resources (or memory) my program consumes, because then I could really aspire to obtain a (well) approximated result about my real CPU speed.
And this leads me to the issue of how to find out that 'resource consumption value' of my program. I thought about the $ top
command, but it's immediately discarded due to the short time my program spends to be executed (0.059 seconds); it's not possible to distinguish by simple sight any peak on the memory usage during this little time.
So what do you think about this? Or what do you recommend me to do? I know there are programs that do this work I try to do, but I prefer to do it by using the raw bash because I'm interested on doing it through the most "universal way" possible (seems like more reliable).
kernel memory cpu time cpu-frequency
add a comment |
My PC has two processors, and I know that each one runs at 1.86 GHz.
I want to measure the clock pulse of my PC processor/s manually, and my idea is just to compute the quotient between the number of assembler lines a program have, and the time my computer spends to execute it, so then I have the number of assembly instructions per time processed by the CPU (this is what I understood a 'clock cycle' is). I thought to do it in the following way:
- I write a C program and I convert it into assembly code.
- I do:
$gcc -S my_program.c
, which tells to gcc compiler to do the whole compiling process except the last step: to transform my_program.c into a binary object. Thus, I have a file named my_program.s that contains the source of my C program translated into assembler code.
I count the lines my program have (let's call this number N). I did:
$ nl -l my_program.s | tail -n 1
and I obtained the following:
1000015 .section .note.GNU-stack,"",@progbits
It is to say, the program has a million of lines of code.
- I do:
$gcc my_program.c
so that I can execute it.
I do:
$time ./a.out
("a.out" is the name of the binary object of my_program.c) for obtaining the time (let's call it T) it is spent for running the program and I obtain:
real 0m0.059s
user 0m0.000s
sys 0m0.004s
It is supposed that the time T I'm searching for is the first one represented in the list: the "real", because the other ones refer on other resources that are running in my system at the same right moment I execute ./a.out
.
So I have that N=1000015 lines and T=0.059 seconds. If I perform N/T division I obtain that the frequency is near to 17 MHz, which is obviously not correct.
Then I thought that maybe the fact that there are other programs running on my computer and consuming hardware resources (without going any further, the operating system itself) makes that the processor "splits" its "processing power" and it does the clock pulse goes slower, but I'm not sure.
But I thought that if this is right, I should also find the percentage of CPU resources (or memory) my program consumes, because then I could really aspire to obtain a (well) approximated result about my real CPU speed.
And this leads me to the issue of how to find out that 'resource consumption value' of my program. I thought about the $ top
command, but it's immediately discarded due to the short time my program spends to be executed (0.059 seconds); it's not possible to distinguish by simple sight any peak on the memory usage during this little time.
So what do you think about this? Or what do you recommend me to do? I know there are programs that do this work I try to do, but I prefer to do it by using the raw bash because I'm interested on doing it through the most "universal way" possible (seems like more reliable).
kernel memory cpu time cpu-frequency
My PC has two processors, and I know that each one runs at 1.86 GHz.
I want to measure the clock pulse of my PC processor/s manually, and my idea is just to compute the quotient between the number of assembler lines a program have, and the time my computer spends to execute it, so then I have the number of assembly instructions per time processed by the CPU (this is what I understood a 'clock cycle' is). I thought to do it in the following way:
- I write a C program and I convert it into assembly code.
- I do:
$gcc -S my_program.c
, which tells to gcc compiler to do the whole compiling process except the last step: to transform my_program.c into a binary object. Thus, I have a file named my_program.s that contains the source of my C program translated into assembler code.
I count the lines my program have (let's call this number N). I did:
$ nl -l my_program.s | tail -n 1
and I obtained the following:
1000015 .section .note.GNU-stack,"",@progbits
It is to say, the program has a million of lines of code.
- I do:
$gcc my_program.c
so that I can execute it.
I do:
$time ./a.out
("a.out" is the name of the binary object of my_program.c) for obtaining the time (let's call it T) it is spent for running the program and I obtain:
real 0m0.059s
user 0m0.000s
sys 0m0.004s
It is supposed that the time T I'm searching for is the first one represented in the list: the "real", because the other ones refer on other resources that are running in my system at the same right moment I execute ./a.out
.
So I have that N=1000015 lines and T=0.059 seconds. If I perform N/T division I obtain that the frequency is near to 17 MHz, which is obviously not correct.
Then I thought that maybe the fact that there are other programs running on my computer and consuming hardware resources (without going any further, the operating system itself) makes that the processor "splits" its "processing power" and it does the clock pulse goes slower, but I'm not sure.
But I thought that if this is right, I should also find the percentage of CPU resources (or memory) my program consumes, because then I could really aspire to obtain a (well) approximated result about my real CPU speed.
And this leads me to the issue of how to find out that 'resource consumption value' of my program. I thought about the $ top
command, but it's immediately discarded due to the short time my program spends to be executed (0.059 seconds); it's not possible to distinguish by simple sight any peak on the memory usage during this little time.
So what do you think about this? Or what do you recommend me to do? I know there are programs that do this work I try to do, but I prefer to do it by using the raw bash because I'm interested on doing it through the most "universal way" possible (seems like more reliable).
kernel memory cpu time cpu-frequency
kernel memory cpu time cpu-frequency
edited Dec 15 at 17:13
Rui F Ribeiro
38.9k1479129
38.9k1479129
asked Apr 18 '13 at 12:39
danielmbcn
193126
193126
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
That won't work. The number of clock cycles each instruction takes to execute ( they take quite a few, not just one ) depends heavily on the exact mix of instructions that surround it, and varies by exact cpu model. You also have interrupts coming in and the kernel and other tasks having instructions executed mixed in with yours. On top of that, the frequency changes dynamically in response to load and temperature.
Modern CPUs have model specific registers that count the exact number of clock cycles. You can read this, and using a high resolution timer, read it again a fixed period later, and compare the two to find out what the (average) frequency was over that period.
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f72873%2fhow-to-measure-the-clock-pulse-of-my-computer-manually%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
That won't work. The number of clock cycles each instruction takes to execute ( they take quite a few, not just one ) depends heavily on the exact mix of instructions that surround it, and varies by exact cpu model. You also have interrupts coming in and the kernel and other tasks having instructions executed mixed in with yours. On top of that, the frequency changes dynamically in response to load and temperature.
Modern CPUs have model specific registers that count the exact number of clock cycles. You can read this, and using a high resolution timer, read it again a fixed period later, and compare the two to find out what the (average) frequency was over that period.
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
add a comment |
That won't work. The number of clock cycles each instruction takes to execute ( they take quite a few, not just one ) depends heavily on the exact mix of instructions that surround it, and varies by exact cpu model. You also have interrupts coming in and the kernel and other tasks having instructions executed mixed in with yours. On top of that, the frequency changes dynamically in response to load and temperature.
Modern CPUs have model specific registers that count the exact number of clock cycles. You can read this, and using a high resolution timer, read it again a fixed period later, and compare the two to find out what the (average) frequency was over that period.
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
add a comment |
That won't work. The number of clock cycles each instruction takes to execute ( they take quite a few, not just one ) depends heavily on the exact mix of instructions that surround it, and varies by exact cpu model. You also have interrupts coming in and the kernel and other tasks having instructions executed mixed in with yours. On top of that, the frequency changes dynamically in response to load and temperature.
Modern CPUs have model specific registers that count the exact number of clock cycles. You can read this, and using a high resolution timer, read it again a fixed period later, and compare the two to find out what the (average) frequency was over that period.
That won't work. The number of clock cycles each instruction takes to execute ( they take quite a few, not just one ) depends heavily on the exact mix of instructions that surround it, and varies by exact cpu model. You also have interrupts coming in and the kernel and other tasks having instructions executed mixed in with yours. On top of that, the frequency changes dynamically in response to load and temperature.
Modern CPUs have model specific registers that count the exact number of clock cycles. You can read this, and using a high resolution timer, read it again a fixed period later, and compare the two to find out what the (average) frequency was over that period.
answered Apr 18 '13 at 13:48
psusi
13.5k22439
13.5k22439
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
add a comment |
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
Hey, thank you for your answer. I have been searching information about what you have told me and the unique way I found to access to CPU registers for reading them is to use assembly code (for example, by embedding it into a C program). I don't know if there are other ways, but seems like it would be a good idea to have at least a rough understanding of assembly language for doing this.
– danielmbcn
Apr 19 '13 at 9:22
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f72873%2fhow-to-measure-the-clock-pulse-of-my-computer-manually%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown