Changeset 8955

Show
Ignore:
Timestamp:
07/20/08 14:47:16
Author:
jcorgan
Message:

Receiving data now flowing through top-level rx_samples with raw copy handler.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/branches/features/host-ng/host-ng/apps/test.sh

    r8749 r8955  
    11#!/bin/sh 
    22 
    3 sudo ./test_usrp2 -d 5 1>cerr 2>&1 
     3sudo ./test_usrp2 -d 4 
    44 
    55 
  • usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc

    r8856 r8955  
    2424#include <usrp2/tune_result.h> 
    2525#include <usrp2/strtod_si.h> 
     26#include <usrp2/copy_handler.h> 
    2627#include <gruel/realtime.h> 
     28#include <sys/time.h> 
    2729#include <iostream> 
    2830#include <string.h> 
     
    120122  } 
    121123 
    122   printf("baseband_freq=%f\n", tr.baseband_freq); 
    123   printf("     ddc_freq=%f\n", tr.dxc_freq); 
    124   printf("residual_freq=%f\n", tr.residual_freq); 
    125   printf("     inverted=%s\n", tr.spectrum_inverted ? "yes" : "no"); 
     124  printf("Daughterboard configuration:\n"); 
     125  printf("  baseband_freq=%f\n", tr.baseband_freq); 
     126  printf("       ddc_freq=%f\n", tr.dxc_freq); 
     127  printf("  residual_freq=%f\n", tr.residual_freq); 
     128  printf("       inverted=%s\n\n", tr.spectrum_inverted ? "yes" : "no"); 
    126129   
    127130  if (!u2->set_rx_decim(rx_decim)) { 
     
    129132    exit(1); 
    130133  } 
     134 
     135  printf("USRP2 using decimation rate of %d\n", rx_decim); 
    131136     
    132137  if (!u2->start_rx_streaming()){ 
     
    135140  } 
    136141 
    137   // Temporary to allow program to finish 
    138   int n = 0; 
    139   while(n++ < 100000) 
    140     u2->rx_samples(0, NULL); 
     142  size_t bufsize = 100e6; 
     143  unsigned char *buf = (unsigned char *)malloc(bufsize); 
     144  usrp2::copy_handler h(buf, bufsize); 
    141145 
     146  printf("Receiving data into buffer of length %li bytes.\n\n", bufsize); 
     147 
     148  struct timeval start, end; 
     149  gettimeofday(&start, 0); 
     150 
     151 
     152  printf("Each '.' is 100 packets:\n"); 
     153  bool ok; 
     154  unsigned int n = 0; 
     155  do { 
     156    ok = u2->rx_samples(0, &h); 
     157    if (h.times() > n) { 
     158      printf("."); fflush(stdout); 
     159      n = n+100; 
     160    } 
     161  } 
     162  while (ok && !h.full()); 
     163 
     164  gettimeofday(&end, 0); 
     165  long n_usecs = end.tv_usec-start.tv_usec; 
     166  long n_secs = end.tv_sec-start.tv_sec; 
     167  double elapsed = (double)n_secs + (double)n_usecs*1e-6; 
     168  double mbs = h.bytes()/elapsed/1e6; 
     169  double pps = h.times()/elapsed; 
     170   
    142171  u2->stop_rx_streaming(); 
     172 
     173  printf("\nCopy handler called %li times.\n", h.times()); 
     174  printf("Copy handler called with %li bytes.\n\n", h.bytes()); 
     175  printf("Elapsed time was %5.3f seconds.\n", elapsed); 
     176  printf("Packet rate was %1.0f pkts/sec.\n", pps); 
     177  printf("Approximate throughput was %5.2f MB/sec.\n", mbs); 
     178  printf("Total instances of overruns was %d.\n", u2->rx_overruns()); 
     179  printf("Total missing frames was %d.\n", u2->rx_missing());  
     180 
     181  free(buf); 
    143182  return 0; 
    144183} 
  • usrp2/branches/features/host-ng/host-ng/include/usrp2/copy_handler.h

    r8647 r8955  
    3939  
    4040    virtual data_handler::result operator()(const void *base, size_t len); 
     41 
     42    size_t bytes() const { return d_bytes; } 
     43    size_t times() const { return d_times; } 
     44 
     45    static const size_t MIN_COPY_LEN = 1484; // FIXME: calculate eth packet - thdr 
     46    bool full() const { return d_space < MIN_COPY_LEN; } 
    4147  }; 
    4248     
  • usrp2/branches/features/host-ng/host-ng/include/usrp2/usrp2.h

    r8749 r8955  
    125125    bool stop_rx_streaming(unsigned int channel=0); 
    126126 
     127    /*! 
     128     * Returns number of times receive overruns have occurred 
     129     */ 
     130    unsigned int rx_overruns(); 
     131     
     132    /*! 
     133     * Returns total number of missing frames from overruns. 
     134     */ 
     135    unsigned int rx_missing(); 
     136 
    127137    /* Ignore :-) */ 
    128138    class impl; 
  • usrp2/branches/features/host-ng/host-ng/lib/copy_handler.cc

    r8647 r8955  
    2525 
    2626#include <usrp2/copy_handler.h> 
     27#include <iostream> 
    2728 
    2829namespace usrp2 { 
     
    4849    d_bytes += len; 
    4950    d_times++; 
     51 
     52    if (d_space < MIN_COPY_LEN) 
     53      return DONE; // don't call me anymore 
    5054     
    51     if (d_space == 0) 
    52       return DONE; // don't call me anymore 
    53  
    5455    return 0; 
    5556  } 
  • usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc

    r8848 r8955  
    3535#include <errno.h> 
    3636 
    37 #define ETH_BUFFER_DEBUG      1 // define to 0 or 1 
     37#define ETH_BUFFER_DEBUG      0 // define to 0 or 1 
    3838#if ETH_BUFFER_DEBUG 
    3939#define DEBUG_LOG(x) ::write(2, (x), 1) 
  • usrp2/branches/features/host-ng/host-ng/lib/usrp2.cc

    r8749 r8955  
    8888  } 
    8989 
     90  unsigned int 
     91  usrp2::rx_overruns() 
     92  { 
     93    return d_impl->rx_overruns(); 
     94  } 
     95   
     96  unsigned int 
     97  usrp2::rx_missing() 
     98  { 
     99    return d_impl->rx_missing(); 
     100  } 
     101 
    90102} // namespace usrp2 
  • usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc

    r8856 r8955  
    3535#include <stdio.h> 
    3636 
    37 #define USRP2_IMPL_DEBUG 1 
     37#define USRP2_IMPL_DEBUG 0 
    3838#if USRP2_IMPL_DEBUG 
    3939#define DEBUG_LOG(x) ::write(2, x, 1) 
     
    7979    : d_buffer(new eth_buffer()), d_pf(0), d_bg_thread(0), d_bg_running(false), 
    8080      d_rx_decim(0), d_rx_seqno(-1), d_tx_seqno(0), d_next_rid(0), 
    81       d_num_rx_frames(0), d_num_rx_lost(0), d_num_rx_bytes(0), d_num_enqueued(0), 
    82       d_enqueued_mutex(), d_bg_pending_cond(&d_enqueued_mutex) 
     81      d_num_rx_frames(0), d_num_rx_missing(0), d_num_rx_overruns(0), d_num_rx_bytes(0),  
     82      d_num_enqueued(0), d_enqueued_mutex(), d_bg_pending_cond(&d_enqueued_mutex) 
    8383  { 
    8484    props_vector_t u2s = find(ifc, addr); 
     
    116116      std::cerr << std::endl 
    117117                << "usrp2 destructor: received " << d_num_rx_frames  
    118                 << " frames, with " << d_num_rx_lost << " lost (" 
    119                 << (d_num_rx_frames == 0 ? 0 : (int)(100.0*d_num_rx_lost/d_num_rx_frames)) 
     118                << " frames, with " << d_num_rx_missing << " lost (" 
     119                << (d_num_rx_frames == 0 ? 0 : (int)(100.0*d_num_rx_missing/d_num_rx_frames)) 
    120120                << "%), totaling " << d_num_rx_bytes 
    121121                << " bytes" << std::endl; 
     
    483483          missing += 256; 
    484484         
    485         d_num_rx_lost += missing; 
     485        d_num_rx_overruns++; 
     486        d_num_rx_missing += missing; 
    486487      } 
    487488    } 
     
    495496    } 
    496497 
    497     if (d_channel_rings[chan]->enqueue(&pkt->samples, 0)) { 
     498    size_t offset = (uint8_t *)(&pkt->samples) - (uint8_t *)base; 
     499    if (d_channel_rings[chan]->enqueue(&pkt->samples, len-offset)) { 
    498500      inc_enqueued(); 
    499501      DEBUG_LOG("+"); 
     
    539541    size_t len; 
    540542    while (rp->dequeue(&p, &len)) { 
    541  
    542       // TODO: Invoke user callback, handle KEEP and DONE 
    543  
    544       // Release frame 
     543      result r = (*handler)(p, len); 
     544 
     545      // Callers are always required to accept a frame, but then to signal when 
     546      // they are done. 
    545547      d_buffer->release_frame(p); 
    546548      DEBUG_LOG("-"); 
    547549      dec_enqueued(); 
     550 
     551      if (r && data_handler::DONE) 
     552        break; 
    548553    } 
    549554 
  • usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h

    r8850 r8955  
    5151    int            d_next_rid; 
    5252    unsigned int   d_num_rx_frames; 
    53     unsigned int   d_num_rx_lost; 
     53    unsigned int   d_num_rx_missing; 
     54    unsigned int   d_num_rx_overruns; 
    5455    unsigned int   d_num_rx_bytes; 
    5556 
     
    9596    bool rx_samples(unsigned int channel, data_handler *handler); 
    9697    bool stop_rx_streaming(unsigned int channel); 
     98    unsigned int rx_overruns() const { return d_num_rx_overruns; } 
     99    unsigned int rx_missing() const { return d_num_rx_missing; } 
    97100  }; 
    98101