home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / test / io / buffer / mt_test4.c < prev    next >
C/C++ Source or Header  |  2006-10-18  |  6KB  |  250 lines

  1. /* this test is used to test refill and flush with multiple threads.
  2.  * The idea is that each thread starts from "id" to issue req_cnt
  3.  * requests. 
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <pthread.h>
  9. #include "ncac-interface.h"
  10. #include "internal.h"
  11.  
  12. #include "trove.h"
  13.  
  14. #include "trove-init.c"
  15.  
  16. TROVE_coll_id coll_id;
  17. TROVE_handle file_handle;
  18. TROVE_context_id trove_context;
  19.  
  20. void do_io(int *myid);
  21. int   loop = 16;
  22. int   req_cnt = 5;
  23.  
  24. int main(int argc, char * argv[])
  25. {
  26.  
  27.     NCAC_info_t info;
  28.  
  29.     int ret1, ret2, ret3;
  30.     int extcnt;
  31.     int threadcnt;
  32.  
  33.     pthread_t thread1, thread2;
  34.  
  35.  
  36.  
  37.     trove_init( &coll_id, &file_handle, &trove_context );
  38.  
  39.     info.max_req_num = 1000;
  40.     info.extsize     = 32768;
  41.     info.cachesize   = 1048576;
  42.  
  43.  
  44.     threadcnt = 2;
  45.     extcnt = info.cachesize/info.extsize;
  46.     req_cnt = extcnt/threadcnt/2;
  47.     req_cnt = 8;
  48.  
  49.     cache_init(&info);
  50.  
  51.     ret1 = 0;
  52.     ret2 = 1*req_cnt;
  53.     ret3 = 2*req_cnt;
  54.  
  55.     if (pthread_create(&thread1,
  56.                  NULL,
  57.                  (void *) do_io,
  58.                  (void *) &ret1) != 0)
  59.         perror("pthread_create"), exit(1);
  60.  
  61.     if (pthread_create(&thread2,
  62.                  NULL,
  63.                  (void *) do_io,
  64.                  (void *) &ret2) != 0)
  65.         perror("pthread_create"), exit(1);
  66.  
  67.  
  68.     if (pthread_join(thread1, NULL) != 0)
  69.         perror("pthread_join"),exit(1);
  70.  
  71.     if (pthread_join(thread2, NULL) != 0)
  72.         perror("pthread_join"),exit(1);
  73.  
  74.  
  75.     //cache_dump_active_list();
  76.     //cache_dump_inactive_list();
  77.  
  78.     trove_close_context(coll_id, trove_context);
  79.     trove_finalize(TROVE_METHOD_DBPF);
  80.  
  81.     return 0;
  82. }
  83.  
  84. void do_io(int *id)
  85. {
  86.     PVFS_offset offarr[100];
  87.     PVFS_size sizearr[100];
  88.  
  89.     cache_write_desc_t desc;
  90.  
  91.     cache_request_t request[100];
  92.     cache_reply_t reply[100];
  93.  
  94.     int ret;
  95.     int flag;
  96.     int i;
  97.  
  98.     int comp = 0;
  99.     int start = 0;
  100.     int end = 0;
  101.  
  102.     desc.coll_id        = coll_id;
  103.     desc.handle         = file_handle;
  104.     desc.context_id     = trove_context;
  105.  
  106.     desc.buffer = 0;
  107.     desc.len    = 0;
  108.  
  109.     desc.stream_array_count=1;
  110.     desc.stream_offset_array = offarr;
  111.     desc.stream_size_array = sizearr;
  112.     offarr[0] = 1024;
  113.     sizearr[0] = 65536;
  114.     
  115.  
  116.     start = *id;
  117.     end = start + req_cnt;
  118.  
  119.     /* first step: many writes to full the cache */
  120.  
  121.     for ( i=start; i< end; i++ ) {
  122.         offarr[0] = i*65536;
  123.         ret = cache_write_post(&desc, &request[i], &reply[i], NULL);
  124.         if (ret<0){
  125.             fprintf(stderr, "cache_write_post error\n");
  126.         }else{
  127.             DPRINT("cache_write_post ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
  128.         }
  129.     }
  130.  
  131.     comp = 0; 
  132.     while ( comp < req_cnt ) {
  133.         for ( i=start; i < end; i++ ) {
  134.             if ( request[i].status == NCAC_COMPLETE ) continue;
  135.             ret = cache_req_test(&request[i], &flag, &reply[i], NULL);
  136.             if (ret<0){
  137.                 fprintf(stderr, "cache_req_test error\n");
  138.                 return;
  139.             }else{
  140.                 DPRINT("cache_req_test ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
  141.             }
  142.  
  143.             if ( flag ){
  144.                 ret = cache_req_done(&request[i]);
  145.                 if (ret<0){
  146.                     fprintf(stderr, "cache_req_done error\n");
  147.                     return;
  148.                 }else{
  149.                     DPRINT("cache_req_done ok---\n");
  150.                     comp ++;
  151.                 }
  152.             }
  153.         }
  154.     }
  155.  
  156.     /* bring it to the active list */
  157.     for ( i=start; i< end; i++ ) {
  158.         offarr[0] = i*65536;
  159.         ret = cache_read_post((cache_read_desc_t*)&desc, &request[i], &reply[i], NULL);
  160.         if (ret<0){
  161.             fprintf(stderr, "cache_read_post error\n");
  162.             return;
  163.         }else{
  164.             DPRINT("cache_read_post ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
  165.         }
  166.     }
  167.  
  168.  
  169.     comp = 0; 
  170.     while ( comp < req_cnt ) {
  171.         for ( i=start; i< end; i++ ) {
  172.             if ( request[i].status == NCAC_COMPLETE ) continue;
  173.             ret = cache_req_test(&request[i], &flag, &reply[i], NULL);
  174.             if (ret<0){
  175.                 fprintf(stderr, "cache_req_test error\n");
  176.                 return;
  177.             }else{
  178.                 DPRINT("cache_req_test ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
  179.             }
  180.  
  181.             if ( flag ){
  182.                 ret = cache_req_done(&request[i]);
  183.                 if (ret<0){
  184.                     fprintf(stderr, "cache_req_done error\n");
  185.                     return;
  186.                 }else{
  187.                     DPRINT("cache_req_done ok---\n");
  188.                     comp ++;
  189.                 }
  190.             }
  191.         }
  192.     }
  193.  
  194.  
  195. #if 1 
  196.  
  197.     //if ( *id == 0 ) {
  198.     if ( 1 ) {
  199.         fprintf(stderr, "*******************refill inactive begins\n");
  200.  
  201.         /* refill inactive needed. */
  202.         for ( i=start; i< end; i++ ) {
  203.             offarr[0] = (i+loop)*65536;
  204.             ret = cache_read_post((cache_read_desc_t*)&desc, &request[i], &reply[i], NULL);
  205.             if (ret<0){
  206.                    fprintf(stderr, "cache_read_post error\n");
  207.                 return;
  208.             }else{
  209.                 DPRINT("cache_read_post ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
  210.             }
  211.         }
  212.  
  213.     }
  214.  
  215.  
  216.     //if ( *id == 0 ) {
  217.     if ( 1 ) {
  218.  
  219.         comp = 0;
  220.         while ( comp < req_cnt ) {
  221.                for ( i=start; i< end; i++ ) {
  222.                 if ( request[i].status == NCAC_COMPLETE ) continue;
  223.  
  224.                 ret = cache_req_test(&request[i], &flag, &reply[i], NULL);
  225.                 if (ret<0){
  226.                     fprintf(stderr, "cache_req_test error:%d\n", request[i].status);
  227.                     return;
  228.                 }else{
  229.                            DPRINT("cache_req_test ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
  230.                 }
  231.  
  232.                 if ( flag ){
  233.                     ret = cache_req_done(&request[i]);
  234.                     if (ret<0){
  235.                         fprintf(stderr, "cache_req_done error\n");
  236.                            return;
  237.                     }else{
  238.                         fprintf(stderr, "cache_req_done ok---\n");
  239.                         comp ++;
  240.                     }
  241.                 }
  242.             }
  243.         }
  244.  
  245.     }
  246. #endif
  247.  
  248.     return;
  249. }
  250.