platform/core/system/resourced.git
6 months agotest: cmocka-heart: Add unit tests for the heart module 81/320481/6 tizen_dev
Unsung Lee [Thu, 14 Nov 2024 02:58:40 +0000 (11:58 +0900)]
test: cmocka-heart: Add unit tests for the heart module

Add unit tests for the heart module to check correctness
of the function (heart_module_add(), heart_module_find(), and heart_module_remove()) in heart.c.
For this goal, several modifications of CMakeLists.txt have been added.
First, make a new static library called resourced_heart_test for linking.
Second, add src/common/conf heart path to UNIT_TESTS_CFLAGS to include dbus-handler.h.

Change-Id: Ib5dbd62d00d3c7645db7e6f51dc83c4b601bff6d
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agoheart: Remove interdependence between heart and logging 80/320480/6
Unsung Lee [Wed, 13 Nov 2024 11:57:11 +0000 (20:57 +0900)]
heart: Remove interdependence between heart and logging

Remove interdependent between heart and logging by preventing
logging from directly referencing the heart module.
Previously, heart.c includes logging.h and logging.c includes heart.h.

Change-Id: I7ecba8fc57fdbb03786fd7102b4b2c0f39591265
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-proc-main: Add unit test for proc_common_request_process_termination() 79/320479/5
Unsung Lee [Sun, 10 Nov 2024 04:43:23 +0000 (13:43 +0900)]
test: cmocka-proc-main: Add unit test for proc_common_request_process_termination()

Add a unit test to check correctness of proc_common_request_process_termination() in proc-main.c.
It is added to remove direct access from lowmem to process module.

Change-Id: I146893b26fd972b1ca6ddb2ec15f6797b5afb49d
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agolowmem: process: Remove direct access from lowmem to process 78/320478/5
Unsung Lee [Sun, 10 Nov 2024 06:16:54 +0000 (15:16 +0900)]
lowmem: process: Remove direct access from lowmem to process

Remove direct header include and function call from lowmem and lowmem-controller modlue to process module.
This is problem because lowmem and lowmem-controller can access and call all functions in defined proc-main.h.
It means that there is strong dependency between them.
It is essential procedure to remove dependency between different modules.

Change-Id: Iad02d8fe3b54bc32b90f11e0ebe122e01463e8c7
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-freezer-common: Add unit test for freezer_common 56/320556/2
Unsung Lee [Mon, 18 Nov 2024 11:00:15 +0000 (20:00 +0900)]
test: cmocka-freezer-common: Add unit test for freezer_common

Add unit test for the function freezer_common_get_freezer_status() in freezer_common.
In previous patch, the resourced was changed to block accessing to freezer module directly
from other modules. Instead, freezer_common_get_freezer_status() is exposed to get
the current status of freezer module.

Change-Id: Ic0a43911195b7474085fd9c4d3dc9ff2791a87a3
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agoprocess: freezer: Remove direct access from process to freezer 77/320477/4
Unsung Lee [Fri, 15 Nov 2024 08:51:50 +0000 (17:51 +0900)]
process: freezer: Remove direct access from process to freezer

Remove direct header include and function call from process modlue to freezer.
This is problem because process can access and call all functions in defined freezer.h.
It means that there is strong dependency from process to freezer.
It is essential procedure to remove dependency between different modules.
To achieve this goal, process module can access only freezer-common instead of freezer.

Change-Id: I48e660ac554a156001cf6e9b97563acc82c31f9b
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agolowmem: freezer: Remove direct access from lowmem to freezer 76/320476/4
Unsung Lee [Sun, 10 Nov 2024 03:19:24 +0000 (12:19 +0900)]
lowmem: freezer: Remove direct access from lowmem to freezer

Remove direct header include and function call from lowmem (including lowmem-controller) modlue to freezer module.
This is problem because lowmem can access and call all functions in defined freezer.h.
It means that there is strong dependency from lowmem to freezer.
It is essential procedure to remove dependency between different modules.
To achieve this goal, freezer enumeration and function required from lowmem
are moved to freezer-common.c/.h

Change-Id: Iab5a944f67118847b41031a3ede339d452274284
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-notifier: Add notifier test for RESOURCED_NOTIFIER_LOWMEM_RESTORE 75/320475/3
Unsung Lee [Tue, 5 Nov 2024 06:17:57 +0000 (15:17 +0900)]
test: cmocka-notifier: Add notifier test for RESOURCED_NOTIFIER_LOWMEM_RESTORE

Add a test case of notifier functions (register_nofitier, resourced_notify, and unregister_notifier)
for RESOURCED_NOTIFIER_LOWMEM_RESTORE. In previous patch,
the resourced was changed to prevent the process module from directly calling the lowmem module function.
It tests whether this modified code functions properly.

Change-Id: I1d4594ece75c3da51b33de17c24c70656b2deedd
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-notifier: Add each list per notifier type 74/320474/3
Unsung Lee [Sun, 3 Nov 2024 12:18:17 +0000 (21:18 +0900)]
test: cmocka-notifier: Add each list per notifier type

Add each list per notifier type to reflect the current notifier implementation.
This test code was created for a notifier with a single list and, therefore,
does not support the current multiple-list notfiers.

Change-Id: Ic4fa29fa988f17734bc9c0fc52824ef4c966deda
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-config-parser: Add cmocka config parser during build 73/320473/3
Unsung Lee [Sat, 9 Nov 2024 07:06:04 +0000 (16:06 +0900)]
test: cmocka-config-parser: Add cmocka config parser during build

Add cmocka test for the config parser. The test code was previously excluded from the build
due to not reflecting the latest resourced code.
config_parse_new() is no longer used in the resourced,
so unit test of this function should be removed.
It allows the cmocka for config parser tests to be executed at build time.

Change-Id: Ic743851dba3ccba953b2e3a46cafcc42c4270996
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-fd-handler: Add cmocka fd handler during build 72/320472/2
Unsung Lee [Sat, 9 Nov 2024 06:12:06 +0000 (15:12 +0900)]
test: cmocka-fd-handler: Add cmocka fd handler during build

Add cmocka test for the fd handler. The test code was previously excluded from the build
due to not reflecting the latest resourced code.
It allows the cmocka for fd handler tests to be executed at build time.

Change-Id: If147c63deff89213106dade8540ff8d0c2f04b8f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: Add separated cmocka test files of cmocka-core.c 71/320471/2
Unsung Lee [Sun, 3 Nov 2024 11:33:17 +0000 (20:33 +0900)]
test: Add separated cmocka test files of cmocka-core.c

Add test files to separate notifier, fd-handler, config-parser from cmocka-core.
Previously cmocka-core includes tests for unrelated different files in one place.
It causes a depdency between tests of notifier, fd-handler, and config-parser.
To resolve the issue, it separates the test file of each file.

Change-Id: I46956757a898368781cf140e7e1db8539fc69dc9
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agoprocess: lowmem: Remove direct access to the lowmem module 70/320470/2
Unsung Lee [Sun, 3 Nov 2024 10:44:32 +0000 (19:44 +0900)]
process: lowmem: Remove direct access to the lowmem module

Remove direct access to the lowmem module from proecss module.
For this goal, modify the process module to call the function of lowmem module
through the common notifier.

Change-Id: I14b621481b815c8ad60bcb56cc0bdec8fcfda6cd
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-memory-cgroup: Add unit test for memory_cgroup getter 59/320559/3
Unsung Lee [Mon, 18 Nov 2024 11:54:02 +0000 (20:54 +0900)]
test: cmocka-memory-cgroup: Add unit test for memory_cgroup getter

Add unit test for memory cgroup getter funtions to check correctness of the function.

Getter functions for memcg_info list:
memory_cgroup_get_memcg_info_name()
memory_cgroup_get_memcg_info_swappiness()
memory_cgroup_get_memcg_info_evfd()
memory_cgroup_get_memcg_info_limit_bytes()
memory_cgroup_get_memcg_info_limit_ratio()
memory_cgroup_get_memcg_info_threshold_mb()
memory_cgroup_get_memcg_info_threshold_leave_mb()

Change-Id: Iaf1831656e0f422e4e168dfd4326d3c0d39bbd31
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agotest: cmocka-memory-cgroup: Add unit test for is_valid_cgroup_type() 86/320486/5
Unsung [Mon, 14 Oct 2024 11:09:16 +0000 (20:09 +0900)]
test: cmocka-memory-cgroup: Add unit test for is_valid_cgroup_type()

Add a unit test for is_valid_cgroup_type() to check correctness of the function.
is_valid_cgroup_type() is currently static function,
so it is impossible to call this function in the cmocka unit test file.
Instead, perform unit test of this function by utilizing another function
that calls 'is_valid_cgroup_type()'.

Change-Id: Idbfc5310d3c4054626abdfef13c976a46c592d0a
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agomemory-cgroup: Add getter to replace direct access to memcg info 85/320485/2
Unsung [Thu, 10 Oct 2024 09:04:42 +0000 (18:04 +0900)]
memory-cgroup: Add getter to replace direct access to memcg info

Add getter functions to block direct access to memcg info structure.
This is because it may cause incorrect memory access by null pointer.

Change-Id: I61d2d33988b9ab408a8eaa628a7832bb4551b0f9
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agomemory-cgroup: Add memory_cgroup_is_valid_cgroup_type() to check cgroup validity 84/320484/1
Unsung [Thu, 10 Oct 2024 07:53:33 +0000 (16:53 +0900)]
memory-cgroup: Add memory_cgroup_is_valid_cgroup_type() to check cgroup validity

Add memory_cgroup_is_valid_cgroup_type() function to check the range of cgroup enum value.
In addition, the range check code is changed to calling the corresponding function.

Change-Id: I1c18af7e83ee8c03ef515007a1940fe69f49c9a0
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
6 months agomemory-cgroup: Check null memory info in memcg_write_optimizer_params() 83/320483/1
Unsung [Thu, 10 Oct 2024 08:47:07 +0000 (17:47 +0900)]
memory-cgroup: Check null memory info in memcg_write_optimizer_params()

Check null memory info in memcg_write_optimizer_params() to avoid SIGABORT.
This is because memory info structure is directly accessed without checking the validity.
If memory cgroup is null then memcg_write_optimizer_params() returns error to notify that
memory cgroup could not be initalized successfully.

Change-Id: I3e35eacdcf00dc96876cbce7694d35f404df05a6
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
7 months agoconfig-parser: Support limiter.conf in limiter.conf.d 84/319484/2
Unsung Lee [Thu, 24 Oct 2024 05:52:06 +0000 (14:52 +0900)]
config-parser: Support limiter.conf in limiter.conf.d

Support limiter.conf configuration file in limiter.conf.d directory.
Previously, resourced supported only one limiter.conf file included in the project.
Now it has been changed so that each user can replace it with their own limiter.conf file.

Example:
/etc/resourced/limiter.conf -> it will be not used for limiter moudle.
/etc/resourced/limiter.conf.d/limiter.conf -> It will be used for limiter

Change-Id: I04ff9b332ee20187ab6fc87de7d26c4a3274bc07
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
7 months agoRevert "config-parser: Support limiter.conf in limiter.conf.d" 83/319483/1
Unsung Lee [Thu, 24 Oct 2024 05:46:43 +0000 (14:46 +0900)]
Revert "config-parser: Support limiter.conf in limiter.conf.d"

This reverts commit e0b67c6b1f63d560d8ec1582716a9d074cefb18f.

Change-Id: I91765a6b2dad9ff5bed21e5070ae60179d841f13

7 months agoAdd resourced-monitor tool
SangYoun Kwak [Wed, 7 Aug 2024 02:55:43 +0000 (11:55 +0900)]
Add resourced-monitor tool

resourced-monitor gets process information and prints them for <app id>s
which is provided as parameters.
resourced-monitor is included in the package 'resourced-monitor'.

7 months agoprocess: Add dbus method to get app info
SangYoun Kwak [Tue, 6 Aug 2024 06:56:31 +0000 (15:56 +0900)]
process: Add dbus method to get app info

To get app information using dbue method, a method "GetAppInfo" is
added. This method gets an app id as a parameter and returns the
informations of app if exists.

Change-Id: Ie22bd26a7a8e58d01067639b7c2e16a36cdf5cef
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
8 months agoconfig-parser: Support limiter.conf in limiter.conf.d 37/318937/5 accepted/tizen_unified_toolchain accepted/tizen/9.0/unified/20241030.233530 accepted/tizen/unified/20241017.114652 accepted/tizen/unified/toolchain/20241022.122354 accepted/tizen/unified/toolchain/20241022.122838 accepted/tizen/unified/x/20241017.170332 accepted/tizen/unified/x/asan/20241022.113428 tizen_9.0_m2_release
Unsung [Fri, 11 Oct 2024 01:51:34 +0000 (10:51 +0900)]
config-parser: Support limiter.conf in limiter.conf.d

Support limiter.conf configuration file in limiter.conf.d directory.
Previously, resourced supported only one limiter.conf file included in the project.
Now it has been changed so that each user can replace it with their own limiter.conf file.

Example:
/etc/resourced/limiter.conf -> it will be not used for limiter moudle.
/etc/resourced/limiter.conf.d/limiter.conf -> It will be used for limiter

Change-Id: I59e496c8375667e5a84b5822aeda0df1256993d3
Signed-off-by: Unsung <unsung.lee@samsung.com>
8 months agocpu-boosting: Change g_hash_table_insert to g_hash_table_replace 33/318633/1 accepted/tizen/unified/20241007.161025 accepted/tizen/unified/x/20241008.034728 accepted/tizen/unified/x/asan/20241013.235729
Unsung [Fri, 4 Oct 2024 06:46:10 +0000 (15:46 +0900)]
cpu-boosting: Change g_hash_table_insert to g_hash_table_replace

Change g_hash_table_insert to g_hash_table_replace to avoid
use-after-free issue due to same keys twice.
g_hash_table_insert changes only value if same key already exists.
Therefore, old key can be used after free.
On the other hand, g_hash_table_replace changes value and key to new ones.

Change-Id: I471e0814527961a338503d8573b64bedfc47e6bc
Signed-off-by: Unsung <unsung.lee@samsung.com>
8 months agospec: Change smack label of resourced-watchdog-handler 81/318581/1 accepted/tizen/unified/20241006.053308 accepted/tizen/unified/x/20241007.013542
Unsung [Wed, 2 Oct 2024 11:20:01 +0000 (20:20 +0900)]
spec: Change smack label of resourced-watchdog-handler

Change smack label of resourced-watchdog-handler from "System" to
"System::Tools". This is because kernel worker thread requires read
access permission to run resourced-watchdog-handler and "_" has read permission
to "System::Tools".
(Subject label "_" does not have read permission to Object label "System")

Change-Id: I3b7c5f106cc12688c658496742c90fa313a33157
Signed-off-by: Unsung <unsung.lee@samsung.com>
9 months agolowmem-controller: Add missing vconf setting for soft warning 07/316507/1 accepted/tizen_unified_dev accepted/tizen/unified/20240826.233017 accepted/tizen/unified/dev/20240828.023757 accepted/tizen/unified/toolchain/20241004.101413 accepted/tizen/unified/x/20240827.053117
Youngjae Cho [Thu, 22 Aug 2024 08:41:59 +0000 (17:41 +0900)]
lowmem-controller: Add missing vconf setting for soft warning

Change-Id: Ifed1210f073dafa3863ad0b4075c9403a57140bc
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
(cherry picked from commit 69a94518bc38dd1d9ac7e77b7f7b061afd3a2268)

10 months agoproc-oom-priority: Change minimum fixed oom score 16/315816/5
Unsung Lee [Thu, 8 Aug 2024 04:45:38 +0000 (13:45 +0900)]
proc-oom-priority: Change minimum fixed oom score

Change minimum fixed oom score to reflect real
minimum fixed oom score configuration "OomScore".
The resourced does not allow OomScore in app structure less than zero.

Change-Id: Ib8ce14bc5cf8310c46bae47ef54b7d59d3f2c95f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
10 months agoresourced: Remove unnecessary comments and indentations 44/315844/1 accepted/tizen/unified/20240809.202907 accepted/tizen/unified/dev/20240812.223006 accepted/tizen/unified/toolchain/20240813.045124 accepted/tizen/unified/x/20240812.041858 accepted/tizen/unified/x/asan/20240813.230226
SangYoun Kwak [Thu, 8 Aug 2024 06:48:36 +0000 (15:48 +0900)]
resourced: Remove unnecessary comments and indentations

Change-Id: Ia9c101dbf2dcce5c37575ba33e6e92cae66e4069
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
10 months agoresourced: Modify switch statement not to fall through 43/315843/1
SangYoun Kwak [Thu, 8 Aug 2024 06:30:38 +0000 (15:30 +0900)]
resourced: Modify switch statement not to fall through

There was fall-through in the switch statement with other statements and
it decreases readability and maintainability so it was removed.

(This commit fixes same issue of
 8ffd276da7741fd124d4571cfa899cb6bd2cbe08)

Change-Id: I35692a6f397cce1197f744896c7e42bef6d32ecf
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
10 months agoprocess: Remove unnecessary comments and indentations 13/315813/1
SangYoun Kwak [Thu, 8 Aug 2024 04:17:58 +0000 (13:17 +0900)]
process: Remove unnecessary comments and indentations

Change-Id: I27827bb5f0ace7b46a44cb437854c07f801e13ec
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
10 months agoModify switch statement not to fall through 11/315811/1
SangYoun Kwak [Thu, 8 Aug 2024 03:57:11 +0000 (12:57 +0900)]
Modify switch statement not to fall through

There was fall-through in the switch statement with other statements and
it decreases readability and maintainability so it was removed.

This patch will fix a SVACE issue with WGID=226809

Change-Id: I23a438cd5b56ad2e4d35767d3b2e5bb1168b811c
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
10 months agospec: Change version to match tizen version 28/315428/1 accepted/tizen/unified/20240807.010654 accepted/tizen/unified/dev/20240807.093018 accepted/tizen/unified/toolchain/20240812.131942 accepted/tizen/unified/x/20240807.014238
Unsung Lee [Thu, 1 Aug 2024 01:40:52 +0000 (10:40 +0900)]
spec: Change version to match tizen version

Change-Id: I22327c57dfbc4fb06e49f21852246ff71bb2d4c0
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
10 months agoproc-monitor: Add support of missing componentbasedapp app type 84/315284/1 accepted/tizen/unified/20240731.010823 accepted/tizen/unified/dev/20240731.044748 accepted/tizen/unified/x/20240731.090026
Chanwoo Choi [Fri, 26 Jul 2024 07:54:11 +0000 (16:54 +0900)]
proc-monitor: Add support of missing componentbasedapp app type

Component-based app contains the UI/Widget/Service components on one
process. This app type is added on Tizen 5.5. Before this, remained app
type except for ui/widget/service has been handled as GUI app type.

In order to remove the confusion, check the accurate app type name
to support "componentbasedapp" app type.

[1] https://docs.tizen.org/application/native/guides/applications/component-based-app/

Change-Id: I38f47fb826b37c312e79148dc6af2bcd6b3c4c16
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
10 months agoproc-monitor: Add support of new robotapp app type 83/315283/1
Chanwoo Choi [Fri, 26 Jul 2024 06:22:24 +0000 (15:22 +0900)]
proc-monitor: Add support of new robotapp app type

Add support of new robotapp app type which is only for robot profile
on SMP platform. "robotapp" is working as service app.

Change-Id: I744c6c4f3b65a3dca008cf2364e67d69dc2e4cc5
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
10 months agoproc-monitor: Remove duplicate code as separate function 82/315282/1
Chanwoo Choi [Fri, 26 Jul 2024 06:01:07 +0000 (15:01 +0900)]
proc-monitor: Remove duplicate code as separate function

proc-monitor module have the duplicate code to parse the app
information. In order to remove duplicate code as separate function
and also it make easy to add newly app type.

Change-Id: If8b894e156e561ab231fd2b7a8cd02f9cf6ad3ec
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
10 months agoproc-monitor: Align indentation of definition 81/315281/1
Chanwoo Choi [Fri, 26 Jul 2024 05:45:49 +0000 (14:45 +0900)]
proc-monitor: Align indentation of definition

Change-Id: Iba5d399b605fc0102d62c1efa4c1d3ab30efe3d6
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
10 months agoproc-main: Init proc_app_info memory strucutre before updating 67/314867/2 accepted/tizen/unified/20240723.034827 accepted/tizen/unified/dev/20240724.110046 accepted/tizen/unified/x/20240723.090004
Unsung Lee [Mon, 22 Jul 2024 05:25:51 +0000 (14:25 +0900)]
proc-main: Init proc_app_info memory strucutre before updating

Initaliize proc_app_info memory structure before updating the structure.
Currently, proc_app_info memory structure is updated before initalizing the structure.
After then, Initalization is done, so oom_score_adj of proc_app_info memory
is overwritten as wrong value.

Change-Id: Id545677f9982eb615636a9a992facc64f73d321f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
11 months agocpu-sched: Get return value from the non-void function 62/313962/6 accepted/tizen/unified/20240709.165118 accepted/tizen/unified/dev/20240710.032407 accepted/tizen/unified/x/20240710.012906
Unsung Lee [Wed, 3 Jul 2024 09:02:09 +0000 (18:02 +0900)]
cpu-sched: Get return value from the non-void function

Get return value from non-void function to check error.

Change-Id: Idbd8382449368fb5e87f986f1c72345c715c8dcb
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
11 months agoheart-abnormal: Remove unreachable code 61/313961/4
Unsung Lee [Wed, 3 Jul 2024 08:53:27 +0000 (17:53 +0900)]
heart-abnormal: Remove unreachable code

Remove unreachable code (always return 0 in the callee).

Change-Id: Id4257b8cd9b6b1f9c1410f1f6a72bc13eba6bdc7
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
11 months agocpu-boosting: Remove meaningless but frequent called log 22/313722/1
Unsung Lee [Mon, 1 Jul 2024 06:21:16 +0000 (15:21 +0900)]
cpu-boosting: Remove meaningless but frequent called log

Remove meaningless but frequent called (useless) log
when cpu stall event is monitored from kernel and the cpu stall handler is turned off.

Change-Id: I0a5dc1f96fdfd44f6662edadfad4a801cddc57d2
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
11 months agocpu-boosting: Add reason to fail boosting cpu in the log 21/313721/1
Unsung Lee [Sat, 29 Jun 2024 12:05:24 +0000 (21:05 +0900)]
cpu-boosting: Add reason to fail boosting cpu in the log

Add reason to fail cpu boosting when printing the error log.

Change-Id: I85df82ad7dcb6d1a912bdefb991617eefe4aa89d
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
11 months agosafe-kill: Add reason to send signal in the log 20/313720/1
Unsung Lee [Fri, 21 Jun 2024 03:34:02 +0000 (12:34 +0900)]
safe-kill: Add reason to send signal in the log

Add reason to send signal when printing the debug log.

Change-Id: I3c5cd6b93e7c96435764be47cff7a50704c0e01f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
11 months agofd-handler: Remove meaningless but frequent called log 19/313719/1
Unsung Lee [Thu, 20 Jun 2024 11:19:41 +0000 (20:19 +0900)]
fd-handler: Remove meaningless but frequent called log

Remove meaningless but frequent called (useless) log
when fd (such as socket) is closed successfully.

Change-Id: Ib2bda4d07edc36f559c4e16be3aa20bf59d3dae8
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
12 months agoMemoryLimit has been replaced by MemoryMax 31/312131/1 accepted/tizen/unified/20240614.010748 accepted/tizen/unified/20240722.104227 accepted/tizen/unified/dev/20240620.005757 accepted/tizen/unified/toolchain/20240624.121320 accepted/tizen/unified/x/20240614.080541 accepted/tizen/unified/x/20240723.043557 accepted/tizen/unified/x/asan/20240625.092018
Łukasz Stelmach [Tue, 4 Jun 2024 12:55:21 +0000 (14:55 +0200)]
MemoryLimit has been replaced by MemoryMax

The  MemoryLimit option is marked as deprecated in systemd and needs to
be changed to MemoryMax in unit files.

Change-Id: Ie7e67b659ebfc85f80a50144702a8ea77c76c30b
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
13 months agoheart-cpu: Remove double unlock code 72/309772/1 accepted/tizen/unified/20240423.164616 accepted/tizen/unified/x/20240425.051106
Unsung Lee [Tue, 16 Apr 2024 10:17:09 +0000 (19:17 +0900)]
heart-cpu: Remove double unlock code

Rmove double unlock code (i.e., unlock after unlock without getting lock).
It causes undefined behavior, so it must be removed.

This problem is reported by Coverity with id = 1750882.

Change-Id: Ia898cc02846d1cc2a9e0de9e363bfd37b0ca25a2
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
13 months agolowmem-governor: Revert "Classify apps & optimize memory cgroup" 40/309740/2
Unsung Lee [Tue, 16 Apr 2024 07:12:58 +0000 (16:12 +0900)]
lowmem-governor: Revert "Classify apps & optimize memory cgroup"

Revert partial update among patch "Classify apps & optimize memory cgroup".
It changes the criterion for determining whether a process is app or not
based on it is managed by resourced as app rather than the oom score.

This approach is based on resourced (branch: tizen_6.0).

Change-Id: I3c9a4911b96c669f8abf8facf922112afbfd2a6b
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
14 months agolowmem: Modify to move cgroup when pid is child 45/309045/1 accepted/tizen/unified/20240408.160614 accepted/tizen/unified/x/20240409.070648
SangYoun Kwak [Thu, 4 Apr 2024 06:38:53 +0000 (15:38 +0900)]
lowmem: Modify to move cgroup when pid is child

Previously, if pid is child's pid and try to move cgroup of it,
resourced does nothing because child pids should be moved with their
parent process.

In the case of Android app, its pid should be grouped with its
corresponding dummy app(Tizen app, android-launcher), but it is treated
as a child of dummy app, resourced does nothing and it is not registered
to the cgroup's tasks.

To fix this issue, modify to call lowmem_limit_move_cgroup() to write
all pids of parent process even if the target(to move cgroup) is child
pid.

Change-Id: I0fd516025e2f0dddd4571f5325c54ef44296bc1c
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
15 months agocompaction: Release lock after finishing critical section 01/306601/5 accepted/tizen/unified/20240306.174200 accepted/tizen/unified/toolchain/20240311.065611 accepted/tizen/unified/x/20240308.033413
Unsung Lee [Thu, 22 Feb 2024 09:29:32 +0000 (18:29 +0900)]
compaction: Release lock after finishing critical section

The problem is reported in coverity with 1743722 id.

Change-Id: I49f676273056eac80824b8584735ae4791017ce2
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
15 months agoheart-battery: Get lock before accessing critical section 00/306600/5
Unsung Lee [Thu, 22 Feb 2024 09:01:21 +0000 (18:01 +0900)]
heart-battery: Get lock before accessing critical section

Get lock before accessing module->cache and
release lock after finishing aceess of module->cache.

This problem is reported in coverity with 1746676 id.

Change-Id: I0e706bf138f5cdc5e8463da255902ddc49dabf45
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
15 months agologging: Remove useless code which causes bug 99/306599/5
Unsung Lee [Thu, 22 Feb 2024 08:41:24 +0000 (17:41 +0900)]
logging: Remove useless code which causes bug

Remove useless code which access critical section without lock.
g_queue_foreach() and g_queue_get_length() already handles empty queue case.

This problem is reported in coverity with 1739919 id.

Change-Id: Id7f678b5731d4339a61848c91251305e3050ff7c
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
16 months agoAdd resourced plugins to ISU configuration 44/301344/14 accepted/tizen/unified/20240201.165114 accepted/tizen/unified/x/20240205.063759
Adam Michalski [Tue, 14 Nov 2023 16:22:41 +0000 (17:22 +0100)]
Add resourced plugins to ISU configuration

resourced is a special case. As the service binary performs mounts that must be
visible by the rest of the system, it cannot use any form of sandboxing. That's
why the binary has to be run directly from the ISU package. In addition, different
images may provide different set of configuration files (/etc/resourced/*) and some
configurations may need plugins in the form of shared libraries. As if that was not
enough, the aforementioned plugins may reside in different directories, depending on
the target architecture (as with all shared libraries on Linux systems). Putting all
this together and preparing a correct and roboust ISU configuration is challenging.

The solution is to prepare an ISU package that will work in all these cases:
- any collection of configuration files (/etc/resourced/*)
- any collection of plugins (possibly with no plugins at all)
- support a whole raft of different combinations of the above two.

The solution is based on direct binary file exchange, bind mounting the whole
/etc/resourced directory and bind mounting the whole plugins directory. The latter
is optional (so possibly resourced can run without plugins at all on some
configurations). Bind mounting entire subdirectories allows for the flexibility of
the whole ISU configuration. Please find the implementation details below.

The following changes have been made for ISU:
* isu/isu.cfg - ISU configuration file.
    [isu] section:
        `name` and `version` have been filled by using the #NAME# and #VERSION#
        that will be replaced into the name and version of the RPM package.
        `system_service` is the systemd service name and must be the same as the
        original one. It has also been extended to add two dependent mount units:
            `##PLUGIN_MOUNT##` will be substituted into
            `usr-lib{64}-resourced-plugins.mount` (depending on the architecture)
            which bind mounts resourced plugins subdirectory allowing it to be
            replaced with the ones provided by the ISU package
            `etc-resourced.mount` which is responsible for replacing /etc/resourced
            with the one provided by ISU
    [files] section:
        contains a list of files/directories that should be added to the ISU package.
        We provide 3 mandatory entries here:
            /usr/bin/resourced - resourced binary
            /etc/resourced - directory containing resourced configuration
            libresourced-private-api.so.* - library that is mandatory for resourced
            resourced/plugins - directory with resourced plugins (optional)
        We use the `##LIBDIR##` snippet to obtain the proper library path (explained
        later).
* isu/resourced.service- modified ISU service file.
    Comparing to the original service file, dependency on plugin mount unit has been
    introduced. Plugin mount unit in turns is dependent on the `etc-resourced` mount
    unit. Also, the ExecStart has been modified so that it loads the service binary
    from the ISU package path rather than the original one (/usr/bin/resourced).
* isu/etc-resourced.mount - mount unit responsible for replacing the original
    /etc/resourced directory with the one provided by the ISU package
* isu/usr-lib-resourced-plugins.mount - mount unit responsible for replacing plugins
    subdirectory with the one provided by the ISU package.
    ##PLUGIN_LIB_DIR## is substituted by the appropriate string generated in the
    resourced.spec file, which depends on the architecture: on 32-bit systems it will
    be /usr/lib, and on 64-bit ones /usr/lib64. This mount unit may be renamed later
    to `usr-lib64-resourced-plugins.mount` as the name of the mount unit must reflect
    the path to which it applies a bind mount. This is done in the isu/CMakeLists.txt.
* packaging/resourced.spec - main resourced RPM spec file.
    The following changes has been made:
    - added isu package, its description, and isu configuration files section
    - added ISU_ARCH_BIT constant to be passed to the cmake invocation, so that it
      knows for which architecture the build was invoked
    - added `##LIBDIR##`, `##PLUGIN_LIB_DIR## ` and `##PLUGIN_MOUNT##` symbols
      expansion to substitute the placeholders in isu configuration, service file and
      mount unit files depending on the architecture:
      ##LIBDIR## exapnds to /usr/lib{64}
      ##PLUGIN_MOUNT## expands to usr-lib{64}-resourced-plugins.mount
      ##PLUGIN_LIB_DIR## expands to /usr/lib{64}/resourced/plugins
    - added packaing plugins directory to the `bin` rpm package. This is needed to
      prevent plugins mount unit from failing when the plugins are not present (they
      are optional).
* isu/CMakeLists.txt - CMake config file for the ISU rpm package
    Added installing ISU config file, isu service file and mount units to the
    appropriate locations (/etc/isu/*). Also added renaming plugins mount unit file
    to the appropriate one (depending on the architecture).
* src/CMakeLists.txt - main CMake config file
    Added creating resourced plugins directory unconditionally. Necessary for the
    spec file to be able to package plugins directory (possibly empty) into the `bin`
    rpm package.

Change-Id: If267bd00999fae84b79a67122af8cd98cd84644f

17 months agocpu-sched: Exclude apps that are not foreground but have PROC_STATE_FOREGROUND state 09/303609/1 accepted/tizen_unified_riscv accepted/tizen/unified/20240104.012423 accepted/tizen/unified/20240105.013014 accepted/tizen/unified/riscv/20240103.054535
Unsung Lee [Thu, 30 Nov 2023 08:19:12 +0000 (17:19 +0900)]
cpu-sched: Exclude apps that are not foreground but have PROC_STATE_FOREGROUND state

Exclude apps that are not foreground but have PROC_STATE_FOREGROUND state from
foreground cpu affinity group. cpu-sched module initially searches already
launched foreground app and move them to foreground cpu affinity grouop.

Change-Id: I3692d6a4e70c08babc5547326133099ac20ebf91
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agocpu-sched: Add background notifiers for fixed oom score app 08/303608/1
Unsung Lee [Sun, 26 Nov 2023 11:07:59 +0000 (20:07 +0900)]
cpu-sched: Add background notifiers for fixed oom score app

Add background notifiers for fixed oom score app. This is because,
ForegroundApps fixs cpu affinity for foreground app, but fixed oom score app
was excluded from cpu affinity update.

newly added notifiers are like below:
  - RESOURCED_NOTIFIER_APP_BACKGRD_WITH_FIXED_OOM_SCORE for background status

Change-Id: I737c568c3bd18bc8fe436df16e8bcc370c6abf71
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agocpu-sched: Check name and cpu_info for app with cpu affinity 07/303607/1
Unsung Lee [Sun, 26 Nov 2023 10:28:53 +0000 (19:28 +0900)]
cpu-sched: Check name and cpu_info for app with cpu affinity

App with cpu affinity has non Null name and cpu_info, but
app without cpu affinity has Null name and cpu_info. Therefore,
name and cpu_info must be checked to judge whehter cpu affinity is
statically fixed at app.

Change-Id: I53693fe769c6a0ffe033fd49b700e44a6f0d3d92
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agomemory-cgroup: Set oom score range between cgroup 06/303606/1
Unsung Lee [Wed, 29 Nov 2023 11:52:11 +0000 (20:52 +0900)]
memory-cgroup: Set oom score range between cgroup

Set oom score range between cgroup. In this case,
only perceptible and favorite apps can be moved between memory cgroups
when the memory limit is set.

Change-Id: I5cc350c3c18350c9f8c047c8fd6e0043bdfdc642
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoproc-main: Revert update oom score of service app launch 05/303605/1
Unsung Lee [Thu, 30 Nov 2023 02:33:08 +0000 (11:33 +0900)]
proc-main: Revert update oom score of service app launch

Revert update oom score when service app is launched. It is process
to revert functionality of resourced 6.0.

Change-Id: I3de83bdf43fc906d899d97d9037c359ea06b2c9a
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agolowmem-limit: Update app (w/ MemLimitAction) cgroup when status is changed 04/303604/1
Unsung Lee [Sun, 3 Dec 2023 10:53:59 +0000 (19:53 +0900)]
lowmem-limit: Update app (w/ MemLimitAction) cgroup when status is changed

Update memory cgroup of MemLimitAction defined app when status is changed.

Change-Id: Ia1211b1c1982c25e8adf7910cee894bfb98a6cf7
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoconf: Support memory limit exception for specific app 03/303603/1
Unsung Lee [Mon, 27 Nov 2023 07:53:48 +0000 (16:53 +0900)]
conf: Support memory limit exception for specific app

Support memory limit exception for specific app if <limit> value is -1.
This functionality is required to exclude specific app from
ServicePerAppLimitAction, WidgetPerAppLimitAction, GUIPerAppLimitAction, and
BackgroundPerAppLimitAction.

Change-Id: Ia58c4538ca541b78adc61a32d870730063915c6f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoconf: Remove action from all LimitAction 02/303602/1
Unsung Lee [Mon, 27 Nov 2023 04:47:28 +0000 (13:47 +0900)]
conf: Remove action from all LimitAction

Remove action from all LimitAction confs
(i.e., ServicePerAppLimitAction, WidgetPerAppLimitAction, GUIPerAppLimitAction,
BackgroundPerAppLimitAction and MemLimitAction).
Action will be decided only by MemoryLimitTrigger conf.
It also change type of memory in mem_action from unsigned long long to uint64_t.

Change-Id: Ieae8ed65d8d55b6a6e70e21fc1024bfaf09664f3
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agolowmem: Restore default value of LmkThresholdLeave and LmkMaxVictimPerOom 01/303601/1
Unsung Lee [Tue, 21 Nov 2023 11:42:41 +0000 (20:42 +0900)]
lowmem: Restore default value of LmkThresholdLeave and LmkMaxVictimPerOom

Set default value of LmkThresholdLeave and LmkMaxVictimPerOom as before
of commit 3b936616d4a2b9e4058ff191c396aebc5f5efc57

Change-Id: I487117ca976b9ab57240385f889f992b67faec75
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoprocess: Fix watchdog handler to use proper appid 00/303600/1
SangYoun Kwak [Fri, 17 Nov 2023 02:23:57 +0000 (11:23 +0900)]
process: Fix watchdog handler to use proper appid

The watchdog handler handles dbus signal(with a pid as a parameter) and
kills an app of this pid if its watchdog action is not configured as
"ignore".  (Watchdog action can be configured by locating proper .conf
file in /etc/resourced/process.conf.d.)

Previously, the watchdog handler uses /proc/<pid>/cmdline as an app
name, which is not an actual app name. This caused the watchdog handler
to think 'this app is not configured as "ignore"' even it is configured
as "ignore" because the actual app name and /proc/<pid>/cmdline are not
matched.
Thus, apps which should be not killed by the watchdog were killed.

To fix this issue, find_app_info() is used, which gets
struct proc_app_info from pid, to get the proper app name.

Change-Id: I2bc9c9d7ffcb45bbc10243241d4786fb73d2f7b4
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
17 months agoconf: Add LmkMaxVictimPerOom to set max victim per oom level during LMK 99/303599/1
Unsung Lee [Fri, 17 Nov 2023 11:29:00 +0000 (20:29 +0900)]
conf: Add LmkMaxVictimPerOom to set max victim per oom level during LMK

Add LmkMaxVictimPerOom to set max victim per oom level during LMK.
It is restoration of 'NumMaxVictims' in tizen 6.0.

Change-Id: I3771d00e1d3f847072039e553d9f8ce3aae1146a
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoconf: Add LmkThresholdLeave to set stop condition of LMK 98/303598/1
Unsung Lee [Fri, 17 Nov 2023 06:28:21 +0000 (15:28 +0900)]
conf: Add LmkThresholdLeave to set stop condition of LMK

Add LmkThresholdLeave to set stop condition of LMK.
It is restoration of 'ThresholdLeave' in tizen 6.0.

Change-Id: I0fb27492d8aae4ae0807fd65e98560c025e6c057
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoproc-oom-priority: Support fixed oom for service type app 97/303597/1
Unsung Lee [Fri, 17 Nov 2023 06:17:10 +0000 (15:17 +0900)]
proc-oom-priority: Support fixed oom for service type app

Change-Id: Ia8c3dfa1f973f44948f6b11cc9a223302505b951
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agolowmem-governor: Remove app with LmkKillException from the LMK victim list 96/303596/1
Unsung Lee [Fri, 10 Nov 2023 07:46:29 +0000 (16:46 +0900)]
lowmem-governor: Remove app with LmkKillException from the LMK victim list

Remove app with LmkKillException configuration property (yes|1|ok|on|)
from the LMK victim list during LMK. If LmkKillException is not declared in
limiter.conf.d, then the process can be included in LMK victim list during LMK
(default is no|0|off).

Change-Id: I8aa5903850438952a6f2f9e024eba1bb4f7ccd43
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoconf: Add LmkKillException to remove app from LMK list 95/303595/1
Unsung Lee [Thu, 9 Nov 2023 11:37:01 +0000 (20:37 +0900)]
conf: Add LmkKillException to remove app from LMK list

Change-Id: I3cd92aa109185a2dbab2171230681e3ec9cf75b3
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoproc-common: Change limit_bytes type to cover larger than 4GB 94/303594/1
Unsung Lee [Thu, 9 Nov 2023 07:55:21 +0000 (16:55 +0900)]
proc-common: Change limit_bytes type to cover larger than 4GB

Change limit_bytes type from unsigned long to uint64_t
to cover more than 4GB in 32bit machine.

Change-Id: I48405ad16066f21a5c569f7eab181ef2d2ef2a14
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agolowmem-limit: Remove useless max limit size check 93/303593/1
Unsung Lee [Thu, 9 Nov 2023 07:37:23 +0000 (16:37 +0900)]
lowmem-limit: Remove useless max limit size check

Resourced already resizes limit size when limit size is larger than total memory size.

Change-Id: I71cf191f07c398e1916bbe6d1397874e7f6df302
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agolowmem-limit: Add oom based event trigger and handler 92/303592/1
Unsung Lee [Wed, 8 Nov 2023 12:21:52 +0000 (21:21 +0900)]
lowmem-limit: Add oom based event trigger and handler

Add oom based event trigger and handler to restore 'MemLimitTrigger=oom' in tizen 6.0.
If memory limit is triggered by oom instead of threshold, then do NOT kill or
reclaim forcely in the resourced (Kernel's oom job).

Change-Id: I3c00412ddac9e89080aee3a2b8bfa5297ef7e5d9
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoconf: Support oom based event trigger and handler in conf 91/303591/1
Unsung Lee [Thu, 9 Nov 2023 01:12:03 +0000 (10:12 +0900)]
conf: Support oom based event trigger and handler in conf

Add 'MemoryLimitTrigger' conf to support oom based event trigger and handler.
If conf value is oom then, memory limit is handled by kernel oom. On the other hand,
reosurced handles memory limit directly with threshold value in the conf.

Change-Id: I785fc8bdac9505f990dc48cf3c4c7d4ead013c01
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoswap: Reclaim memory when LCD is off 90/303590/1
Unsung Lee [Thu, 17 Aug 2023 05:34:57 +0000 (14:34 +0900)]
swap: Reclaim memory when LCD is off

Reclaim memory from BackgroundMru memory cgroup when LCD is off
to reserve memory.

This is one of patch to restore BackgroundReclaim configuration of resourced 6.0.

Change-Id: I3657689a11931f8f80deeaaebc64fcdc4dc35747
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agomemory-cgroup: Add BackgroundMru cgroup 89/303589/1
Unsung Lee [Thu, 17 Aug 2023 08:33:22 +0000 (17:33 +0900)]
memory-cgroup: Add BackgroundMru cgroup

Add a memory cgroup called BackgroundMru to include apps
which have oom_score_adj like below range.
OOMADJ_BACKGRD_PERCEPTIBLE <= oom_score_adj
< OOMADJ_BACKGRD_UNLOCKED + OOMADJ_APP_INCREASE

resourced allows process migration from Private to BackgroundMru and vice versa.
However, it is impossible to be migrated from Private to / (top) or BackgroundLru
and vice versa.

This is one of patch to restore BackgroundReclaim configuration of resourced 6.0.

Change-Id: Icd540641b65e75e87fd73ee3511f7b3c33c32957
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agomemory-cgroup: Rename memory throttling to memory background LRU 88/303588/1
Unsung Lee [Thu, 17 Aug 2023 06:31:49 +0000 (15:31 +0900)]
memory-cgroup: Rename memory throttling to memory background LRU

Rename memory throttling to memory background LRU to emphasize the meaning
of the corresponding memory cgroup.

This is one of patch to restore BackgroundReclaim configuration of resourced 6.0.

Change-Id: I7f7243d40cc1a1c9e4762bea2176d4abbbe62b1c
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
17 months agoconfig: Add AfterScreenDim configuration 87/303587/1
Unsung Lee [Thu, 17 Aug 2023 04:39:04 +0000 (13:39 +0900)]
config: Add AfterScreenDim configuration

Add AfterScreenDim configuration of MemoryBackgroundReclaim section
in optimizer.conf to reclaim memory from most recently used background apps.

This is one of patch to restore BackgroundReclaim configuration of resourced 6.0.

Change-Id: I30fbb0814c3622ea1d4615f8e3b424a4c105ace7
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
19 months agoAdd ISU package 95/300695/3
Adam Michalski [Tue, 31 Oct 2023 09:36:29 +0000 (10:36 +0100)]
Add ISU package

Change-Id: Ibe9c1e87d8af96c49a75cc3ab1196940578f17f6

19 months agolowmem-monitor-psi: Add the lowest PSI level 21/300621/1 accepted/tizen/unified/20231031.163521
Unsung Lee [Mon, 30 Oct 2023 04:41:45 +0000 (13:41 +0900)]
lowmem-monitor-psi: Add the lowest PSI level

Add the lowest PSI level to monitor low memory early.
This is because, sometimes Out-of-Memory (OOM) is triggered earlier than LMK
in ths past 3 level PSIs.

New PSI also cannot perfectly detect LMK status before OOM is triggered.
However, it covers some LMK status detected by vmpressure(low).

In conclusion, change PSI like below:
PSI_LEVEL1(NEW): 30ms/500ms (6%)
LOW -> PSI_LEVEL2
MEDIUM -> PSI_LEVEL3
HIGH -> PSI_LEVEL4

Change-Id: Ib8fe1f75f8baf07d585fd1af8ef4306994d9c442
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agoconf: Add governor (post) configurations 50/299050/1 accepted/tizen/8.0/unified/20231005.093836 accepted/tizen/unified/20230920.072014 tizen_8.0_m2_release
Unsung Lee [Thu, 7 Sep 2023 03:05:33 +0000 (12:05 +0900)]
conf: Add governor (post) configurations

Add memory (LMK) and cpu (boosting stall) governor configurations to
turn on/off options.

Two new section is added like below:
  - MemoryLMKGovernor in limiter.conf
    : LMK post governor related section
  - CpuBoostingStallGovernor in optimizer.conf
    : Cpu boosting stall governor related section

MemoryLMKGovernor includes configurations
  - ForegroundAppListPostGovernor: LMK post governor for foreground app list
  - WorkingSetSizePostGovernor: LMK post governor for working set size

CpuBoostingStallGovernor includes a configuration
  - CpuBoostingStallGovernor: Cpu boosting governor for stall handler

Change-Id: I901915bc6d80b66256466a54d56e9216d80f5737
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agoconf: Move proc-common to memory-common for consistency 49/299049/1
Unsung Lee [Thu, 7 Sep 2023 06:01:00 +0000 (15:01 +0900)]
conf: Move proc-common to memory-common for consistency

Move function and variable of configuration defined in proc-common
to memory-common for consistency.
foreground_app_list_status_enabled configuration is actually used in
LMK (lowmem.c). In addition, both configuration foreground_app_list_status_enabled
and lmk_governor_post_wss_enabled are related to LMK post governors.
Therefore, function and variable related to two configurations needs to be gathered
together in memory-common.c.

Change-Id: I0fffbd0fa0bea0846517ffcbbdde17742eaa4681
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting-monitor: Check return value of eventfd_write and remove useless code 18/298718/4 accepted/tizen/unified/20230914.100402
Unsung Lee [Wed, 13 Sep 2023 01:51:39 +0000 (10:51 +0900)]
cpu-boosting-monitor: Check return value of eventfd_write and remove useless code

Check return value of eventfd_write and remove eventfd_read function. This is
because if eventfd_write is not correctly working (return value is -1),
then monitor pthread will not be exited. In addition, eventfd_read is used to
read dummy value, so psi monitor will be exited correctly regardless of eventfd_read.

It solves problems reported by Coverity with cid = 1704480 and cid = 1704688.

Change-Id: Ife5e17998a0edd46e3d7e6ad028d7a0a7285f19a
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agoproc-monitor: Modify variable type and function to parse window info 03/298703/3
Unsung Lee [Fri, 8 Sep 2023 01:56:49 +0000 (10:56 +0900)]
proc-monitor: Modify variable type and function to parse window info

Modify variable type and function to parse an array of windows received
from the window system. This is fundamentally to solve the issue while
parsing window info.

In gvariant, i and b are gint32 and gboolean, whereas previously
int and bool types were used respectively.

In addition, g_variant_iter_next() is definitely preferred over
g_variant_iter_loop() when parsing simple type such as integer and string within a loop.

Change-Id: If19b9199f9bdd4a0a32518f9a400dbf9423ff410
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agolowmem-controller: Exclude app from kill when is_killed_free_from is true 83/298383/3 accepted/tizen/unified/20230907.175319
Unsung Lee [Tue, 5 Sep 2023 12:16:44 +0000 (21:16 +0900)]
lowmem-controller: Exclude app from kill when is_killed_free_from is true

Exclude app from LMK from kill when is_killed_free_from is true.
This value can be set by LMK governor post function in resourced LMK plugin backend.

Change-Id: I2b70370d05c9e08fbb7d168cb8c2717faa44a028
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agolowmem: Add active, inactive, and swap usage in task_info 82/298382/3
Unsung Lee [Tue, 5 Sep 2023 04:42:01 +0000 (13:42 +0900)]
lowmem: Add active, inactive, and swap usage in task_info

Add active, inactive, and swap usage of each app in task_info structure.
This infomration will be used in get_kill_candidates_post_with_wss() function.

Active, inactive, and swap usage are counted by
  - Active usage is sum of active_anon + active_file in memcg
  - Inactive usage is sum of inactive_anon + inactive_file in memcg
  - Swap usage is a mount of swap in memcg

Change-Id: I1e96d12023eb303754a0120e18c20ee9e66a1459
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agolowmem-limit: Make private memcg for each app 81/298381/2
Unsung Lee [Tue, 5 Sep 2023 07:45:00 +0000 (16:45 +0900)]
lowmem-limit: Make private memcg for each app

Private memory cgroup for each app is essential to monitor app information
such as working set size. This is because calculation ofworking set size
is based on memory stat in memcg.

Change-Id: Ic2d840bad0aa54eb9293ced1333c14de81917c13
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agolowmem: Add lmk_try_count in syscommon_plugin_resourced_memory_lmk_get_kill_candidate... 89/298389/1
Unsung Lee [Wed, 6 Sep 2023 08:51:53 +0000 (17:51 +0900)]
lowmem: Add lmk_try_count in syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post_with_wss()

Add lmk_try_count argument
into syscommon_plugin_resourced_memory_lmk_get_kill_candidates_post_with_wss to
notify the current LMK cycle to resourced LMK backend plugin.

Change-Id: Ia83ab53c6179beec00b3f2430e9218256077032e
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agoconf: Add lmk_governor_post_wss_enabled to turn on/off governor post with WSS 80/298380/2
Unsung Lee [Tue, 5 Sep 2023 02:47:24 +0000 (11:47 +0900)]
conf: Add lmk_governor_post_wss_enabled to turn on/off governor post with WSS

Add lmk_governor_post_wss_enabled variable to turn on/off governor post with
working set size (WSS).

Change-Id: I31f24e0dde2514893338429fc65ed83e75a3697e
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Check whether cpu stall handler is turned on 55/298255/2 accepted/tizen/unified/20230906.014625
Unsung Lee [Fri, 1 Sep 2023 08:19:24 +0000 (17:19 +0900)]
cpu-boosting: Check whether cpu stall handler is turned on

Check cpu stall handler is turned on.
If so, wake up cpu boosting thread to handle cpu stall.
If not, ignore event from the cpu boosting monitor.

Change-Id: Idc14a3804200291a6c4e9d021e590e98ba199e56
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Remove useless overhead caused by governor 54/298254/2
Unsung Lee [Mon, 4 Sep 2023 07:50:29 +0000 (16:50 +0900)]
cpu-boosting: Remove useless overhead caused by governor

Remove useless overhead caused by cpu boosting governor.

It removes useless overhead in two cases
  1. If cpu is not busy when stall event is monitored, then
     do not decrease boost thread level
  2. If action list to do is empty and no already decreased thread,
     then do not make an additional timer. This timer is used to check
     whether there is not stall event during interval.

Change-Id: I01ce568278a7acdb2b958644b95a97c838c3da70
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Decrease timer from 2000ms to 500ms 53/298253/1
Unsung Lee [Fri, 1 Sep 2023 08:45:57 +0000 (17:45 +0900)]
cpu-boosting: Decrease timer from 2000ms to 500ms

Decrease timer for checking additional PSIs from 2000ms to 500ms.
That is, if no addition PSIs are triggered during 500ms,
then cpu boosting level is restored.
This is because 2000ms is too long to check cpu contention is alleviated or not.

Change-Id: I4485d6499e1317a4af92398b2a7d5ef0053423a7
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Move is_cpu_contention_alleviated to libsyscommon 52/298252/1
Unsung Lee [Fri, 1 Sep 2023 07:08:39 +0000 (16:08 +0900)]
cpu-boosting: Move is_cpu_contention_alleviated to libsyscommon

Move is_cpu_contention_alleviated function to libsyscommon and
reference syscommon_resourced_is_cpu_contention_alleviated() from libsyscommon.

Change-Id: I7f799bd4c1b8f0f7970c2731d9035e217b7696bb
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Modify cpu boosting level to handle cpu contention 38/297138/7
Unsung Lee [Thu, 10 Aug 2023 23:55:39 +0000 (08:55 +0900)]
cpu-boosting: Modify cpu boosting level to handle cpu contention

Modify cpu boosting level to handle cpu contention.
The cpu boosting governor makes a list of commands to handle cpu contention,
and it decreases cpu boosting level of some threads (victims).

The cpu boosting module waits for timer events to check whehter cpu contention
is alleviated or not. If so, restoring cpu boosting level.
If not, making a new timer to check cpu contention after some interval.

Currently, cpu boosting module just checks whether PSI events are not
triggered for some interval. It is not the best solution, but simple
and intuitive solution.

Change-Id: I897c89c054ab11ed08ad16ef171610d7fa2944bd
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Execute cpu boosting backend (governor) 27/297127/5
Unsung Lee [Thu, 10 Aug 2023 03:09:00 +0000 (12:09 +0900)]
cpu-boosting: Execute cpu boosting backend (governor)

Execute cpu boosting governor in plugin backend to govern cpu contention.
The prototype of governor function is like below:
  - int syscommon_plugin_resourced_cpu_boosting_governor_govern_request
(GHashTable *cpu_boosting_info_table,
 cpu_boosting_level_e cpu_boosting_level,
 GSList **cpu_boosting_controller_action);
    * This function receives cpu_boosting_info_table and cpu_boosting_level
      as inputs and gives cpu_boosting_controller_action as an output.
      If return value of this function is not 0,
      then cpu_boosting_controller_action is meaningless.

Change-Id: I6c8d805b63e258147932fb7ce8928001ef715ca8
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Move cpu boosting common struct to libsyscommon 26/297126/5
Unsung Lee [Wed, 9 Aug 2023 12:52:19 +0000 (21:52 +0900)]
cpu-boosting: Move cpu boosting common struct to libsyscommon

Extract cpu boosting common struct and move it to libsyscmmon to be referenced
between resourced cpu boosting module and cpu boosting plugin backend.

structure name is changed like below for consistency:
  - cpu_boosting_info -> syscommon_resourced_cpu_boosting_info
  - cpu_boosting_input -> syscommon_resourced_cpu_boosting_input

Change-Id: Id1296115c984cd03250cbb3cf182b79f4067ecaf
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting-monitor: Notify cpu boosting module when monitoring cpu PSIs 25/297125/5
Unsung Lee [Wed, 9 Aug 2023 07:27:06 +0000 (16:27 +0900)]
cpu-boosting-monitor: Notify cpu boosting module when monitoring cpu PSIs

Notify cpu boosting module when cpu PSIs are triggered.
When monitoring cpu PSIs, the monitor needs to wake up cpu boosting main thread.
This is because cpu boosting monitor just catches cpu PSIs and need to
wait for next PSI events.

Thread running cpu boosting monitor should wake up main cpu boosting thread
running g_main_loop_run() function. When main cpu boosting is idle,
the thread is woken up immediately.

Change-Id: I7f89265f4e7394c07c86cb0f3e40edc785eb922c
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Init cpu boosting module early 24/297124/5
Unsung Lee [Wed, 9 Aug 2023 04:42:10 +0000 (13:42 +0900)]
cpu-boosting: Init cpu boosting module early

Initialize cpu boosting module earlier than cpu boosting monitor module.
This is because, cpu boosting module must be ready to accept requests from
cpu boosting monitor.
Currently, cpu boosting module does not depend on any other resourced modules,
so initailize cpu boosting module with the highest priority (i.e., MODULE_PRIORITY_EARLY).

Change-Id: I9cff9d0c24205d7887b4d6d758b7410efe1fc165
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting-monitor: Add cpu PSI monitor module 23/297123/5
Unsung Lee [Wed, 9 Aug 2023 03:23:25 +0000 (12:23 +0900)]
cpu-boosting-monitor: Add cpu PSI monitor module

Add cpu PSI monitor to detect cpu contention.
cpu PSI monitor code works very similar with lowmem PSI monitor (memory PSI).
However, CPU PSI is only focusing on 'some' events.
This is because, global CPU PSI information (i.e., /proc/pressure/cpu)
always has zero (i.e., meaningless value) for 'full'.

Change-Id: Ie4d06bda0a57d7918abc1dddd23eb09dfffce053
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agocpu-boosting: Split a cpu boosting info table into three tables 22/297122/4
Unsung Lee [Thu, 10 Aug 2023 07:44:13 +0000 (16:44 +0900)]
cpu-boosting: Split a cpu boosting info table into three tables

Split a cpu boosting info table into three independent cpu boosting info tables
according to cpu boosting level.
Currently, resourced supports three cpu boosting level
(CPU_BOOSTING_LEVEL_STRONG, CPU_BOOSTING_LEVEL_MEDIUM, and CPU_BOOSTING_LEVEL_WEAK).

Separate cpu boosting info table according to cpu boosting level
to find and handle threads with same cpu boosting level easily.

Change-Id: I9eb8eac89df8112e91802154401fd59bd0626781
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agolowmem-monitor: Check return value of eventfd_write and remove useless code 73/297673/3 accepted/tizen/unified/20230825.044230 accepted/tizen/unified/riscv/20230829.072052
Unsung Lee [Tue, 22 Aug 2023 11:47:50 +0000 (20:47 +0900)]
lowmem-monitor: Check return value of eventfd_write and remove useless code

Check return value of eventfd_write and remove eventfd_read function. This is
because if eventfd_write is not correctly working (return value is -1),
then monitor pthread will not be exited. In addition, eventfd_read is used to
read dummy value, so psi monitor will be exited correctly regardless of eventfd_read.

It solves problems reported by Coverity with cid = 1704480 and cid = 1704688.

Change-Id: Ic753aaf3b96c95d7f1e2e629c165800728b92289
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
21 months agolowmem-monitor: Add a module for PSI and vmpressure 08/297508/1 accepted/tizen/unified/20230822.162228
SangYoun Kwak [Mon, 21 Aug 2023 05:57:25 +0000 (14:57 +0900)]
lowmem-monitor: Add a module for PSI and vmpressure

A new module "lowmem-monitor" is added:
 - Initialize monitor: PSI or vmpressure
    - Use PSI if the PSI initialization was successful.
    - Use vmpressure otherwise.

Change-Id: I37d9b223698d3742dd4a02b27c94f65852810fb4
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
22 months agolowmem-monitor: Modify PSI monitor to do one action per monitor 11/296711/1 accepted/tizen/unified/20230809.071852 accepted/tizen/unified/riscv/20230809.013259
SangYoun Kwak [Thu, 3 Aug 2023 08:24:44 +0000 (17:24 +0900)]
lowmem-monitor: Modify PSI monitor to do one action per monitor

Multiple events can be occured at one epoll_wait return.
In this case, lowmem_trigger_memory_state_action can be called multiple
times which is unnecessary.
With this patch, lowmem_trigger_memory_state_action will be called only
once per epoll_wait's return.

Change-Id: I6ef5cc7aeee4c9baa273517333c1cd2655752d58
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
22 months agolowmem-monitor: Modify PSI's epoll_wait as blocking 04/296704/1
SangYoun Kwak [Thu, 3 Aug 2023 07:56:49 +0000 (16:56 +0900)]
lowmem-monitor: Modify PSI's epoll_wait as blocking

Previously, epoll_wait was non-blocking and the timeout was 0.
It means that epoll_wait will return immediately after checking events.
With this method, the psi monitor thread will consume cpu(it will check
events intensively) so sleep(3) was used to prevent the consuming
situation.
But it makes psi monitor thread to sleep, which might miss events within
the sleeping period.

By making epoll_wait blocking, this problem will be solved.

Change-Id: I4f2b1ff06b53bcca2830d4c2ecb972fc17904f52
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>