Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Raghav Rawat committed Dec 6, 2024
1 parent 6075595 commit 515269b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 57 deletions.
12 changes: 6 additions & 6 deletions source/server/core_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "logging.h"
#include "server_configuration_parser.h"
#include "server_security_configuration.h"
#include "streaming_core_configuration.h"
#include "cpu_affinity_configuration.h"

#if defined(__GNUC__)
#include <sys/mman.h>
Expand Down Expand Up @@ -38,7 +38,7 @@ struct ServerConfiguration {
int max_message_size;
int sideband_port;
nidevice_grpc::FeatureToggles feature_toggles;
StreamingCoreConfiguration streaming_core_config;
CpuAffinityConfiguration cpu_affinity;
};

static ServerConfiguration GetConfiguration(const std::string& config_file_path)
Expand All @@ -53,7 +53,7 @@ static ServerConfiguration GetConfiguration(const std::string& config_file_path)
config.server_address = server_config_parser.parse_address();
config.sideband_address = server_config_parser.parse_sideband_address();
config.sideband_port = server_config_parser.parse_sideband_port();
config.streaming_core_config = server_config_parser.parse_streaming_core_configuration();
config.cpu_affinity = server_config_parser.parse_cpu_affinity();
config.server_cert = server_config_parser.parse_server_cert();
config.server_key = server_config_parser.parse_server_key();
config.root_cert = server_config_parser.parse_root_cert();
Expand Down Expand Up @@ -116,7 +116,7 @@ static void RunServer(const ServerConfiguration& config)
server = builder.BuildAndStart();
if (ni::data_monikers::is_sideband_streaming_enabled(config.feature_toggles)) {
auto sideband_socket_thread = new std::thread(RunSidebandSocketsAccept, config.sideband_address.c_str(), config.sideband_port);
ni::data_monikers::configure_streaming_cores_for_cpu_pinning(config.streaming_core_config);
ni::data_monikers::configure_cpu_affinity(config.cpu_affinity);
// auto sideband_rdma_send_thread = new std::thread(AcceptSidebandRdmaSendRequests);
// auto sideband_rdma_recv_thread = new std::thread(AcceptSidebandRdmaReceiveRequests);
}
Expand Down Expand Up @@ -276,10 +276,10 @@ int main(int argc, char** argv)
schedParam.sched_priority = 95;
sched_setscheduler(0, SCHED_FIFO, &schedParam);

if (config.streaming_core_config.server_run_core >= 0) {
if (config.cpu_affinity.server >= 0) {
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(config.streaming_core_config.server_run_core, &cpuSet);
CPU_SET(config.cpu_affinity.server, &cpuSet);
sched_setaffinity(0, sizeof(cpu_set_t), &cpuSet);
}

Expand Down
10 changes: 10 additions & 0 deletions source/server/cpu_affinity_configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CPU_AFFINITY_CONFIGURATION_H
#define CPU_AFFINITY_CONFIGURATION_H

struct CpuAffinityConfiguration {
int sideband_read_write;
int stream_write;
int server;
};

#endif // CPU_AFFINITY_CONFIGURATION_H
16 changes: 8 additions & 8 deletions source/server/data_moniker_service.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------
//---------------------------------------------------------------------
#include "data_moniker_service.h"
#include "streaming_core_configuration.h"
#include "cpu_affinity_configuration.h"

#include <sideband_data.h>
#include <sideband_grpc.h>
Expand Down Expand Up @@ -46,11 +46,11 @@ static void SysFsWrite(const std::string& fileName, const std::string& value)

namespace ni::data_monikers {

static StreamingCoreConfiguration s_StreamingCoreConfig;
static CpuAffinityConfiguration c_CpuAffinityConfig;

void configure_streaming_cores_for_cpu_pinning(const StreamingCoreConfiguration& streaming_core_config)
void configure_cpu_affinity(const CpuAffinityConfiguration& cpu_affinity)
{
s_StreamingCoreConfig = streaming_core_config;
c_CpuAffinityConfig = cpu_affinity;
}

bool is_sideband_streaming_enabled(const nidevice_grpc::FeatureToggles& feature_toggles)
Expand Down Expand Up @@ -117,13 +117,13 @@ void DataMonikerService::RunSidebandReadWriteLoop(string sidebandIdentifier, ::S
{
#ifndef _WIN32
if ((strategy == ::SidebandStrategy::RDMA_LOW_LATENCY ||
strategy == ::SidebandStrategy::SOCKETS_LOW_LATENCY) && s_StreamingCoreConfig.sideband_read_write_core >= 0) {
strategy == ::SidebandStrategy::SOCKETS_LOW_LATENCY) && c_CpuAffinityConfig.sideband_read_write >= 0) {
pid_t threadId = syscall(SYS_gettid);
::SysFsWrite("/dev/cgroup/cpuset/LabVIEW_tl_set/tasks", std::to_string(threadId));

cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(s_StreamingCoreConfig.sideband_read_write_core, &cpuSet);
CPU_SET(c_CpuAffinityConfig.sideband_read_write, &cpuSet);
sched_setaffinity(threadId, sizeof(cpu_set_t), &cpuSet);
}
#endif
Expand Down Expand Up @@ -248,10 +248,10 @@ Status DataMonikerService::StreamRead(ServerContext* context, const MonikerList*
Status DataMonikerService::StreamWrite(ServerContext* context, ServerReaderWriter<StreamWriteResponse, MonikerWriteRequest>* stream)
{
#ifndef _WIN32
if(s_StreamingCoreConfig.stream_write_core >= 0) {
if(c_CpuAffinityConfig.stream_write >= 0) {
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(s_StreamingCoreConfig.stream_write_core, &cpuSet);
CPU_SET(c_CpuAffinityConfig.stream_write, &cpuSet);
sched_setaffinity(0, sizeof(cpu_set_t), &cpuSet);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions source/server/data_moniker_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <map>
#include <sideband_data.h>
#include "feature_toggles.h"
#include "streaming_core_configuration.h"
#include "cpu_affinity_configuration.h"

//---------------------------------------------------------------------
//---------------------------------------------------------------------
namespace ni::data_monikers
{
void configure_streaming_cores_for_cpu_pinning(const StreamingCoreConfiguration& streaming_core_config);
void configure_cpu_affinity(const CpuAffinityConfiguration& cpu_affinity);
bool is_sideband_streaming_enabled(const nidevice_grpc::FeatureToggles& feature_toggles);
//---------------------------------------------------------------------
//---------------------------------------------------------------------
Expand Down
44 changes: 22 additions & 22 deletions source/server/server_configuration_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <sstream>

#include "feature_toggles.h"
#include "streaming_core_configuration.h"
#include "cpu_affinity_configuration.h"

#if defined(_MSC_VER)
#include <windows.h>
Expand All @@ -20,10 +20,10 @@ static const char* kAddressJsonKey = "address";
static const char* kPortJsonKey = "port";
static const char* kSidebandAddressJsonKey = "sideband_address";
static const char* kSidebandPortJsonKey = "sideband_port";
static const char* kStreamingCoreConfigurationKey = "streaming_core_configuration";
static const char* kSidebandReadWriteCoreKey = "sideband_read_write_core";
static const char* kStreamWriteCoreKey = "stream_write_core";
static const char* kServerRunCoreKey = "server_run_core";
static const char* kCpuAffinityConfigurationKey = "streaming_core_configuration";
static const char* kSidebandReadWriteKey = "sideband_read_write_core";
static const char* kStreamWriteKey = "stream_write_core";
static const char* kServerKey = "server_run_core";
static const char* kServerCertJsonKey = "server_cert";
static const char* kServerKeyJsonKey = "server_key";
static const char* kRootCertJsonKey = "root_cert";
Expand Down Expand Up @@ -292,27 +292,27 @@ int ServerConfigurationParser::parse_port_with_key(const std::string& key) const
return parsed_port;
}

StreamingCoreConfiguration ServerConfigurationParser::parse_streaming_core_configuration() const
CpuAffinityConfiguration ServerConfigurationParser::parse_cpu_affinity() const
{
StreamingCoreConfiguration streaming_core_config;
CpuAffinityConfiguration cpu_affinity;

auto core_config_it = config_file_.find(kStreamingCoreConfigurationKey);
auto core_config_it = config_file_.find(kCpuAffinityConfigurationKey);
if (core_config_it != config_file_.end()) {
streaming_core_config.sideband_read_write_core = parse_streaming_core_with_key(kSidebandReadWriteCoreKey);
streaming_core_config.stream_write_core = parse_streaming_core_with_key(kStreamWriteCoreKey);
streaming_core_config.server_run_core = parse_streaming_core_with_key(kServerRunCoreKey);
cpu_affinity.sideband_read_write = parse_cpu_affinity_with_key(kSidebandReadWriteKey);
cpu_affinity.stream_write = parse_cpu_affinity_with_key(kStreamWriteKey);
cpu_affinity.server = parse_cpu_affinity_with_key(kServerKey);
}
else{
// -1 is set as the default value for the cores which indicates that any available core can be used.
streaming_core_config.sideband_read_write_core = -1;
streaming_core_config.stream_write_core = -1;
streaming_core_config.server_run_core = -1;
cpu_affinity.sideband_read_write = -1;
cpu_affinity.stream_write = -1;
cpu_affinity.server = -1;
}

return streaming_core_config;
return cpu_affinity;
}

int ServerConfigurationParser::parse_streaming_core_with_key(const std::string& key) const
int ServerConfigurationParser::parse_cpu_affinity_with_key(const std::string& key) const
{
int parsed_core = -1;

Expand All @@ -322,12 +322,12 @@ int ServerConfigurationParser::parse_streaming_core_with_key(const std::string&
parsed_core = it->get<int>();
}
catch (const nlohmann::json::type_error& ex) {
throw WrongStreamingCoreTypeException(ex.what());
throw WrongCpuAffinityTypeException(ex.what());
}
}

if (parsed_core < -1) {
throw InvalidStreamingCoreException();
throw InvalidCpuAffinityException();
}

return parsed_core;
Expand All @@ -353,8 +353,8 @@ ServerConfigurationParser::InvalidPortException::InvalidPortException()
{
}

ServerConfigurationParser::InvalidStreamingCoreException::InvalidStreamingCoreException()
: std::runtime_error(kInvalidStreamingCoreMessage)
ServerConfigurationParser::InvalidCpuAffinityException::InvalidCpuAffinityException()
: std::runtime_error(kInvalidCpuAffinityMessage)
{
}

Expand All @@ -368,8 +368,8 @@ ServerConfigurationParser::WrongPortTypeException::WrongPortTypeException(const
{
}

ServerConfigurationParser::WrongStreamingCoreTypeException::WrongStreamingCoreTypeException(const std::string& type_error_details)
: std::runtime_error(kWrongStreamingCoreTypeMessage + type_error_details)
ServerConfigurationParser::WrongCpuAffinityTypeException::WrongCpuAffinityTypeException(const std::string& type_error_details)
: std::runtime_error(kWrongCpuAffinityTypeMessage + type_error_details)
{
}

Expand Down
18 changes: 9 additions & 9 deletions source/server/server_configuration_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#include <nlohmann/json.hpp>

#include "feature_toggles.h"
#include "streaming_core_configuration.h"
#include "cpu_affinity_configuration.h"

namespace nidevice_grpc {

static const char* kConfigFileNotFoundMessage = "The server configuration file was not found at: ";
static const char* kInvalidAddressMessage = "The specified address is not valid.\n Use a valid IPv4 or IPv6 address. Valid values include localhost, 192.168.1.1, [::], [::1], etc.";
static const char* kWrongAddressTypeMessage = "The server address must be specified in the server's configuration file as a string: \n\n";
static const char* kInvalidPortMessage = "The specified port number must between 0 and 65535.";
static const char* kInvalidStreamingCoreMessage = "The specified core number must be -1 or greater. -1 indicates that any available core can be used.";
static const char* kInvalidCpuAffinityMessage = "The specified affinity must be -1 or greater. -1 indicates that any available core can be used.";
static const char* kMalformedJsonMessage = "The JSON in the server configuration file is malformed: \n\n";
static const char* kWrongPortTypeMessage = "The server port must be specified in the server's configuration file as an integer: \n\n";
static const char* kWrongStreamingCoreTypeMessage = "The cpu core must be specified in the server's configuration file as an integer: \n\n";
static const char* kWrongCpuAffinityTypeMessage = "The cpu affinity must be specified in the server's configuration file as an integer: \n\n";
static const char* kUnspecifiedPortMessage = "The server port must be specified in the server's configuration file.";
static const char* kValueTypeNotStringMessage = "The following key must be specified in the server's configuration file as a string enclosed with double quotes: ";
static const char* kFileNotFoundMessage = "The following certificate file was not found: ";
Expand Down Expand Up @@ -45,7 +45,7 @@ class ServerConfigurationParser {
std::string parse_root_cert() const;
int parse_max_message_size() const;
int parse_sideband_port() const;
StreamingCoreConfiguration parse_streaming_core_configuration() const;
CpuAffinityConfiguration parse_cpu_affinity() const;
FeatureToggles parse_feature_toggles() const;
FeatureToggles::CodeReadiness parse_code_readiness() const;

Expand All @@ -65,8 +65,8 @@ class ServerConfigurationParser {
InvalidPortException();
};

struct InvalidStreamingCoreException : public std::runtime_error {
InvalidStreamingCoreException();
struct InvalidCpuAffinityException : public std::runtime_error {
InvalidCpuAffinityException();
};

struct MalformedJsonException : public std::runtime_error {
Expand All @@ -77,8 +77,8 @@ class ServerConfigurationParser {
WrongPortTypeException(const std::string& type_error_details);
};

struct WrongStreamingCoreTypeException : public std::runtime_error {
WrongStreamingCoreTypeException(const std::string& type_error_details);
struct WrongCpuAffinityTypeException : public std::runtime_error {
WrongCpuAffinityTypeException(const std::string& type_error_details);
};

struct UnspecifiedPortException : public std::runtime_error {
Expand Down Expand Up @@ -117,7 +117,7 @@ class ServerConfigurationParser {
std::string parse_bind_address() const;
int parse_port() const;
int parse_port_with_key(const std::string& key) const;
int parse_streaming_core_with_key(const std::string& key) const;
int parse_cpu_affinity_with_key(const std::string& key) const;

std::string config_file_path_;
nlohmann::json config_file_;
Expand Down
10 changes: 0 additions & 10 deletions source/server/streaming_core_configuration.h

This file was deleted.

0 comments on commit 515269b

Please sign in to comment.