win-pvdrivers

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/liblfds.6/test/src/test_stack.c	Sun Jan 31 21:28:42 2010 +1100
     1.3 @@ -0,0 +1,223 @@
     1.4 +#include "internal.h"
     1.5 +
     1.6 +
     1.7 +
     1.8 +
     1.9 +
    1.10 +/****************************************************************************/
    1.11 +void test_stack( void )
    1.12 +{
    1.13 +  unsigned int
    1.14 +    loop,
    1.15 +    cpu_count;
    1.16 +
    1.17 +  struct stack_state
    1.18 +    *ss;
    1.19 +
    1.20 +  thread_state_t
    1.21 +    *thread_handles;
    1.22 +
    1.23 +  /* TRD : there are 5 tests
    1.24 +
    1.25 +           1. single reader thread per CPU
    1.26 +              - stack always empty
    1.27 +           2. single writer thread per CPU
    1.28 +              - stack always full
    1.29 +           3. one reader and one writer thread per CPU
    1.30 +              - stack balanced
    1.31 +           4. one reader and two writer threads per CPU
    1.32 +              - stack grows
    1.33 +           5. two reader and one writer thread per CPU
    1.34 +              - stack tends to empty
    1.35 +  */
    1.36 +
    1.37 +  cpu_count = abstraction_cpu_count();
    1.38 +
    1.39 +  printf( "\n"
    1.40 +          "Stack Test\n"
    1.41 +          "==========\n" );
    1.42 +
    1.43 +  // TRD : 1. single reader thread per CPU
    1.44 +
    1.45 +  printf( "\n"
    1.46 +          "1. single reader thread per CPU\n"
    1.47 +          "===============================\n" );
    1.48 +
    1.49 +  stack_new( &ss, 10000 );
    1.50 +
    1.51 +  thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
    1.52 +
    1.53 +  for( loop = 0 ; loop < cpu_count ; loop++ )
    1.54 +    abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
    1.55 +
    1.56 +  for( loop = 0 ; loop < cpu_count ; loop++ )
    1.57 +    abstraction_thread_wait( thread_handles[loop] );
    1.58 +
    1.59 +  stack_delete( ss, NULL, NULL );
    1.60 +
    1.61 +  free( thread_handles );
    1.62 +
    1.63 +  // TRD : 2. single writer thread per CPU
    1.64 +
    1.65 +  printf( "\n"
    1.66 +          "2. single writer thread per CPU\n"
    1.67 +          "===============================\n" );
    1.68 +
    1.69 +  stack_new( &ss, 10000 );
    1.70 +
    1.71 +  thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
    1.72 +
    1.73 +  for( loop = 0 ; loop < cpu_count ; loop++ )
    1.74 +    abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_writer, ss );
    1.75 +
    1.76 +  for( loop = 0 ; loop < cpu_count ; loop++ )
    1.77 +    abstraction_thread_wait( thread_handles[loop] );
    1.78 +
    1.79 +  stack_delete( ss, NULL, NULL );
    1.80 +
    1.81 +  free( thread_handles );
    1.82 +
    1.83 +  // TRD : 3. one reader and one writer thread per CPU
    1.84 +
    1.85 +  printf( "\n"
    1.86 +          "3. one reader and one writer thread per CPU\n"
    1.87 +          "===========================================\n" );
    1.88 +
    1.89 +  stack_new( &ss, 10000 );
    1.90 +
    1.91 +  thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
    1.92 +
    1.93 +  for( loop = 0 ; loop < cpu_count ; loop++ )
    1.94 +  {
    1.95 +    abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
    1.96 +    abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_writer, ss );
    1.97 +  }
    1.98 +
    1.99 +  for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
   1.100 +    abstraction_thread_wait( thread_handles[loop] );
   1.101 +
   1.102 +  stack_delete( ss, NULL, NULL );
   1.103 +
   1.104 +  free( thread_handles );
   1.105 +
   1.106 +  // TRD : 4. one reader and two writer threads per CPU
   1.107 +
   1.108 +  printf( "\n"
   1.109 +          "4. one reader and two writer threads per CPU\n"
   1.110 +          "============================================\n" );
   1.111 +
   1.112 +  stack_new( &ss, 10000 );
   1.113 +
   1.114 +  thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 );
   1.115 +
   1.116 +  for( loop = 0 ; loop < cpu_count ; loop++ )
   1.117 +  {
   1.118 +    abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
   1.119 +    abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_writer, ss );
   1.120 +    abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, stack_internal_thread_writer, ss );
   1.121 +  }
   1.122 +
   1.123 +  for( loop = 0 ; loop < cpu_count * 3 ; loop++ )
   1.124 +    abstraction_thread_wait( thread_handles[loop] );
   1.125 +
   1.126 +  stack_delete( ss, NULL, NULL );
   1.127 +
   1.128 +  free( thread_handles );
   1.129 +
   1.130 +  // TRD : 5. two reader and one writer thread per CPU
   1.131 +
   1.132 +  printf( "\n"
   1.133 +          "5. two reader and one writer thread per CPU\n"
   1.134 +          "===========================================\n" );
   1.135 +
   1.136 +  stack_new( &ss, 10000 );
   1.137 +
   1.138 +  thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 );
   1.139 +
   1.140 +  for( loop = 0 ; loop < cpu_count ; loop++ )
   1.141 +  {
   1.142 +    abstraction_thread_start( &thread_handles[loop], loop, stack_internal_thread_reader, ss );
   1.143 +    abstraction_thread_start( &thread_handles[loop+cpu_count], loop, stack_internal_thread_reader, ss );
   1.144 +    abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, stack_internal_thread_writer, ss );
   1.145 +  }
   1.146 +
   1.147 +  for( loop = 0 ; loop < cpu_count * 3 ; loop++ )
   1.148 +    abstraction_thread_wait( thread_handles[loop] );
   1.149 +
   1.150 +  stack_delete( ss, NULL, NULL );
   1.151 +
   1.152 +  free( thread_handles );
   1.153 +
   1.154 +  return;
   1.155 +}
   1.156 +
   1.157 +
   1.158 +
   1.159 +
   1.160 +
   1.161 +/****************************************************************************/
   1.162 +thread_return_t CALLING_CONVENTION stack_internal_thread_reader( void *stack_state )
   1.163 +{
   1.164 +  struct stack_state
   1.165 +    *ss;
   1.166 +
   1.167 +  void
   1.168 +    *user_data;
   1.169 +
   1.170 +  time_t
   1.171 +    start_time;
   1.172 +
   1.173 +  unsigned long long int
   1.174 +    count = 0;
   1.175 +
   1.176 +  assert( stack_state != NULL );
   1.177 +
   1.178 +  ss = (struct stack_state *) stack_state;
   1.179 +
   1.180 +  time( &start_time );
   1.181 +
   1.182 +  while( time(NULL) < start_time + 10 )
   1.183 +  {
   1.184 +    if( stack_pop(ss, &user_data) )
   1.185 +      count++;
   1.186 +  }
   1.187 +
   1.188 +  printf( "read count = %llu\n", count );
   1.189 +
   1.190 +  return( (thread_return_t) EXIT_SUCCESS );
   1.191 +}
   1.192 +
   1.193 +
   1.194 +
   1.195 +
   1.196 +
   1.197 +/****************************************************************************/
   1.198 +thread_return_t CALLING_CONVENTION stack_internal_thread_writer( void *stack_state )
   1.199 +{
   1.200 +  struct stack_state
   1.201 +    *ss;
   1.202 +
   1.203 +  time_t
   1.204 +    start_time;
   1.205 +
   1.206 +  unsigned long long int
   1.207 +    count = 0;
   1.208 +
   1.209 +  assert( stack_state != NULL );
   1.210 +
   1.211 +  ss = (struct stack_state *) stack_state;
   1.212 +
   1.213 +  time( &start_time );
   1.214 +
   1.215 +  while( time(NULL) < start_time + 10 )
   1.216 +  {
   1.217 +    // TRD : we don't store any user data
   1.218 +    if( stack_push(ss, NULL) )
   1.219 +      count++;
   1.220 +  }
   1.221 +
   1.222 +  printf( "write count = %llu\n", count );
   1.223 +
   1.224 +  return( (thread_return_t) EXIT_SUCCESS );
   1.225 +}
   1.226 +