Profiling with bochs
Posted: Tue Nov 11, 2003 4:50 pm
After rewriting my bootloader to read my custom filesystem, I was considering profiling it to see how long it was taking to run. I noticed in bochs that the bochsout.txt file can have timestamps printed to it. I wasn't sure if these were accurate or not, so I decided to test them. I put the instructions "cli hlt" at the beginning of my bootloader, assembled it, and ran bochs.
I tested it 3 times, and each time it showed the following in the bochsout.txt file:
[tt]00000833195i[CPU ] WARNING: HLT instruction with IF=0![/tt]
Then I removed those two instructions from the beginning of the boot sector and moved them to the end of stage 2 (right after I switched to PMode)...
I tested it 3 times again, and it returned the following each time:
[tt]00000843762i[CPU ] WARNING: HLT instruction with IF=0![/tt]
At the end were two instructions that were useless, considering I wasn't using the fs and gs segment registers, so I removed these two lines from the end:
I tested it 3 times again, and got the following:
[tt]00000843760i[CPU ] WARNING: HLT instruction with IF=0![/tt]
The timings seem to be very accurate. The difference from removing those 2 instructions was 2 on the bochs timer, which I'm assuming is clock cycles. The bochs timings for disk reads seem to be exactly the same each time, as well.
The total time for the boot code to run from beginning to end, with the 2 instructions removed, was 10,565, which I got by subtracting the beginning time from the end time.
These results seem to be accurate and make it much easier to profile your code.
I tested it 3 times, and each time it showed the following in the bochsout.txt file:
[tt]00000833195i[CPU ] WARNING: HLT instruction with IF=0![/tt]
Then I removed those two instructions from the beginning of the boot sector and moved them to the end of stage 2 (right after I switched to PMode)...
I tested it 3 times again, and it returned the following each time:
[tt]00000843762i[CPU ] WARNING: HLT instruction with IF=0![/tt]
At the end were two instructions that were useless, considering I wasn't using the fs and gs segment registers, so I removed these two lines from the end:
Code: Select all
???mov???fs, eax
???mov???gs, eax
[tt]00000843760i[CPU ] WARNING: HLT instruction with IF=0![/tt]
The timings seem to be very accurate. The difference from removing those 2 instructions was 2 on the bochs timer, which I'm assuming is clock cycles. The bochs timings for disk reads seem to be exactly the same each time, as well.
The total time for the boot code to run from beginning to end, with the 2 instructions removed, was 10,565, which I got by subtracting the beginning time from the end time.
These results seem to be accurate and make it much easier to profile your code.