Skip to content
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

Perf analysis based on tsc delta measurements #79

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cli/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ void fillValue(std::optional<TArg>& value, const std::string& string)
}
}

void fillValue(bool& value, const std::string& string)
{
if (string == "false" || string == "true")
{
value = string == "true";
}
else
{
throw std::string("invalid argument, must be true or false");
}
}

void fillValue(uint8_t& value, const std::string& string)
{
value = std::stoull(string, nullptr, 0);
Expand Down
4 changes: 4 additions & 0 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ std::vector<std::tuple<std::string,
{},
{"show shm info", "", [](const auto& args) { call(show::shm_info, args); }},
{},
{"tsc show shm info", "", [](const auto& args) { call(show::shm_tsc_info, args); }},
{"tsc set state", "[true|false]", [](const auto& args) { call(show::shm_tsc_set_state, args); }},
{"tsc set base", "[handle] [value]", [](const auto& args) { call(show::shm_tsc_set_base_value, args); }},
{},
{"samples show", "", [](const auto& args) { call(show::samples, args); }},
{"samples dump", "", [](const auto& args) { call(show::samples_dump, args); }},
{},
Expand Down
71 changes: 71 additions & 0 deletions cli/show.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/idataplane.h"
#include "common/version.h"

#include "dataplane/tsc_deltas.h"
#include "helper.h"

namespace show
Expand Down Expand Up @@ -850,4 +851,74 @@ 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();
}

void shm_tsc_set_state(bool state)
{
interface::dataPlane dataplane;
common::idp::updateGlobalBase::request globalbase;
globalbase.emplace_back(common::idp::updateGlobalBase::requestType::tsc_state_update,
state);
dataplane.updateGlobalBase(globalbase);
}

static const std::map<std::string, unsigned int> counter_name_to_offset = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should i use array instead of struct for dataplane::perf::tsc_base_values, to avoid this?

{"logicalPort_ingress_handle", offsetof(dataplane::perf::tsc_base_values, logicalPort_ingress_handle)},
{"acl_ingress_handle4", offsetof(dataplane::perf::tsc_base_values, acl_ingress_handle4)},
{"acl_ingress_handle6", offsetof(dataplane::perf::tsc_base_values, acl_ingress_handle6)},
{"tun64_ipv4_handle", offsetof(dataplane::perf::tsc_base_values, tun64_ipv4_handle)},
{"tun64_ipv6_handle", offsetof(dataplane::perf::tsc_base_values, tun64_ipv6_handle)},
{"route_handle4", offsetof(dataplane::perf::tsc_base_values, route_handle4)},
{"route_handle6", offsetof(dataplane::perf::tsc_base_values, route_handle6)},
{"decap_handle", offsetof(dataplane::perf::tsc_base_values, decap_handle)},
{"nat64stateful_lan_handle", offsetof(dataplane::perf::tsc_base_values, nat64stateful_lan_handle)},
{"nat64stateful_wan_handle", offsetof(dataplane::perf::tsc_base_values, nat64stateful_wan_handle)},
{"nat64stateless_egress_handle", offsetof(dataplane::perf::tsc_base_values, nat64stateless_egress_handle)},
{"nat64stateless_ingress_handle", offsetof(dataplane::perf::tsc_base_values, nat64stateless_ingress_handle)},
{"balancer_handle", offsetof(dataplane::perf::tsc_base_values, balancer_handle)},
{"balancer_icmp_reply_handle", offsetof(dataplane::perf::tsc_base_values, balancer_icmp_reply_handle)},
{"balancer_icmp_forward_handle", offsetof(dataplane::perf::tsc_base_values, balancer_icmp_forward_handle)},
{"route_tunnel_handle4", offsetof(dataplane::perf::tsc_base_values, route_tunnel_handle4)},
{"route_tunnel_handle6", offsetof(dataplane::perf::tsc_base_values, route_tunnel_handle6)},
{"acl_egress_handle4", offsetof(dataplane::perf::tsc_base_values, acl_egress_handle4)},
{"acl_egress_handle6", offsetof(dataplane::perf::tsc_base_values, acl_egress_handle6)},
{"logicalPort_egress_handle", offsetof(dataplane::perf::tsc_base_values, logicalPort_egress_handle)},
{"controlPlane_handle", offsetof(dataplane::perf::tsc_base_values, controlPlane_handle)},
};

void shm_tsc_set_base_value(std::string counter_name, uint32_t value)
{
if (counter_name_to_offset.count(counter_name) != 0)
{
interface::dataPlane dataplane;
common::idp::updateGlobalBase::request globalbase;
globalbase.emplace_back(common::idp::updateGlobalBase::requestType::tscs_base_value_update,
common::idp::updateGlobalBase::tscs_base_value_update::request{counter_name_to_offset.at(counter_name), value});
dataplane.updateGlobalBase(globalbase);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to update GlobalBase from cli?

}
else
{
std::string args;
std::for_each(counter_name_to_offset.cbegin(), counter_name_to_offset.cend(), [&](const auto& e) { args += " " + e.first; });
throw std::string("invalid argument: ") + counter_name + ", supported types:" + args;
}
}

}
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
34 changes: 30 additions & 4 deletions common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ enum class requestType : uint32_t
version,
get_counter_by_name,
get_shm_info,
get_shm_tsc_info,
set_shm_tsc_state,
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 @@ -153,7 +155,9 @@ enum class requestType : uint32_t
tun64_update,
tun64mappings_update,
serial_update,
dump_tags_ids
dump_tags_ids,
tsc_state_update,
tscs_base_value_update
};

namespace updateLogicalPort
Expand Down Expand Up @@ -466,6 +470,16 @@ namespace serial_update
using request = uint32_t; ///< serial
}

namespace tsc_state_update
{
using request = bool;
}

namespace tscs_base_value_update
{
using request = std::tuple<uint32_t, uint32_t>;
}

using requestVariant = std::variant<std::tuple<>,
updateLogicalPort::request,
updateDecap::request,
Expand Down Expand Up @@ -498,8 +512,9 @@ using requestVariant = std::variant<std::tuple<>,
dregress_neighbor_update::request,
dregress_value_update::request,
fwstate_synchronization_update::request,
sampler_update::request, /// + update_early_decap_flags::request
serial_update::request>;
sampler_update::request, /// + update_early_decap_flags::request, tsc_state_update::request
serial_update::request,
tscs_base_value_update::request>;

using request = std::vector<std::tuple<requestType,
requestVariant>>;
Expand Down Expand Up @@ -852,6 +867,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 +972,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
12 changes: 12 additions & 0 deletions dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rte_lcore.h>
#include <rte_malloc.h>

#include "common/idp.h"
#include "common/version.h"

#include "checksum.h"
Expand Down Expand Up @@ -1228,6 +1229,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
45 changes: 44 additions & 1 deletion dataplane/dataplane.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <arpa/inet.h>
#include <cstdint>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -27,9 +28,12 @@
#include <sys/mman.h>

#include "common.h"
#include "common/idp.h"
#include "common/result.h"
#include "dataplane.h"
#include "report.h"
#include "sock_dev.h"
#include "tsc_deltas.h"
#include "worker.h"

common::log::LogPriority common::log::logPriority = common::log::TLOG_INFO;
Expand Down Expand Up @@ -1248,6 +1252,17 @@ eResult cDataPlane::allocateSharedMemory()
}
}

for (const auto& [socket_id, num] : number_of_workers_per_socket)
{
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 += sizeof(dataplane::perf::tsc_deltas) * (num + ((int)socket_id == numa_node_of_cpu(config.controlPlaneCoreId)));
}

/// allocating IPC shared memory
key_t key = YANET_DEFAULT_IPC_SHMKEY;
for (const auto& [socket_id, size] : shm_size_per_socket)
Expand Down Expand Up @@ -1279,7 +1294,6 @@ 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);

key++;
Expand Down Expand Up @@ -1354,6 +1368,25 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()
}
}

for (auto& [core_id, worker] : workers)
{
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& [key, shm] = it->second;

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 @@ -1367,6 +1400,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
3 changes: 3 additions & 0 deletions 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 @@ -329,6 +330,8 @@ class cDataPlane
common::idp::get_shm_info::response dumps_meta;
std::map<std::string, uint64_t> tag_to_id;

common::idp::get_shm_tsc_info::response tscs_meta;

/// modules
cReport report;
std::unique_ptr<cControlPlane> controlPlane;
Expand Down
22 changes: 22 additions & 0 deletions dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ eResult generation::update(const common::idp::updateGlobalBase::request& request
result = eResult::success;
serial = std::get<common::idp::updateGlobalBase::serial_update::request>(data);
}
else if (type == common::idp::updateGlobalBase::requestType::tsc_state_update)
{
result = tsc_state_update(std::get<common::idp::updateGlobalBase::tsc_state_update::request>(data));
}
else if (type == common::idp::updateGlobalBase::requestType::tscs_base_value_update)
{
result = tscs_base_value_update(std::get<common::idp::updateGlobalBase::tscs_base_value_update::request>(data));
}
else
{
YADECAP_LOG_ERROR("invalid request type\n");
Expand Down Expand Up @@ -736,6 +744,20 @@ eResult generation::tun64mappings_update(const common::idp::updateGlobalBase::tu
return eResult::success;
}

eResult generation::tsc_state_update(const common::idp::updateGlobalBase::tsc_state_update::request& request)
{
tscs_active = request;
return eResult::success;
}

eResult generation::tscs_base_value_update(const common::idp::updateGlobalBase::tscs_base_value_update::request& request)
{
const auto& [offset, value] = request;
*(uint32_t*)((uintptr_t)(&tsc_base_values) + offset) = value;

return eResult::success;
}

eResult generation::updateDecap(const common::idp::updateGlobalBase::updateDecap::request& request)
{
using common::eDscpMarkType;
Expand Down
Loading