diff options
author | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-04-11 11:07:08 +0100 |
---|---|---|
committer | Rupert Swarbrick <rswarbrick@lowrisc.org> | 2022-04-12 11:10:46 +0100 |
commit | 9f0cf3437051b1ff0da9f087d001f768c2242870 (patch) | |
tree | bb0767afe4ea19067db35aea4732018f6f05d766 | |
parent | 61b4f61a857de65d1a341f55597bfceeb7b7690d (diff) | |
download | spike-9f0cf3437051b1ff0da9f087d001f768c2242870.zip spike-9f0cf3437051b1ff0da9f087d001f768c2242870.tar.gz spike-9f0cf3437051b1ff0da9f087d001f768c2242870.tar.bz2 |
Remove nprocs from cfg_t
Now we have hartids, we can remove nprocs so that we have a single
source of truth.
-rw-r--r-- | riscv/cfg.h | 6 | ||||
-rw-r--r-- | riscv/sim.cc | 2 | ||||
-rw-r--r-- | spike_main/spike.cc | 15 |
3 files changed, 11 insertions, 12 deletions
diff --git a/riscv/cfg.h b/riscv/cfg.h index 6410c81..1e40aed 100644 --- a/riscv/cfg.h +++ b/riscv/cfg.h @@ -54,13 +54,12 @@ class cfg_t { public: cfg_t(std::pair<reg_t, reg_t> default_initrd_bounds, - const char *default_bootargs, size_t default_nprocs, + const char *default_bootargs, const char *default_isa, const char *default_priv, const std::vector<mem_cfg_t> &default_mem_layout, const std::vector<int> default_hartids) : initrd_bounds(default_initrd_bounds), bootargs(default_bootargs), - nprocs(default_nprocs), isa(default_isa), priv(default_priv), mem_layout(default_mem_layout), @@ -70,13 +69,14 @@ public: cfg_arg_t<std::pair<reg_t, reg_t>> initrd_bounds; cfg_arg_t<const char *> bootargs; - cfg_arg_t<size_t> nprocs; cfg_arg_t<const char *> isa; cfg_arg_t<const char *> priv; cfg_arg_t<std::vector<mem_cfg_t>> mem_layout; std::optional<reg_t> start_pc; cfg_arg_t<std::vector<int>> hartids; bool explicit_hartids; + + size_t nprocs() const { return hartids().size(); } }; #endif diff --git a/riscv/sim.cc b/riscv/sim.cc index d7585ca..6945c64 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -62,8 +62,6 @@ sim_t::sim_t(const cfg_t *cfg, const char* varch, bool halted, bool real_time_cl remote_bitbang(NULL), debug_module(this, dm_config) { - assert(cfg->hartids().size() == cfg->nprocs()); - signal(SIGINT, &handle_signal); sout_.rdbuf(std::cerr.rdbuf()); // debug output goes to stderr by default diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 12b8dc0..6395466 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -272,9 +272,10 @@ int main(int argc, char** argv) .support_haltgroups = true, .support_impebreak = true }; + cfg_arg_t<size_t> nprocs(1); + cfg_t cfg(/*default_initrd_bounds=*/std::make_pair((reg_t)0, (reg_t)0), /*default_bootargs=*/nullptr, - /*default_nprocs=*/1, /*default_isa=*/DEFAULT_ISA, /*default_priv=*/DEFAULT_PRIV, /*default_mem_layout=*/parse_mem_layout("2048"), @@ -332,7 +333,7 @@ int main(int argc, char** argv) #ifdef HAVE_BOOST_ASIO parser.option('s', 0, 0, [&](const char* s){socket = true;}); #endif - parser.option('p', 0, 1, [&](const char* s){cfg.nprocs = atoul_nonzero_safe(s);}); + parser.option('p', 0, 1, [&](const char* s){nprocs = atoul_nonzero_safe(s);}); parser.option('m', 0, 1, [&](const char* s){cfg.mem_layout = parse_mem_layout(s);}); // I wanted to use --halted, but for some reason that doesn't work. parser.option('H', 0, 0, [&](const char* s){halted = true;}); @@ -462,11 +463,11 @@ int main(int argc, char** argv) #endif if (cfg.explicit_hartids) { - if (cfg.nprocs.overridden() && (cfg.nprocs() != cfg.hartids().size())) { + if (nprocs.overridden() && (nprocs() != cfg.nprocs())) { std::cerr << "Number of specified hartids (" - << cfg.hartids().size() + << cfg.nprocs() << ") doesn't match specified number of processors (" - << cfg.nprocs() << ").\n"; + << nprocs() << ").\n"; exit(1); } } else { @@ -474,8 +475,8 @@ int main(int argc, char** argv) // explicit_hartids flag (which means that downstream code can know that // we've only set the number of harts, not explicitly chosen their IDs). std::vector<int> default_hartids; - default_hartids.reserve(cfg.nprocs()); - for (size_t i = 0; i < cfg.nprocs(); ++i) { + default_hartids.reserve(nprocs()); + for (size_t i = 0; i < nprocs(); ++i) { default_hartids.push_back(i); } cfg.hartids = default_hartids; |