Seastar
High performance C++ framework for concurrent servers
resource.hh
1 /*
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.
6  *
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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
16  * under the License.
17  */
18 /*
19  * Copyright (C) 2014 Cloudius Systems, Ltd.
20  */
21 
22 #pragma once
23 
24 #include <seastar/util/std-compat.hh>
25 #include <seastar/util/spinlock.hh>
26 #include <seastar/util/modules.hh>
27 #ifndef SEASTAR_MODULE
28 #include <cassert>
29 #include <cstdlib>
30 #include <string>
31 #include <vector>
32 #include <set>
33 #include <sched.h>
34 #include <boost/any.hpp>
35 #include <unordered_map>
36 #ifdef SEASTAR_HAVE_HWLOC
37 #include <hwloc.h>
38 #endif
39 #endif
40 
41 namespace seastar {
42 
43 cpu_set_t cpuid_to_cpuset(unsigned cpuid);
44 class io_queue;
45 class io_group;
46 
47 namespace resource {
48 
49 using std::optional;
50 
51 using cpuset = std::set<unsigned>;
52 
54 std::optional<cpuset> parse_cpuset(std::string value);
56 
57 namespace hwloc::internal {
58 
59 #ifdef SEASTAR_HAVE_HWLOC
60 class topology_holder {
61  hwloc_topology_t _topology;
62 
63 public:
64  topology_holder() noexcept
65  : _topology(nullptr)
66  { }
67 
68  topology_holder(topology_holder&& o) noexcept;
69 
70  ~topology_holder();
71 
72  topology_holder& operator=(topology_holder&& o) noexcept;
73 
74  operator bool() const noexcept {
75  return _topology != nullptr;
76  }
77 
78  void init_and_load();
79  hwloc_topology_t get();
80 };
81 
82 #else // SEASTAR_HAVE_HWLOC
83 
84 struct topology_holder {};
85 
86 #endif // SEASTAR_HAVE_HWLOC
87 
88 } // namespace hwloc::internal
89 
90 SEASTAR_MODULE_EXPORT_BEGIN
91 
92 struct configuration {
93  optional<size_t> total_memory;
94  optional<size_t> reserve_memory; // if total_memory not specified
95  size_t reserve_additional_memory_per_shard;
96  size_t cpus;
97  cpuset cpu_set;
98  bool assign_orphan_cpus = false;
99  std::vector<dev_t> devices;
100  unsigned num_io_groups;
102 };
103 
104 struct memory {
105  size_t bytes;
106  unsigned nodeid;
107 
108 };
109 
111  std::vector<std::unique_ptr<io_queue>> queues;
112  std::vector<unsigned> shard_to_group;
113  std::vector<unsigned> shards_in_group;
114  std::vector<std::shared_ptr<io_group>> groups;
115 
116  util::spinlock lock;
117 
119  io_queue_topology(const io_queue_topology&) = delete;
122 };
123 
124 struct cpu {
125  unsigned cpu_id;
126  std::vector<memory> mem;
127 };
128 
129 struct resources {
130  std::vector<cpu> cpus;
131  std::unordered_map<dev_t, io_queue_topology> ioq_topology;
132  std::unordered_map<unsigned /* numa node id */, cpuset> numa_node_id_to_cpuset;
133 };
134 
135 resources allocate(configuration& c);
136 unsigned nr_processing_units(configuration& c);
137 
138 SEASTAR_MODULE_EXPORT_END
139 
140 std::optional<resource::cpuset> parse_cpuset(std::string value);
141 
142 
143 }
144 }
Definition: spinlock.hh:88
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: resource.hh:92
Definition: resource.hh:124
Definition: resource.hh:110
Definition: resource.hh:104
Definition: resource.hh:129