root/branches/Orange-Branch/test/io/buffer/mt_test4.c @ 8871

Revision 8871, 5.8 KB (checked in by mtmoore, 2 years ago)

compiler warning cleanup

Line 
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
16TROVE_coll_id coll_id;
17TROVE_handle file_handle;
18TROVE_context_id trove_context;
19
20void do_io(int *myid);
21int   loop = 16;
22int   req_cnt = 5;
23
24int 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
54    if (pthread_create(&thread1,
55                 NULL,
56                 (void *) do_io,
57                 (void *) &ret1) != 0)
58        perror("pthread_create"), exit(1);
59
60    if (pthread_create(&thread2,
61                 NULL,
62                 (void *) do_io,
63                 (void *) &ret2) != 0)
64        perror("pthread_create"), exit(1);
65
66
67    if (pthread_join(thread1, NULL) != 0)
68        perror("pthread_join"),exit(1);
69
70    if (pthread_join(thread2, NULL) != 0)
71        perror("pthread_join"),exit(1);
72
73
74    //cache_dump_active_list();
75    //cache_dump_inactive_list();
76
77    trove_close_context(coll_id, trove_context);
78    trove_finalize(TROVE_METHOD_DBPF);
79
80    return 0;
81}
82
83void do_io(int *id)
84{
85    PVFS_offset offarr[100];
86    PVFS_size sizearr[100];
87
88    cache_write_desc_t desc;
89
90    cache_request_t request[100];
91    cache_reply_t reply[100];
92
93    int ret;
94    int flag;
95    int i;
96
97    int comp = 0;
98    int start = 0;
99    int end = 0;
100
101    desc.coll_id        = coll_id;
102    desc.handle         = file_handle;
103    desc.context_id     = trove_context;
104
105    desc.buffer = 0;
106    desc.len    = 0;
107
108    desc.stream_array_count=1;
109    desc.stream_offset_array = offarr;
110    desc.stream_size_array = sizearr;
111    offarr[0] = 1024;
112    sizearr[0] = 65536;
113   
114
115    start = *id;
116    end = start + req_cnt;
117
118    /* first step: many writes to full the cache */
119
120    for ( i=start; i< end; i++ ) {
121        offarr[0] = i*65536;
122        ret = cache_write_post(&desc, &request[i], &reply[i], NULL);
123        if (ret<0){
124            fprintf(stderr, "cache_write_post error\n");
125        }else{
126            DPRINT("cache_write_post ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
127        }
128    }
129
130    comp = 0;
131    while ( comp < req_cnt ) {
132        for ( i=start; i < end; i++ ) {
133            if ( request[i].status == NCAC_COMPLETE ) continue;
134            ret = cache_req_test(&request[i], &flag, &reply[i], NULL);
135            if (ret<0){
136                fprintf(stderr, "cache_req_test error\n");
137                            return;
138            }else{
139                DPRINT("cache_req_test ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
140            }
141
142            if ( flag ){
143                ret = cache_req_done(&request[i]);
144                if (ret<0){
145                    fprintf(stderr, "cache_req_done error\n");
146                                return;
147                }else{
148                    DPRINT("cache_req_done ok---\n");
149                    comp ++;
150                }
151            }
152        }
153    }
154
155    /* bring it to the active list */
156    for ( i=start; i< end; i++ ) {
157        offarr[0] = i*65536;
158        ret = cache_read_post((cache_read_desc_t*)&desc, &request[i], &reply[i], NULL);
159        if (ret<0){
160            fprintf(stderr, "cache_read_post error\n");
161                        return;
162        }else{
163            DPRINT("cache_read_post ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
164        }
165    }
166
167
168    comp = 0;
169    while ( comp < req_cnt ) {
170            for ( i=start; i< end; i++ ) {
171            if ( request[i].status == NCAC_COMPLETE ) continue;
172            ret = cache_req_test(&request[i], &flag, &reply[i], NULL);
173            if (ret<0){
174                fprintf(stderr, "cache_req_test error\n");
175                                return;
176                }else{
177                        DPRINT("cache_req_test ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
178                }
179
180                if ( flag ){
181                        ret = cache_req_done(&request[i]);
182                        if (ret<0){
183                        fprintf(stderr, "cache_req_done error\n");
184                                        return;
185                        }else{
186                        DPRINT("cache_req_done ok---\n");
187                                        comp ++;
188                        }
189                }
190                }
191        }
192
193
194#if 1
195
196    //if ( *id == 0 ) {
197    if ( 1 ) {
198        fprintf(stderr, "*******************refill inactive begins\n");
199
200                /* refill inactive needed. */
201                for ( i=start; i< end; i++ ) {
202                offarr[0] = (i+loop)*65536;
203                ret = cache_read_post((cache_read_desc_t*)&desc, &request[i], &reply[i], NULL);
204                if (ret<0){
205                        fprintf(stderr, "cache_read_post error\n");
206                                return;
207                }else{
208                        DPRINT("cache_read_post ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
209                }
210                }
211
212        }
213
214
215        //if ( *id == 0 ) {
216    if ( 1 ) {
217
218        comp = 0;
219        while ( comp < req_cnt ) {
220                for ( i=start; i< end; i++ ) {
221                                if ( request[i].status == NCAC_COMPLETE ) continue;
222
223                ret = cache_req_test(&request[i], &flag, &reply[i], NULL);
224                if (ret<0){
225                                fprintf(stderr, "cache_req_test error:%d\n", request[i].status);
226                                        return;
227                        }else{
228                                DPRINT("cache_req_test ok: status: %d, cbufcnt=%d\n", request[i].status, reply[i].count);
229                        }
230
231                        if ( flag ){
232                                ret = cache_req_done(&request[i]);
233                                if (ret<0){
234                                fprintf(stderr, "cache_req_done error\n");
235                                            return;
236                            }else{
237                                fprintf(stderr, "cache_req_done ok---\n");
238                                                comp ++;
239                                }
240                                }
241                }
242                }
243
244        }
245#endif
246
247    return;
248}
Note: See TracBrowser for help on using the browser.