INtime Tech

INtime Top


Thread Switch


 

½º·¹µå½ºÀ§ÄªÀÇ ¿À¹öÇìµå ½Ã°£ ÃøÁ¤

Àú¿ì¼±µµ ½º·¹µå·ÎºÎÅÍ °í¿ì¼±µµ ½º·¹µå¿¡ ´ëÇÑ ¼ÒÇÁÆ®¿þ¾î À̺¥Æ® ¹ßÇàÀÇ ¼ø°£ºÎÅÍ ½ÇÁ¦·Î ¿£Æ®¸® Çϱâ±îÁö ¼Ò¿äÇÑ ½Ã°£À» ÃøÁ¤ÇÑ °á°ú¸¦ °ÔÀçÇÕ´Ï´Ù.

ÃøÁ¤ ȯ°æ

OS INtime3.02J ,WindowsXP(SP2) Professional
CPU Pentium4 3.0GHz*1
MEMORY 512MB
ThreadPriority 1

ÃøÁ¤ ¹æ¹ý

  • Àú¿ì¼±µµ ½º·¹µå·Î ºÎÅÍ semaphore À̺¥Æ®¸¦ ¹ßÇàÇÏ´Â ½ÃÁ¡¿¡¼­ RDTSC CPU ¸í·ÉÀ¸·Î ½Ã°¢À» »êÃâ
  • °í¿ì¼±µµ ½º·¹µå°¡ semaphore À̺¥Æ®¸¦ ¹Þ¾Æ µéÀÎ Á÷ÈÄ¿¡ RDTSC CPU ¸í·ÉÀ¸·Î ½Ã°¢À» »êÃâ
  • ½Ã°¢ÀÇ Â÷À̸¦ »êÃâ
  • 10000ȸÀÇ ÃøÁ¤À» ½Ç½Ã

ÃøÁ¤ °á°ú

  • 1¥ìÃʹ̸¸À¸·Î ½ºÀ§ÄªÀÌ ¿Ï·áÇØ, º¯µ¿µµ °ÅÀÇ ¾ø½À´Ï´Ù. ÃÖ¼Ò 937 ³ª³ëÃÊ, Æò±Õ 950 ³ª³ëÃÊ, ÃÖ´ë Áö¿¬Àº 975 ³ª³ëÃÊ¿´½À´Ï´Ù.
  • CPU ij½¬°¡ Å« ¸¸Å­ º¯µ¿Àº Àû°Ô µË´Ï´Ù

°ü·Ã Á¤º¸

 

°èÃø¿¡ »ç¿ëÇÑ ÄÚµå

*----------------------------------------------------------------
    measuring RT thread and RT thread switching
 
        Programmed by Kazumix 2005.9.2
 ------------------------------------------------------------------*/
 #include <rt.h>
 #include <stdio.h>
 #include <string.h>
 
 typedef struct RECORDFORMAT {
    QWORD       p1;
    QWORD       p2;
    QWORD       p3;
 }LOGSTRUCT ,*LPLOGSTRUCT;
 
 extern QWORD GetPentiumCounter(void);
 extern DWORD GetCPUSpeed(void);
 extern double CalcTime( QWORD start ,QWORD end );
 
 RTHANDLE       hSoftEvent;
 RTHANDLE       hReturnBackEvent;
 RTHANDLE       hFinishEvent;
 DWORD          dwCounter;
 LPLOGSTRUCT    lpLogData;
 
 #define    MAXRECORD       10000
 
 
 // High priority thread / receiving event
 void Thread2 ( void )
 {
    while(1)
    {
        WaitForRtSemaphore( hSoftEvent ,1 ,WAIT_FOREVER );
        lpLogData[dwCounter].p2 = GetPentiumCounter();  // (2)
 
        ReleaseRtSemaphore( hReturnBackEvent ,1 );
    }
 }
 
 // Low priority thread / sending event
 void Thread1 ( void )
 {
    RtSleep( 1000 );
 
    lpLogData[dwCounter].p1 = 0;    // dummy memory access 
    lpLogData[dwCounter].p2 = 0;    // (for removing memory cache delay time)
 
    while(1)
    {
        lpLogData[dwCounter].p1 = GetPentiumCounter();  // (1)
        ReleaseRtSemaphore( hSoftEvent ,1 );
 
        WaitForRtSemaphore( hReturnBackEvent ,1 ,WAIT_FOREVER );
 //     lpLogData[dwCounter].p3 = GetPentiumCounter();  // (3)
 
        dwCounter ++;
 
        if( dwCounter > MAXRECORD ){
            ReleaseRtSemaphore( hFinishEvent ,1 );
            SuspendRtThread( NULL_RTHANDLE );
        }
    }
 }
 
 // the main
 main()
 {
    FILE            *fp;
    DWORD           lp1;
    RTHANDLE        Th1 ,Th2;
 
    SetRtProcessMaxPriority( 0 ,0 );
    SetRtThreadPriority( NULL_RTHANDLE ,2 );
 
    printf("CPU speed is %u Hz\n" , GetCPUSpeed());
 
    // create semaphore objects
    hSoftEvent          = CreateRtSemaphore( 0 ,128 ,FIFO_QUEUING );
    hReturnBackEvent    = CreateRtSemaphore( 0 ,128 ,FIFO_QUEUING );
    hFinishEvent        = CreateRtSemaphore( 0 ,1 ,FIFO_QUEUING );
 
    // logging buffer
    lpLogData   = AllocateRtMemory( sizeof(LOGSTRUCT) * MAXRECORD );
    memset( lpLogData ,0 ,sizeof( sizeof(LOGSTRUCT) * MAXRECORD) );
 
    // log counter
    dwCounter = 0;
 
    // create test threads
    Th2 = CreateRtThread( 1 ,Thread2 ,4096 ,0 );
    Th1 = CreateRtThread( 2 ,Thread1 ,4096 ,0 );
 
    // fait for the finish event
    WaitForRtSemaphore( hFinishEvent ,1 ,WAIT_FOREVER );
 
    // save results to CSV format
    fp = fopen("c:\\R22RT.csv" ,"wt");
    fprintf( fp ,"Count ,Thread switching delay in nano seconds\n");
    for( lp1=0 ;lp1<MAXRECORD ;lp1++ ){
        fprintf( fp ,"%d ,%.1f\n" ,lp1+1
            ,CalcTime( lpLogData[lp1].p1 ,lpLogData[lp1].p2 )   // nano seconds
        );
    }
    fclose( fp );
 
    // delete test threads
    DeleteRtThread( Th1 );
    DeleteRtThread( Th2 );
 }

 

*1 HyperThreaddingÚ±ÞÅéÄ


HOME | INtime