-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the use of rte_ring for dumping in/out/drop packets to a newer… #155
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
#include "sock_dev.h" | ||
#include "worker.h" | ||
|
||
#define MAX_PACK_SIZE 16384 | ||
|
||
common::log::LogPriority common::log::logPriority = common::log::TLOG_INFO; | ||
|
||
cDataPlane::cDataPlane() : | ||
|
@@ -1209,6 +1211,25 @@ eResult cDataPlane::allocateSharedMemory() | |
} | ||
} | ||
|
||
// init size for in/out/drop lowPriority ring | ||
for (const auto& [socket_id, num] : number_of_workers_per_socket) | ||
{ | ||
auto unit_size = sizeof(sharedmemory::item_header_t) + MAX_PACK_SIZE; | ||
if (unit_size % RTE_CACHE_LINE_SIZE != 0) | ||
{ | ||
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up | ||
} | ||
|
||
auto size = sizeof(sharedmemory::ring_header_t) + unit_size * getConfigValues().ring_lowPriority_size; | ||
|
||
auto it = shm_size_per_socket.find(socket_id); | ||
if (it == shm_size_per_socket.end()) | ||
{ | ||
it = shm_size_per_socket.emplace_hint(it, socket_id, 0); | ||
} | ||
it->second += size * num; | ||
} | ||
|
||
for (const auto& [socket_id, num] : number_of_workers_per_socket) | ||
{ | ||
auto it = shm_size_per_socket.find(socket_id); | ||
|
@@ -1327,6 +1348,28 @@ eResult cDataPlane::splitSharedMemoryPerWorkers() | |
|
||
ring_id++; | ||
} | ||
// init lowPriority ring | ||
{ | ||
auto name = "r_lp_" + std::to_string(core_id); | ||
auto offset = offsets[shm]; | ||
auto memaddr = (void*)((intptr_t)shm + offset); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid c-style casts. Here we should use named casts: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use C-style typecast in sake of performance and the code is on our most important hot-path. Also this memory region will contain many data structures (and arrays of them) mapped dynamically with data offsets. Another requirement that the region layout should be parseable by third-party application written in C or Go for example. However, I think we could improve the approach but let us do this in the another piece of work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, but I cannot resolve the conversation by myself, I guess I don't have the related permissions :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So there is no penalty in using |
||
sharedmemory::cSharedMemory ring; | ||
|
||
auto unit_size = sizeof(sharedmemory::item_header_t) + MAX_PACK_SIZE; | ||
if (unit_size % RTE_CACHE_LINE_SIZE != 0) | ||
{ | ||
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up | ||
} | ||
const auto units_number = getConfigValues().ring_lowPriority_size; | ||
const auto size = sizeof(sharedmemory::ring_header_t) + unit_size * units_number; | ||
ring.init(memaddr, unit_size, units_number); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I don't know if we allow or prohibit this, but C++ Core Guidelines tells us "ES.46: Avoid lossy (narrowing, truncating) arithmetic conversions". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
offsets[shm] += size; | ||
|
||
worker->lowPriorityRing = ring; | ||
|
||
auto meta = common::idp::get_shm_info::dump_meta(name, "lp", unit_size, units_number, core_id, socket_id, key, offset); | ||
dumps_meta.emplace_back(meta); | ||
} | ||
Comment on lines
+1351
to
+1372
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This almost looks like a previous block of code (body of void foo(arguments)
{
auto name = base_name + std::to_string(core_id) + (is_low_priority ? "" : "_" + std::to_string(ring_id));
auto unit_size = sizeof(sharedmemory::item_header_t) + dump_size;
if (unit_size % RTE_CACHE_LINE_SIZE != 0)
{
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE;
}
auto size = sizeof(sharedmemory::ring_header_t) + unit_size * units_number;
auto offset = offsets[shm];
auto memaddr = reinterpret_cast<void*>(reinterpret_cast<std::uintptr_t>(shm) + offset);
sharedmemory::cSharedMemory ring;
ring.init(memaddr, unit_size, units_number);
offsets[shm] += size;
auto meta = common::idp::get_shm_info::dump_meta(name, tag, unit_size, units_number, core_id, socket_id, key, offset);
dumps_meta.emplace_back(meta);
} as we cannot interact with private Then the "low priority ring" turns into:
and loop body turns into
|
||
} | ||
|
||
for (auto& [core_id, worker] : workers) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, we don't have any coding style document apart from .clang-format which should specify such things. However, if we strive to use "modern C++", we shouldn't use macros.
From C++ Core Guidelines, part ES.31:
Don’t use macros for constants or “functions”
Reason
Macros are a major source of bugs. Macros don’t obey the usual scope and type rules. Macros don’t obey the usual rules for argument passing. Macros ensure that the human reader sees something different from what the compiler sees. Macros complicate tool building.
Here we could use
constexpr unsigned long max_pack_size = 16384;
or maybeconstexpr auto MY_CONSTANT{42}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least we should move the definition to common/config.release.h where it will be look more consistent.