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