]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/resource.hh
import quincy beta 17.1.0
[ceph.git] / ceph / src / seastar / include / seastar / core / 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 <cassert>
25 #include <cstdlib>
26 #include <string>
27 #include <seastar/util/std-compat.hh>
28 #include <seastar/util/spinlock.hh>
29 #include <vector>
30 #include <set>
31 #include <sched.h>
32 #include <boost/any.hpp>
33 #include <unordered_map>
34 #ifdef SEASTAR_HAVE_HWLOC
35 #include <hwloc.h>
36 #endif
37
38 namespace seastar {
39
40 cpu_set_t cpuid_to_cpuset(unsigned cpuid);
41 class io_queue;
42 class io_group;
43
44 namespace resource {
45
46 using std::optional;
47
48 using cpuset = std::set<unsigned>;
49
50 /// \cond internal
51 std::optional<cpuset> parse_cpuset(std::string value);
52 /// \endcond
53
54 namespace hwloc::internal {
55
56 #ifdef SEASTAR_HAVE_HWLOC
57 class topology_holder {
58 hwloc_topology_t _topology;
59
60 public:
61 topology_holder() noexcept
62 : _topology(nullptr)
63 { }
64
65 topology_holder(topology_holder&& o) noexcept;
66
67 ~topology_holder();
68
69 topology_holder& operator=(topology_holder&& o) noexcept;
70
71 operator bool() const noexcept {
72 return _topology != nullptr;
73 }
74
75 void init_and_load();
76 hwloc_topology_t get();
77 };
78
79 #else // SEASTAR_HAVE_HWLOC
80
81 struct topology_holder {};
82
83 #endif // SEASTAR_HAVE_HWLOC
84
85 } // namespace hwloc::internal
86
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;
96 };
97
98 struct memory {
99 size_t bytes;
100 unsigned nodeid;
101
102 };
103
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;
108
109 util::spinlock lock;
110
111 io_queue_topology();
112 io_queue_topology(const io_queue_topology&) = delete;
113 io_queue_topology(io_queue_topology&&);
114 ~io_queue_topology();
115 };
116
117 struct cpu {
118 unsigned cpu_id;
119 std::vector<memory> mem;
120 };
121
122 struct resources {
123 std::vector<cpu> cpus;
124 std::unordered_map<dev_t, io_queue_topology> ioq_topology;
125 };
126
127 resources allocate(configuration& c);
128 unsigned nr_processing_units(configuration& c);
129
130 std::optional<resource::cpuset> parse_cpuset(std::string value);
131
132 }
133 }