Skip to content

Commit

Permalink
Add show tsc info handle to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Abrosimov committed Dec 14, 2023
1 parent 9ab7944 commit 0a31e77
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 26 deletions.
1 change: 1 addition & 0 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ std::vector<std::tuple<std::string,
{"fw list", "<original|generated|state|all|dispatcher>", [](const auto& args) { call(show::fwlist, args); }},
{},
{"show shm info", "", [](const auto& args) { call(show::shm_info, args); }},
{"show shm tsc info", "", [](const auto& args) { call(show::shm_tsc_info, args); }},
{},
{"samples show", "", [](const auto& args) { call(show::samples, args); }},
{"samples dump", "", [](const auto& args) { call(show::samples_dump, args); }},
Expand Down
19 changes: 19 additions & 0 deletions cli/show.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,23 @@ void shm_info()
table.print();
}

void shm_tsc_info()
{
interface::dataPlane dataplane;
const auto response = dataplane.get_shm_tsc_info();

table_t table;
table.insert("core id",
"socket id",
"ipc key",
"offset");

for (const auto& [core, socket, ipc_key, offset] : response)
{
table.insert(core, socket, ipc_key, offset);
}

table.print();
}

}
5 changes: 5 additions & 0 deletions common/idataplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class dataPlane
return get<common::idp::requestType::get_shm_info, common::idp::get_shm_info::response>();
}

auto get_shm_tsc_info() const
{
return get<common::idp::requestType::get_shm_tsc_info, common::idp::get_shm_tsc_info::response>();
}

auto dump_physical_port(const common::idp::dump_physical_port::request& request) const
{
return get<common::idp::requestType::dump_physical_port, eResult>(request);
Expand Down
14 changes: 13 additions & 1 deletion common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum class requestType : uint32_t
version,
get_counter_by_name,
get_shm_info,
get_shm_tsc_info,
dump_physical_port,
balancer_state_clear,
size, // size should always be at the bottom of the list, this enum allows us to find out the size of the enum list
Expand Down Expand Up @@ -852,6 +853,16 @@ using dump_meta = std::tuple<std::string, ///< ring name
using response = std::vector<dump_meta>;
}

namespace get_shm_tsc_info
{
using tsc_meta = std::tuple<tCoreId, ///< core id
tSocketId, ///< socket id
key_t, /// ipc shm key
uint64_t>; /// offset

using response = std::vector<tsc_meta>;
}

namespace dump_physical_port
{
using request = std::tuple<std::string, ///< interface_name
Expand Down Expand Up @@ -947,6 +958,7 @@ using response = std::variant<std::tuple<>,
limits::response,
samples::response,
get_counter_by_name::response,
get_shm_info::response>;
get_shm_info::response,
get_shm_tsc_info::response>;

}
4 changes: 4 additions & 0 deletions dataplane/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ void cBus::clientThread(int clientSocket)
{
response = callWithResponse(&cControlPlane::get_shm_info, request);
}
else if (type == common::idp::requestType::get_shm_tsc_info)
{
response = callWithResponse(&cControlPlane::get_shm_tsc_info, request);
}
else if (type == common::idp::requestType::dump_physical_port)
{
response = callWithResponse(&cControlPlane::dump_physical_port, request);
Expand Down
11 changes: 11 additions & 0 deletions dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,17 @@ common::idp::get_shm_info::response cControlPlane::get_shm_info()
return response;
}

common::idp::get_shm_tsc_info::response cControlPlane::get_shm_tsc_info()
{
common::idp::get_shm_tsc_info::response response;
for (const auto& key : dataPlane->getShmTscInfo())
{
response.emplace_back(key);
}

return response;
}

eResult cControlPlane::dump_physical_port(const common::idp::dump_physical_port::request& request)
{
const auto& [interface_name, direction, state] = request;
Expand Down
1 change: 1 addition & 0 deletions dataplane/controlplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class cControlPlane ///< @todo: move to cDataPlane
common::idp::get_counter_by_name::response get_counter_by_name(const common::idp::get_counter_by_name::request& request);
common::idp::nat64stateful_state::response nat64stateful_state(const common::idp::nat64stateful_state::request& request);
common::idp::get_shm_info::response get_shm_info();
common::idp::get_shm_tsc_info::response get_shm_tsc_info();
eResult dump_physical_port(const common::idp::dump_physical_port::request& request);
eResult balancer_state_clear();

Expand Down
39 changes: 20 additions & 19 deletions dataplane/dataplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ eResult cDataPlane::allocateSharedMemory()
{
it = shm_size_per_socket.emplace_hint(it, socket_id, 0);
}
it->second += sizeof(dataplane::perf::num_of_workers);

it->second += sizeof(dataplane::perf::tsc_deltas) * (num + ((int)socket_id == numa_node_of_cpu(config.controlPlaneCoreId)));
}

Expand Down Expand Up @@ -1292,7 +1292,7 @@ eResult cDataPlane::allocateSharedMemory()
YADECAP_LOG_ERROR("shmat(%d, NULL, %d) = %d\n", shmid, 0, errno);
return eResult::errorInitSharedMemory;
}
shm_by_socket_id[socket_id] = std::make_tuple(key, shmaddr, number_of_workers_per_socket[socket_id]);
shm_by_socket_id[socket_id] = std::make_tuple(key, shmaddr);

key++;
}
Expand Down Expand Up @@ -1324,8 +1324,7 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()
continue;
}

const auto& key = std::get<0>(it->second);
const auto& shm = std::get<1>(it->second);
const auto& [key, shm] = it->second;

int ring_id = 0;
for (const auto& [tag, ring_cfg] : config.shared_memory)
Expand Down Expand Up @@ -1367,31 +1366,23 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()
}
}

for (const auto& [socket_id, shm_info] : shm_by_socket_id)
{
const auto& shm = std::get<1>(shm_info);
const auto& number_of_workers = std::get<2>(shm_info);

auto num_of_workers = (dataplane::perf::num_of_workers*)((intptr_t)shm + offsets[shm]);
num_of_workers->number = number_of_workers + ((int)socket_id == numa_node_of_cpu(config.controlPlaneCoreId));
offsets[shm] += sizeof(dataplane::perf::num_of_workers);
}

for (auto& core_id_to_worker : workers)
for (auto& [core_id, worker] : workers)
{
auto worker = std::get<1>(core_id_to_worker);

const auto& socket_id = worker->socketId;
const auto& it = shm_by_socket_id.find(socket_id);
if (it == shm_by_socket_id.end())
{
continue;
}
const auto& shm = std::get<1>(it->second);
const auto& [key, shm] = it->second;

worker->tsc_deltas = (dataplane::perf::tsc_deltas*)((intptr_t)shm + offsets[shm]);
auto offset = offsets[shm];
worker->tsc_deltas = (dataplane::perf::tsc_deltas*)((intptr_t)shm + offset);
memset(worker->tsc_deltas, 0, sizeof(dataplane::perf::tsc_deltas));
offsets[shm] += sizeof(dataplane::perf::tsc_deltas);

auto meta = common::idp::get_shm_tsc_info::tsc_meta(core_id, socket_id, key, offset);
tscs_meta.emplace_back(meta);
}

return eResult::success;
Expand All @@ -1407,6 +1398,16 @@ common::idp::get_shm_info::response cDataPlane::getShmInfo()
return result;
}

common::idp::get_shm_tsc_info::response cDataPlane::getShmTscInfo()
{
common::idp::get_shm_tsc_info::response result;
result.reserve(tscs_meta.size());

std::copy(tscs_meta.begin(), tscs_meta.end(), std::back_inserter(result));

return result;
}

std::map<std::string, common::uint64> cDataPlane::getPortStats(const tPortId& portId) const
{
/// unsafe
Expand Down
4 changes: 3 additions & 1 deletion dataplane/dataplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class cDataPlane

std::optional<uint64_t> getCounterValueByName(const std::string& counter_name, uint32_t coreId);
common::idp::get_shm_info::response getShmInfo();
common::idp::get_shm_tsc_info::response getShmTscInfo();

template<typename type,
typename... args_t>
Expand Down Expand Up @@ -327,6 +328,7 @@ class cDataPlane
rte_mempool* mempool_log;

common::idp::get_shm_info::response dumps_meta;
common::idp::get_shm_tsc_info::response tscs_meta;
std::map<std::string, uint64_t> tag_to_id;

/// modules
Expand All @@ -337,7 +339,7 @@ class cDataPlane
// array instead of the table - how many coreIds can be there?
std::unordered_map<uint32_t, std::unordered_map<std::string, uint64_t*>> coreId_to_stats_tables;

std::map<tSocketId, std::tuple<key_t, void*, uint64_t>> shm_by_socket_id;
std::map<tSocketId, std::tuple<key_t, void*>> shm_by_socket_id;

std::mutex hugepage_pointers_mutex;
std::map<void*, hugepage_pointer> hugepage_pointers;
Expand Down
5 changes: 0 additions & 5 deletions dataplane/tsc_deltas.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace dataplane
namespace perf
{

struct num_of_workers
{
uint64_t number;
} __attribute__((__aligned__(64)));

struct tsc_deltas
{
uint64_t iter_num;
Expand Down

0 comments on commit 0a31e77

Please sign in to comment.