VirtualBox

Changeset 45264 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Mar 31, 2013 12:40:20 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84653
Message:

tstR0ThreadPreemptionDriver.cpp: Start a bunch of threads to make sure the CPU will require preemption.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp

    r44529 r45264  
    3030#include <iprt/initterm.h>
    3131
     32#include <iprt/asm.h>
     33#include <iprt/cpuset.h>
    3234#include <iprt/err.h>
    3335#include <iprt/path.h>
     
    4244#endif
    4345
     46/*******************************************************************************
     47*   Global Variables                                                           *
     48*******************************************************************************/
     49static bool volatile g_fTerminate = false;
     50
     51
     52/**
     53 * Try make sure all online CPUs will be engaged.
     54 */
     55static DECLCALLBACK(int) MyThreadProc(RTTHREAD hSelf, void *pvCpuIdx)
     56{
     57    RTCPUSET Affinity;
     58    RTCpuSetEmpty(&Affinity);
     59    RTCpuSetAddByIndex(&Affinity, (intptr_t)pvCpuIdx);
     60    RTThreadSetAffinity(&Affinity); /* ignore return code as it's not supported on all hosts. */
     61
     62    while (!g_fTerminate)
     63        RTThreadSleep(50);
     64
     65    return VINF_SUCCESS;
     66}
     67
    4468
    4569int main(int argc, char **argv)
     
    141165     * Stay in ring-0 until preemption is pending.
    142166     */
     167    RTTHREAD ahThreads[RTCPUSET_MAX_CPUS];
     168    uint32_t cThreads = RTMpGetCount();
     169    RTCPUSET OnlineSet;
     170    RTMpGetOnlineSet(&OnlineSet);
     171    for (uint32_t i = 0; i < RT_ELEMENTS(ahThreads); i++)
     172    {
     173        ahThreads[i] = NIL_RTTHREAD;
     174        if (RTCpuSetIsMemberByIndex(&OnlineSet, i))
     175            RTThreadCreateF(&ahThreads[i], MyThreadProc, (void *)(uintptr_t)i, 0, RTTHREADTYPE_DEFAULT,
     176                            RTTHREADFLAGS_WAITABLE, "cpu=%u", i);
     177    }
     178
    143179RTThreadSleep(250); /** @todo fix GIP initialization? */
     180
    144181    RTTestSub(hTest, "Pending Preemption");
    145182    for (int i = 0; ; i++)
     
    163200    }
    164201
     202    ASMAtomicWriteBool(&g_fTerminate, true);
     203    for (uint32_t i = 0; i < RT_ELEMENTS(ahThreads); i++)
     204        if (ahThreads[i] != NIL_RTTHREAD)
     205            RTThreadWait(ahThreads[i], 5000, NULL);
     206
    165207    /*
    166208     * Test nested RTThreadPreemptDisable calls.
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette