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
219 changes: 106 additions & 113 deletions contextual-classifier/ContextualClassifier.cpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions contextual-classifier/ContextualClassifierInit.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause-Clear

#include "ComponentRegistry.h"
#include "Logger.h"
#include <dlfcn.h>
#include <string>
#include <cstdarg>

#include "Logger.h"
#include "ComponentRegistry.h"

// Helper function from ContextualClassifier to format strings
static std::string format_string(const char *fmt, ...) {
char buffer[1024];
Expand Down
7 changes: 2 additions & 5 deletions contextual-classifier/Include/ContextualClassifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ struct ProcEvent {

class ContextualClassifier {
private:
pid_t mOurPid;
pid_t mOurTid;
int64_t mRestuneHandle;
int8_t mDebugMode = false;
volatile int8_t mNeedExit = false;
Expand Down Expand Up @@ -81,9 +79,7 @@ class ContextualClassifier {
uint32_t &ctxDetails);

// Fetch signal configuration info
void GetSignalDetailsForWorkload(int32_t contextType,
uint32_t &sigId,
uint32_t &sigSubtype);
uint32_t GetSignalIDForWorkload(int32_t contextType);

// Methods for tuning / untuning signals based on the workload
void ApplyActions(uint32_t sigId, uint32_t sigType);
Expand All @@ -100,6 +96,7 @@ class ContextualClassifier {
// Helper methods to move the current process to focused-cgroup
ResIterable* createMovePidResource(int32_t cGroupdId, pid_t pid);
void MoveAppThreadsToCGroup(pid_t incomingPID,
pid_t incomingTID,
const std::string& comm,
int32_t cgroupIdentifier);

Expand Down
29 changes: 26 additions & 3 deletions contextual-classifier/NetLinkComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@
#include "ContextualClassifier.h"

#define CLASSIFIER_TAG "NetLinkComm"
#define PROCP_THRESH 50

static pid_t getParent(pid_t pid) {
std::string statusFile = "/proc/" + std::to_string(pid) + "/status";
std::ifstream file(statusFile);
std::string line;

if(!file.is_open()) {
return 0;
}

while(std::getline(file, line)) {
if(line.rfind("PPid:", 0) == 0) {
std::istringstream iss(line);
std::string label;
pid_t parentPid;
iss >> label >> parentPid;
return parentPid;
}
}

return 0;
}

NetLinkComm::NetLinkComm() {
this->mNlSock = -1;
Expand Down Expand Up @@ -98,7 +121,7 @@ int32_t NetLinkComm::recvEvent(ProcEvent &ev) {
return 0;
}
if(rc == -1) {
if (errno == EINTR) {
if(errno == EINTR) {
// Caller (ContextualClassifier::HandleProcEv) will handle EINTR.
return -1;
}
Expand All @@ -125,7 +148,7 @@ int32_t NetLinkComm::recvEvent(ProcEvent &ev) {
ev.type = CC_APP_OPEN;

rc = CC_APP_OPEN;
if(!AuxRoutines::fileExists(COMM(ev.pid))) {
if(!AuxRoutines::fileExists(COMM(ev.pid)) || (getParent(ev.pid) <= PROCP_THRESH)) {
rc = ev.type = CC_IGNORE;
}
break;
Expand All @@ -136,7 +159,7 @@ int32_t NetLinkComm::recvEvent(ProcEvent &ev) {
ev.type = CC_APP_CLOSE;

rc = CC_APP_CLOSE;
if(!AuxRoutines::fileExists(COMM(ev.pid))) {
if(!AuxRoutines::fileExists(COMM(ev.pid)) || (getParent(ev.pid) <= PROCP_THRESH)) {
rc = ev.type = CC_IGNORE;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion extensions/Include/Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef void (*PostProcessingCallback)(void*);
typedef struct {
pid_t mPid;
uint32_t mSigId;
uint32_t mSigSubtype;
uint32_t mSigType;
} PostProcessCBData;

/**
Expand Down
3 changes: 0 additions & 3 deletions modula/Common/Include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
// Used to define the new config value, relative to the already configured value
#define OPT_WITHREL 0X00000004

// Stores name of focused slice
#define FOCUSED_SLICE "focused.slice"

/**
* @struct SysResource
* @brief Used to store information regarding Resources / Tunables which need to be
Expand Down
4 changes: 2 additions & 2 deletions modula/Common/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int32_t Message::getClientTID() const {
}

int8_t Message::getPriority() const {
return (int8_t)(this->mProperties & ((((int32_t) 1 << 8)) - 1));
return (int8_t) ((this->mProperties) & (((int32_t)1 << 8) - 1));
}

int64_t Message::getDuration() const {
Expand All @@ -32,7 +32,7 @@ int32_t Message::getProperties() const {
}

int8_t Message::getProcessingModes() const {
return (int8_t) ((this->mProperties >> 8) & ((((int32_t) 1 << 8)) - 1));
return (int8_t) ((this->mProperties >> 8) & (((int32_t)1 << 8) - 1));
}

void Message::setRequestType(int8_t reqType) {
Expand Down
1 change: 0 additions & 1 deletion modula/CoreModules/AuxRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ pid_t AuxRoutines::fetchPid(const std::string& process_name) {
int32_t AuxRoutines::fetchComm(pid_t pid, std::string &comm) {
std::string proc_path = "/proc/" + std::to_string(pid);
if(!AuxRoutines::fileExists(proc_path)) {
LOGD("URM_AUX_ROUTINE", "Process %d has exited." + std::to_string(pid));
return -1;
}

Expand Down
1 change: 1 addition & 0 deletions modula/CoreModules/Include/AuxRoutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <getopt.h>
#include <mutex>
#include <dirent.h>
#include <algorithm>

#include "Logger.h"
#include "Request.h"
Expand Down
1 change: 1 addition & 0 deletions modula/CoreModules/Include/UrmSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class UrmSettings {

static const std::string mDeviceNamePath;
static const std::string mBaseCGroupPath;
static const std::string focusedCgroup;

static const std::string mPersistenceFile;

Expand Down
3 changes: 2 additions & 1 deletion modula/CoreModules/UrmSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ const std::string UrmSettings::mExtensionsPluginLibPath =

const std::string UrmSettings::mDeviceNamePath =
"/sys/devices/soc0/machine";

const std::string UrmSettings::mBaseCGroupPath =
"/sys/fs/cgroup/";
const std::string UrmSettings::focusedCgroup =
"focused.slice";

const std::string UrmSettings::mPersistenceFile =
"/etc/urm/data/resource_original_values.txt";
Expand Down
3 changes: 1 addition & 2 deletions resource-tuner/init/RestuneInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,10 @@ static void configureFocusedSlice() {
const char *cgroupParam[][2] = {
{ "cgroup.max.depth", "3" },
{ "cgroup.max.descendants", "10" },
// { "pids.max", "100" },
};

for (size_t i = 0; i < sizeof(cgroupParam)/sizeof(cgroupParam[0]); i++) {
setCgroupParam(FOCUSED_SLICE, cgroupParam[i][0], cgroupParam[i][1]);
setCgroupParam(UrmSettings::focusedCgroup.c_str(), cgroupParam[i][0], cgroupParam[i][1]);
}
}

Expand Down
Loading