Skip to content

Commit 657d866

Browse files
authored
Merge branch 'main' into urm-memory-reduction
2 parents 742bb27 + 37112ee commit 657d866

35 files changed

Lines changed: 788 additions & 366 deletions

.github/workflows/qcom-preflight-checks.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ permissions:
1212

1313
jobs:
1414
qcom-preflight-checks:
15-
uses: qualcomm/qcom-reusable-workflows/.github/workflows/qcom-preflight-checks-reusable-workflow.yml@v1.1.4
15+
uses: qualcomm/qcom-reusable-workflows/.github/workflows/reusable-qcom-preflight-checks-orchestrator.yml@v2
1616
with:
17-
# ✅ Preflight Checkers
18-
repolinter: true # default: true
19-
semgrep: true # default: true
20-
copyright-license-detector: true # default: true
21-
pr-check-emails: true # default: true
22-
dependency-review: true # default: true
23-
secrets:
24-
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
17+
enable-armor-checkers: true
18+
armor-checker-options: '{"build-script":"ci/build.sh","runs-on":{"group":"GHA-CSEPerf-prd-SelfHosted-RG","labels":["self-hosted", "cseperf-prd-u2204-arm64-xlrg-od-ephem"]}}'

.github/workflows/run_armor.yml

Lines changed: 0 additions & 63 deletions
This file was deleted.

ci/build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/bash
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
set -euo pipefail
7+
8+
echo "Installing required packages"
9+
sudo apt-get update -y
10+
sudo apt-get install -y cmake pkg-config libyaml-dev libsystemd-dev
11+
12+
echo "Installing optional packages (fasttext)"
13+
sudo apt-get install -y fasttext libfasttext-dev || {
14+
echo "Warning: optional fasttext packages could not be installed."
15+
}
16+
17+
echo "Running CMake configure"
18+
mkdir -p build
19+
cd build
20+
cmake .. -DBUILD_TESTS=ON -DBUILD_CLASSIFIER=OFF -DCMAKE_INSTALL_PREFIX="./urm-bins/"
21+
cmake --build .
22+
sudo make install

configs/PropertiesConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ PropertyConfigs:
3939
Value: "SYSLOG"
4040

4141
- Name: urm.extensions_lib.count
42-
Value: "3"
42+
Value: "6"

configs/ResourcesConfig.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,12 @@ ResourceConfigs:
398398
Modes: ["display_on"]
399399
Policy: "pass_through"
400400
ApplyType: "global"
401+
402+
- ResType: "0x0c"
403+
ResID: "0x0000"
404+
Name: "RES_PER_TASK_AFFINITY"
405+
Supported: true
406+
Permissions: "third_party"
407+
Modes: ["display_on"]
408+
Policy: "pass_through"
409+
ApplyType: "global"

contextual-classifier/Artifacts/fasttext_model_supervised.bin renamed to contextual-classifier/Artifacts/floret_model_supervised.bin

File renamed without changes.

contextual-classifier/CMakeLists.txt

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include_directories(${CMAKE_SOURCE_DIR}/modula/CoreModules/Include)
66
include_directories(${CMAKE_SOURCE_DIR}/extensions/Include)
77
include_directories(${CMAKE_SOURCE_DIR}/resource-tuner/core/Include)
88
include_directories(${CMAKE_SOURCE_DIR}/resource-tuner/signals/Include/)
9+
include_directories(${CMAKE_SOURCE_DIR}/resource-tuner/dbus-modules/Include/)
910

1011
# Single shared library that contains parser + classifier + netlink glue
1112
add_library(ContextualClassifier SHARED
@@ -22,60 +23,61 @@ target_include_directories(ContextualClassifier
2223
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include
2324
)
2425

25-
# fastText detection and USE_FASTTEXT macro
26-
option(ENABLE_FASTTEXT "Build ML inference with fastText support" ON)
26+
# floret detection and USE_FLORET macro using pkg-config
27+
option(ENABLE_FLORET "Build ML inference with floret support" ON)
2728

28-
set(FASTTEXT_FOUND FALSE)
29-
set(FASTTEXT_TARGET "")
29+
set(FLORET_FOUND FALSE)
30+
set(FLORET_LIBRARIES "")
31+
set(FLORET_INCLUDE_DIRS "")
3032

31-
if(ENABLE_FASTTEXT)
32-
# First try a CMake package
33-
find_package(fasttext QUIET)
34-
35-
if(TARGET fasttext::fasttext)
36-
set(FASTTEXT_FOUND TRUE)
37-
set(FASTTEXT_TARGET fasttext::fasttext)
38-
elseif(TARGET fasttext)
39-
set(FASTTEXT_FOUND TRUE)
40-
set(FASTTEXT_TARGET fasttext)
41-
else()
42-
# Fallback: probe the linker directly for -lfasttext
43-
include(CheckLibraryExists)
44-
check_library_exists(fasttext fasttext_version "" FASTTEXT_LINKABLE)
45-
if(FASTTEXT_LINKABLE)
46-
set(FASTTEXT_FOUND TRUE)
47-
set(FASTTEXT_TARGET fasttext)
48-
endif()
33+
if(ENABLE_FLORET)
34+
# Use pkg-config to find floret
35+
pkg_check_modules(PC_FLORET QUIET floret)
36+
if(PC_FLORET_FOUND)
37+
message(STATUS "floret not found via pkg-config")
38+
set(FLORET_FOUND TRUE)
39+
set(FLORET_LIBRARIES ${PC_FLORET_LIBRARIES})
40+
set(FLORET_INCLUDE_DIRS ${PC_FLORET_INCLUDE_DIRS})
4941
endif()
5042
endif()
5143

52-
if(FASTTEXT_FOUND)
53-
message(STATUS "fastText found, building MLInference with USE_FASTTEXT=1")
54-
add_definitions(-DUSE_FASTTEXT=1)
44+
if(FLORET_FOUND)
45+
message(STATUS "floret found via pkg-config, building MLInference with USE_FLORET=1")
46+
add_definitions(-DUSE_FLORET=1)
5547

56-
# Define the ML inference library that actually uses fastText
57-
add_library(ml_inference_lib STATIC
48+
# Define the ML inference library that actually uses FLORET
49+
add_library(ml_inference_lib SHARED
5850
FeatureExtractor.cpp
5951
FeaturePruner.cpp
6052
MLInference.cpp
6153
)
6254

55+
set_target_properties(ml_inference_lib PROPERTIES
56+
VERSION 1.0.0
57+
SOVERSION 1
58+
)
59+
60+
target_link_libraries(ContextualClassifier PRIVATE ml_inference_lib)
61+
6362
target_link_libraries(ml_inference_lib
64-
PRIVATE ${FASTTEXT_TARGET}
63+
PRIVATE
64+
${FLORET_LIBRARIES}
6565
)
6666

6767
target_include_directories(ml_inference_lib
68-
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include
68+
PUBLIC
69+
${CMAKE_CURRENT_SOURCE_DIR}/Include
70+
${FLORET_INCLUDE_DIRS}
6971
)
7072
else()
71-
message(STATUS "fastText not found or ENABLE_FASTTEXT=OFF — falling back to base Inference only")
73+
message(STATUS "floret not found via pkg-config or ENABLE_FLORET=OFF — falling back to base Inference only")
7274
endif()
7375

7476
# Installation rules
75-
install(TARGETS ContextualClassifier DESTINATION ${CMAKE_INSTALL_LIBDIR})
76-
if(FASTTEXT_FOUND)
77-
install(TARGETS ml_inference_lib DESTINATION ${CMAKE_INSTALL_LIBDIR})
78-
install(FILES ${CMAKE_SOURCE_DIR}/contextual-classifier/Artifacts/fasttext_model_supervised.bin DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/urm/classifier)
77+
install(TARGETS ContextualClassifier DESTINATION lib)
78+
if(FLORET_FOUND)
79+
install(TARGETS ml_inference_lib DESTINATION lib)
80+
install(FILES ${CMAKE_SOURCE_DIR}/contextual-classifier/Artifacts/floret_model_supervised.bin DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/urm/classifier)
7981
endif()
8082

8183
install(

contextual-classifier/ContextualClassifier.cpp

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@
2727
#define CLASSIFIER_TAG "CONTEXTUAL_CLASSIFIER"
2828
#define CLASSIFIER_CONFIGS_DIR "/etc/urm/classifier/"
2929

30-
#define CURR_RESTUNE_CGRP_HNDL 0
31-
#define CURR_RESTUNE_SIG_HNDL 1
32-
33-
static const std::string FT_MODEL_PATH =
34-
CLASSIFIER_CONFIGS_DIR "fasttext_model_supervised.bin";
35-
static const std::string IGNORE_PROC_PATH =
30+
const std::string FT_MODEL_PATH =
31+
CLASSIFIER_CONFIGS_DIR "floret_model_supervised.bin";
32+
const std::string IGNORE_PROC_PATH =
3633
CLASSIFIER_CONFIGS_DIR "classifier-blocklist.txt";
3734
static const std::string IGNORE_TOKENS_PATH =
3835
CLASSIFIER_CONFIGS_DIR "ignore-tokens.txt";
3936
static const std::string ALLOW_LIST_PATH =
4037
CLASSIFIER_CONFIGS_DIR "allow-list.txt";
4138

42-
#ifdef USE_FASTTEXT
39+
#ifdef USE_FLORET
4340
#include "MLInference.h"
4441
#include "FeatureExtractor.h"
4542
#include "FeaturePruner.h"
@@ -60,17 +57,15 @@ static ContextualClassifier *gClassifier = nullptr;
6057
static const int32_t pendingQueueControlSize = 30;
6158

6259
ContextualClassifier::ContextualClassifier() {
63-
this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurHandle = -1;
64-
this->mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurHandle = -1;
6560
mInference = GetInferenceObject();
6661
}
6762

68-
void ContextualClassifier::untuneRequestHelper(int32_t index) {
63+
void ContextualClassifier::untuneRequestHelper(int64_t handle) {
6964
try {
7065
Request* untuneRequest = MPLACED(Request);
7166

7267
untuneRequest->setRequestType(REQ_RESOURCE_UNTUNING);
73-
untuneRequest->setHandle(this->mRestuneHandles[index].mCurHandle);
68+
untuneRequest->setHandle(handle);
7469
untuneRequest->setDuration(-1);
7570
// Passing priority as HIGH_TRANSFER_PRIORITY (= -1)
7671
// - Ensures untune requests are processed before even SERVER_HIGH priority tune requests
@@ -79,8 +74,8 @@ void ContextualClassifier::untuneRequestHelper(int32_t index) {
7974
// not free up the underlying Request object, allowing for reuse.
8075
// Priority Level: -2 is used to force server termination and cleanup so should not be used otherwise.
8176
untuneRequest->setPriority(SYSTEM_HIGH);
82-
untuneRequest->setClientPID(this->mRestuneHandles[index].mCurReqPid);
83-
untuneRequest->setClientTID(this->mRestuneHandles[index].mCurReqTid);
77+
untuneRequest->setClientPID(0);
78+
untuneRequest->setClientTID(0);
8479

8580
// fast path to Request Queue
8681
// Mark verification status as true. Request still goes through RequestManager though.
@@ -257,6 +252,15 @@ void ContextualClassifier::ClassifierMain() {
257252
// For example: game, browser, multimedia
258253
sigId = this->GetSignalIDForWorkload(contextType);
259254

255+
// Step 2:
256+
// Untune any Configurations from the last proc-invocation
257+
for(int64_t handle: this->mCurrRestuneHandles) {
258+
if(handle > 0) {
259+
untuneRequestHelper(handle);
260+
}
261+
}
262+
this->mCurrRestuneHandles.clear();
263+
260264
// Step 2:
261265
// - Move the process to focused-cgroup, Also involves removing the process
262266
// already there from the cgroup.
@@ -379,26 +383,17 @@ void ContextualClassifier::ApplyActions(uint32_t sigId,
379383
uint32_t sigType,
380384
pid_t incomingPID,
381385
pid_t incomingTID) {
382-
383-
if(this->mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurHandle != -1) {
384-
untuneRequestHelper(CURR_RESTUNE_SIG_HNDL);
385-
mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurHandle = -1;
386-
}
387-
388386
Request* request = createTuneRequestFromSignal(sigId, sigType, incomingPID, incomingTID);
389387
if(request != nullptr) {
390388
if(request->getResourcesCount() > 0) {
391389
// Record:
392-
this->mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurHandle = request->getHandle();
393-
this->mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurReqPid = incomingPID;
394-
this->mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurReqTid = incomingTID;
390+
this->mCurrRestuneHandles.push_back(request->getHandle());
395391

396392
// fast path to Request Queue
397393
submitResProvisionRequest(request, true);
398394

399395
} else {
400396
Request::cleanUpRequest(request);
401-
this->mRestuneHandles[CURR_RESTUNE_SIG_HNDL].mCurHandle = -1;
402397
}
403398
}
404399
}
@@ -496,12 +491,6 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
496491
const std::string& comm,
497492
int32_t cgroupIdentifier) {
498493
try {
499-
// Check for any outstanding request, if found untune it.
500-
if(this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurHandle != -1) {
501-
untuneRequestHelper(CURR_RESTUNE_CGRP_HNDL);
502-
mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurHandle = -1;
503-
}
504-
505494
int64_t handleGenerated = -1;
506495
// Issue a tune request for the new pid (and any associated app-config pids)
507496
Request* request = MPLACED(Request);
@@ -537,22 +526,42 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
537526
// Anything to issue
538527
if(request->getResourcesCount() > 0) {
539528
// Record:
540-
this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurHandle = handleGenerated;
541-
this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurReqPid = incomingPID;
542-
this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurReqTid = incomingTID;
529+
this->mCurrRestuneHandles.push_back(request->getHandle());
543530

544531
// fast path to Request Queue
545532
submitResProvisionRequest(request, true);
546533

547534
} else {
548535
Request::cleanUpRequest(request);
549-
this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurHandle = -1;
536+
}
537+
538+
// Configure any associated signal
539+
if(appConfig != nullptr && appConfig->mSignalCodes != nullptr) {
540+
int32_t numSignals = appConfig->mNumSignals;
541+
// Go over the list of proc names (comm) and get their pids
542+
for(int32_t i = 0; i < numSignals; i++) {
543+
Request* request = createTuneRequestFromSignal(
544+
appConfig->mSignalCodes[i],
545+
0,
546+
incomingPID,
547+
incomingTID);
548+
549+
if(request != nullptr) {
550+
if(request->getResourcesCount() > 0) {
551+
// fast path to Request Queue
552+
this->mCurrRestuneHandles.push_back(request->getHandle());
553+
submitResProvisionRequest(request, true);
554+
555+
} else {
556+
Request::cleanUpRequest(request);
557+
}
558+
}
559+
}
550560
}
551561

552562
} catch(const std::exception& e) {
553563
LOGE(CLASSIFIER_TAG,
554564
"Failed to move per-app threads to cgroup, Error: " + std::string(e.what()));
555-
this->mRestuneHandles[CURR_RESTUNE_CGRP_HNDL].mCurHandle = -1;
556565
}
557566
}
558567

0 commit comments

Comments
 (0)