Apollo 10.0
自动驾驶开放平台
shm_conf.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18#include "cyber/common/log.h"
19
20namespace apollo {
21namespace cyber {
22namespace transport {
23
24ShmConf::ShmConf() { Update(MESSAGE_SIZE_16K); }
25
26ShmConf::ShmConf(const uint64_t& real_msg_size) { Update(real_msg_size); }
27
29
30void ShmConf::Update(const uint64_t& real_msg_size) {
31 ceiling_msg_size_ = GetCeilingMessageSize(real_msg_size);
32 block_buf_size_ = GetBlockBufSize(ceiling_msg_size_);
33 block_num_ = GetBlockNum(ceiling_msg_size_);
34 managed_shm_size_ = EXTRA_SIZE + STATE_SIZE + \
35 (BLOCK_SIZE + block_buf_size_) * block_num_ + \
36 (BLOCK_SIZE + ARENA_MESSAGE_SIZE) * ARENA_BLOCK_NUM;
37}
38
39const uint64_t ShmConf::EXTRA_SIZE = 1024 * 4;
40const uint64_t ShmConf::STATE_SIZE = 1024;
41const uint64_t ShmConf::BLOCK_SIZE = 1024;
42const uint64_t ShmConf::MESSAGE_INFO_SIZE = 1024;
43
44const uint32_t ShmConf::ARENA_BLOCK_NUM = 512;
45const uint64_t ShmConf::ARENA_MESSAGE_SIZE = 1024;
46
47const uint32_t ShmConf::BLOCK_NUM_16K = 512;
48const uint64_t ShmConf::MESSAGE_SIZE_16K = 1024 * 16;
49
50const uint32_t ShmConf::BLOCK_NUM_128K = 128;
51const uint64_t ShmConf::MESSAGE_SIZE_128K = 1024 * 128;
52
53const uint32_t ShmConf::BLOCK_NUM_1M = 64;
54const uint64_t ShmConf::MESSAGE_SIZE_1M = 1024 * 1024;
55
56const uint32_t ShmConf::BLOCK_NUM_8M = 32;
57const uint64_t ShmConf::MESSAGE_SIZE_8M = 1024 * 1024 * 8;
58
59const uint32_t ShmConf::BLOCK_NUM_16M = 16;
60const uint64_t ShmConf::MESSAGE_SIZE_16M = 1024 * 1024 * 16;
61
62const uint32_t ShmConf::BLOCK_NUM_MORE = 8;
63const uint64_t ShmConf::MESSAGE_SIZE_MORE = 1024 * 1024 * 32;
64
65uint64_t ShmConf::GetCeilingMessageSize(const uint64_t& real_msg_size) {
66 uint64_t ceiling_msg_size = MESSAGE_SIZE_16K;
67 if (real_msg_size <= MESSAGE_SIZE_16K) {
68 ceiling_msg_size = MESSAGE_SIZE_16K;
69 } else if (real_msg_size <= MESSAGE_SIZE_128K) {
70 ceiling_msg_size = MESSAGE_SIZE_128K;
71 } else if (real_msg_size <= MESSAGE_SIZE_1M) {
72 ceiling_msg_size = MESSAGE_SIZE_1M;
73 } else if (real_msg_size <= MESSAGE_SIZE_8M) {
74 ceiling_msg_size = MESSAGE_SIZE_8M;
75 } else if (real_msg_size <= MESSAGE_SIZE_16M) {
76 ceiling_msg_size = MESSAGE_SIZE_16M;
77 } else {
78 ceiling_msg_size = MESSAGE_SIZE_MORE;
79 }
80 return ceiling_msg_size;
81}
82
83uint64_t ShmConf::GetBlockBufSize(const uint64_t& ceiling_msg_size) {
84 return ceiling_msg_size + MESSAGE_INFO_SIZE;
85}
86
87uint32_t ShmConf::GetBlockNum(const uint64_t& ceiling_msg_size) {
88 uint32_t num = 0;
89 switch (ceiling_msg_size) {
90 case MESSAGE_SIZE_16K:
91 num = BLOCK_NUM_16K;
92 break;
93 case MESSAGE_SIZE_128K:
94 num = BLOCK_NUM_128K;
95 break;
96 case MESSAGE_SIZE_1M:
97 num = BLOCK_NUM_1M;
98 break;
99 case MESSAGE_SIZE_8M:
100 num = BLOCK_NUM_8M;
101 break;
102 case MESSAGE_SIZE_16M:
103 num = BLOCK_NUM_16M;
104 break;
105 case MESSAGE_SIZE_MORE:
106 num = BLOCK_NUM_MORE;
107 break;
108 default:
109 AERROR << "unknown ceiling_msg_size[" << ceiling_msg_size << "]";
110 break;
111 }
112 return num;
113}
114
115} // namespace transport
116} // namespace cyber
117} // namespace apollo
static const uint32_t ARENA_BLOCK_NUM
Definition shm_conf.h:41
const uint64_t & ceiling_msg_size()
Definition shm_conf.h:35
static const uint64_t ARENA_MESSAGE_SIZE
Definition shm_conf.h:42
void Update(const uint64_t &real_msg_size)
Definition shm_conf.cc:30
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37