[COMMIT seastar master] core/resource: do not check c.cpu_set for null

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Feb 1, 2023, 1:26:19 PM2/1/23
to seastar-dev@googlegroups.com, Kefu Chai
From: Kefu Chai <kefu...@scylladb.com>
Committer: Kefu Chai <tcha...@gmail.com>
Branch: master

core/resource: do not check c.cpu_set for null

* change configuration::cpu_set to a plain cpuset instead of an optional
* do not check configuration::cpu_set for nullopt anymore

along with `rc.cpus`, `rc.cpu_set` is already set at the caller site
before `resource::allocate(rc)` gets called. so `rc.cpu_set` always has
a value.

Signed-off-by: Kefu Chai <kefu...@scylladb.com>

---
diff --git a/include/seastar/core/resource.hh b/include/seastar/core/resource.hh
--- a/include/seastar/core/resource.hh
+++ b/include/seastar/core/resource.hh
@@ -89,7 +89,7 @@ struct configuration {
optional<size_t> reserve_memory; // if total_memory not specified
size_t reserve_additional_memory;
size_t cpus;
- optional<cpuset> cpu_set;
+ cpuset cpu_set;
bool assign_orphan_cpus = false;
std::vector<dev_t> devices;
unsigned num_io_groups;
diff --git a/src/core/resource.cc b/src/core/resource.cc
--- a/src/core/resource.cc
+++ b/src/core/resource.cc
@@ -477,29 +477,27 @@ hwloc_topology_t topology_holder::get() {

resources allocate(configuration& c) {
auto topology = c.topology.get();
- if (c.cpu_set) {
- auto bm = hwloc_bitmap_alloc();
- auto free_bm = defer([&] () noexcept { hwloc_bitmap_free(bm); });
- for (auto idx : *c.cpu_set) {
- hwloc_bitmap_set(bm, idx);
- }
- auto r = hwloc_topology_restrict(topology, bm,
+ auto bm = hwloc_bitmap_alloc();
+ auto free_bm = defer([&] () noexcept { hwloc_bitmap_free(bm); });
+ for (auto idx : c.cpu_set) {
+ hwloc_bitmap_set(bm, idx);
+ }
+ auto r = hwloc_topology_restrict(topology, bm,
#if HWLOC_API_VERSION >= 0x00020000
- 0
+ 0
#else
- HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES
+ HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES
#endif
- | HWLOC_RESTRICT_FLAG_ADAPT_MISC
- | HWLOC_RESTRICT_FLAG_ADAPT_IO);
- if (r == -1) {
- if (errno == ENOMEM) {
- throw std::bad_alloc();
- }
- if (errno == EINVAL) {
- throw std::runtime_error("bad cpuset");
- }
- abort();
+ | HWLOC_RESTRICT_FLAG_ADAPT_MISC
+ | HWLOC_RESTRICT_FLAG_ADAPT_IO);
+ if (r == -1) {
+ if (errno == ENOMEM) {
+ throw std::bad_alloc();
}
+ if (errno == EINVAL) {
+ throw std::runtime_error("bad cpuset");
+ }
+ abort();
}
auto machine_depth = hwloc_get_type_depth(topology, HWLOC_OBJ_MACHINE);
assert(hwloc_get_nbobjs_by_depth(topology, machine_depth) == 1);
@@ -677,14 +675,8 @@ resources allocate(configuration& c) {
// limit memory address to fit in 36-bit, see core/memory.cc:Memory map
constexpr size_t max_mem_per_proc = 1UL << 36;
auto mem_per_proc = std::min(mem / procs, max_mem_per_proc);
- if (c.cpu_set) {
- for (auto cpuid : *c.cpu_set) {
- ret.cpus.push_back(cpu{cpuid, {{mem_per_proc, 0}}});
- }
- } else {
- for (unsigned i = 0; i < procs; ++i) {
- ret.cpus.push_back(cpu{i, {{mem_per_proc, 0}}});
- }
+ for (auto cpuid : c.cpu_set) {
+ ret.cpus.push_back(cpu{cpuid, {{mem_per_proc, 0}}});
}

ret.ioq_topology.emplace(0, allocate_io_queues(c, ret.cpus));
Reply all
Reply to author
Forward
0 new messages