win-pvdrivers

annotate liblfds.6/test/src/test_stack.c @ 766:6300617040e0

Big changes - not ready for production use.
Removed all the custom DMA handling code as it was completely incompatible with the Windows verifier.
Added liblfds (using the lock free stack) from liblfds.org so that grant's can be obtained at DIRQL.
Fixed xennet and xenvbd to support the changes.
xenusb and xenscsi almost certainly will not yet work after the changes.
author James Harper <james.harper@bendigoit.com.au>
date Sun Jan 31 21:28:42 2010 +1100 (2010-01-31)
parents
children
rev   line source
james@766 1 #include "internal.h"
james@766 2
james@766 3
james@766 4
james@766 5
james@766 6
james@766 7 /****************************************************************************/
james@766 8 void test_stack( void )
james@766 9 {
james@766 10 unsigned int
james@766 11 loop,
james@766 12 cpu_count;
james@766 13
james@766 14 struct stack_state
james@766 15 *ss;
james@766 16
james@766 17 thread_state_t
james@766 18 *thread_handles;
james@766 19
james@766 20 /* TRD : there are 5 tests
james@766 21
james@766 22 1. single reader thread per CPU
james@766 23 - stack always empty
james@766 24 2. single writer thread per CPU
james@766 25 - stack always full
james@766 26 3. one reader and one writer thread per CPU
james@766 27 - stack balanced
james@766 28 4. one reader and two writer threads per CPU
james@766 29 - stack grows
james@766 30 5. two reader and one writer thread per CPU
james@766 31 - stack tends to empty
james@766 32 */
james@766 33
james@766 34 cpu_count = abstraction_cpu_count();
james@766 35
james@766 36 printf( "\n"
james@766 37 "Stack Test\n"
james@766 38 "==========\n" );
james@766 39
james@766 40 // TRD : 1. single reader thread per CPU
james@766 41
james@766 42 printf( "\n"
james@766 43 "1. single reader thread per CPU\n"
james@766 44 "===============================\n" );
james@766 45
james@766 46 stack_new( &ss, 10000 );
james@766 47
james@766 48 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
james@766 49
james@766 50 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 51 abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
james@766 52
james@766 53 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 54 abstraction_thread_wait( thread_handles[loop] );
james@766 55
james@766 56 stack_delete( ss, NULL, NULL );
james@766 57
james@766 58 free( thread_handles );
james@766 59
james@766 60 // TRD : 2. single writer thread per CPU
james@766 61
james@766 62 printf( "\n"
james@766 63 "2. single writer thread per CPU\n"
james@766 64 "===============================\n" );
james@766 65
james@766 66 stack_new( &ss, 10000 );
james@766 67
james@766 68 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
james@766 69
james@766 70 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 71 abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_writer, ss );
james@766 72
james@766 73 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 74 abstraction_thread_wait( thread_handles[loop] );
james@766 75
james@766 76 stack_delete( ss, NULL, NULL );
james@766 77
james@766 78 free( thread_handles );
james@766 79
james@766 80 // TRD : 3. one reader and one writer thread per CPU
james@766 81
james@766 82 printf( "\n"
james@766 83 "3. one reader and one writer thread per CPU\n"
james@766 84 "===========================================\n" );
james@766 85
james@766 86 stack_new( &ss, 10000 );
james@766 87
james@766 88 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
james@766 89
james@766 90 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 91 {
james@766 92 abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
james@766 93 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_writer, ss );
james@766 94 }
james@766 95
james@766 96 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
james@766 97 abstraction_thread_wait( thread_handles[loop] );
james@766 98
james@766 99 stack_delete( ss, NULL, NULL );
james@766 100
james@766 101 free( thread_handles );
james@766 102
james@766 103 // TRD : 4. one reader and two writer threads per CPU
james@766 104
james@766 105 printf( "\n"
james@766 106 "4. one reader and two writer threads per CPU\n"
james@766 107 "============================================\n" );
james@766 108
james@766 109 stack_new( &ss, 10000 );
james@766 110
james@766 111 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 );
james@766 112
james@766 113 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 114 {
james@766 115 abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
james@766 116 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_writer, ss );
james@766 117 abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, stack_internal_thread_writer, ss );
james@766 118 }
james@766 119
james@766 120 for( loop = 0 ; loop < cpu_count * 3 ; loop++ )
james@766 121 abstraction_thread_wait( thread_handles[loop] );
james@766 122
james@766 123 stack_delete( ss, NULL, NULL );
james@766 124
james@766 125 free( thread_handles );
james@766 126
james@766 127 // TRD : 5. two reader and one writer thread per CPU
james@766 128
james@766 129 printf( "\n"
james@766 130 "5. two reader and one writer thread per CPU\n"
james@766 131 "===========================================\n" );
james@766 132
james@766 133 stack_new( &ss, 10000 );
james@766 134
james@766 135 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 );
james@766 136
james@766 137 for( loop = 0 ; loop < cpu_count ; loop++ )
james@766 138 {
james@766 139 abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
james@766 140 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_reader, ss );
james@766 141 abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, stack_internal_thread_writer, ss );
james@766 142 }
james@766 143
james@766 144 for( loop = 0 ; loop < cpu_count * 3 ; loop++ )
james@766 145 abstraction_thread_wait( thread_handles[loop] );
james@766 146
james@766 147 stack_delete( ss, NULL, NULL );
james@766 148
james@766 149 free( thread_handles );
james@766 150
james@766 151 return;
james@766 152 }
james@766 153
james@766 154
james@766 155
james@766 156
james@766 157
james@766 158 /****************************************************************************/
james@766 159 thread_return_t CALLING_CONVENTION stack_internal_thread_reader( void *stack_state )
james@766 160 {
james@766 161 struct stack_state
james@766 162 *ss;
james@766 163
james@766 164 void
james@766 165 *user_data;
james@766 166
james@766 167 time_t
james@766 168 start_time;
james@766 169
james@766 170 unsigned long long int
james@766 171 count = 0;
james@766 172
james@766 173 assert( stack_state != NULL );
james@766 174
james@766 175 ss = (struct stack_state *) stack_state;
james@766 176
james@766 177 time( &start_time );
james@766 178
james@766 179 while( time(NULL) < start_time + 10 )
james@766 180 {
james@766 181 if( stack_pop(ss, &user_data) )
james@766 182 count++;
james@766 183 }
james@766 184
james@766 185 printf( "read count = %llu\n", count );
james@766 186
james@766 187 return( (thread_return_t) EXIT_SUCCESS );
james@766 188 }
james@766 189
james@766 190
james@766 191
james@766 192
james@766 193
james@766 194 /****************************************************************************/
james@766 195 thread_return_t CALLING_CONVENTION stack_internal_thread_writer( void *stack_state )
james@766 196 {
james@766 197 struct stack_state
james@766 198 *ss;
james@766 199
james@766 200 time_t
james@766 201 start_time;
james@766 202
james@766 203 unsigned long long int
james@766 204 count = 0;
james@766 205
james@766 206 assert( stack_state != NULL );
james@766 207
james@766 208 ss = (struct stack_state *) stack_state;
james@766 209
james@766 210 time( &start_time );
james@766 211
james@766 212 while( time(NULL) < start_time + 10 )
james@766 213 {
james@766 214 // TRD : we don't store any user data
james@766 215 if( stack_push(ss, NULL) )
james@766 216 count++;
james@766 217 }
james@766 218
james@766 219 printf( "write count = %llu\n", count );
james@766 220
james@766 221 return( (thread_return_t) EXIT_SUCCESS );
james@766 222 }
james@766 223