2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
27 #include <seastar/util/std-compat.hh>
28 #include <seastar/util/spinlock.hh>
32 #include <boost/any.hpp>
33 #include <unordered_map>
34 #ifdef SEASTAR_HAVE_HWLOC
40 cpu_set_t cpuid_to_cpuset(unsigned cpuid);
48 using cpuset = std::set<unsigned>;
51 std::optional<cpuset> parse_cpuset(std::string value);
54 namespace hwloc::internal {
56 #ifdef SEASTAR_HAVE_HWLOC
57 class topology_holder {
58 hwloc_topology_t _topology;
61 topology_holder() noexcept
65 topology_holder(topology_holder&& o) noexcept;
69 topology_holder& operator=(topology_holder&& o) noexcept;
71 operator bool() const noexcept {
72 return _topology != nullptr;
76 hwloc_topology_t get();
79 #else // SEASTAR_HAVE_HWLOC
81 struct topology_holder {};
83 #endif // SEASTAR_HAVE_HWLOC
85 } // namespace hwloc::internal
87 struct configuration {
88 optional<size_t> total_memory;
89 optional<size_t> reserve_memory; // if total_memory not specified
90 optional<size_t> cpus;
91 optional<cpuset> cpu_set;
92 bool assign_orphan_cpus = false;
93 std::vector<dev_t> devices;
94 unsigned num_io_groups;
95 hwloc::internal::topology_holder topology;
104 struct io_queue_topology {
105 std::vector<std::unique_ptr<io_queue>> queues;
106 std::vector<unsigned> shard_to_group;
107 std::vector<std::shared_ptr<io_group>> groups;
112 io_queue_topology(const io_queue_topology&) = delete;
113 io_queue_topology(io_queue_topology&&);
114 ~io_queue_topology();
119 std::vector<memory> mem;
123 std::vector<cpu> cpus;
124 std::unordered_map<dev_t, io_queue_topology> ioq_topology;
127 resources allocate(configuration& c);
128 unsigned nr_processing_units(configuration& c);
130 std::optional<resource::cpuset> parse_cpuset(std::string value);