3 * Copyright 2007,2008 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 #ifndef INCLUDED_GC_JOB_MANAGER_H
23 #define INCLUDED_GC_JOB_MANAGER_H
25 #include <boost/utility.hpp>
29 #include "gc_job_desc.h"
39 * \brief Options that configure the job_manager.
40 * The default values are reasonable.
42 struct gc_jm_options {
43 unsigned int max_jobs; // max # of job descriptors in system
44 unsigned int max_client_threads; // max # of client threads of job manager
45 unsigned int nspes; // how many SPEs shall we use? 0 -> all of them
46 bool gang_schedule; // shall we gang schedule?
47 bool use_affinity; // shall we try for affinity (FIXME not implmented)
48 bool enable_logging; // shall we log SPE events?
49 uint32_t log2_nlog_entries; // log2 of number of log entries (default is 12 == 4k)
50 spe_program_handle_t *program_handle; // program to load into SPEs
53 max_jobs(0), max_client_threads(0), nspes(0),
54 gang_schedule(true), use_affinity(false),
55 enable_logging(false), log2_nlog_entries(12),
63 * \brief Create an instance of the job manager
66 gc_make_job_manager(const gc_jm_options *options = 0);
70 * \brief Abstract class that manages SPE jobs.
72 * There is typically a single instance derived from this class.
73 * It is safe to call its methods from any thread.
75 class gc_job_manager : boost::noncopyable
78 gc_job_manager(const gc_jm_options *options = 0);
80 virtual ~gc_job_manager();
83 * Stop accepting new jobs. Wait for existing jobs to complete.
84 * Return all managed SPE's to the system.
86 virtual bool shutdown() = 0;
89 * \brief Return number of SPE's currently allocated to job manager.
91 virtual int nspes() const = 0;
94 * \brief Return a pointer to a properly aligned job descriptor,
95 * or zero if none are available.
97 virtual gc_job_desc *alloc_job_desc() = 0;
100 *! Free a job descriptor previously allocated with alloc_job_desc()
102 * \param[in] jd pointer to job descriptor to free.
104 virtual void free_job_desc(gc_job_desc *jd) = 0;
107 * \brief Submit a job for asynchronous processing on an SPE.
109 * \param[in] jd pointer to job description
111 * The caller must not read or write the job description
112 * or any of the memory associated with any indirect arguments
113 * until after calling wait_job.
115 * \returns true iff the job was successfully enqueued.
116 * If submit_job returns false, check jd->status for additional info.
118 virtual bool submit_job(gc_job_desc *jd) = 0;
121 * \brief Wait for job to complete.
123 * A thread may only wait for jobs which it submitted.
125 * \returns true if sucessful, else false.
128 wait_job(gc_job_desc *jd) = 0;
131 * \brief wait for 1 or more jobs to complete.
133 * \param[input] njobs is the length of arrays \p jd and \p done.
134 * \param[input] jd are the jobs that are to be waited for.
135 * \param[output] done indicates whether the corresponding job is complete.
136 * \param[input] mode indicates whether to wait for ALL or ANY of the jobs
137 * in \p jd to complete.
139 * A thread may only wait for jobs which it submitted.
141 * \returns number of jobs completed, or -1 if error.
144 wait_jobs(unsigned int njobs,
145 gc_job_desc *jd[], bool done[], gc_wait_mode mode) = 0;
148 * Return the maximum number of bytes of EA arguments that may be
149 * copied to or from the SPE in a single job. The limit applies
150 * independently to the "get" and "put" args.
151 * \sa gc_job_desc_t, gc_job_ea_args_t
153 virtual int ea_args_maxsize() = 0;
156 * Return gc_proc_id_t associated with spu procedure \p proc_name if one
157 * exists, otherwise return GCP_UNKNOWN_PROC.
159 virtual gc_proc_id_t lookup_proc(const std::string &proc_name) = 0;
162 * Return a vector of all known spu procedure names.
164 virtual std::vector<std::string> proc_names() = 0;
166 virtual void set_debug(int debug);
171 #endif /* INCLUDED_GC_JOB_MANAGER_H */