Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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/spinlock.hh>
25#include <seastar/util/modules.hh>
26#ifndef SEASTAR_MODULE
27#include <cassert>
28#include <cstdlib>
29#include <memory>
30#include <optional>
31#include <string>
32#include <vector>
33#include <set>
34#include <sched.h>
35#include <unordered_map>
36#ifdef SEASTAR_HAVE_HWLOC
37#include <hwloc.h>
38#endif
39#endif
40
41namespace seastar {
42
43cpu_set_t cpuid_to_cpuset(unsigned cpuid);
44class io_queue;
45class io_group;
46
47namespace resource {
48
49using std::optional;
50
51using cpuset = std::set<unsigned>;
52
54std::optional<cpuset> parse_cpuset(std::string value);
56
57namespace hwloc::internal {
58
59#ifdef SEASTAR_HAVE_HWLOC
60class topology_holder {
61 hwloc_topology_t _topology;
62
63public:
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
85
86#endif // SEASTAR_HAVE_HWLOC
87
88} // namespace hwloc::internal
89
90SEASTAR_MODULE_EXPORT_BEGIN
91
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
104struct 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
124struct cpu {
125 unsigned cpu_id;
126 std::vector<memory> mem;
127};
128
129struct 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
135resources allocate(configuration& c);
136unsigned nr_processing_units(configuration& c);
137
138SEASTAR_MODULE_EXPORT_END
139
140std::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