]>
git.proxmox.com Git - ceph.git/blob - ceph/src/msg/async/dpdk/dpdk_rte.cc
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 #include <rte_config.h>
20 #include <rte_common.h>
21 #include <rte_ethdev.h>
22 #include <rte_version.h>
29 static inline std::vector
<char> string2vector(std::string str
) {
30 auto v
= std::vector
<char>(str
.begin(), str
.end());
35 bool eal::initialized
= false;
38 std::condition_variable
eal::cond
;
39 std::list
<std::function
<void()>> eal::funcs
;
41 static int bitcount(unsigned n
)
49 int eal::init(CephContext
*c
)
56 t
= std::thread([&]() {
57 // TODO: Inherit these from the app parameters - "opts"
58 std::vector
<std::vector
<char>> args
{
59 string2vector(string("ceph")),
60 string2vector("-c"), string2vector(c
->_conf
->get_val
<std::string
>("ms_dpdk_coremask")),
61 string2vector("-n"), string2vector(c
->_conf
->ms_dpdk_memory_channel
),
64 Tub
<std::string
> hugepages_path
;
65 if (!c
->_conf
->ms_dpdk_hugepages
.empty()) {
66 hugepages_path
.construct(c
->_conf
->ms_dpdk_hugepages
);
69 // If "hugepages" is not provided and DPDK PMD drivers mode is requested -
70 // use the default DPDK huge tables configuration.
72 args
.push_back(string2vector("--huge-dir"));
73 args
.push_back(string2vector(*hugepages_path
));
76 // We don't know what is going to be our networking configuration so we
77 // assume there is going to be a queue per-CPU. Plus we'll give a DPDK
78 // 64MB for "other stuff".
82 ss
<< std::hex
<< "fffefffe";
84 size_t size_MB
= mem_size(bitcount(x
)) >> 20;
85 std::stringstream size_MB_str
;
86 size_MB_str
<< size_MB
;
88 args
.push_back(string2vector("-m"));
89 args
.push_back(string2vector(size_MB_str
.str()));
90 } else if (!c
->_conf
->ms_dpdk_pmd
.empty()) {
91 args
.push_back(string2vector("--no-huge"));
94 std::string rte_file_prefix
;
95 rte_file_prefix
= "rte_";
96 rte_file_prefix
+= c
->_conf
->name
.to_str();
97 args
.push_back(string2vector("--file-prefix"));
98 args
.push_back(string2vector(rte_file_prefix
));
100 std::vector
<char*> cargs
;
102 for (auto&& a
: args
) {
103 cargs
.push_back(a
.data());
105 /* initialise the EAL for all */
106 int ret
= rte_eal_init(cargs
.size(), cargs
.data());
110 std::unique_lock
<std::mutex
> l(lock
);
115 if (!funcs
.empty()) {
116 auto f
= std::move(funcs
.front());
126 std::unique_lock
<std::mutex
> l(lock
);
132 size_t eal::mem_size(int num_cpus
)
136 // PMD mempool memory:
138 // We don't know what is going to be our networking configuration so we
139 // assume there is going to be a queue per-CPU.
141 memsize
+= num_cpus
* qp_mempool_obj_size();
143 // Plus we'll give a DPDK 64MB for "other stuff".
144 memsize
+= (64UL << 20);