Statistics
| Branch: | Tag: | Revision:

root / gcell / apps / benchmark_nop.cc @ 06e7a031

History | View | Annotate | Download (4.2 kB)

1 28361a1b eb
/* -*- c++ -*- */
2 28361a1b eb
/*
3 8f2a5f38 eb
 * Copyright 2007,2008 Free Software Foundation, Inc.
4 28361a1b eb
 * 
5 28361a1b eb
 * This file is part of GNU Radio
6 28361a1b eb
 * 
7 28361a1b eb
 * GNU Radio is free software; you can redistribute it and/or modify
8 28361a1b eb
 * it under the terms of the GNU General Public License as published by
9 28361a1b eb
 * the Free Software Foundation; either version 3, or (at your option)
10 28361a1b eb
 * any later version.
11 28361a1b eb
 * 
12 28361a1b eb
 * GNU Radio is distributed in the hope that it will be useful,
13 28361a1b eb
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 28361a1b eb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 28361a1b eb
 * GNU General Public License for more details.
16 28361a1b eb
 * 
17 28361a1b eb
 * You should have received a copy of the GNU General Public License along
18 28361a1b eb
 * with this program; if not, write to the Free Software Foundation, Inc.,
19 28361a1b eb
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 28361a1b eb
 */
21 28361a1b eb
22 166bf655 eb
#if defined(HAVE_CONFIG_H)
23 166bf655 eb
#include <config.h>
24 166bf655 eb
#endif
25 06e7a031 eb
#include <gcell/gc_job_manager.h>
26 8b04fb2b eb
#include <omni_time.h>
27 28361a1b eb
#include <getopt.h>
28 28361a1b eb
#include <stdlib.h>
29 28361a1b eb
#include <stdio.h>
30 28361a1b eb
31 28361a1b eb
// handle to embedded SPU executable that contains benchmark routines
32 28361a1b eb
// (The name of the variable (benchmark_procs) is the name of the spu executable.)
33 28361a1b eb
extern spe_program_handle_t benchmark_procs;
34 28361a1b eb
35 28361a1b eb
static gc_proc_id_t gcp_benchmark_udelay = GCP_UNKNOWN_PROC;
36 28361a1b eb
37 28361a1b eb
static void
38 28361a1b eb
init_jd(gc_job_desc *jd, unsigned int usecs)
39 28361a1b eb
{
40 28361a1b eb
  jd->proc_id = gcp_benchmark_udelay;
41 28361a1b eb
  jd->input.nargs = 1;
42 28361a1b eb
  jd->input.arg[0].u32 = usecs;
43 28361a1b eb
  jd->output.nargs = 0;
44 28361a1b eb
  jd->eaa.nargs = 0;
45 28361a1b eb
}
46 28361a1b eb
47 28361a1b eb
static void
48 28361a1b eb
run_test(unsigned int nspes, unsigned int usecs, int njobs)
49 28361a1b eb
{
50 28361a1b eb
  static const int NJDS = 64;
51 28361a1b eb
  int nsubmitted = 0;
52 28361a1b eb
  int ncompleted = 0;
53 28361a1b eb
  gc_job_desc *all_jds[NJDS];
54 28361a1b eb
  gc_job_desc *jds[2][NJDS];
55 28361a1b eb
  unsigned int njds[2];
56 28361a1b eb
  unsigned int ci;                // current index
57 28361a1b eb
  bool done[NJDS];
58 28361a1b eb
  
59 28361a1b eb
  gc_jm_options opts;
60 8f2a5f38 eb
  opts.program_handle = gc_program_handle_from_address(&benchmark_procs);
61 28361a1b eb
  opts.nspes = nspes;
62 28361a1b eb
  opts.gang_schedule = true;
63 8f2a5f38 eb
  gc_job_manager_sptr mgr = gc_make_job_manager(&opts);
64 28361a1b eb
65 28361a1b eb
  if ((gcp_benchmark_udelay = mgr->lookup_proc("benchmark_udelay")) == GCP_UNKNOWN_PROC){
66 28361a1b eb
    fprintf(stderr, "lookup_proc: failed to find \"benchmark_udelay\"\n");
67 28361a1b eb
    return;
68 28361a1b eb
  }
69 28361a1b eb
70 28361a1b eb
  // allocate and init all job descriptors
71 28361a1b eb
  for (int i = 0; i < NJDS; i++){
72 28361a1b eb
    all_jds[i] = mgr->alloc_job_desc();
73 28361a1b eb
    init_jd(all_jds[i], usecs);
74 28361a1b eb
  }
75 28361a1b eb
76 8b04fb2b eb
  omni_time t_start = omni_time::time();
77 28361a1b eb
78 28361a1b eb
  ci = 0;
79 28361a1b eb
  njds[0] = 0;
80 28361a1b eb
  njds[1] = 0;
81 28361a1b eb
  
82 28361a1b eb
  // submit the first batch
83 28361a1b eb
  for (int i = 0; i < NJDS; i++){
84 28361a1b eb
    if (mgr->submit_job(all_jds[i])){
85 28361a1b eb
      jds[ci][njds[ci]++] = all_jds[i];
86 28361a1b eb
      nsubmitted++;
87 28361a1b eb
    }
88 28361a1b eb
    else {
89 28361a1b eb
      printf("submit_job(jds[%d]) failed, status = %d\n",
90 28361a1b eb
             i, all_jds[i]->status);
91 28361a1b eb
    }
92 28361a1b eb
  }
93 28361a1b eb
  
94 28361a1b eb
  while (ncompleted < njobs){
95 28361a1b eb
    njds[ci^1] = 0;
96 28361a1b eb
    int n = mgr->wait_jobs(njds[ci], jds[ci], done, GC_WAIT_ANY);
97 28361a1b eb
    // printf("%2d\n", n);
98 28361a1b eb
    if (n < 0){
99 28361a1b eb
      fprintf(stderr, "mgr->wait_jobs failed\n");
100 28361a1b eb
      break;
101 28361a1b eb
    }
102 28361a1b eb
    for (unsigned int i = 0; i < njds[ci]; i++){
103 28361a1b eb
      if (!done[i]){        // remember for next iteration
104 28361a1b eb
        jds[ci^1][njds[ci^1]++] = jds[ci][i];
105 28361a1b eb
      }
106 28361a1b eb
      else {
107 28361a1b eb
        ncompleted++;
108 28361a1b eb
        // printf("ncompleted = %7d\n", ncompleted);
109 28361a1b eb
        if (nsubmitted < njobs){                    // submit another one
110 28361a1b eb
          if (mgr->submit_job(jds[ci][i])){
111 28361a1b eb
            jds[ci^1][njds[ci^1]++] = jds[ci][i];  // remember for next iter
112 28361a1b eb
            nsubmitted++;
113 28361a1b eb
          }
114 28361a1b eb
          else {
115 28361a1b eb
            printf("submit_job(jds[%d]) failed, status = %d\n",
116 28361a1b eb
                   i, jds[ci][i]->status);
117 28361a1b eb
          }
118 28361a1b eb
        }
119 28361a1b eb
      }
120 28361a1b eb
    }
121 28361a1b eb
    ci ^= 1;        // toggle current
122 28361a1b eb
  }
123 28361a1b eb
124 28361a1b eb
  // stop timing
125 8b04fb2b eb
  omni_time t_stop = omni_time::time();
126 28361a1b eb
  double delta = (t_stop - t_start).double_time();
127 28361a1b eb
  printf("nspes: %2d  udelay: %4d  elapsed_time: %7.3f  njobs: %g  speedup: %6.3f\n",
128 28361a1b eb
         mgr->nspes(), usecs, delta, (double) njobs,
129 28361a1b eb
         njobs * usecs * 1e-6 / delta);
130 28361a1b eb
}
131 28361a1b eb
132 28361a1b eb
int
133 28361a1b eb
main(int argc, char **argv)
134 28361a1b eb
{
135 28361a1b eb
  unsigned int nspes = 0;
136 28361a1b eb
  unsigned int usecs = 0;
137 28361a1b eb
  int njobs = 500000;
138 28361a1b eb
  int ch;
139 28361a1b eb
140 28361a1b eb
  while ((ch = getopt(argc, argv, "n:u:N:")) != EOF){
141 28361a1b eb
    switch(ch){
142 28361a1b eb
    case 'n':
143 28361a1b eb
      nspes = strtol(optarg, 0, 0);
144 28361a1b eb
      break;
145 28361a1b eb
146 28361a1b eb
    case 'u':
147 28361a1b eb
      usecs = strtol(optarg, 0, 0);
148 28361a1b eb
      break;
149 28361a1b eb
150 28361a1b eb
    case 'N':
151 28361a1b eb
      njobs = strtol(optarg, 0, 0);
152 28361a1b eb
      break;
153 28361a1b eb
154 28361a1b eb
    case '?':
155 28361a1b eb
    default:
156 28361a1b eb
      fprintf(stderr, "usage: benchmark_nop [-n <nspes>] [-u <udelay>] [-N <njobs>]\n");
157 28361a1b eb
      return 1;
158 28361a1b eb
    }
159 28361a1b eb
  }
160 28361a1b eb
161 28361a1b eb
  run_test(nspes, usecs, njobs);
162 28361a1b eb
  return 0;
163 28361a1b eb
}