]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/src/core/dpdk_rte.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / seastar / src / core / dpdk_rte.cc
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 #ifdef SEASTAR_HAVE_DPDK
19
20 #include <cinttypes>
21 #include <seastar/net/dpdk.hh>
22 #include <seastar/core/dpdk_rte.hh>
23 #include <seastar/util/conversions.hh>
24 #include <seastar/util/std-compat.hh>
25 #include <rte_pci.h>
26
27 namespace seastar {
28
29 namespace dpdk {
30
31 bool eal::initialized = false;
32
33 void eal::init(cpuset cpus, const std::string& argv0, const std::optional<std::string>& hugepages_path, bool dpdk_pmd)
34 {
35 if (initialized) {
36 return;
37 }
38
39 std::stringstream mask;
40 cpuset nibble = 0xF;
41 while (cpus.any()) {
42 mask << std::hex << (cpus & nibble).to_ulong();
43 cpus >>= 4;
44 }
45
46 std::string mask_str = mask.str();
47 std::reverse(mask_str.begin(), mask_str.end());
48
49 std::vector<std::vector<char>> args {
50 string2vector(argv0),
51 string2vector("-c"), string2vector(mask_str),
52 string2vector("-n"), string2vector("1")
53 };
54
55 // If "hugepages" is not provided and DPDK PMD drivers mode is requested -
56 // use the default DPDK huge tables configuration.
57 if (hugepages_path) {
58 args.push_back(string2vector("--huge-dir"));
59 args.push_back(string2vector(hugepages_path.value()));
60
61 //
62 // We don't know what is going to be our networking configuration so we
63 // assume there is going to be a queue per-CPU. Plus we'll give a DPDK
64 // 64MB for "other stuff".
65 //
66 size_t size_MB = mem_size(cpus.count()) >> 20;
67 std::stringstream size_MB_str;
68 size_MB_str << size_MB;
69
70 args.push_back(string2vector("-m"));
71 args.push_back(string2vector(size_MB_str.str()));
72 } else if (!dpdk_pmd) {
73 args.push_back(string2vector("--no-huge"));
74 }
75 #ifdef HAVE_OSV
76 args.push_back(string2vector("--no-shconf"));
77 #endif
78
79 std::vector<char*> cargs;
80
81 for (auto&& a: args) {
82 cargs.push_back(a.data());
83 }
84 /* initialise the EAL for all */
85 int ret = rte_eal_init(cargs.size(), cargs.data());
86 if (ret < 0) {
87 rte_exit(EXIT_FAILURE, "Cannot init EAL\n");
88 }
89
90 initialized = true;
91 }
92
93 uint32_t __attribute__((weak)) qp_mempool_obj_size(bool hugetlbfs_membackend)
94 {
95 return 0;
96 }
97
98 size_t eal::mem_size(int num_cpus, bool hugetlbfs_membackend)
99 {
100 size_t memsize = 0;
101 //
102 // PMD mempool memory:
103 //
104 // We don't know what is going to be our networking configuration so we
105 // assume there is going to be a queue per-CPU.
106 //
107 memsize += num_cpus * qp_mempool_obj_size(hugetlbfs_membackend);
108
109 // Plus we'll give a DPDK 64MB for "other stuff".
110 memsize += (64UL << 20);
111
112 return memsize;
113 }
114
115 } // namespace dpdk
116
117 }
118
119 #endif // SEASTAR_HAVE_DPDK