Skip to content

Commit

Permalink
TMP: add pcaps, for now dealing with capacity of shm
Browse files Browse the repository at this point in the history
  • Loading branch information
ol-imorozko committed Dec 23, 2024
1 parent 51f25bb commit 772a3eb
Show file tree
Hide file tree
Showing 11 changed files with 724 additions and 74 deletions.
29 changes: 24 additions & 5 deletions common/bufferring.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,39 @@ struct PacketBufferRing
{
PacketBufferRing() = default;

PacketBufferRing(void* memory, size_t ring_size, size_t item_count) :
unit_size(sizeof(item_header_t) + ring_size), units_number(item_count)
// static function, helps to get capacity in DumpRingRaw
static size_t GetCapacity(size_t ring_size, size_t item_count, size_t unit_size = 0)
{
if (unit_size % RTE_CACHE_LINE_SIZE != 0)
if (unit_size == 0)
{
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up
unit_size = sizeof(item_header_t) + ring_size;

if (unit_size % RTE_CACHE_LINE_SIZE != 0)
{
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up
}
}

capacity = sizeof(ring_header_t) + unit_size * units_number;
size_t capacity = sizeof(ring_header_t) + unit_size * item_count;

if (capacity % RTE_CACHE_LINE_SIZE != 0)
{
capacity += RTE_CACHE_LINE_SIZE - capacity % RTE_CACHE_LINE_SIZE; /// round up
}

return capacity;
}

PacketBufferRing(void* memory, size_t ring_size, size_t item_count) :
unit_size(sizeof(item_header_t) + ring_size), units_number(item_count)
{
if (unit_size % RTE_CACHE_LINE_SIZE != 0)
{
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up
}

capacity = GetCapacity(ring_size, item_count, unit_size);

ring = (ring_t*)memory;
}

Expand Down
7 changes: 5 additions & 2 deletions dataplane/action_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ struct ActionDispatcher
return;
}

auto& ring = args.worker->dumpRings[ring_id];
ring.write(args.mbuf, flow.type);
cWorker* worker = args.worker;

// polymorphic, will execute either DumpRingRaw or DumpRingPcap method,
// likely to be devirtualized
worker->dump_rings[ring_id]->Write(args.mbuf, flow.type, worker->CurrentTime());
}

static void execute(const common::StateTimeoutAction& action, const Flow& flow, const ActionDispatcherArgs& args)
Expand Down
3 changes: 2 additions & 1 deletion dataplane/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ struct tDataPlaneConfig
kPcap
};

//TODO: add here path, prefix, pcap files count? like std::variant if format == pcap?
struct DumpConfig
{
DumpFormat format;
unsigned int size;
unsigned int count;
DumpFormat format;
};

static DumpFormat StringToDumpFormat(const std::string& format_str)
Expand Down
2 changes: 1 addition & 1 deletion dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ common::idp::hexdump_ring::response cControlPlane::hexdump_ring(const common::id

for (cWorker* worker : dataPlane->workers_vector)
{
auto ring = worker->dumpRings[ring_id];
auto ring = worker->dump_rings[ring_id];

auto addr = reinterpret_cast<char*>(ring.buffer.ring);

Expand Down
28 changes: 10 additions & 18 deletions dataplane/dataplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,12 +1601,7 @@ static std::unordered_map<tSocketId, size_t> calculate_shared_memory_size(const
// Calculate sizes based on shared memory configuration
for (const auto& ring_cfg : config.shared_memory)
{
const auto& [dump_size, dump_count, format] = ring_cfg.second;
YANET_GCC_BUG_UNUSED(format);

// Temporarily materialization will occur to create an object and get it's capacity.
// It's okay, because this object is lightweight
size_t size = common::PacketBufferRing(nullptr, dump_size, dump_count).capacity;
size_t size = sharedmemory::GetCapacity(ring_cfg.second);

for (const auto& [socket_id, worker_count] : workers_per_socket)
{
Expand All @@ -1623,6 +1618,7 @@ static std::unordered_map<tSocketId, size_t> calculate_shared_memory_size(const
return shm_size_per_socket;
}

//FIXME: why is this class not using class SharedMemory from common/shared_memory.h?
eResult cDataPlane::allocateSharedMemory()
{
// shared memory size for each numa
Expand Down Expand Up @@ -1681,8 +1677,7 @@ eResult cDataPlane::allocateSharedMemory()
/// split memory per worker
eResult cDataPlane::splitSharedMemoryPerWorkers()
{
using sharedmemory::SharedMemoryDumpRing;
using utils::ShiftBuffer;
using namespace sharedmemory;

for (cWorker* worker : workers_vector)
{
Expand All @@ -1701,16 +1696,15 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()
int ring_id = 0;
for (const auto& [tag, ring_cfg] : config.shared_memory)
{
const auto& [dump_size, dump_count, format] = ring_cfg;
const auto& [format, dump_size, dump_count] = ring_cfg;

auto memaddr = utils::ShiftBuffer(shm, offset);
offset += GetCapacity(ring_cfg);

sharedmemory::SharedMemoryDumpRing ring(format, memaddr, dump_size, dump_count);
worker->dumpRings[ring_id] = ring;

offset += ring.Capacity();
worker->dump_rings[ring_id] = CreateSharedMemoryDumpRing(ring_cfg, memaddr);

std::string name = "shm_" + std::to_string(core_id) + "_" + std::to_string(ring_id);
// TODO: add format here
dumps_meta.emplace_back(name, tag, dump_size, dump_count, core_id, socket_id, key, offset);

tag_to_id[tag] = ring_id;
Expand All @@ -1719,10 +1713,10 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()
}

auto memaddr = utils::ShiftBuffer(shm, offset);
worker->tsc_deltas = new (memaddr) dataplane::perf::tsc_deltas{};

offset += sizeof(dataplane::perf::tsc_deltas);

worker->tsc_deltas = new (memaddr) dataplane::perf::tsc_deltas{};

tscs_meta.emplace_back(core_id, socket_id, key, offset);
}

Expand Down Expand Up @@ -2204,8 +2198,6 @@ eResult cDataPlane::parseRateLimits(const nlohmann::json& json)

eResult cDataPlane::parseSharedMemory(const nlohmann::json& json)
{
using DumpFormat = tDataPlaneConfig::DumpFormat;

for (const auto& shmJson : json)
{
std::string tag = shmJson["tag"];
Expand All @@ -2219,7 +2211,7 @@ eResult cDataPlane::parseSharedMemory(const nlohmann::json& json)
return eResult::invalidConfigurationFile;
}

config.shared_memory[tag] = {size, count, tDataPlaneConfig::StringToDumpFormat(format_str)};
config.shared_memory[tag] = {tDataPlaneConfig::StringToDumpFormat(format_str), size, count};
}

return eResult::success;
Expand Down
2 changes: 2 additions & 0 deletions dataplane/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies += libdpdk.get_variable('dpdk_dep')
dependencies += libjson.get_variable('nlohmann_json_dep')
dependencies += dependency('libsystemd')
dependencies += dependency('threads')
dependencies += pcapplusplus_deps

sources = files('bus.cpp',
'controlplane.cpp',
Expand All @@ -20,6 +21,7 @@ sources = files('bus.cpp',
'neighbor.cpp',
'report.cpp',
'sharedmemory.cpp',
'pcap_shm_device.cpp',
'slow_worker.cpp',
'sock_dev.cpp',
'worker.cpp',
Expand Down
Loading

0 comments on commit 772a3eb

Please sign in to comment.