19 #include "ArrayPool.hpp" 
   23 #include "ndbd_malloc_impl.hpp" 
   24 #include "SimulatedBlock.hpp" 
   27 #include <valgrind/callgrind.h> 
   29 #define CALLGRIND_TOGGLE_COLLECT() 
   32 #define T_TEST_AP   (1 << 0) 
   33 #define T_TEST_WO   (1 << 1) 
   34 #define T_TEST_RW   (1 << 2) 
   36 #define T_SEIZE       (1 << 0) 
   37 #define T_RELEASE     (1 << 1) 
   38 #define T_G_RELEASE   (1 << 2) 
   39 #define T_R_RELEASE   (1 << 3) 
   40 #define T_R_G_RELEASE (1 << 4) 
   41 #define T_MIX         (1 << 5) 
   42 #define T_GETPTR      (1 << 6) 
   43 #define T_FIFO        (1 << 7) 
   45 const char *test_names[] = {
 
   85   pool.wo_pool_init(0x2001, pc);
 
   94   pool.init(0x2001, pc);
 
   97 template <
typename T, 
typename R>
 
   99 test_pool(R& pool, Uint32 cnt, Uint32 loops)
 
  102   Uint32 *arr = (Uint32*)alloca(cnt * 
sizeof(Uint32));
 
  103   memset(arr, 0, cnt * 
sizeof(Uint32));
 
  107     for(Uint32 
i = 0; 
i<loops; 
i++)
 
  109       Uint64 start = NdbTick_CurrentMillisecond();
 
  110       CALLGRIND_TOGGLE_COLLECT();
 
  111       for(Uint32 j = 0; j<cnt; j++)
 
  113         bool b = pool.seize(ptr);
 
  118       CALLGRIND_TOGGLE_COLLECT();
 
  119       Uint64 stop = NdbTick_CurrentMillisecond();      
 
  121       for(Uint32 j = 0; j<cnt; j++)
 
  129       sum += (stop - start);
 
  131     printf(
" ; %lld", sum); fflush(stdout);
 
  134   if (tests & T_RELEASE)
 
  137     for(Uint32 
i = 0; 
i<loops; 
i++)
 
  139       for(Uint32 j = 0; j<cnt; j++)
 
  141         bool b = pool.seize(ptr);
 
  146       Uint64 start = NdbTick_CurrentMillisecond();
 
  147       CALLGRIND_TOGGLE_COLLECT();
 
  148       for(Uint32 j = 0; j<cnt; j++)
 
  150         pool.release(arr[j]);
 
  153       CALLGRIND_TOGGLE_COLLECT();
 
  154       Uint64 stop = NdbTick_CurrentMillisecond();      
 
  156       sum += (stop - start);
 
  158     printf(
" ; %lld", sum); fflush(stdout);
 
  161   if (tests & T_G_RELEASE)
 
  164     for(Uint32 
i = 0; 
i<loops; 
i++)
 
  166       for(Uint32 j = 0; j<cnt; j++)
 
  168         bool b = pool.seize(ptr);
 
  173       Uint64 start = NdbTick_CurrentMillisecond();
 
  174       CALLGRIND_TOGGLE_COLLECT();
 
  175       for(Uint32 j = 0; j<cnt; j++)
 
  177         pool.getPtr(ptr, arr[j]);
 
  182       CALLGRIND_TOGGLE_COLLECT();
 
  183       Uint64 stop = NdbTick_CurrentMillisecond();      
 
  185       sum += (stop - start);
 
  187     printf(
" ; %lld", sum); fflush(stdout);
 
  190   if (tests & T_R_RELEASE)
 
  193     for(Uint32 
i = 0; 
i<loops; 
i++)
 
  195       for(Uint32 j = 0; j<cnt; j++)
 
  197         bool b = pool.seize(ptr);
 
  202       Uint64 start = NdbTick_CurrentMillisecond();
 
  203       CALLGRIND_TOGGLE_COLLECT();
 
  204       for(Uint32 j = 0; j<cnt; j++)
 
  206         pool.release(arr[cnt - j - 1]);
 
  207         arr[cnt - j - 1] = RNIL;
 
  209       CALLGRIND_TOGGLE_COLLECT();
 
  210       Uint64 stop = NdbTick_CurrentMillisecond();      
 
  212       sum += (stop - start);
 
  214     printf(
" ; %lld", sum); fflush(stdout);
 
  217   if (tests & T_R_G_RELEASE)
 
  220     for(Uint32 
i = 0; 
i<loops; 
i++)
 
  222       for(Uint32 j = 0; j<cnt; j++)
 
  224         bool b = pool.seize(ptr);
 
  229       Uint64 start = NdbTick_CurrentMillisecond();
 
  230       CALLGRIND_TOGGLE_COLLECT();
 
  231       for(Uint32 j = 0; j<cnt; j++)
 
  233         pool.getPtr(ptr, arr[cnt - j - 1]);
 
  236         arr[cnt - j - 1] = RNIL;
 
  238       CALLGRIND_TOGGLE_COLLECT();
 
  239       Uint64 stop = NdbTick_CurrentMillisecond();      
 
  241       sum += (stop - start);
 
  243     printf(
" ; %lld", sum); fflush(stdout);
 
  249     Uint64 start = NdbTick_CurrentMillisecond();
 
  251     CALLGRIND_TOGGLE_COLLECT();
 
  252     for(Uint32 
i = 0; 
i<loops * cnt; 
i++)
 
  254       int pos = rand_r(&lseed) % cnt;
 
  260         assert(ptr.i != RNIL);
 
  271     CALLGRIND_TOGGLE_COLLECT();
 
  272     Uint64 stop = NdbTick_CurrentMillisecond();    
 
  274     for(Uint32 j = 0; j<cnt; j++)
 
  285     sum += (stop - start);
 
  286     printf(
" ; %lld", sum); fflush(stdout);
 
  289   if (tests & T_GETPTR)
 
  292     for(Uint32 j = 0; j<cnt; j++)
 
  294       bool b = pool.seize(ptr);
 
  301     Uint64 start = NdbTick_CurrentMillisecond();
 
  302     CALLGRIND_TOGGLE_COLLECT();
 
  303     for(Uint32 
i = 0; 
i<loops * cnt; 
i++)
 
  305       int pos = rand_r(&lseed) % cnt;
 
  310     CALLGRIND_TOGGLE_COLLECT();
 
  311     Uint64 stop = NdbTick_CurrentMillisecond();    
 
  313     for(Uint32 j = 0; j<cnt; j++)
 
  322     sum += (stop - start);
 
  323     printf(
" ; %lld", sum); fflush(stdout);
 
  329     Uint64 start = NdbTick_CurrentMillisecond();
 
  330     CALLGRIND_TOGGLE_COLLECT();
 
  331     for(Uint32 
i = 0; 
i<loops; 
i++)
 
  337       for(Uint32 j = 0; j<cnt; j++)
 
  341         ptr.p->m_nextList = RNIL;
 
  348           T* t = pool.getPtr(last);
 
  349           t->m_nextList = ptr.i;
 
  356         pool.getPtr(ptr, head);
 
  358         head = ptr.p->m_nextList;
 
  362     CALLGRIND_TOGGLE_COLLECT();
 
  363     Uint64 stop = NdbTick_CurrentMillisecond();    
 
  364     sum += (stop - start);
 
  365     printf(
" ; %lld", sum); fflush(stdout);
 
  381     Uint32 *ptr = (Uint32*)
this; 
 
  382     for(Uint32 
i = 0; i<(sz >> 2); 
i++)
 
  393 template <
typename T>
 
  394 void test_ap(Uint32 cnt, Uint32 loop)
 
  396   printf(
"AP ; %d ; %d", 
sizeof(T), (cnt * 
sizeof(T))>>10); fflush(stdout);
 
  399   test_pool<T, ArrayPool<T> >(pool, cnt, loop);
 
  402 template <
typename T>
 
  403 void test_rw(Uint32 cnt, Uint32 loop)
 
  405   printf(
"RW ; %d ; %d", 
sizeof(T), (cnt * 
sizeof(T))>>10); fflush(stdout);
 
  408   test_pool<T, RecordPool<T, RWPool> >(pool, cnt, loop);
 
  411 template <
typename T>
 
  412 void test_wo(Uint32 cnt, Uint32 loop)
 
  414   printf(
"WO ; %d ; %d", 
sizeof(T), (cnt * 
sizeof(T))>>10); fflush(stdout);
 
  417   test_pool<T, RecordPool<T, WOPool> >(pool, cnt, loop);
 
  420 #include <EventLogger.hpp> 
  424 main(
int argc, 
char **argv)
 
  426   Uint32 loops = 300000;
 
  427   for (Uint32 
i = 1 ; 
i<argc ; 
i++)
 
  429     if (argc > 
i+1 && strcmp(argv[
i], 
"-pools") == 0)
 
  432       for (Uint32 j = 0; j<strlen(argv[i+1]); j++)
 
  434         char c = argv[i+1][j];
 
  435         if (c >= 
'0' && c <= 
'9')
 
  436           pools |= 1 << (c - 
'0');
 
  438           pools |= 1 << (10 + (c - 
'a'));
 
  441     else if (argc > i+1 && strcmp(argv[i], 
"-tests") == 0)
 
  444       for (Uint32 j = 0; j<strlen(argv[i+1]); j++)
 
  446         char c = argv[i+1][j];
 
  447         if (c >= 
'0' && c <= 
'9')
 
  448           tests |= 1 << (c - 
'0');
 
  450           tests |= 1 << (10 + (c - 
'a'));
 
  453     else if (argc > i+1 && strcmp(argv[i], 
"-sizes") == 0)
 
  456       for (Uint32 j = 0; j<strlen(argv[i+1]); j++)
 
  458         char c = argv[i+1][j];
 
  459         if (c >= 
'0' && c <= 
'9')
 
  460           sizes |= 1 << (c - 
'0');
 
  462           sizes |= 1 << (10 + (c - 
'a'));
 
  465     else if (argc > i+1 && strcmp(argv[i], 
"-records") == 0)
 
  468       for (Uint32 j = 0; j<strlen(argv[i+1]); j++)
 
  470         char c = argv[i+1][j];
 
  471         if (c >= 
'0' && c <= 
'9')
 
  472           records |= 1 << (c - 
'0');
 
  474           records |= 1 << (10 + (c - 
'a'));
 
  477     else if (argc > i+1 && strcmp(argv[i], 
"-loop") == 0)
 
  479       loops = atoi(argv[i+1]);
 
  486   rl.m_resource_id = 0;
 
  497   printf(
"pool ; rs ; ws");
 
  498   for (Uint32 i = 0; test_names[
i] && i<31; i++)
 
  499     if (tests & (1 << i))
 
  500       printf(
" ; %s", test_names[i]);
 
  503   while(cnt <= 1000000)
 
  505     Uint32 loop = 768 * loops / cnt;
 
  506     if (sizes & (1 << sz))
 
  510         if (pools & T_TEST_AP)
 
  511           test_ap<Rec32>(cnt, loop);
 
  512         if (pools & T_TEST_WO)
 
  513           test_wo<Rec32>(cnt, loop);
 
  514         if (pools & T_TEST_RW)
 
  515           test_rw<Rec32>(cnt, loop);
 
  519         if (pools & T_TEST_AP)
 
  520           test_ap<Rec36>(cnt, loop);
 
  521         if (pools & T_TEST_WO)
 
  522           test_wo<Rec36>(cnt, loop);
 
  523         if (pools & T_TEST_RW)
 
  524           test_rw<Rec36>(cnt, loop);
 
  528         if (pools & T_TEST_AP)
 
  529           test_ap<Rec56>(cnt, loop);
 
  530         if (pools & T_TEST_WO)
 
  531           test_wo<Rec56>(cnt, loop);
 
  532         if (pools & T_TEST_RW)
 
  533           test_rw<Rec56>(cnt, loop);
 
  537         if (pools & T_TEST_AP)
 
  538           test_ap<Rec224>(cnt, loop);
 
  539         if (pools & T_TEST_WO)
 
  540           test_wo<Rec224>(cnt, loop);
 
  541         if (pools & T_TEST_RW)
 
  542           test_rw<Rec224>(cnt, loop);
 
  551 Uint32 g_currentStartPhase;
 
  556 UpgradeStartup::sendCmAppChg(
Ndbcntr& cntr, 
Signal* signal, Uint32 startLevel){
 
  564 UpgradeStartup::sendCntrMasterReq(
Ndbcntr& cntr, 
Signal* signal, Uint32 
n){
 
  571 #include <SimBlockList.hpp> 
  574 SimBlockList::unload()
 
  579 #define INSTANCE(X) \ 
  580 template void test_ap<X>(unsigned, unsigned);\ 
  581 template void test_wo<X>(unsigned, unsigned);\ 
  582 template void test_rw<X>(unsigned, unsigned);\ 
  583 template void test_pool<X, ArrayPool<X> >(ArrayPool<X>&, unsigned, unsigned);\ 
  584 template void test_pool<X, RecordPool<X, RWPool> >(RecordPool<X, RWPool>&, unsigned, unsigned); \ 
  585 template void test_pool<X, RecordPool<X, WOPool> >(RecordPool<X, WOPool>&, unsigned, unsigned);\ 
  586 template void init<X>(ArrayPool<X>&, unsigned);\ 
  587 template void init<X>(RecordPool<X, RWPool>&, unsigned);\ 
  588 template void init<X>(RecordPool<X, WOPool>&, unsigned)