Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions contextual-classifier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include_directories(${CMAKE_SOURCE_DIR}/modula/CoreModules/Include)
include_directories(${CMAKE_SOURCE_DIR}/extensions/Include)
include_directories(${CMAKE_SOURCE_DIR}/resource-tuner/core/Include)
include_directories(${CMAKE_SOURCE_DIR}/resource-tuner/signals/Include/)
include_directories(${CMAKE_SOURCE_DIR}/resource-tuner/dbus-modules/Include/)

# Single shared library that contains parser + classifier + netlink glue
add_library(ContextualClassifier SHARED
Expand Down
1 change: 1 addition & 0 deletions modula/Common/Include/ErrCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum ErrCode {
RC_WORKER_THREAD_ASSIGNMENT_FAILURE,
RC_LOGICAL_TO_PHYSICAL_GEN_FAILED,
RC_CGROUP_CREATION_FAILURE,
RC_DBUS_COMM_FAIL,
};

#define RC_IS_OK(rc) ({ \
Expand Down
1 change: 1 addition & 0 deletions modula/Components/Include/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ enum CommonMessageTypes {
NOTIFY_CLASSIFIER_PROC_EVENT,
NOTIFY_CLASSIFIER_PROC_IGNORE,
NOTIFY_MODEL_PREDICTION,
SYSTEM_BUS_CONN_FAILED,
};

/**
Expand Down
7 changes: 7 additions & 0 deletions modula/Components/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,13 @@ void Logger::typeLog(CommonMessageTypes type, const std::string& funcName, ...)
Logger::log(LOG_INFO, "CONTEXTUAL_CLASSIFIER", funcName, buffer);
break;

case CommonMessageTypes::SYSTEM_BUS_CONN_FAILED:
vsnprintf(buffer, sizeof(buffer),
"Failed to establish connection with system bus, Error: %s", args);

Logger::log(LOG_ERR, "RESTUNE_COCO_TABLE", funcName, std::string(buffer));
break;

default:
break;
}
Expand Down
32 changes: 28 additions & 4 deletions resource-tuner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Mandatory Dependencies
pkg_check_modules(LIBYAML REQUIRED yaml-0.1)

# Optional Dependency: libsystemd
set(LIB_SYSTEMD_DEP_FOUND FALSE)
pkg_check_modules(PC_SYSTEMD QUIET systemd)
if(PC_SYSTEMD_FOUND)
pkg_check_modules(SYSTEMD QUIET libsystemd)
if(SYSTEMD_FOUND)
set(LIB_SYSTEMD_DEP_FOUND TRUE)
endif()
endif()

# Optional Modules
option(BUILD_TESTS "Testing" OFF)
option(BUILD_STATE_DETECTOR "Display Detector" OFF)
Expand All @@ -18,19 +28,33 @@ list(APPEND LINK_LIBS
${LIBYAML_LIBRARIES}
)

if(BUILD_STATE_DETECTOR)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
list(APPEND SOURCES extensions/StateDetector.cpp)
if(LIB_SYSTEMD_DEP_FOUND)
list(APPEND LINK_LIBS ${SYSTEMD_LIBRARIES})
list(APPEND SOURCES dbus-modules/RestuneDBusInternal.cpp)
if(BUILD_STATE_DETECTOR)
list(APPEND SOURCES dbus-modules/StateDetector.cpp)
endif()
else()
list(APPEND SOURCES dbus-modules/RestuneDBusStubs.cpp)
endif()

add_library(RestuneCore ${SOURCES})
set_target_properties(RestuneCore PROPERTIES VERSION 1.0.0 SOVERSION 1)
target_include_directories(RestuneCore PRIVATE ${LIBYAML_INCLUDE_DIRS})
target_link_libraries(RestuneCore PUBLIC ${LINK_LIBS})

target_include_directories(RestuneCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/core/Include)
target_include_directories(RestuneCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/core/Server/Include)
target_include_directories(RestuneCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/signals/Include)
target_include_directories(RestuneCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/init/Include)
target_include_directories(RestuneCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/dbus-modules/Include)

# libyaml headers
target_include_directories(RestuneCore PRIVATE ${LIBYAML_INCLUDE_DIRS})

# libsystemd headers
if(LIB_SYSTEMD_DEP_FOUND)
target_include_directories(RestuneCore PRIVATE ${SYSTEMD_INCLUDE_DIRS})
endif()

# Install RestuneCore
install(TARGETS RestuneCore LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
2 changes: 1 addition & 1 deletion resource-tuner/core/CocoTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int8_t comparLBetter(DLRootNode* newNode, DLRootNode* targetNode) {
return newValue < targetValue;
}

int8_t CocoTable::needAllocation(Resource* res) {
int8_t CocoTable::needsAllocation(Resource* res) {
ResConfInfo* rConf = this->mResourceRegistry->getResConf(res->getResCode());
return (rConf->mPolicy != Policy::PASS_THROUGH);
}
Expand Down
2 changes: 1 addition & 1 deletion resource-tuner/core/Include/CocoTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class CocoTable {

void fastPathApply(Resource* resource);
void fastPathReset(Resource* resource);
int8_t needAllocation(Resource* res);
int8_t needsAllocation(Resource* res);

public:
~CocoTable();
Expand Down
6 changes: 4 additions & 2 deletions resource-tuner/core/Include/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#include <regex>
#include <memory>

#include "Logger.h"
#include "ErrCodes.h"
#include "UrmSettings.h"
#include "AuxRoutines.h"
#include "ErrCodes.h"
#include "Logger.h"
#include "RestuneDBus.h"

#define POLICY_DIR_PATH "/sys/devices/system/cpu/cpufreq/"
#define ONLINE_CPU_FILE_PATH "/sys/devices/system/cpu/online"
Expand Down Expand Up @@ -166,6 +167,7 @@ class TargetRegistry {

ErrCode addIrqAffine(std::vector<std::string>& values,
int8_t areClusterValues = false);
ErrCode addLogLimit(std::vector<std::string>& values);

static std::shared_ptr<TargetRegistry> getInstance() {
if(targetRegistryInstance == nullptr) {
Expand Down
95 changes: 95 additions & 0 deletions resource-tuner/core/TargetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ void TargetRegistry::generatePolicyBasedMapping(std::vector<std::string>& policy
}
}

static std::string trimStr(const std::string &s) {
size_t start = s.find_first_not_of(" \t");
size_t end = s.find_last_not_of(" \t\r");
return (start == std::string::npos) ? "" : s.substr(start, end - start + 1);
}

void TargetRegistry::getClusterIdBasedMapping() {
const std::string cpuDir = "/sys/devices/system/cpu";
const std::regex cpuRegex("^cpu([0-9]+)$");
Expand Down Expand Up @@ -551,6 +557,95 @@ ErrCode TargetRegistry::addIrqAffine(std::vector<std::string>& values,
return RC_SUCCESS;
}

ErrCode TargetRegistry::addLogLimit(std::vector<std::string>& values) {
if(values.size() < 1) {
return RC_INVALID_VALUE;
}

std::string logLevel = values[0];
if(logLevel != "minimal") {
return RC_SUCCESS;
}

const std::string journaldConfFile = "/etc/systemd/journald.conf";
const std::unordered_map<std::string, std::string> configOptions = {
{"RuntimeMaxUse", "20M"},
{"RuntimeMaxFileSize", "128K"},
{"MaxLevelStore", "notice"},
{"MaxLevelSyslog", "notice"},
{"MaxLevelKMsg", "notice"},
{"MaxLevelConsole", "notice"},
{"ForwardToSyslog", "no"}
};

std::ifstream confInStream(journaldConfFile);
if(!confInStream) {
return RC_SUCCESS;
}

std::ostringstream oldContent;
std::ostringstream newContent;
std::string line;
int8_t journalSectionFound = false;

std::unordered_map<std::string, int8_t> keyUpdated;
for(auto &entry : configOptions) {
keyUpdated[entry.first] = false;
}

while(std::getline(confInStream, line)) {
std::string trimmedLine = trimStr(line);
int8_t replaced = false;

if(trimmedLine == "[Journal]") {
journalSectionFound = true;
}

for(auto &entry : configOptions) {
if(trimmedLine.find(entry.first + "=") == 0 ||
trimmedLine.find("#" + entry.first + "=") == 0) {
newContent << entry.first << "=" << entry.second << "\n";
keyUpdated[entry.first] = true;
replaced = true;
break;
}
}
if(!replaced) {
newContent << line << "\n";
}
oldContent << line << "\n";
}
confInStream.close();

if(!journalSectionFound) {
newContent << "\n[Journal]\n";
}

for(auto &entry : configOptions) {
if(!keyUpdated[entry.first]) {
newContent << entry.first << "=" << entry.second << "\n";
}
}

std::ofstream confOutStream(journaldConfFile);
confOutStream << newContent.str();
confOutStream.close();

// Set printk kernel logging to minimal
const std::string printkPath = "/proc/sys/kernel/printk";
const std::string newLevels = "3 4 1 3";

std::ofstream printkFile(printkPath);
if(printkFile.is_open()) {
printkFile << newLevels;
printkFile.close();
}

// Restart journald
RestuneSDBus::getInstance()->restartService("systemd-journald.service");
return RC_SUCCESS;
}

// Methods for Building CGroup Config from InitConfigs.yaml
CGroupConfigInfoBuilder::CGroupConfigInfoBuilder() {
this->mCGroupConfigInfo = new(std::nothrow) CGroupConfigInfo;
Expand Down
38 changes: 38 additions & 0 deletions resource-tuner/dbus-modules/Include/RestuneDBus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause-Clear

#ifndef RESTUNE_DBUS_INTERNAL_H
#define RESTUNE_DBUS_INTERNAL_H

#include <memory>

#include "Logger.h"
#include "ErrCodes.h"

class RestuneSDBus {
private:
static std::shared_ptr<RestuneSDBus> restuneSDBusInstance;
void* mBus;

RestuneSDBus();

public:
~RestuneSDBus();

ErrCode stopService(const std::string& unitName);
ErrCode startService(const std::string& unitName);
ErrCode restartService(const std::string& unitName);

// For custom use-cases, like StateDetector while still keeping
// a single open connection to system-bus.
void* getBus();

static std::shared_ptr<RestuneSDBus> getInstance() {
if(restuneSDBusInstance == nullptr) {
restuneSDBusInstance = std::shared_ptr<RestuneSDBus>(new RestuneSDBus());
}
return restuneSDBusInstance;
}
};

#endif
Loading