 |
|
|
 |
|
 |
Hi,
I am using xp. when i open task manager->Performance,View->CPU history->One graph per CPU, it is whoing two seperate graphs. But, i have only one processor in my machine. When i run this tool, the total load is going on 2nd processor, so maximum load can be 50%. I created two instances of this load tool, set affinity of 1st as CPU0 and 2nd as CPU1. Still the entire load is going on 2nd processor only.
How to put 90-100% load on my CPU.
Thanks,
Loka
|
|
|
|
 |
|
 |
Hi!
I have ported this application in Visual C++ 6.0.
If anyone is interested e-mail me and I will send the zip file containing the application.
It wasn't an easy thing to do.
Best wishes,
Christian.
I am in love with VC++
|
|
|
|
 |
|
 |
I tested your demo execution file and didn't see any blue bar or percent of loading for processor. Any percent entered by me manually equally didn't work.
AleksMain
|
|
|
|
 |
|
 |
Sorry for late reply. The calls to measure CPU load are somewhat black magic to me as it is merely a call to the Windows API.
The function OnTimer is called every ~1 second to update the CPU load percentage. This function calls an internal function GetCPUCycle() which then calls the windows API functions PdhCollectQueryData() and PdhGetRawCounterValue() to get the CPU load percentage. These Pdh functions are where all the magic happens and unfortunately I am not very familiar with them as I just used an example for how to measure CPU load for the sake of controlling it. Perhaps the implementation is wrong. I would suggest looking in MSDN documentation for an example of how to use these. It may be a problem in your version of MFC or possible of the DLL that the Pdh functions use. The person in the above post may have experienced this same problem when he or she had so much "trouble" porting to VC6.0.
|
|
|
|
 |
|
 |
Have you tried setting the processor affinity for each thread? Please see SetThreadAffinityMask() in the MSDN documentation. It lets you divert the execution of threads to specific CPUs.
|
|
|
|
 |
|
 |
Yep. That would achieve almost.
|
|
|
|
 |
|
 |
I tried setting the thread affinity with no luck. Based on the documentation, I seem to have set everything up correctly - the following code detects my two processors, and starts two threads setting up each to run on a different processor, but the load still maxes out at 50%. I setup the load thread to run a while(1){} loop just to make sure and still can't go above 50%. The thread affinity on the process and the thread prior to calling SetThreadAffinity() was set to 0x03, which should have meant they would run on both processors anyway. Maybe I just missed something in the documentation... any suggestions from anyone with more experience w/ multicores?
//Update to get number of processors
DWORD procmask = 0;
DWORD systemmask = 0;
//Get the current processor and system affinity to determine what processors are avaialble
//and which this process can use
HANDLE proc = GetCurrentProcess();
GetProcessAffinityMask(proc, &procmask, &systemmask);
//Count the number of bits set to get the total number of processors on the system
DWORD temp = systemmask;
int numprocs = 0;
while (temp)
{
if (temp & 0x00000001) //increment count for each bit (processor) set
numprocs++;
temp >>= 1;
}
if (systemmask != procmask)
SetProcessAffinityMask(proc, systemmask);
m_desiredLoad = 0;
HANDLE thread;
DWORD threadaffinity = 0x00000001; //first thread runs on proc1
//now create a thread for each processor and set it to run on a unique proc
for (int i = 0; i < numprocs; ++i)
{
thread = CreateThread(NULL, 0, &ThreadProc, this, 0, NULL);
DWORD res = SetThreadAffinityMask(thread, threadaffinity);
threadaffinity <<= 1;
}
|
|
|
|
 |
|
 |
Do the new duo-chips have hyperthreading enabled? Windows reports each "hyper unit" as a processor of its own (at least XP does). Maybe you have to adjust for that.
Also, what does SetThreadAffinityMask() return? Anything of significance?
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
 |
|
 |
Just use the task manager. You can set which programm should be run on which core (works with my core 2 duo). I don't think core 2 duos have hyperthreading, btw, but even if they did, you'd see in the task manager.
EDIT: Obviously, you'll need to start two versions of the programm, one for each core. Set one instance to core 1 and the other to core 2.
|
|
|
|
 |
|
 |
Great-er wrote: Obviously, you'll need to start two versions of the programm, one for each core. Set one instance to core 1 and the other to core 2.
Why so when you direct specific threads to specific CPUs?
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
 |
|
 |
hmm, you are right, i couldn't test the program (wasn't at home), so i didn't know it was threaded/had to threads. but i hope i helped, nevertheless.
EDIT: If you download the original program, you have to run it twice, because it only starts one thread.
-- modified at 15:03 Tuesday 27th February, 2007
|
|
|
|
 |
|
 |
SetThreadAffinity returned 0x03. Based on the documentation, the return value was the previous thread affinity which means the thread was already setup to run on either CPU.
|
|
|
|
 |
|
 |
Haven't tried it myself, but maybe you can use SetProcessAffinityMask and SetThreadAffinityMask to force each of the threads on a specific core.
|
|
|
|
 |
|
|
 |
|
 |
why need this?
don't understand
!!!
welcome
|
|
|
|
 |