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
6 changes: 2 additions & 4 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
- SeLinux Rules enablement
- Enable Classifier on meta-qcom builds
- Analyze CodeQL reported issues
- Documentation Reordering

2. Process tasks (GitHub actions and repo workflow)
- Enable Axiom CI tests
Expand All @@ -11,9 +10,8 @@
- Integrate and Enable ARMOR

3. Implementation specific
- Adding irq resources
- Client API requests encoding / decoding support
- Client API requests encoding / decoding support (Making Buffers smaller for efficiency)
- Client CLI improvements, to support all types of requests
- Focused cgroup creation
- Memory Leaks analysis and reduction. Major issues are resolved, still observing some lost blocks.
- Coordination Table changes (will add details here).
- Tests Cleanup
3 changes: 3 additions & 0 deletions configs/PropertiesConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ PropertyConfigs:
- Name: urm.logging.redirect_to
# Possible values: FILE, SYSLOG, FTRACE, LOGCAT.
Value: "SYSLOG"

- Name: urm.extensions_lib.count
Value: "3"
1 change: 1 addition & 0 deletions modula/Common/Include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ typedef void (*MessageReceivedCallback)(int32_t, MsgForwardInfo*);
#define LOGGER_LOGGING_LEVEL "urm.logging.level"
#define LOGGER_LOGGING_LEVEL_TYPE "urm.logging.level.exact"
#define LOGGER_LOGGING_OUTPUT_REDIRECT "urm.logging.redirect_to"
#define URM_MAX_PLUGIN_COUNT "urm.extensions_lib.count"

#define COMM(pid) ("/proc/" + std::to_string(pid) + "/comm")
#define COMM_S(pidstr) ("/proc/" + pidstr + "/comm")
Expand Down
4 changes: 2 additions & 2 deletions modula/Components/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ void Logger::typeLog(CommonMessageTypes type, const std::string& funcName, ...)

case CommonMessageTypes::NOTIFY_EXTENSIONS_LOAD_FAILED:
vsnprintf(buffer, sizeof(buffer),
"Error loading extension lib, Error: %s", args);
"Error loading extension lib: [%s], Error: [%s]", args);

Logger::log(LOG_ERR, "RESTUNE_SERVER_INIT", funcName, buffer);
break;

case CommonMessageTypes::NOTIFY_EXTENSIONS_LIB_LOADED_SUCCESS:
Logger::log(LOG_INFO, "RESTUNE_SERVER_INIT", funcName,
"Extension library present and successfully loaded");
"Successfully Loaded: [%d] extension plugins");
break;

case CommonMessageTypes::NOTIFY_COCO_TABLE_INSERT_START:
Expand Down
7 changes: 4 additions & 3 deletions modula/CoreModules/Include/UrmSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct {
uint32_t mCleanupBatchSize;
double mPenaltyFactor;
double mRewardFactor;
uint32_t mPluginCount;
} MetaConfigs;

typedef struct {
Expand All @@ -42,8 +43,8 @@ class UrmSettings {
static int32_t serverOnlineStatus;

public:
static const int32_t desiredThreadCount = 15;
static const int32_t maxScalingCapacity = 30;
static const int32_t desiredThreadCount = 5;
static const int32_t maxScalingCapacity = 10;

// Support both versions: Common and Custom
static const std::string mCommonResourceFilePath;
Expand All @@ -64,7 +65,7 @@ class UrmSettings {
static const std::string mDeviceNamePath;
static const std::string mBaseCGroupPath;
static const std::string mPersistenceFile;
static const std::string mExtensionsPluginLibPath;
static const std::string mExtensionPluginsLibPath;

// Target Information Stores
static MetaConfigs metaConfigs;
Expand Down
4 changes: 2 additions & 2 deletions modula/CoreModules/UrmSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const std::string UrmSettings::mCustomExtFeaturesFilePath =
const std::string UrmSettings::mCustomAppConfigFilePath =
"/etc/urm/custom/PerApp.yaml";

const std::string UrmSettings::mExtensionsPluginLibPath =
"libRestunePlugin.so";
const std::string UrmSettings::mExtensionPluginsLibPath =
"/etc/urm/extensions";

const std::string UrmSettings::mDeviceNamePath =
"/sys/devices/soc0/machine";
Expand Down
106 changes: 84 additions & 22 deletions resource-tuner/init/RestuneInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#include "SignalRegistry.h"
#include "RestuneParser.h"

static void* extensionsLibHandle = nullptr;
#define MAX_EXTENSION_LIB_HANDLES 3
static void** extensionLibHandles = nullptr;

// Request Listener and Handler Threads
static std::thread restuneHandlerThread;
static std::thread resourceTunerListener;

Expand All @@ -37,16 +40,40 @@
// Load the Extensions Plugin lib if it is available
// If the lib is not present, we simply return Success. Since this lib is optional
static ErrCode loadExtensionsLib() {
std::string libPath = UrmSettings::mExtensionsPluginLibPath;
if(extensionLibHandles == nullptr) {
extensionLibHandles = (void**) calloc(MAX_EXTENSION_LIB_HANDLES, sizeof(void*));
if(extensionLibHandles == nullptr) {
return RC_MODULE_INIT_FAILURE;
}
}
std::string libDirPath = UrmSettings::mExtensionPluginsLibPath;

DIR* dir = opendir(libDirPath.c_str());
if(dir == nullptr) {
return RC_SUCCESS; // Return success regardless, since this is an extension.
}

uint32_t extLibHandleIndex = 0;
int32_t libsLoaded = 0;
struct dirent* entry;
while(((entry = readdir(dir)) != nullptr) &&
(extLibHandleIndex < UrmSettings::metaConfigs.mPluginCount)) {
std::string libPath = libDirPath + "/" + entry->d_name;

// Check if the library file exists
extensionsLibHandle = dlopen(libPath.c_str(), RTLD_NOW);
if(extensionsLibHandle == nullptr) {
TYPELOGV(NOTIFY_EXTENSIONS_LOAD_FAILED, dlerror());
return RC_SUCCESS; // Return success regardless, since this is an extension.
// Check if the library file exists
extensionLibHandles[extLibHandleIndex] = dlopen(libPath.c_str(), RTLD_NOW);
if(extensionLibHandles[extLibHandleIndex] != nullptr) {
libsLoaded++;
} else {
TYPELOGV(NOTIFY_EXTENSIONS_LOAD_FAILED, libPath.c_str(), dlerror());
}
extLibHandleIndex++;
}
closedir(dir);

TYPELOGD(NOTIFY_EXTENSIONS_LIB_LOADED_SUCCESS);
if(libsLoaded > 0) {
TYPELOGV(NOTIFY_EXTENSIONS_LIB_LOADED_SUCCESS, libsLoaded);
}
return RC_SUCCESS;
}

Expand Down Expand Up @@ -77,7 +104,7 @@
std::string resultBuffer;

int32_t logLevel = LOG_DEBUG;
submitPropGetRequest(LOGGER_LOGGING_LEVEL, resultBuffer, "DEBUG");

Check notice

Code scanning / CodeQL

Unused static function Note

Static function fetchMetaConfigs is unreachable (
init
must be removed at the same time)
Static function fetchMetaConfigs is unreachable (
_moduleMOD_RESTUNE
must be removed at the same time)
std::string level = std::string(resultBuffer);

if(level == "DEBUG") logLevel = LOG_DEBUG;
Expand Down Expand Up @@ -123,7 +150,7 @@

submitPropGetRequest(GARBAGE_COLLECTOR_DURATION, resultBuffer, "83000");
UrmSettings::metaConfigs.mClientGarbageCollectorDuration = (uint32_t)std::stol(resultBuffer);

Check notice

Code scanning / CodeQL

Unused static function Note

Static function parseUtil is unreachable (
init
must be removed at the same time)
Static function parseUtil is unreachable (
fetchCommonProperties
must be removed at the same time)
Static function parseUtil is unreachable (
fetchCustomProperties
must be removed at the same time)
Static function parseUtil is unreachable (
fetchTargetInfo
must be removed at the same time)
Static function parseUtil is unreachable (
fetchInitInfo
must be removed at the same time)
Static function parseUtil is unreachable (
fetchResources
must be removed at the same time)
Static function parseUtil is unreachable (
fetchSignals
must be removed at the same time)
Static function parseUtil is unreachable (
fetchPerAppConfigs
must be removed at the same time)
Static function parseUtil is unreachable (
fetchExtFeatureConfigs
must be removed at the same time)
Static function parseUtil is unreachable (
_moduleMOD_RESTUNE
must be removed at the same time)
submitPropGetRequest(GARBAGE_COLLECTOR_BATCH_SIZE, resultBuffer, "5");
UrmSettings::metaConfigs.mCleanupBatchSize = (uint32_t)std::stol(resultBuffer);

Expand All @@ -136,7 +163,8 @@
submitPropGetRequest(RATE_LIMITER_REWARD_FACTOR, resultBuffer, "0.4");
UrmSettings::metaConfigs.mRewardFactor = std::stod(resultBuffer);

initLogger();
submitPropGetRequest(URM_MAX_PLUGIN_COUNT, resultBuffer, "3");
UrmSettings::metaConfigs.mPluginCount = (uint32_t)std::stol(resultBuffer);

} catch(const std::invalid_argument& e) {
TYPELOGV(META_CONFIG_PARSE_FAILURE, e.what());
Expand Down Expand Up @@ -171,18 +199,22 @@
return opStatus;
}

static ErrCode fetchProperties() {
static ErrCode fetchCommonProperties() {
Comment thread Dismissed
ErrCode opStatus = RC_SUCCESS;

// Parse Common Properties Configs
std::string filePath = UrmSettings::mCommonPropertiesFilePath;
opStatus = parseUtil(filePath, COMMON_PROPERTIES, ConfigType::PROPERTIES_CONFIG);
if(RC_IS_NOTOK(opStatus)) {
// Common Properties Parsing Failed
return opStatus;
if(RC_IS_OK(opStatus)) {
return fetchMetaConfigs();
}
return opStatus;
}

filePath = Extensions::getPropertiesConfigFilePath();
static ErrCode fetchCustomProperties() {
Comment thread Dismissed
ErrCode opStatus = RC_SUCCESS;

std::string filePath = Extensions::getPropertiesConfigFilePath();
// Parse Custom Properties Configs provided via Extension Interface (if any)
if(filePath.length() > 0) {
TYPELOGV(NOTIFY_CUSTOM_CONFIG_FILE, "Property", filePath.c_str());
Expand Down Expand Up @@ -429,37 +461,58 @@
// Mandatory Configs include: Properties Configs, Resource Configs and Signal Configs (if Signal
// module is plugged in)

// Fetch common properties
if(RC_IS_NOTOK(fetchCommonProperties())) {
TYPELOGD(PROPERTY_RETRIEVAL_FAILED);
return RC_MODULE_INIT_FAILURE;
}

uint32_t pluginCount = UrmSettings::metaConfigs.mPluginCount;
if(pluginCount > MAX_EXTENSION_LIB_HANDLES) {
extensionLibHandles = (void**) realloc(extensionLibHandles, pluginCount * sizeof(void*));
if(extensionLibHandles == nullptr) {
return RC_MODULE_INIT_FAILURE;
}
}

// Check if Extensions Plugin lib is available
if(RC_IS_NOTOK(loadExtensionsLib())) {
return RC_MODULE_INIT_FAILURE;
}

if(RC_IS_NOTOK(fetchProperties())) {
// Fetch custom Properties
if(RC_IS_NOTOK(fetchCustomProperties())) {
TYPELOGD(PROPERTY_RETRIEVAL_FAILED);
return RC_MODULE_INIT_FAILURE;
}

// Pre-Allocate Memory for Commonly used Types via Memory Pool
preAllocateMemory();

// Setup the logger, according to configuration urm can log to either:
// syslog, ftrace or regular text file.
initLogger();

// Pre Allocate some Worker Threads in the Thread Pool for handling requests
if(RC_IS_NOTOK(preAllocateWorkers())) {
return RC_MODULE_INIT_FAILURE;
}

// Target Configs
// Fetch and Parse: Custom Target Configs
if(RC_IS_NOTOK(fetchTargetInfo())) {
return RC_MODULE_INIT_FAILURE;
}
TargetRegistry::getInstance()->displayTargetInfo();

// Fetch and Parse:
// - Init Configs
// Fetch and Parse: Init Configs
// Init Configs which will be considered:
// - Common Init Configs
// - Custom Init Configs (if present)
if(RC_IS_NOTOK(fetchInitInfo())) {
return RC_MODULE_INIT_FAILURE;
}

// Fetch and Parse Resource Configs
// Resource Parsing which will be considered:
// Resource Configs which will be considered:
// - Common Resource Configs
// - Custom Resource Configs (if present)
// Note by this point, we will know the Target Info, i.e. number of Core, Clusters etc.
Expand All @@ -475,10 +528,12 @@
return RC_MODULE_INIT_FAILURE;
}

// Fetch and Parse: Custom Per-App Configs
if(RC_IS_NOTOK(fetchPerAppConfigs())) {
return RC_MODULE_INIT_FAILURE;
}

// Fetch and Parse: Custom ExtFeature Configs
if(RC_IS_NOTOK(fetchExtFeatureConfigs())) {
return RC_MODULE_INIT_FAILURE;
}
Expand Down Expand Up @@ -564,8 +619,15 @@
// Delete the Sysfs Persistent File
AuxRoutines::deleteFile(UrmSettings::mPersistenceFile);

if(extensionsLibHandle != nullptr) {
dlclose(extensionsLibHandle);
if(extensionLibHandles != nullptr) {
for(uint32_t i = 0; i < UrmSettings::metaConfigs.mPluginCount; i++) {
if(extensionLibHandles[i] != nullptr) {
dlclose(extensionLibHandles[i]);
extensionLibHandles[i] = nullptr;
}
}

free(extensionLibHandles);
}

return RC_SUCCESS;
Expand Down
Loading