Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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
50   static std::mutex lock;
51   static std::condition_variable cond;
52   static std::list<std::function<void()>> funcs;
53   static int init(CephContext *c);
54   static void execute_on_master(std::function<void()> &&f) {
55     bool done = false;
56     std::unique_lock<std::mutex> l(lock);
57     funcs.emplace_back([&]() { f(); done = true; });
58     cond.notify_all();
59     while (!done)
60       cond.wait(l);
61   }
62   /**
63    * Returns the amount of memory needed for DPDK
64    * @param num_cpus Number of CPUs the application is going to use
65    *
66    * @return
67    */
68   static size_t mem_size(int num_cpus);
69   static bool initialized;
70   static std::thread t;
71 };
72
73 } // namespace dpdk
74 #endif // CEPH_DPDK_RTE_H_