inline void CRPCClient<TRequest, TReply>::Ask(const TRequest& request, TReply& reply) { CMutexGuard LOCK(m_Mutex); unsigned int tries = 0; for (;;) { try { SetAffinity(GetAffinity(request)); Connect(); // No-op if already connected *m_Out << request; *m_In >> reply; break; } catch (CException& e) { // Some exceptions tend to correspond to transient glitches; // the remainder, however, may as well get propagated immediately. if ( !dynamic_cast<CSerialException*>(&e) && !dynamic_cast<CIOException*>(&e) ) { throw; } else if (++tries == m_RetryLimit || !x_ShouldRetry(tries)) { throw; } else if ( !(tries & 1) ) { // reset on every other attempt in case we're out of sync try { Reset(); } STD_CATCH_ALL_XX(Serial_RPCClient,1,"CRPCClient<>::Reset()"); } SleepSec(m_RetryDelay.GetCompleteSeconds()); SleepMicroSec(m_RetryDelay.GetNanoSecondsAfterSecond() / 1000); } } }
int main ( int argc, char ** argv ) { const char * hashToTest = "murmur3a"; if(argc < 2) { printf("No test hash given on command line, testing %s (Murmur3_x86_32).\n", hashToTest); } else { hashToTest = argv[1]; if (strcmp(hashToTest,"--list") == 0) { for(size_t i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++) { printf("%s\t(%s)\n", g_hashes[i].name, g_hashes[i].desc); } exit(0); } } // Code runs on the 3rd CPU by default SetAffinity((1 << 2)); SelfTest(); int timeBegin = clock(); g_testAll = true; //g_testSanity = true; g_testSpeed = true; //g_testAvalanche = true; //g_testBIC = true; //g_testCyclic = true; //g_testTwoBytes = true; //g_testDiff = true; //g_testDiffDist = true; //g_testSparse = true; g_testPermutation = true; //g_testWindow = true; //g_testZeroes = true; testHash(hashToTest); //---------- int timeEnd = clock(); printf("\n"); printf("Input vcode 0x%08x, Output vcode 0x%08x, Result vcode 0x%08x\n",g_inputVCode,g_outputVCode,g_resultVCode); printf("Verification value is 0x%08x - Testing took %f seconds\n",g_verify,double(timeEnd-timeBegin)/double(CLOCKS_PER_SEC)); printf("-------------------------------------------------------------------------------\n"); return 0; }
int main ( int argc, char ** argv ) { const char * hashToTest = "murmur3a"; if(argc < 2) { printf("(No test hash given on command line, testing Murmur3_x86_32.)\n"); } else { hashToTest = argv[1]; } // Code runs on the 3rd CPU by default SetAffinity((1 << 2)); SelfTest(); int timeBegin = clock(); g_testAll = true; //g_testSanity = true; //g_testSpeed = true; //g_testAvalanche = true; //g_testBIC = true; //g_testCyclic = true; //g_testTwoBytes = true; //g_testDiff = true; //g_testDiffDist = true; //g_testSparse = true; //g_testPermutation = true; //g_testWindow = true; //g_testZeroes = true; testHash(hashToTest); //---------- int timeEnd = clock(); printf("\n"); printf("Input vcode 0x%08x, Output vcode 0x%08x, Result vcode 0x%08x\n",g_inputVCode,g_outputVCode,g_resultVCode); printf("Verification value is 0x%08x - Testing took %f seconds\n",g_verify,double(timeEnd-timeBegin)/double(CLOCKS_PER_SEC)); printf("-------------------------------------------------------------------------------\n"); return 0; }
int main(int argc, char **argv) { if(SetAffinity() != 0) error("set cpu affinity error\n"); if(argc > 1) if(SetPolicy() != 0) error("set policy error\n"); printf("Sched policy = %d\n" , sched_getscheduler(0)); pthread_t pthreads[threadnum]; for(int thr_id = 0 ; thr_id < threadnum ; thr_id++) { if(pthread_create(&pthreads[thr_id], NULL, RunSleep, (void *)thr_id) != 0) error("create thread error\n"); else printf("Thread %d was created.\n", thr_id); } for(int i = 0 ; i < threadnum ; i++) pthread_join(pthreads[i], NULL); }
static void *Worker(void *) { WorkerTid = GetTid(); if (!SetPriority(WorkerTid, PRIORITY_HIGH) || !SetAffinity(WorkerTid)) IsError = true; pthread_mutex_lock(&Lock); WorkerIsInitialized = true; pthread_cond_signal(&WorkerInitialized); pthread_mutex_unlock(&Lock); // Execute the work loop via a volatile pointer to prevent the compiler // from inlining. The Pin tool instruments DoWorkInstrumentedWithPin(), // so we don't want its body to be inlined. // volatile VOIDFUNPTR doWork = DoWorkInstrumentedWithPin; doWork(); return 0; }
CD3DX12AffinityObject::CD3DX12AffinityObject(CD3DX12AffinityDevice* device, IUnknown** objects, UINT Count) { for (UINT i = 0; i < D3DX12_MAX_ACTIVE_NODES; i++) { if (i < Count) { mObjects[i] = objects[i]; } else { mObjects[i] = nullptr; } } #ifdef DEBUG_OBJECT_NAME mObjectTypeName = L"Object"; #endif mReferenceCount = 1; mParentDevice = device; SetAffinity(mParentDevice->GetNodeMask()); }
static void *Scheduler(void *) { if (!SetPriority(GetTid(), PRIORITY_HIGH) || !SetAffinity(GetTid())) IsError = true; // Wait for the worker to initialize itself. // pthread_mutex_lock(&Lock); while (!WorkerIsInitialized) pthread_cond_wait(&WorkerInitialized, &Lock); pthread_mutex_unlock(&Lock); // This loop tries to lower the priority of the worker while it holds // the PIN_LOCK. // volatile VOIDFUNPTR doGetLockWithPin = DoGetLockWithPin; for (unsigned long i = 0; i < NUM_SCHEDULES && !IsError; i++) { // Lower the priority, then try to acquire the PIN_LOCK. We want // to attempt to acuire the lock here while the worker has the // lock and is running at low priority. // if (!SetPriority(WorkerTid, PRIORITY_LOW)) IsError = true; doGetLockWithPin(); if ((i % (NUM_SCHEDULES / 10)) == 0) std::cout << "Iterations: " << std::dec << i << std::endl; // Raise the worker priority and yield the processor to it. Let the // worker start running again before the next attempt. // if (!SetPriority(WorkerTid, PRIORITY_HIGH)) IsError = true; sched_yield(); } Done = true; return 0; }
void Scheduler::HandleThreadStart() { ATOMIC_ADD_AND_FETCH(&curr_num_threads_, 1); ATOMIC_ADD_AND_FETCH(&total_num_threads_, 1); if (main_thread_started_) { // child thread start_sched_ = true; if (!delay_) { int priority = RandomPriority(); SetPriority(priority); } } else { // main thread if (!delay_) { SetAffinity(); // force all the threads to be executed on one processor int priority = RandomPriority(); SetPriority(priority); } } ExecutionControl::HandleThreadStart(); }
void test ( hashfunc<hashtype> hash, HashInfo * info ) { const int hashbits = sizeof(hashtype) * 8; printf("-------------------------------------------------------------------------------\n"); printf("--- Testing %s (%s)\n\n",info->name,info->desc); //----------------------------------------------------------------------------- // Sanity tests if(g_testSanity || g_testAll) { printf("[[[ Sanity Tests ]]]\n\n"); VerificationTest(hash,hashbits,info->verification,true); SanityTest(hash,hashbits); AppendedZeroesTest(hash,hashbits); printf("\n"); } //----------------------------------------------------------------------------- // Speed tests if(g_testSpeed || g_testAll) { printf("[[[ Speed Tests ]]]\n\n"); SetAffinity((1 << 2)); // Run speed tests on 3rd CPU to ensure that RDTSC always the the same core BulkSpeedTest(info->hash,info->hashbits,info->verification); printf("\n"); const int max_keysize = 66; TinySpeedTest(info->hash,info->hashbits,max_keysize,info->verification,true); ResetAffinity(); // Use all cores for the rest of code printf("\n"); } //----------------------------------------------------------------------------- // Avalanche tests if(g_testAvalanche || g_testAll) { printf("[[[ Avalanche Tests ]]]\n\n"); bool result = true; result &= AvalancheTest< Blob< 32>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 40>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 48>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 56>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 64>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 72>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 80>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 88>, hashtype > (hash,300000); result &= AvalancheTest< Blob< 96>, hashtype > (hash,300000); result &= AvalancheTest< Blob<104>, hashtype > (hash,300000); result &= AvalancheTest< Blob<112>, hashtype > (hash,300000); result &= AvalancheTest< Blob<120>, hashtype > (hash,300000); result &= AvalancheTest< Blob<128>, hashtype > (hash,300000); result &= AvalancheTest< Blob<136>, hashtype > (hash,300000); result &= AvalancheTest< Blob<144>, hashtype > (hash,300000); result &= AvalancheTest< Blob<152>, hashtype > (hash,300000); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'Cyclic' - keys of the form "abcdabcdabcd..." if(g_testCyclic || g_testAll) { printf("[[[ Keyset 'Cyclic' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+0,8,10000000,drawDiagram); result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+1,8,10000000,drawDiagram); result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+2,8,10000000,drawDiagram); result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+3,8,10000000,drawDiagram); result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+4,8,10000000,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'TwoBytes' - all keys up to N bytes containing two non-zero bytes // This generates some huge keysets, 128-bit tests will take ~1.3 gigs of RAM. if(g_testTwoBytes || g_testAll) { printf("[[[ Keyset 'TwoBytes' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; for(int i = 4; i <= 20; i += 4) { result &= TwoBytesTest2<hashtype>(hash,i,drawDiagram); } if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'Sparse' - keys with all bits 0 except a few if(g_testSparse || g_testAll) { printf("[[[ Keyset 'Sparse' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; result &= SparseKeyTest< 32,hashtype>(hash,6,true,true,true,drawDiagram); result &= SparseKeyTest< 40,hashtype>(hash,6,true,true,true,drawDiagram); result &= SparseKeyTest< 48,hashtype>(hash,5,true,true,true,drawDiagram); result &= SparseKeyTest< 56,hashtype>(hash,5,true,true,true,drawDiagram); result &= SparseKeyTest< 64,hashtype>(hash,5,true,true,true,drawDiagram); result &= SparseKeyTest< 96,hashtype>(hash,4,true,true,true,drawDiagram); result &= SparseKeyTest< 256,hashtype>(hash,3,true,true,true,drawDiagram); result &= SparseKeyTest<2048,hashtype>(hash,2,true,true,true,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'Permutation' - all possible combinations of a set of blocks if(g_testPermutation || g_testAll) { { // This one breaks lookup3, surprisingly printf("[[[ Keyset 'Combination Lowbits' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; uint32_t blocks[] = { 0x00000000, 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007, }; result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } { printf("[[[ Keyset 'Combination Highbits' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; uint32_t blocks[] = { 0x00000000, 0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000 }; result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } { printf("[[[ Keyset 'Combination 0x8000000' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; uint32_t blocks[] = { 0x00000000, 0x80000000, }; result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } { printf("[[[ Keyset 'Combination 0x0000001' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; uint32_t blocks[] = { 0x00000000, 0x00000001, }; result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } { printf("[[[ Keyset 'Combination Hi-Lo' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; uint32_t blocks[] = { 0x00000000, 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007, 0x80000000, 0x40000000, 0xC0000000, 0x20000000, 0xA0000000, 0x60000000, 0xE0000000 }; result &= CombinationKeyTest<hashtype>(hash,6,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram); if(!result) printf("*********FAIL*********\n"); printf("\n"); } } //----------------------------------------------------------------------------- // Keyset 'Window' // Skip distribution test for these - they're too easy to distribute well, // and it generates a _lot_ of testing if(g_testWindow || g_testAll) { printf("[[[ Keyset 'Window' Tests ]]]\n\n"); bool result = true; bool testCollision = true; bool testDistribution = false; bool drawDiagram = false; result &= WindowedKeyTest< Blob<hashbits*2>, hashtype > ( hash, 20, testCollision, testDistribution, drawDiagram ); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'Text' if(g_testText || g_testAll) { printf("[[[ Keyset 'Text' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; const char * alnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; result &= TextKeyTest( hash, "Foo", alnum,4, "Bar", drawDiagram ); result &= TextKeyTest( hash, "FooBar", alnum,4, "", drawDiagram ); result &= TextKeyTest( hash, "", alnum,4, "FooBar", drawDiagram ); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'Zeroes' if(g_testZeroes || g_testAll) { printf("[[[ Keyset 'Zeroes' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; result &= ZeroKeyTest<hashtype>( hash, drawDiagram ); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Keyset 'Seed' if(g_testSeed || g_testAll) { printf("[[[ Keyset 'Seed' Tests ]]]\n\n"); bool result = true; bool drawDiagram = false; result &= SeedTest<hashtype>( hash, 1000000, drawDiagram ); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Differential tests if(g_testDiff || g_testAll) { printf("[[[ Differential Tests ]]]\n\n"); bool result = true; bool dumpCollisions = false; result &= DiffTest< Blob<64>, hashtype >(hash,5,1000,dumpCollisions); result &= DiffTest< Blob<128>, hashtype >(hash,4,1000,dumpCollisions); result &= DiffTest< Blob<256>, hashtype >(hash,3,1000,dumpCollisions); if(!result) printf("*********FAIL*********\n"); printf("\n"); } //----------------------------------------------------------------------------- // Differential-distribution tests if(g_testDiffDist /*|| g_testAll*/) { printf("[[[ Differential Distribution Tests ]]]\n\n"); bool result = true; result &= DiffDistTest2<uint64_t,hashtype>(hash); printf("\n"); } //----------------------------------------------------------------------------- // Bit Independence Criteria. Interesting, but doesn't tell us much about // collision or distribution. if(g_testBIC) { printf("[[[ Bit Independence Criteria ]]]\n\n"); bool result = true; //result &= BicTest<uint64_t,hashtype>(hash,2000000); BicTest3<Blob<88>,hashtype>(hash,2000000); if(!result) printf("*********FAIL*********\n"); printf("\n"); } }