Blitzmax: Multicore aushebeln (Win).

Übersicht Sonstiges News

Neue Antwort erstellen

Abrexxes

Betreff: Blitzmax: Multicore aushebeln (Win).

BeitragMo, Nov 15, 2010 21:06
Antworten mit Zitat
Benutzer-Profile anzeigen
user posted image (Windows)
Der eine oder andere will sicher mal testen ob ein Programm auf einem "Single Core" genau so gut läuft wie auf dem heimischen "Multi Core".
James L Boyd (BRL Support) hat dazu für Windows einen kleinen Code gepostet der euch direkten Zugriff auf die Prozessoraffinität gibt. Für fortgeschrittene BM User sicherlich nicht uninteressant.

Code: [AUSKLAPPEN]

Extern "win32"

   Const CREATE_SUSPENDED=$4
   Const STACK_SIZE_PARAM_IS_A_RESERVATION=$10000
   
   Const INFINITE=$ffffffff
   Const WAIT_ABANDONED=$80
   Const WAIT_OBJECT_0=$0
   Const WAIT_TIMEOUT=$102
   Const WAIT_FAILED=$ffffffff
   
   Const THREAD_MODE_BACKGROUND_BEGIN = $00010000
   Const THREAD_MODE_BACKGROUND_END = $00020000
   Const THREAD_PRIORITY_ABOVE_NORMAL = 1
   Const THREAD_PRIORITY_BELOW_NORMAL = -1
   Const THREAD_PRIORITY_HIGHEST = 2
   Const THREAD_PRIORITY_IDLE = -15
   Const THREAD_PRIORITY_LOWEST = -2
   Const THREAD_PRIORITY_NORMAL = 0
   Const THREAD_PRIORITY_TIME_CRITICAL = 15

   Function ResumeThread( thread )
   Function SuspendThread( thread )
   Function CloseThread( thread )
   Function WaitForSingleObject( handle,timeout )
   Function GetThreadPriority (thread)
   Function SetThreadPriority (thread, priority)
   Function GetCurrentThread ()

   Const PROCESS_SET_INFORMATION = $200
   
   Function GetCurrentProcessId ()
   Function OpenProcess (desiredaccess, inherithandle, processid)
   Function SetProcessAffinityMask (processhandle, processaffinitymask)
   
End Extern





' -------------------------------------------------------------------------
' Get process and open process handle...
' -------------------------------------------------------------------------

Local proc:Int = GetCurrentProcessId ()
Local handle:Int = OpenProcess (PROCESS_SET_INFORMATION, 0, proc)

' -------------------------------------------------------------------------
' Force process to CPU...
' -------------------------------------------------------------------------

' First CPU:
SetProcessAffinityMask (handle, %00000000000000000000000000000001)

' Second CPU:
'SetProcessAffinityMask (handle, %00000000000000000000000000000010)

' First 2 CPUs (default on dual-core):
'SetProcessAffinityMask (handle, %00000000000000000000000000000011)
   
' -------------------------------------------------------------------------

Print "Open task manager and view process affinity (right click app, Set Affinity)..."

Repeat

   Delay 100
   
Until KeyHit (KEY_ESCAPE)

End


Rem

<a href="http://msdn.microsoft.com/en-us/library/ms686277(VS.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms686277(VS.85).aspx</a>

THREAD_MODE_BACKGROUND_BEGIN = $00010000
Begin background processing mode. The system lowers the resource scheduling priorities of the thread so that it can perform background work without significantly affecting activity in the foreground.
This value can be specified only if hThread is a handle to the current thread. The function fails if the thread is already in background processing mode.
Windows Server 2003 and Windows XP/2000:  This value is not supported.

THREAD_MODE_BACKGROUND_END = $00020000
End background processing mode. The system restores the resource scheduling priorities of the thread as they were before the thread entered background processing mode.
This value can be specified only if hThread is a handle to the current thread. The function fails if the thread is not in background processing mode.
Windows Server 2003 and Windows XP/2000:  This value is not supported.

THREAD_PRIORITY_ABOVE_NORMAL = 1
Priority 1 point above the priority class.

THREAD_PRIORITY_BELOW_NORMAL = -1
Priority 1 point below the priority class.

THREAD_PRIORITY_HIGHEST = 2
Priority 2 points above the priority class.

THREAD_PRIORITY_IDLE = -15
Base priority of 1 for IDLE_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority of 16 for REALTIME_PRIORITY_CLASS processes.

THREAD_PRIORITY_LOWEST = -2
Priority 2 points below the priority class.

THREAD_PRIORITY_NORMAL = 0
Normal priority for the priority class.

THREAD_PRIORITY_TIME_CRITICAL = 15
Base priority of 15 for IDLE_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority of 31 for REALTIME_PRIORITY_CLASS processes.

If the thread has the REALTIME_PRIORITY_CLASS base class, this parameter can also be -7, -6, -5, -4, -3, 3, 4, 5, or 6.

End Rem


RELATED TOPIC Original Thema (eng)

BlitzBasic Portal News RSS Feed Halt dich auf dem laufenden!

Neue Antwort erstellen


Übersicht Sonstiges News

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group