]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/async/dpdk/dpdk_rte.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / msg / async / dpdk / dpdk_rte.h
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 #ifndef CEPH_DPDK_RTE_H_
19 #define CEPH_DPDK_RTE_H_
20
21
22 #include <condition_variable>
23 #include <mutex>
24 #include <thread>
25
26 #include <bitset>
27 #include <rte_config.h>
28 #include <rte_version.h>
29 #include <boost/program_options.hpp>
30
31 /*********************** Compat section ***************************************/
32 // We currently support only versions 2.0 and above.
33 #if (RTE_VERSION < RTE_VERSION_NUM(2,0,0,0))
34 #error "DPDK version above 2.0.0 is required"
35 #endif
36
37 #if defined(RTE_MBUF_REFCNT_ATOMIC)
38 #warning "CONFIG_RTE_MBUF_REFCNT_ATOMIC should be disabled in DPDK's " \
39 "config/common_linuxapp"
40 #endif
41 /******************************************************************************/
42
43 namespace dpdk {
44
45 // DPDK Environment Abstraction Layer
46 class eal {
47 public:
48 using cpuset = std::bitset<RTE_MAX_LCORE>;
49 explicit eal(CephContext *cct) : cct(cct) {}
50 int start();
51 void stop();
52 void execute_on_master(std::function<void()> &&f) {
53 bool done = false;
54 std::unique_lock<std::mutex> l(lock);
55 funcs.emplace_back([&]() { f(); done = true; });
56 cond.notify_all();
57 while (!done)
58 cond.wait(l);
59 }
60 /**
61 * Returns the amount of memory needed for DPDK
62 * @param num_cpus Number of CPUs the application is going to use
63 *
64 * @return
65 */
66 size_t mem_size(int num_cpus);
67 static bool rte_initialized;
68 private:
69 CephContext *cct;
70 bool initialized = false;
71 bool stopped = false;
72 std::thread t;
73 std::mutex lock;
74 std::condition_variable cond;
75 std::list<std::function<void()>> funcs;
76 };
77
78 } // namespace dpdk
79 #endif // CEPH_DPDK_RTE_H_