win-pvdrivers

view liblfds.6/test/src/test_slist.c @ 1025:aa2e51f67f7c

Fix hibernate under Win8. Change debugprints.
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:14:53 2013 +1100 (2013-02-19)
parents 6300617040e0
children
line source
1 #include "internal.h"
7 /****************************************************************************/
8 void test_slist( void )
9 {
10 unsigned int
11 loop,
12 cpu_count;
14 thread_state_t
15 *thread_handles;
17 struct slist_thread_start_state
18 stss;
20 /* TRD : 1. one head writer per CPU
21 2. make one element, then one after writer per CPU
22 3. make a list, then one list traverser per CPU
23 4. one head writer and one list traverser per CPU
24 5. make one element, then one after writer and one list traverser per CPU
25 6. make a list, then one 100% deleter-traverser per CPU
26 7. make a list, then one 25% deleter-traverser per CPU
27 8. one head writer and one 100% deleter-traverse per CPU
28 9. one head writer and one 25% deleter-traverse per CPU
29 10. make one element, then one after writer and one 100% deleter-traverser per CPU
30 11. make one element, then one after writer and one 25% deleter-traverser per CPU
31 12. one head writer, one after writer, one traverser and one 25% deleter-traverser per CPU
32 */
34 cpu_count = abstraction_cpu_count();
36 printf( "\n"
37 "SList Test\n"
38 "==========\n" );
40 // TRD : 1. one head writer per CPU
42 printf( "\n"
43 "1. one head writer per CPU\n"
44 "==========================\n" );
46 slist_new( &stss.ss, NULL, NULL );
47 stss.iteration_modulo = 1;
48 stss.se = NULL;
49 stss.duration = 1;
51 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
53 for( loop = 0 ; loop < cpu_count ; loop++ )
54 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_head_writer, &stss );
56 for( loop = 0 ; loop < cpu_count ; loop++ )
57 abstraction_thread_wait( thread_handles[loop] );
59 slist_delete( stss.ss );
61 free( thread_handles );
63 // TRD : 2. make one element, then one after writer per CPU
65 printf( "\n"
66 "2. make one element, then one after writer per CPU\n"
67 "==================================================\n" );
69 slist_new( &stss.ss, NULL, NULL );
70 stss.iteration_modulo = 1;
71 stss.se = slist_new_head( stss.ss, (void *) NULL );
72 stss.duration = 1;
74 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
76 for( loop = 0 ; loop < cpu_count ; loop++ )
77 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_after_writer, &stss );
79 for( loop = 0 ; loop < cpu_count ; loop++ )
80 abstraction_thread_wait( thread_handles[loop] );
82 slist_delete( stss.ss );
84 free( thread_handles );
86 // TRD : 3. make a list, then one list traverser per CPU
88 printf( "\n"
89 "3. make a list, then one list traverser per CPU\n"
90 "===============================================\n" );
92 slist_new( &stss.ss, NULL, NULL );
93 stss.iteration_modulo = 1;
94 stss.se = NULL;
95 stss.duration = 10;
97 // TRD : small list so we get collisions
98 for( loop = 0 ; loop < 10 ; loop++ )
99 slist_new_head( stss.ss, (void *) 0 );
101 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
103 for( loop = 0 ; loop < cpu_count ; loop++ )
104 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_traverser, &stss );
106 for( loop = 0 ; loop < cpu_count ; loop++ )
107 abstraction_thread_wait( thread_handles[loop] );
109 slist_delete( stss.ss );
111 free( thread_handles );
113 // TRD : 4. one head writer and one list traverser per CPU
115 printf( "\n"
116 "4. one head writer and one list traverser per CPU\n"
117 "=================================================\n" );
119 slist_new( &stss.ss, NULL, NULL );
120 stss.iteration_modulo = 1;
121 stss.se = NULL;
122 stss.duration = 1;
124 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
126 for( loop = 0 ; loop < cpu_count ; loop++ )\
127 {
128 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_head_writer, &stss );
129 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_traverser, &stss );
130 }
132 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
133 abstraction_thread_wait( thread_handles[loop] );
135 slist_delete( stss.ss );
137 free( thread_handles );
139 // TRD : 5. make one element, then one after writer and one list traverser per CPU
141 printf( "\n"
142 "5. make one element, then one after writer and one list traverser per CPU\n"
143 "=========================================================================\n" );
145 slist_new( &stss.ss, NULL, NULL );
146 stss.iteration_modulo = 1;
147 stss.se = slist_new_head( stss.ss, (void *) NULL );
148 stss.duration = 1;
150 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
152 for( loop = 0 ; loop < cpu_count ; loop++ )\
153 {
154 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_after_writer, &stss );
155 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_traverser, &stss );
156 }
158 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
159 abstraction_thread_wait( thread_handles[loop] );
161 slist_delete( stss.ss );
163 free( thread_handles );
165 // TRD : 6. make a list, then one 100% deleter-traverser per CPU
167 printf( "\n"
168 "6. make a list, then one 100%% deleter-traverser per CPU\n"
169 "=======================================================\n" );
171 slist_new( &stss.ss, NULL, NULL );
172 stss.iteration_modulo = 1;
173 stss.se = NULL;
174 stss.duration = 1;
176 for( loop = 0 ; loop < 10000 ; loop++ )
177 slist_new_head( stss.ss, (void *) 0 );
179 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
181 for( loop = 0 ; loop < cpu_count ; loop++ )
182 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_deleter_traverser, &stss );
184 for( loop = 0 ; loop < cpu_count ; loop++ )
185 abstraction_thread_wait( thread_handles[loop] );
187 slist_delete( stss.ss );
189 free( thread_handles );
191 // TRD : 7. make a list, then one 25% deleter-traverser per CPU
193 printf( "\n"
194 "7. make a list, then one 25%% deleter-traverser per CPU\n"
195 "======================================================\n" );
197 slist_new( &stss.ss, NULL, NULL );
198 stss.iteration_modulo = 4;
199 stss.se = NULL;
200 stss.duration = 1;
202 for( loop = 0 ; loop < 10000 ; loop++ )
203 slist_new_head( stss.ss, (void *) 0 );
205 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
207 for( loop = 0 ; loop < cpu_count ; loop++ )
208 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_deleter_traverser, &stss );
210 for( loop = 0 ; loop < cpu_count ; loop++ )
211 abstraction_thread_wait( thread_handles[loop] );
213 slist_delete( stss.ss );
215 free( thread_handles );
217 // TRD : 8. one head writer and one 100% deleter-traverse per CPU
219 printf( "\n"
220 "8. one head writer and one 100%% deleter-traverse per CPU\n"
221 "========================================================\n" );
223 slist_new( &stss.ss, NULL, NULL );
224 stss.iteration_modulo = 1;
225 stss.se = NULL;
226 stss.duration = 10;
228 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
230 for( loop = 0 ; loop < cpu_count ; loop++ )
231 {
232 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_head_writer, &stss );
233 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_deleter_traverser, &stss );
234 }
236 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
237 abstraction_thread_wait( thread_handles[loop] );
239 slist_delete( stss.ss );
241 free( thread_handles );
243 // TRD : 9. one head writer and one 25% deleter-traverse per CPU
245 printf( "\n"
246 "9. one head writer and one 25%% deleter-traverse per CPU\n"
247 "=======================================================\n" );
249 slist_new( &stss.ss, NULL, NULL );
250 stss.iteration_modulo = 4;
251 stss.se = NULL;
252 stss.duration = 1;
254 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
256 for( loop = 0 ; loop < cpu_count ; loop++ )
257 {
258 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_head_writer, &stss );
259 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_deleter_traverser, &stss );
260 }
262 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
263 abstraction_thread_wait( thread_handles[loop] );
265 slist_delete( stss.ss );
267 free( thread_handles );
269 // TRD : 10. make one element, then one after writer and one 100% deleter-traverser per CPU
271 printf( "\n"
272 "10. make one element, then one after writer and one 100%% deleter-traverser per CPU\n"
273 "==================================================================================\n" );
275 slist_new( &stss.ss, NULL, NULL );
276 stss.iteration_modulo = 1;
277 stss.se = slist_new_head( stss.ss, (void *) NULL );
278 stss.duration = 10;
280 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
282 for( loop = 0 ; loop < cpu_count ; loop++ )
283 {
284 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_after_writer, &stss );
285 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_deleter_traverser, &stss );
286 }
288 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
289 abstraction_thread_wait( thread_handles[loop] );
291 slist_delete( stss.ss );
293 free( thread_handles );
295 // TRD : 11. make one element, then one after writer and one 25% deleter-traverser per CPU
297 printf( "\n"
298 "11. make one element, then one after writer and one 25%% deleter-traverser per CPU\n"
299 "=================================================================================\n" );
301 slist_new( &stss.ss, NULL, NULL );
302 stss.iteration_modulo = 4;
303 stss.se = slist_new_head( stss.ss, (void *) NULL );
304 stss.duration = 1;
306 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
308 for( loop = 0 ; loop < cpu_count ; loop++ )
309 {
310 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_after_writer, &stss );
311 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_deleter_traverser, &stss );
312 }
314 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
315 abstraction_thread_wait( thread_handles[loop] );
317 slist_delete( stss.ss );
319 free( thread_handles );
321 // TRD : 12. one head writer, one after writer, one traverser and one 25% deleter-traverser per CPU
323 printf( "\n"
324 "12. one head writer, one after writer, one traverser and one 25%% deleter-traverser per CPU\n"
325 "==========================================================================================\n" );
327 slist_new( &stss.ss, NULL, NULL );
328 stss.iteration_modulo = 4;
329 stss.se = slist_new_head( stss.ss, (void *) NULL );
330 stss.duration = 1;
332 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 4 );
334 for( loop = 0 ; loop < cpu_count ; loop++ )
335 {
336 abstraction_thread_start( &thread_handles[loop], loop, slist_internal_thread_head_writer, &stss );
337 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, slist_internal_thread_after_writer, &stss );
338 abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, slist_internal_thread_traverser, &stss );
339 abstraction_thread_start( &thread_handles[loop+cpu_count*3], loop, slist_internal_thread_deleter_traverser, &stss );
340 }
342 for( loop = 0 ; loop < cpu_count * 4 ; loop++ )
343 abstraction_thread_wait( thread_handles[loop] );
345 slist_delete( stss.ss );
347 free( thread_handles );
349 return;
350 }
356 /****************************************************************************/
357 thread_return_t CALLING_CONVENTION slist_internal_thread_head_writer( void *slist_thread_start_state )
358 {
359 struct slist_thread_start_state
360 *stss;
362 time_t
363 start_time;
365 unsigned long int
366 count = 0;
368 assert( slist_thread_start_state != NULL );
370 stss = (struct slist_thread_start_state *) slist_thread_start_state;
372 time( &start_time );
374 while( time(NULL) < start_time + stss->duration )
375 if( slist_new_head(stss->ss, (void *) 0) )
376 count++;
378 printf( "head writer count = %lu\n", count );
380 return( (thread_return_t) EXIT_SUCCESS );
381 }
387 /****************************************************************************/
388 thread_return_t CALLING_CONVENTION slist_internal_thread_after_writer( void *slist_thread_start_state )
389 {
390 struct slist_thread_start_state
391 *stss;
393 time_t
394 start_time;
396 unsigned long int
397 count = 0;
399 assert( slist_thread_start_state != NULL );
401 stss = (struct slist_thread_start_state *) slist_thread_start_state;
403 time( &start_time );
405 while( time(NULL) < start_time + stss->duration )
406 if( slist_new_next(stss->se, (void *) 0) )
407 count++;
409 printf( "after writer count = %lu\n", count );
411 return( (thread_return_t) EXIT_SUCCESS );
412 }
418 /****************************************************************************/
419 thread_return_t CALLING_CONVENTION slist_internal_thread_traverser( void *slist_thread_start_state )
420 {
421 struct slist_thread_start_state
422 *stss;
424 time_t
425 start_time;
427 unsigned long int
428 count = 0,
429 iteration = 0;
431 struct slist_element
432 *se;
434 assert( slist_thread_start_state != NULL );
436 stss = (struct slist_thread_start_state *) slist_thread_start_state;
438 time( &start_time );
440 slist_get_head( stss->ss, &se );
442 while( time(NULL) < start_time + stss->duration )
443 {
444 if( !(iteration % stss->iteration_modulo) )
445 {
446 slist_get_next( se, &se );
447 count++;
448 }
450 if( se == NULL )
451 {
452 slist_get_head( stss->ss, &se );
453 count++;
454 }
456 iteration++;
457 }
459 printf( "traverser count = %lu\n", count );
461 return( (thread_return_t) EXIT_SUCCESS );
462 }
468 /****************************************************************************/
469 thread_return_t CALLING_CONVENTION slist_internal_thread_deleter_traverser( void *slist_thread_start_state )
470 {
471 struct slist_thread_start_state
472 *stss;
474 time_t
475 start_time;
477 unsigned long int
478 count = 0,
479 iteration = 0;
481 struct slist_element
482 *se;
484 assert( slist_thread_start_state != NULL );
486 stss = (struct slist_thread_start_state *) slist_thread_start_state;
488 time( &start_time );
490 slist_get_head( stss->ss, &se );
492 while( time(NULL) < start_time + stss->duration )
493 {
494 if( se != NULL and !(iteration % stss->iteration_modulo) )
495 {
496 slist_delete_element( stss->ss, se );
497 count++;
498 }
500 if( se != NULL )
501 slist_get_next( se, &se );
503 if( se == NULL )
504 slist_get_head( stss->ss, &se );
506 iteration++;
507 }
509 printf( "deleter-traverser count = %lu\n", count );
511 return( (thread_return_t) EXIT_SUCCESS );
512 }