示例#1
0
//static int count=0;
static RCCResult ProducerWorker_run(RCCWorker *this_,RCCBoolean timedout,RCCBoolean *newRunCondition)
{
  ( void ) timedout;
  ( void ) newRunCondition;
  uint32_t n;
  size_t len;
  uint32_t *b;

  //  sleep( 1 );

  ProducerWorkerStaticMemory *mem = this_->memories[0];
 // ProducerWorkerProperties *props = this_->properties;


  //  printf("\n\n\n\n\ IN ProducerWorker_run\n\n\n\n");

  //  if ( count++ > 0 )return RCC_OK;

  
  /* Generate a simple pattern and send it */
  char* out_buffer = (char*)this_->ports[ProducerWorker_Data_Out_Port].current.data;

#ifndef NDEBUG
  /*  printf("Out maxlen = %d\n", this_->ports[ProducerWorker_Data_Out_Port].current.maxLength ); */
#endif

  OCPI_TIME_EMIT_C( "Producer Start" );

  //#define LIMIT_PRODUCTION
#ifdef LIMIT_PRODUCTION
#define PP_LIMIT 1
  static int r_count=0;
  if ( ++r_count > PP_LIMIT ) {
    if ( r_count == (PP_LIMIT+1)) {
      printf("**** NOT PRODUCING ANY MORE DATA ****\n"); 
    }
    return RCC_OK;
  }
#endif

#ifndef NDEBUG
  /*    printf("Producing buffer number %d\n", mem->b_count ); */
#endif

  len = this_->ports[ProducerWorker_Data_Out_Port].current.maxLength;

#define GEN_PATTERN
#ifdef GEN_PATTERN
  b = (uint32_t*)out_buffer;
  *b = mem->b_count;
  for ( n=4; n<len; n++ ) out_buffer[n] = (char)(n+mem->b_count)%23; 
#endif

  mem->b_count++; 
  g_prod_p_count =  mem->b_count;

  OCPI_TIME_EMIT_C( "Producer Start Send" );


  /*  printf("Producer is producing with a length = %d\n", len);  */


  this_->ports[ProducerWorker_Data_Out_Port].output.length = len;
  this_->ports[ProducerWorker_Data_Out_Port].output.u.operation = 0;
  this_->container.send( &this_->ports[ProducerWorker_Data_Out_Port], 
			 &this_->ports[ProducerWorker_Data_Out_Port].current, (RCCOpCode)0x54, len );

#define DELAY_AFTER_SEND__
#ifdef DELAY_AFTER_SEND
    printf("Just produced, sleeping for 1 seconds\n");
    sleep( 1 );
    printf("Done sleeping ... \n");
#endif


  OCPI_TIME_EMIT_C( "Producer End Send" );
        
  return RCC_OK;

}
// static int r_count = 0;
static RCCResult ProducerWorker_run(RCCWorker *this_,RCCBoolean timedout,RCCBoolean *newRunCondition)
{
  ( void ) timedout;
  ( void ) newRunCondition;
  uint32_t n;
  uint32_t len;
  int      *b;
  ProducerWorkerProperties *props = this_->properties;
  char* out_buffer = (char*)this_->ports[ProducerWorker_Data_Out_Port].current.data;

  if ( props->buffersProcessed == props->run2BufferCount ) {
    return RCC_OK;
  }

#ifdef TIME_IT
  OCPI_TIME_EMIT_C( "Producer Start" );
#endif

#ifndef NDEBUG
  printf("Producing buffer number %d\n", props->buffersProcessed );
#endif

  len = this_->ports[ProducerWorker_Data_Out_Port].current.maxLength;

#ifndef NDEBUG
  printf("Producing len = %d\n", len );
#endif

  len = len - (props->buffersProcessed%127);

  b = (int*)out_buffer;
  *b = props->buffersProcessed;
  for ( n=4; n<len; n++ ) out_buffer[n] = (char)(n+props->buffersProcessed)%23; 

  props->buffersProcessed++; 

#ifdef TIME_IT
  OCPI_TIME_EMIT_C( "Producer Start Send" ); 
#endif

#ifndef NDEBUG
  printf("Producer is producing\n"); 
#endif

  this_->ports[ProducerWorker_Data_Out_Port].output.length = len;
  this_->ports[ProducerWorker_Data_Out_Port].output.u.operation = (props->buffersProcessed-1)%256;

  if ( props->transferMode == ProducerSend ) {
    this_->container->send( &this_->ports[ProducerWorker_Data_Out_Port], 
                          &this_->ports[ProducerWorker_Data_Out_Port].current, 
                            this_->ports[ProducerWorker_Data_Out_Port].output.u.operation, len );
  }
  else {
     this_->container->advance( &this_->ports[ProducerWorker_Data_Out_Port], 0 );
  }

  props->bytesProcessed += len;

#ifdef TIME_IT
  OCPI_TIME_EMIT_C( "Producer End Send" ); 
#endif
        
  return RCC_OK;

}
static RCCResult ConsumerWorker_run(RCCWorker *this_,RCCBoolean timedout,RCCBoolean *newRunCondition)
{
  ( void ) timedout;
  ( void ) newRunCondition;
  int ncount, *b;
  uint32_t len,n;
//  ConsumerWorkerStaticMemory *mem = this_->memories[0];
  ConsumerWorkerProperties *props = this_->properties;
  int passed = 1;

            
#ifdef TIME_TP
  double          usecs;
  Timespec        cTime;
#endif
                
  char* in_buffer = (char*)this_->ports[ConsumerWorker_Data_In_Port].current.data;

#ifdef TIME_IT
  OCPI_TIME_EMIT_C( "Consumer Start" );
#endif
                    
#ifdef TIME_TP
  if ( mem->b_count == 0 ) {
    get_timestamp( &mem->startTime );
  }
#endif
                      
  len = this_->ports[ConsumerWorker_Data_In_Port].input.length;

#ifdef TESTOC
  printf("OC = %d\n", this_->ports[ConsumerWorker_Data_In_Port].input.u.operation );  
  if ( this_->ports[ConsumerWorker_Data_In_Port].input.u.operation !=  props->buffersProcessed ) {
    passed = 0;
    printf("ERROR!! op code is not correct !!\n");
  }
#endif

  props->bytesProcessed += len;
                          
  if ( len == 0 ) {
#ifndef NDEBUG
    printf("Error !! Got a Zero length buffer\n"); 
#endif
    props->droppedBuffers++;
    return RCC_ADVANCE;
  }
  len -= 4;
                              
  b = (int*)(in_buffer);
  if ( *b != (int)props->buffersProcessed ) {
#ifndef NDEBUG
    printf("ERROR!! Dropped a buffer, got buffer %d, expected %d\n", 
           *b, props->buffersProcessed );
#endif     
    props->droppedBuffers++;
    /* resync */
    props->buffersProcessed = *b;
  }
                                  
  ncount = 0;
  for (n=4; n<len+4; n++) {
    if ( (in_buffer[n] != (char)(n+props->buffersProcessed)%23) && (ncount++ < 100) ) {
                                        
#ifndef NDEBUG
      printf("\nConsumer(b-> %d): Data integrity error(%d) !!, expected %d, got %d\n", 
             props->buffersProcessed,n, (char)(n+props->buffersProcessed)%23, in_buffer[n]);
#endif
      passed = 0;
    }
  }
  if ( passed ) {
#ifndef NDEBUG
    printf("Buffer %d data integrity test passed\n", props->buffersProcessed); 
#endif
  }
  else {
    props->passfail = 0;
  }
                                        
  if ( props->droppedBuffers ) {
#ifndef NDEBUG
    printf("ERROR!! Dropped %d buffer(s)\n", props->droppedBuffers);
#endif
  } 
                                          
  props->buffersProcessed++; 
                                            
#ifdef TIME_TP
  if ( (props->buffersProcessed%50000) == 0 ) { 
    get_timestamp( &cTime );
    usecs = elapsed_usecs ( &mem->startTime, &cTime );
    printf ( "xfer n_bytes %lld %16.4f usecs/transfer %16.4f MB/s\n",
             (unsigned long long)(mem->b_count * len),
             ( usecs / ( double ) mem->b_count ),
             ( ( double ) mem->b_count * ( double )len ) / usecs );
  }
#endif
                                
  if ( props->transferMode == ConsumerConsume ) {
#ifdef TIME_IT
    OCPI_TIME_EMIT_C( "Consumer Start Release" );
#endif
    this_->container->release( &this_->ports[ConsumerWorker_Data_In_Port].current ); 
#ifdef TIME_IT
    OCPI_TIME_EMIT_C( "Consumer End Release" );
#endif
  }
  else {

          if ( props->takenBuffers[props->releaseBufferIndex].data ) {
        this_->container->take( &this_->ports[ConsumerWorker_Data_In_Port],
                   &props->takenBuffers[props->releaseBufferIndex], &props->takenBuffers[props->takenBufferIndex] );
        props->releaseBufferIndex =  (props->releaseBufferIndex + 1)%CONSUMER_TAKE_COUNT;
          }
          else {
        this_->container->take( &this_->ports[ConsumerWorker_Data_In_Port],
                   NULL, &props->takenBuffers[props->takenBufferIndex] );
          }

      
          // Take the buffers for a simulated sliding window algorithm
          props->takenBufferIndex =  (props->takenBufferIndex + 1)%CONSUMER_TAKE_COUNT;
 
  }

  return RCC_OK;

}
示例#4
0
static RCCResult ConsumerWorker_run(RCCWorker *this_,RCCBoolean timedout,RCCBoolean *newRunCondition)
{
  ( void ) timedout;
  ( void ) newRunCondition;
  uint32_t ncount, *b;
  size_t len,n;
  ConsumerWorkerStaticMemory *mem = this_->memories[0];
  ConsumerWorkerProperties *props = this_->properties;
  unsigned passed = 1;

  //  printf("\n\n\n\n\ IN ConsumerWorker_run\n\n\n\n");

#ifdef TIME_TP
  double          usecs;
  Timespec        cTime;
#endif

  char* in_buffer = (char*)this_->ports[ConsumerWorker_Data_In_Port].current.data;

  /*  printf("Cos buffer = %lld\n", in_buffer ); 
      printf("In maxlen = %d\n", this_->ports[ConsumerWorker_Data_In_Port].current.maxLength ); 
  */


    OCPI_TIME_EMIT_C( "Worker Consumer Start" );

#ifdef TIME_TP
  if ( mem->b_count == 0 ) {
    get_timestamp( &mem->startTime );
  }
#endif

  len = this_->ports[ConsumerWorker_Data_In_Port].input.length;

  /*
  printf("Consumer: got a buffer(%d) of data, len = %d first words = %d,%d \n", 
         mem->b_count, len, (int)in_buffer[0],(int)in_buffer[4] ); 
  */

  /* printf("Con: Actual len = %d, max = %d\n", len, this_->ports[ConsumerWorker_Data_In_Port].maxLength );
   */
  if ( len == 0 ) {
    printf("Error !! Got a Zero length buffer\n"); 
    return RCC_ADVANCE;
  }
  len -= 4;
  
#define CHECK_DATA
#ifdef CHECK_DATA
  b = (unsigned*)(in_buffer);

#define RESYNC
#ifdef RESYNC

  //  sleep( 2 );

  if ( *b != mem->b_count ) {
    printf("ERROR!! Dropped a buffer, got buffer %d, expected %d\n", 
           *b, mem->b_count );
    dropped_b++;
    /* resync */
    mem->b_count = *b;
  }
#endif

  ncount = 0;
  for (n=4; n<len+4; n++) {
    if ( (in_buffer[n] != (char)(n+mem->b_count)%23) && (ncount++ < 100000) ) {
      printf("Consumer(%u, %zu, b-> %d): Data integrity error(%zd) !!, expected %d, got %d\n", 
             props->startIndex, len, mem->b_count,n, (char)(n+mem->b_count)%23, in_buffer[n]);
      passed = 0;
    }
  }
  props->startIndex++;
  if ( passed ) {
    if ( (mem->b_count%5000) == 0 ) 
      printf("Buffer %d data integrity test passed\n", mem->b_count);
  }
#endif

  if ( ((report_er++)%10000) == 0 ) { 
    if ( dropped_b ) {
      printf("ERROR!! Dropped %d buffer(s)\n", dropped_b);
    }
  } 
  mem->b_count++; 
#ifdef TIME_TP
  if ( (mem->b_count%50000) == 0 ) { 
    get_timestamp( &cTime );
    usecs = elapsed_usecs ( &mem->startTime, &cTime );
    printf ( "xfer n_bytes %lld %16.4f usecs/transfer %16.4f MB/s\n",
             (unsigned long long)(mem->b_count * len),
             ( usecs / ( double ) mem->b_count ),
             ( ( double ) mem->b_count * ( double )len ) / usecs );
  }
#endif


  OCPI_TIME_EMIT_C("Consumer Start Release");
  //  this_->container.release( &this_->ports[ConsumerWorker_Data_In_Port].current ); 
  OCPI_TIME_EMIT_C("Consumer End Release");
  return RCC_ADVANCE;
}
static RCCResult UTGProducerWorker_run(RCCWorker *this_,RCCBoolean timedout,RCCBoolean *newRunCondition)
{
  ( void ) timedout;
  ( void ) newRunCondition;
  uint32_t n;
  size_t len;
  uint32_t *b;
  UTGProducerWorkerProperties *props = this_->properties;
  char* out_buffer = (char*)this_->ports[UTGProducerWorker_Data_Out_Port0].current.data;

#ifdef TEST_ONE_SHOT
  if ( PROD_PRODUCE == 0 ) {
    return RCC_OK;
  }
  PROD_PRODUCE = 0;
#endif


  if ( ! out_buffer ) {
    this_->container.request( &this_->ports[UTGProducerWorker_Data_Out_Port0], 0 );
  }
  out_buffer = (char*)this_->ports[UTGProducerWorker_Data_Out_Port0].current.data;
  if ( ! out_buffer ) {
    return RCC_OK;
  }

  if ( props->buffersProcessed == props->run2BufferCount ) {
    return RCC_OK;
  }


  OCPI_TIME_EMIT_C( "Producer Start" );

#ifndef NDEBUG
  printf("Producing buffer number %d\n", props->buffersProcessed );
#endif

  len = this_->ports[UTGProducerWorker_Data_Out_Port0].current.maxLength;

#ifndef NDEBUG
  printf("lenght = %zu\n", len);
#endif

  b = (uint32_t*)out_buffer;
  *b = props->buffersProcessed;
  for ( n=4; n<len; n++ ) out_buffer[n] = (char)(n+props->buffersProcessed)%23; 

  props->buffersProcessed++; 
 
  OCPI_TIME_EMIT_C( "Producer Start Send" );

#ifndef NDEBUG
  printf("Producer is producing..\n"); 
#endif

  this_->ports[UTGProducerWorker_Data_Out_Port0].output.length = len;
  this_->ports[UTGProducerWorker_Data_Out_Port0].output.u.operation = props->buffersProcessed%256;
  this_->container.send( &this_->ports[UTGProducerWorker_Data_Out_Port0], 
                          &this_->ports[UTGProducerWorker_Data_Out_Port0].current, 0x54, len );

  OCPI_TIME_EMIT_C( "Producer Start End" );
        
  return RCC_OK;

}
static RCCResult UTGConsumerWorker_run(RCCWorker *this_,RCCBoolean timedout,RCCBoolean *newRunCondition)
{
  ( void ) timedout;
  ( void ) newRunCondition;

  uint32_t ncount, *b;
  size_t len,n;
//  UTGConsumerWorkerStaticMemory *mem = this_->memories[0];
  UTGConsumerWorkerProperties *props = this_->properties;
  int passed = 1;

#ifdef TIME_TP
  double          usecs;
  Timespec        cTime;
#endif

  char* in_buffer = (char*)this_->ports[UTGConsumerWorker_Data_In_Port0].current.data;

  OCPI_TIME_EMIT_C( "Consumer Start" );

#ifdef TIME_TP
  if ( mem->b_count == 0 ) {
    get_timestamp( &mem->startTime );
  }
#endif

  len = this_->ports[UTGConsumerWorker_Data_In_Port0].input.length;

  if ( len == 0 ) {
#ifndef NDEBUG
    printf("Error !! Got a Zero length buffer\n"); 
#endif
    props->droppedBuffers++;
    return RCC_ADVANCE;
  }
  len -= 4;
  
  b = (uint32_t*)(in_buffer);
  if ( *b != props->buffersProcessed ) {
#ifndef NDEBUG
    printf("ERROR!! Dropped a buffer, got buffer %d, expected %d\n", 
           *b, props->buffersProcessed );
#endif     
    props->droppedBuffers++;
    /* resync */
    props->buffersProcessed = *b;
  }
  
  ncount = 0;
  for (n=4; n<len+4; n++) {
    if ( (in_buffer[n] != (char)(n+props->buffersProcessed)%23) && (ncount++ < 100000) ) {
      printf("UTGConsumer(b-> %d): Data integrity error(%zu) !!, expected %d, got %d\n", 
             props->buffersProcessed,n, (char)(n+props->buffersProcessed)%23, in_buffer[n]);
      passed = 0;
    }
  }
  if ( passed ) {
#ifndef NDEBUG
    printf("Buffer %d data integrity test passed\n", props->buffersProcessed); 
#endif
  }
  else {
    props->passfail = 0;
  }

  if ( props->droppedBuffers ) {
#ifndef NDEBUG
    printf("ERROR!! Dropped %d buffer(s)\n", props->droppedBuffers);
#endif
  } 

  props->buffersProcessed++; 

#ifdef TIME_TP
  if ( (props->buffersProcessed%50000) == 0 ) { 
    get_timestamp( &cTime );
    usecs = elapsed_usecs ( &mem->startTime, &cTime );
    printf ( "xfer n_bytes %lld %16.4f usecs/transfer %16.4f MB/s\n",
             (unsigned long long)(mem->b_count * len),
             ( usecs / ( double ) mem->b_count ),
             ( ( double ) mem->b_count * ( double )len ) / usecs );
  }
#endif

  OCPI_TIME_EMIT_C( "Consumer Start Release" );
  this_->container.advance( &this_->ports[UTGConsumerWorker_Data_In_Port0], 0 ); 
  OCPI_TIME_EMIT_C( "Consumer End Release" );
  return RCC_OK;
}