3 * Copyright 2007,2008,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #if defined(HAVE_CONFIG_H)
25 #include <gcell/gc_job_manager.h>
26 #include <boost/date_time/posix_time/posix_time_types.hpp>
31 // handle to embedded SPU executable that contains benchmark routines
32 // (The name of the variable (benchmark_procs) is the name of the spu executable.)
33 extern spe_program_handle_t benchmark_procs;
35 static gc_proc_id_t gcp_benchmark_udelay = GCP_UNKNOWN_PROC;
38 init_jd(gc_job_desc *jd, unsigned int usecs)
40 jd->proc_id = gcp_benchmark_udelay;
42 jd->input.arg[0].u32 = usecs;
48 run_test(unsigned int nspes, unsigned int usecs, int njobs)
50 using namespace boost::posix_time;
52 static const int NJDS = 64;
55 gc_job_desc *all_jds[NJDS];
56 gc_job_desc *jds[2][NJDS];
58 unsigned int ci; // current index
62 opts.program_handle = gc_program_handle_from_address(&benchmark_procs);
64 opts.gang_schedule = true;
65 gc_job_manager_sptr mgr = gc_make_job_manager(&opts);
67 if ((gcp_benchmark_udelay = mgr->lookup_proc("benchmark_udelay")) == GCP_UNKNOWN_PROC){
68 fprintf(stderr, "lookup_proc: failed to find \"benchmark_udelay\"\n");
72 // allocate and init all job descriptors
73 for (int i = 0; i < NJDS; i++){
74 all_jds[i] = mgr->alloc_job_desc();
75 init_jd(all_jds[i], usecs);
78 ptime t_start(microsec_clock::universal_time());
84 // submit the first batch
85 for (int i = 0; i < NJDS; i++){
86 if (mgr->submit_job(all_jds[i])){
87 jds[ci][njds[ci]++] = all_jds[i];
91 printf("submit_job(jds[%d]) failed, status = %d\n",
92 i, all_jds[i]->status);
96 while (ncompleted < njobs){
98 int n = mgr->wait_jobs(njds[ci], jds[ci], done, GC_WAIT_ANY);
99 // printf("%2d\n", n);
101 fprintf(stderr, "mgr->wait_jobs failed\n");
104 for (unsigned int i = 0; i < njds[ci]; i++){
105 if (!done[i]){ // remember for next iteration
106 jds[ci^1][njds[ci^1]++] = jds[ci][i];
110 // printf("ncompleted = %7d\n", ncompleted);
111 if (nsubmitted < njobs){ // submit another one
112 if (mgr->submit_job(jds[ci][i])){
113 jds[ci^1][njds[ci^1]++] = jds[ci][i]; // remember for next iter
117 printf("submit_job(jds[%d]) failed, status = %d\n",
118 i, jds[ci][i]->status);
123 ci ^= 1; // toggle current
127 ptime t_stop(microsec_clock::universal_time());
128 double delta = (t_stop - t_start).total_microseconds() * 1e-6;
129 printf("nspes: %2d udelay: %4d elapsed_time: %7.3f njobs: %g speedup: %6.3f\n",
130 mgr->nspes(), usecs, delta, (double) njobs,
131 njobs * usecs * 1e-6 / delta);
135 main(int argc, char **argv)
137 unsigned int nspes = 0;
138 unsigned int usecs = 0;
142 while ((ch = getopt(argc, argv, "n:u:N:")) != EOF){
145 nspes = strtol(optarg, 0, 0);
149 usecs = strtol(optarg, 0, 0);
153 njobs = strtol(optarg, 0, 0);
158 fprintf(stderr, "usage: benchmark_nop [-n <nspes>] [-u <udelay>] [-N <njobs>]\n");
163 run_test(nspes, usecs, njobs);