Sung-hun Kim [Mon, 19 Sep 2022 10:51:54 +0000 (19:51 +0900)]
monitor: Use the systemd Unix socket
Systemd creates an Unix socket when the system is booted on
by using existing configuration files in /usr/lib/systemd.
Previously, the resource monitor always creates a new Unix
socket whether the socket exists or not. From now on, the
resource monitor checks that the Unix socket is existed on
the given path. If so, it uses the Unix socket instead of
open a newer one. By doing so, the permission of the Unix
socket can follow the given configuration denoted in the
Systemd socket configuration file.
Change-Id: I1eab46cd238340cc9700e1a2d52481270c06b8b1
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Sung-hun Kim [Mon, 19 Sep 2022 04:42:34 +0000 (13:42 +0900)]
resource-monitor-tests: Prevent possible memory leaks
Change-Id: I9ff9c4bd7ef970ca1541c756fd1b11c5506980f9
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Dongwoo Lee [Thu, 15 Sep 2022 10:51:18 +0000 (19:51 +0900)]
resource: Fix missing NULL check
Change-Id: I8a9f2d5139ad6298788d373485d24110e9d85979
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 15 Sep 2022 02:15:27 +0000 (11:15 +0900)]
resource: Pass error result directly from resource creation
Previously, it was lost by returning NULL instead of the error code
that occurred during the resource creation process, but now the error
code is passed directly so that the caller can know the exact reason.
Change-Id: Iffc25c266186195d23ef0f61bba989ff5e36b4d7
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Sung-hun Kim [Thu, 15 Sep 2022 05:56:02 +0000 (14:56 +0900)]
systemd: Fix socket file path
Change from a invalid socket file path /run/.pass.socket
to a valid socket file path /run/.pass-resource-monitor.socket
Change-Id: I197c24710ba76ffc5b8fe195129d6057cd0e2035
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Dongwoo Lee [Tue, 13 Sep 2022 06:00:28 +0000 (15:00 +0900)]
monitor: Add dbus interface for turning on/off debug mode
In order to provide the way to change debug mode dynamically, the new
dbus interface is now applied as below:
- dbus path: /Org/Tizen/System/Pass/Monitor
- dbus interface: org.tizen.system.pass.monitor
- dbus method: org.tizen.system.pass.monitor.SetDebug
- parameter: boolean value for representing debug mode is enabled
Change-Id: I431182809d23b1b7ee795c392bdeb84f9ef741bf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Tue, 13 Sep 2022 08:08:54 +0000 (17:08 +0900)]
monitor: providing ip socket server when debug mode is enabled
To protect against attacks using network socket vulnerabilities, open
the TCP/IP based socket interface only when debug mode is enabled.
Change-Id: Ie8b3d392b783c63225f30f6dc611524ccb7c6a09
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Chanwoo Choi [Wed, 31 Aug 2022 14:28:33 +0000 (23:28 +0900)]
pass: parser: Add get_property_set to simplify getting properties
And get_property_set function to reduce the get_property function call.
It makes the getting propertis more simpler than before
Also, get the property value from json configuration file
and then stored them to local variables. And fill out the allocated
memory of structure with local variables. But, local variables
are not necessary. In order to reduce the LOC (line of code),
get property value directly without local variables.
Change-Id: Ib993d11d6ad22d3fd12fca54a591ae30cd3b9b20
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 27 Jun 2022 09:30:13 +0000 (18:30 +0900)]
tests: unittest: Add pass-parser invalid test
Add pass-parser invalid unittests for each section
- Test for invalid level section
- Test for invalid pmqos section
- Test for invalid thermal section
- Test for invalid header section
- Test for invalid battery h/w resource type
- Test for invalid memory h/w resource type
Change-Id: Ibdf109751560fc130ce3d8680867c9ac81be1c56
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Wed, 7 Sep 2022 03:05:52 +0000 (12:05 +0900)]
util: kernel: Fix possible vulnerability
Change-Id: I14a31746037d78670418b2b3b615e042b9a6aab4
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Sung-hun Kim [Fri, 2 Sep 2022 05:41:47 +0000 (14:41 +0900)]
monitor: lib: Support Unix domain socket (UDS) and TCP/IP socket concurrently
Previous TCP/IP socket-based IPC has a security issue that
anyone can access the opened port without credential. Since
UDS is exported as a file, we can apply file-based access
control to it. So, we use UDS instead of TCP/IP socket by
default.
At the same time, we also support TCP/IP socket for
resource-monitor-tool which is a web-based monitoring tool
in user space. In the future, we will support TCP/IP socket
only in debugging mode which is turned on/off by root-
privileged command line tool.
Change-Id: Id46a5e7560cf95d09f31222e5022ce3ea209753a
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Chanwoo Choi [Thu, 1 Sep 2022 10:10:50 +0000 (19:10 +0900)]
lib: resource-monitor: Remove unneeded privilege check
commit
fccfb02d128c("lib: resource-monitor: Check systemmonitor privilege")
added the unneeded privilege check code. In result, cynara is running by
preempting CPU resource. So that remove unneeded privilege check code.
Only check the privilege when pass_resource_monitor_init() call.
Change-Id: I0a9c7b2ca76a781dcf88ab19ddf0ec597c98b6a5
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 1 Sep 2022 08:32:01 +0000 (17:32 +0900)]
tests: resource-monitor-tests: Fix test fail by changing the return value
commit
b5d308519f73("util: resource: Change error code from -EPERM to
-EACCES") changed the return value from -EPERM to -EACCESS.
In order to pass the test, change the return value
according to commit
b5d308519f73.
Change-Id: I2e3261fe80ceea0fd70645484778916a928e8872
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 1 Sep 2022 06:36:41 +0000 (15:36 +0900)]
lib: resource-monitor: Check systemmonitor privilege
In order to prevent the unauthorized client,
check the systemmonitor privilege[1] .
[1] http://tizen.org/privilege/systemmonitor
For example of rejection when don't have systemmonitor privilege
- Connect sdb without root and then executes resource-monitor/resource-monitor-tests.
In result, cannot use the resource monitor. I checked it the log as following:
E/PASS ( 1395): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor
E/PASS ( 1395): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor
(snip)
E/PASS ( 1429): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor-tests
E/PASS ( 1429): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor-tests
Change-Id: I77531ca1717b3592f0803cc585e0f205c46edcee
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 1 Sep 2022 06:34:57 +0000 (15:34 +0900)]
util: privilege: Add is_privilege_supported function
is_privilege_supported checks privilege permission of self process.
Change-Id: Ife85a74a494e12de1e1418036d8c84d389518c4b
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Sung-hun Kim [Thu, 1 Sep 2022 05:02:05 +0000 (14:02 +0900)]
util: resource: Change error code from -EPERM to -EACCES
To match Tizen error code, I changed -EPERM to -EACCES.
Which corresponds to TIZEN_ERROR_PERMISSION_DENIED.
Change-Id: I1d3675435eba319637710c4cef3981398e7ab96a
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Chanwoo Choi [Wed, 31 Aug 2022 13:48:39 +0000 (22:48 +0900)]
monitor: request-handler: Fix build error
Fix the following build error by using the proper output type
when printing the error log.
45s] /home/abuild/rpmbuild/BUILD/pass-2.0.0/src/monitor/request-handler.c:295:31: note: format string is defined here
[ 45s] 295 | _E("failed to set flag to %lx, client(%d) | res:name(%s)id(%d)\n",
[ 45s] | ~~^
[ 45s] | |
[ 45s] | long unsigned int
[ 45s] | %llx
Change-Id: I401b2b912ed71d40b8e4a0f06d42d6b9b01c4837
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Sung-hun Kim [Mon, 29 Aug 2022 06:41:39 +0000 (15:41 +0900)]
tests: resource-monitor-tests: Add a test for pass_resource_monitor_set_resource_flag
Add a test for newly added operation which is used for
distinguishing PRIVATE and PUBLIC resources.
Change-Id: I56d6eed1e68a292aee8075041d402bc7a8a6bb6c
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Sung-hun Kim [Tue, 23 Aug 2022 11:45:57 +0000 (20:45 +0900)]
lib: Add pass_resource_monitor_set_resource_flag
By using the added function, the user of libpass can
set the resource as PUBLIC. Note that, the error will
be thrown at pass_resource_monitor_set_resource_attr,
not at pass_resource_monitor_set_resource_flag.
Change-Id: Id012ca5cf2eca90653a17c85b86e6a1913b86d35
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Sung-hun Kim [Tue, 23 Aug 2022 11:27:56 +0000 (20:27 +0900)]
monitor: Add a handler function for REQUEST_SET_RESOURCE_FLAG
For users of capi, some information such as process information
does not be provided. To distinguish users, we set the visibility
of each resource to PUBLIC or PRIVATE due to the user's context.
When an user sets the visibility of the resource to PUBLIC and
then sets the interest of the resource attribute which has PRIVATE
visibility, the pass daemon will reject it and return -EPERM error.
Change-Id: I23a6b279aa2983aeb6e88cd51458d0c430e8692b
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Sung-hun Kim [Tue, 23 Aug 2022 11:13:57 +0000 (20:13 +0900)]
resource: Add a new property "flag" to attributes
To distinguish visibility of resource attributes, a new property
is added to each attribute. The visibility of each attribute is
pre-defined. Pass allows or rejects user's request for setting
interested attributes depends on the combination of the
visibility of each resource and the visibility of each attribute.
We used a flag variable for representing the visibility of the
resource attribute. The flag variable can extend to represent
other properties of the resource attribute.
Change-Id: Ie48f00f89ec6095e05e9f8fcf395e1ea0da026bb
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Dongwoo Lee [Tue, 30 Aug 2022 06:57:18 +0000 (23:57 -0700)]
tests: resource-monitor: Consider failure of monitor_init as fatal
Change-Id: Ifd7c90e2e92e7623d01928d933ed3ce7165a567c
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
Dongwoo Lee [Tue, 30 Aug 2022 06:49:49 +0000 (23:49 -0700)]
tools: resource-monitor: Fix to use proper loop bound
Change-Id: I06f4561ea5ba3a626b03da5c8b4e7c6212b0bb9b
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
Dongwoo Lee [Thu, 25 Aug 2022 05:11:42 +0000 (14:11 +0900)]
util: kernel: Get the name of smaps entry with limited width
Since sscanf has no limitation for buffer width and thus it can cause
overflows for name buffer, this limits the number of reading
characters.
Change-Id: I83128e01d9b840d41bb14bfda022e27ee80dd78e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 08:06:18 +0000 (17:06 +0900)]
util: kernel: Use snprintf() instead of sprintf()
Change-Id: Ibb145e0928f2b582088a302788a33c586ccc4625
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 07:34:51 +0000 (16:34 +0900)]
pass: Remove unnecessarily included headers
Change-Id: I165330bec604d60a46ebb4fca175671cda701b51
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 08:04:01 +0000 (17:04 +0900)]
pass: Change the unit for gov_timeout into milliseconds from seconds
Since comparing two floating point number variable causes unintended
result, it converts type of gov_timeout from double to int, and keeps
precison by using unint as milliseconds instead of seconds.
for instance, 0.2sec can represent as 200ms, so despite of converting
type, users can setup gov_timeout with same precision.
Change-Id: Ib8efbca7e5d044a6871e2ef6c23274518cf1875e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Chanwoo Choi [Wed, 24 Aug 2022 05:29:31 +0000 (14:29 +0900)]
resource-monitor: Fix coverity issue
Change-Id: I1df8b406efd54de3154d3e26f74b97f5f57b8160
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 05:47:00 +0000 (14:47 +0900)]
tools: resource-monitor: Check validation of '-n' option argument
Change-Id: I28dc6a85d44455043a56c49bdee824d2590757c0
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 05:30:01 +0000 (14:30 +0900)]
tools: resource-monitor: Use strncat() instead of strcat()
Change-Id: I24ed13b38bdec088d2230b473033ef4888802893
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 08:15:24 +0000 (17:15 +0900)]
resource: disk: Remove unnecessary pre-checking for opening file
Instead of checking file existence before opening, now just try to
open file. If the file does not exist, it makes errors though.
This also fixes the vulnerability reports about TOCTOU race condition
(CWE-367).
Change-Id: I10affc264666566b635e1cd8b91ad34fe5613845
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 04:57:27 +0000 (13:57 +0900)]
tests: unittest: pass: Use proper type for iteration index
This fixes to use proper type for iteration index, and also refactor
the part of clear progress with same code for both success and failure
cases.
Change-Id: Ide70626a93328ef2bc9668addbf4ede73a345dca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Wed, 24 Aug 2022 05:30:03 +0000 (14:30 +0900)]
tests: resource-monitor-tests: Fix wrong expected value on invalid test
commit
5f56fe2eddb0("lib: resource-monitor: Change
pass_resourced_monitor_is_resource_attr_supported prototype")
added the wrong expected value in
pass_resource_monitor_is_resource_attr_supported_invalid test case.
For invalid case test, the expected value is not same with 0 (zero).
Fix wrong expected value on pass_resource_monitor_is_resource_attr_supported_invalid.
Change-Id: I2a564f4b548b86733b265c9b64217653133697dc
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 04:46:28 +0000 (13:46 +0900)]
resource: process: Fix to convert to double before integer division
In order to prevent losing floating point number for the result of
integer division, integer value is coverted to double before
calculation.
Change-Id: I38c19c1468167ed1203417f03d187dcf0893e6ca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 04:44:44 +0000 (13:44 +0900)]
resource: system: Fix to check NULL for private data
Change-Id: I70cb0cfd108ec165d8a863cf6c4c35ea42571b69
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 25 Aug 2022 04:38:58 +0000 (13:38 +0900)]
util: kernel: Use proper data type for the id of cpu stat
To represent 'cpu' case in '/proc/stat' which has summation for all
cpus, the number of cpu is set to -1, but data type of number is
unsigned int. This corrects data type and change the name of member
from 'cpu' to 'id' for understanding meaning easily.
In addition, since 'id' is used as index of cpu stat array, it also
checks that the index is in the proper range.
Change-Id: I7e368176257c695d59420e7b4906d5bdb6d8aadf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Sung-hun Kim [Tue, 23 Aug 2022 07:20:48 +0000 (16:20 +0900)]
monitor: Add a missing request name
Change-Id: I9016d95e8dd2391fc9a6bd2f35fd6b2ef1798c54
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Seung-Woo Kim [Tue, 23 Aug 2022 08:50:00 +0000 (17:50 +0900)]
util: common: Add missing case break
Non fall through case has no break. Add the missing
case break.
Change-Id: I45876a7c36b6d4c9642f0534d9b82aa3e54fa928
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Dongwoo Lee [Fri, 19 Aug 2022 10:05:05 +0000 (19:05 +0900)]
resource: system: Calculate average cpu utilization with per-cpu stat
In a situation where the number of online cpus is dynamically changed,
measuring the total system cpu usage by using the sum of the online
cpus usage time located at the top of '/proc/stat' will result in
inaccurate results. For example, suppose that the number of online
cpus changed from 2 to 1 between two time intervals. In this case, the
sum of the cpu time measured later is rather reduced than the sum of
the cpu time measured first, and if the cpu usage rate is calculated
using the difference between these two cpu times, a negative result
will come out. To prevent this situation, the average usage is
calculated by summing the usage time of each CPU; assuming that the
usage rate is 0% for offline CPUs.
Change-Id: I93e4561f525b54488df46bf0f895fa76b3b710ca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Fri, 19 Aug 2022 10:03:59 +0000 (19:03 +0900)]
util: kernel: Fix to return valid result on getting cpu stat
In the case of the target which supports cpu hotplug, the number of
possible online cpus can be changed and thus __get_cpu_stat can be
failed for offline cpus. At worst case if the last __get_cpu_stat is
resulted in negative, kernel_get_per_cpu_stat can return error even
though it is not actual failure. To prevent this situation, this
ignores the case that __get_cpu_stat returns failure.
Change-Id: I5d33e740b2451e7c644b407c1f92785a1e570585
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Fri, 19 Aug 2022 09:21:57 +0000 (18:21 +0900)]
resource: Distinguish driver initalization from instance creation
In the previous commits, each resource driver has the distinguished
operation for both initialization and creation. This makes the codes
are properly distributed into two operations.
Change-Id: Ia3d72914a3277e0d6d18634dff60a9e9763ec362
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Fri, 19 Aug 2022 07:30:29 +0000 (16:30 +0900)]
resource: Initialize all resource drivers at start up
Instead of initalizing common or permanent data for resource drivers
at creation, now all initialization will be done at start up once.
Change-Id: Idf673d3997c3567b572bcc9ea6dae5e887a0d3f3
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 18 Aug 2022 11:23:56 +0000 (20:23 +0900)]
resource: Add the new device ops create/delete
To separate initialization and instance creation on resource driver,
the new ops create/delete are introduced. Now, each operation is
used as below:
- init: Setup the common contexts for resource (called once)
- exit: Clear the init-ed contexts (called once)
- create: Create resource instance with an individual context
- delete: Free own context and remove resource instance
Change-Id: I4987f26afd6de7e7ec0b1d8ed6a724acbf55e374
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Mon, 22 Aug 2022 23:27:57 +0000 (08:27 +0900)]
pass: Include resource header inside pass.c
Currently resource.h is only used in pass.c, but it is included in
pass.h and it rather prevents using "delete" keyword due to be used
in haltests which is built by cpp compiler. So, this makes resource
header be only included in pass.c directly.
Change-Id: I3360ceb217ec5d95a75f17a65f2b39bf10e12af6
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Thu, 18 Aug 2022 11:09:54 +0000 (20:09 +0900)]
monitor: Restructure request server
In order to make all initialization about resource monitor handled
in monitor module, convert request-server and request-handler from
the distinguish module to a part of monitor module.
Change-Id: I820147add2b44c40fb0ce1d8e9223c708037adc1
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Chanwoo Choi [Mon, 22 Aug 2022 07:59:08 +0000 (16:59 +0900)]
lib: resource-monitor: Change pass_resourced_monitor_is_resource_attr_supported prototype
Change pass_resourced_monitor_is_resource_attr_supported prototype
to express the various error case and then get the value from l-value
style parameter.
[Before]
bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id);
[After]
int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported);
Change-Id: If4943e034db0a180807a85700ac2db7c87ecef5a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 19 Aug 2022 06:00:06 +0000 (15:00 +0900)]
lib: resource-monitor: Replace with TIZNE_ERROR_* defintion to handle error
Replace with TIZNE_ERROR_* defintion to handle error as following:
0 : TIZEN_ERROR_NONE (success)
-EINVAL : TIZEN_ERROR_INVALID_PARAMETER
-EIO : TIZEN_ERROR_NO_DATA
-ENOMEM : TIZEN_ERROR_OUT_OF_MEMORY
Change-Id: I1d14719c21c3a4f6f2224c9f76e00ff762b8c889
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 18 Aug 2022 09:39:51 +0000 (18:39 +0900)]
tools: resource-monitor: Keep the alignment of resource attribute name
commit
f59279ad7f63 ("resource: Change bytes unit attributes to kilo-bytes")
changed the attribute name of both PROCESS_GROUP_ATTR_DISK_READ_PER_SEC
and PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC. So that break the alignment
when print the resource attribute name by resource-monitor cli tool.
Extend the width length for resource attribute name to keep the printing
alignement.
- Before change:
7: 2| PROCESS_GROUP_ATTR_CPU_UTIL | 0.27 | % | Process-group CPU utilization
7: 3| PROCESS_GROUP_ATTR_DISK_READ_PER_SEC | 0.00 | kB/s | Process-group disk read per second
7: 4| PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC | 0.00 | kB/s | Process-group disk write per second
7: 5| PROCESS_GROUP_ATTR_MEM_VIRT |
132923188 | kB | Process-group VIRT memory size
- After change:
7: 2| PROCESS_GROUP_ATTR_CPU_UTIL | 0.21 | % | Process-group CPU utilization
7: 3| PROCESS_GROUP_ATTR_DISK_READ_PER_SEC | 0.00 | kB/s | Process-group disk read per second
7: 4| PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC | 0.00 | kB/s | Process-group disk write per second
7: 5| PROCESS_GROUP_ATTR_MEM_VIRT |
135495517 | kB | Process-group VIRT memory size
Change-Id: I62a937f1edb9c85979cd6f309b12e94256dbeaed
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Wed, 17 Aug 2022 08:45:58 +0000 (17:45 +0900)]
resource: process: Fix to use proper attribute name
Change-Id: Icef625156eb2036672f2798f4f0d65d943e3ab6f
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Wed, 17 Aug 2022 08:42:43 +0000 (17:42 +0900)]
resource: process: Handle the case that target cannot support taskstats
Since PROCESS resource has some attributes which require taskstats,
those attributes are mark to unsupported or provided by other methods
when the target does not support taskstats.
Change-Id: I83a0eab243367f59c518d1b1c422b741f3e611bb
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Wed, 17 Aug 2022 06:33:18 +0000 (15:33 +0900)]
resource: process-group: Handle the case that target cannot support taskstats
all attributes in PROCESS_GROUP resource require taskstats, all
attributes are mark to unsupported when the target does not support
taskstats.
Change-Id: I21a36949e34e7cf3fb050694b1cbddd31e954247
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Wed, 17 Aug 2022 06:31:53 +0000 (15:31 +0900)]
util: kernel: Add check whether taskstats is supported
Since taskstats has various version by kernel, handling it should be
taken by considering versions. However, some task accounting is not
supported by older kernel, we should check whether it is supported or
not. This adds check procedure into constructor.
Change-Id: Ib18f01b1a3060baaba3212fdc728cd7a7ff77849
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Chanwoo Choi [Fri, 12 Aug 2022 02:48:03 +0000 (11:48 +0900)]
PASS v2.0.0
Changes from v1.2.0
1. Add new resource-monitor framework with daemon and various resource drivers
2. Provide libpass-resource-monitor library for resource monitoring
3. Provide resource-monitor tool and resource-monitor-tests
Change-Id: I5d6ccbeb08d29a15181e2c74112b509f99769c58
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 11 Aug 2022 07:29:49 +0000 (16:29 +0900)]
tests: resource-monitor-tests: Add missing array data type if DATA_TYPE_ARRAY
Change-Id: I3606a29597ba9cd16c47defba5b99055b25b5d22
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Tue, 9 Aug 2022 06:00:23 +0000 (15:00 +0900)]
tools: resource-monitor: Add missing BATTERY_ATTR_ONLINE attribute
Change-Id: I37cea2d7cfd3b5f3b4478d152c1fa84682da021e
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 8 Aug 2022 19:41:13 +0000 (04:41 +0900)]
lib: resource-monitor: Add missing request for the readability
Add missing request for the readability to switch statement
to improve the readability when handling the request.
Change-Id: I1b322bd30d4db913fd438394089e95b4716133a6
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Wed, 20 Jul 2022 08:53:37 +0000 (17:53 +0900)]
lib: resource-monitor: Add pass_resource_monitor_is_resource_attr_set
Provide pass_resource_monitor_is_resource_attr_set function
to check whether some attributes are set or not.
And fix the comment of pass_resource_monitor_is_resource_attr_supported.
Change-Id: I3b1372ecc1138d2244da66e79745ca6454ff67eb
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 8 Aug 2022 18:46:42 +0000 (03:46 +0900)]
util: resource: Add resource flag to express the specific features
Each resource are able to have the non-common features.
The resource flag will be used to indicate the characteristics
of resource.
- RESOURCE_FLAG_COUNT_ONLY_ONE
: Some resource's resource count is only one on all board such as system and
memory resources. Add this flag when want to return 1 as resource count.
- RESOURCE_FLAG_PROCESS
: process and process-group are not physical resource like CPU/GPU/Memory.
Sometimes, it should be handled by the different handling. In order to
separate out them, use this flag.
Change-Id: Ic7df2cae2105b14382c0f084c30fbbcde5efdac4
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 5 Aug 2022 17:31:24 +0000 (02:31 +0900)]
lib: resource-monitor: Change prototype of pass_resource_monitor_get_resource_count
Almost get_value functions get the value by using l-value parameter.
In order to keep the consistent function prototype stule,
change the prototype of pass_resource_monitor_get_resource_count function
as following:
- before: int pass_resource_monitor_get_resource_count(int id, int resource_type);
- after : int pass_resource_monitor_get_resource_count(int id, int resource_type, int *resource_count);
Change-Id: Ic18f45a1ee4bbd4f9320751541cf00b3f4d9f5c8
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Sung-hun Kim [Tue, 9 Aug 2022 05:45:55 +0000 (14:45 +0900)]
resource: display: Add a display monitor thread to deal with multiple clients
When multiple clients request to get fps concurrently,
unacceptable delays (upto tens of seconds for hundred
clients) are incurred. I guess that the dbus function
g_dbus_connection_send_message_with_reply_sync() cannot
deal with multiple concurrent calls.
This patch added a monitor thread to read current fps
value via dbus. The thread shares read fps value to
clients. By doing so, multiple clients can get the fps
value without delays.
Change-Id: I726092658ef79af3610baa6fa356d8a54c6cf299
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Sung-hun Kim [Tue, 9 Aug 2022 02:01:48 +0000 (11:01 +0900)]
util: thread: Use wait_for_completion without result
Change-Id: I3969491c2ce9d8ecccfdb064bc65274cb05cb53f
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Dongwoo Lee [Tue, 9 Aug 2022 01:53:47 +0000 (18:53 -0700)]
resource: Change bytes unit attributes to kilo-bytes
In order to sync up with attributes of disk resource, the remaining
memory- and disk-related attributes are changed to use kilo-bytes unit
from now on. As following the unit changes, the name of attributes are
either changed as belows:
- PROCESS_ATTR_DISK_READ_BPS -> PROCESS_ATTR_DISK_READ_PER_SEC
- PROCESS_ATTR_DISK_WRITE_BPS -> PROCESS_ATTR_DISK_WRITE_PER_SEC
- PROCESS_GROUP_ATTR_DISK_READ_BPS -> PROCESS_GROUP_ATTR_DISK_READ_PER_SEC
- PROCESS_GROUP_ATTR_DISK_WRITE_BPS -> PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC
Change-Id: I2c09a6f4ef9511c2add3a559efa19f94d0253216
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
Chanwoo Choi [Wed, 20 Jul 2022 08:52:13 +0000 (17:52 +0900)]
lib: resource-monitor: Extract common function for readability and remove duplicate code
Almost resource-monitor functions are composed with the following steps
to communicate with resource-monitor daemon. It means that there are
the many similiar code to support resource-monitor feature.
1. send request
2. recv response
3. parse data from response
4. validate the data
In order to reduece the duplicate code and improve the readability,
extract the common functions as handle_request with struct request_data.
Change-Id: I413e3dd157093507d099892b0d3123bcf0641f4b
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Sun, 7 Aug 2022 20:05:12 +0000 (05:05 +0900)]
lib: resource-monitor: Fix wrong data type of pass_resource_monitor_get_value_uint
uint need to use '%u' instead of '%d'. Fix wrong data type format.
Change-Id: Ibec1b362cca3b1ad649ee1aedbf08368f1b1db24
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Sun, 7 Aug 2022 20:02:54 +0000 (05:02 +0900)]
lib: resource-monitor: Fix pass_resource_monitor_get_resource_timestamp issue
Change-Id: I6730f5451b335dd8a4759d528989d846bcf686e0
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Tue, 2 Aug 2022 06:06:12 +0000 (15:06 +0900)]
lib: resource-monitor: Fix get_value_string issue by allocating string buffer
The resource-monitor has the following policy of getting sting value
1. resource-monitor allocate the meory for string value
2. user of resource-monitor have to free the allocated memory
But, pass_resource_monitor_get_value_string didn't allocate
the memory for string value until now. Allocate memory for getting
string value on pass_resource_monitor_get_value_string.
Change-Id: I1517ab4362d754cb75b54d1887c1d031de14787d
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 21 Jul 2022 09:58:45 +0000 (18:58 +0900)]
util: resource: Check whether interest_mask is valid or not
unset_resource_attr_interest function is able to unset
the resource interest state when resource interest were already
interested. If wrong interest_mask is used, should return fail.
So that Check whether interest_mask is valid or not
before unsetting resource attribute interest.
Change-Id: I047a30ab1fa5c0cafd23327a7fbfabc9c3c9b274
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Wed, 20 Jul 2022 03:56:22 +0000 (12:56 +0900)]
util: resource: Check validation of resource control id
When uses the wrong resource control id by client, crash happen
because the invalid array index is used. In order to prevent crash
issue, check the validation of resource control id.
Change-Id: I621757bb17b054dafb246ceac57d3eabf419fc31
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Wed, 20 Jul 2022 06:22:58 +0000 (15:22 +0900)]
tests: resource-monitor-tests: Add all resource attributes for testing
Add all defined resource and resources attributes for testing
and fix wrong usage of pass_resource_moniotor functions.
- PhysicalResourceMonitorTest's changes as following:
1. Add all resource types and resource attributes for testing
- memory / battery / system / display / disk / network resources and resource attributes
- the missing resource attributes for cpu/bus/gpu resources
2. Fix wrong usage of pass_resource_monitor_set_resource_attr function
3. Call pass_resource_monitor_update function to update resource attribute value
- ProcessResourceMonitorTest's changes as following:
1. Add process and process-group resources and resource attributes
Change-Id: I4820102c3c8f00bd73d751ce720f6162d682343a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 25 Feb 2022 10:29:06 +0000 (19:29 +0900)]
tools: Add resource-monitor monitoring tool
The resource-monitor monitors the available all resource attribute
on device and print them.
- Monitoring sequence as following:
1. Get resource count of each resource type
2. Set resource attributes of each resource
3. Update resource attributes to get value
4. Get value from resources
5. Print value of resources
- Usage
resource-monitor -h | -d secs -n max -p pid -g ppid | --pid pid --ppid ppid
- For example on rpi4 board,
$ resource-monitor --pid 1 --ppid 1
-------------------------------------------------------------------------------------------------------------------------------
: | Resource Attribute Name | Resource Attribute Value | Unit | Resource Attribute Description
-------------------------------------------------------------------------------------------------------------------------------
0: 0| SYSTEM_ATTR_CPU_UTIL | 4.96 | % | CPU average utilization
0: 1| SYSTEM_ATTR_CPU_USER_UTIL | 0.65 | % | CPU average utilization on user
0: 2| SYSTEM_ATTR_CPU_SYS_UTIL | 4.31 | % | CPU average utilization on system
0: 3| SYSTEM_ATTR_PER_CPU_UTIL | 1.72 1.71 13.91 1.72 | % | Per-CPU utilization
0: 4| SYSTEM_ATTR_PER_CPU_USER_UTIL | 0.00 0.00 1.74 0.00 | % | Per-CPU utilization on user
0: 5| SYSTEM_ATTR_PER_CPU_SYS_UTIL | 1.72 1.71 12.17 1.72 | % | Per-CPU utilization on system
0: 6| SYSTEM_ATTR_POSSIBLE_CPU | 4 | ea | Number of possible CPU
0: 7| SYSTEM_ATTR_ONLINE_CPU | 4 | ea | Number of online CPU
1: 0| MEMORY_ATTR_TOTAL |
3974103040 | byte | Memory total size
1: 1| MEMORY_ATTR_AVAILABLE |
3560730624 | byte | Memory available size
1: 2| MEMORY_ATTR_FREE |
3405287424 | byte | Memory free size
1: 3| MEMORY_ATTR_BUFFER |
20500480 | byte | Memorry buffer size
1: 4| MEMORY_ATTR_CACHED |
220078080 | byte | Memory cached size
1: 5| MEMORY_ATTR_CMA_TOTAL |
419430400 | byte | CMA memory total size
1: 6| MEMORY_ATTR_CMA_FREE |
381743104 | byte | CMA memory free size
1: 7| MEMORY_ATTR_SWAP_TOTAL |
1589637120 | byte | Swap memory total size
1: 8| MEMORY_ATTR_SWAP_FREE |
1495789568 | byte | Swap memory free size
2: 0| DISPLAY_ATTR_NAME | hdmi0 | | Display device name
2: 1| DISPLAY_ATTR_FPS | 0.00 | fps | Frame per second (fps)
3: 0| CPU_ATTR_NAME | cpu0 | | CPU cluster name
3: 1| CPU_ATTR_CUR_FREQ | 600000 | kHz | Current CPU frequency
3: 2| CPU_ATTR_MIN_FREQ | 600000 | kHz | Current CPU minimum frequency
3: 3| CPU_ATTR_MAX_FREQ | 1500000 | kHz | Current CPU maximum frequency
3: 4| CPU_ATTR_AVAILABLE_MIN_FREQ | 600000 | kHz | Available CPU minimum frequency
3: 5| CPU_ATTR_AVAILABLE_MAX_FREQ | 1500000 | kHz | Available CPU maximum frequency
3: 6| CPU_ATTR_CUR_GOVERNOR | schedutil | | Current CPU frequency governor name
4: 0| DISK_ATTR_NAME | zram0 | | Disk device name
4: 1| DISK_ATTR_READ_PER_SEC | 0.00 | kB/s | Disk read per second
4: 2| DISK_ATTR_WRITE_PER_SEC | 0.00 | kB/s | Disk write per second
4: 3| DISK_ATTR_READ_TOTAL | 46496 | kB | Disk read total size
4: 4| DISK_ATTR_WRITE_TOTAL | 230640 | kB | Disk write total size
5: 0| DISK_ATTR_NAME | mmcblk0 | | Disk device name
5: 1| DISK_ATTR_READ_PER_SEC | 0.00 | kB/s | Disk read per second
5: 2| DISK_ATTR_WRITE_PER_SEC | 0.00 | kB/s | Disk write per second
5: 3| DISK_ATTR_READ_TOTAL | 1041514 | kB | Disk read total size
5: 4| DISK_ATTR_WRITE_TOTAL | 388458 | kB | Disk write total size
6: 0| NETWORK_ATTR_NAME | eth0 | | Network device name
7: 0| PROCESS_ATTR_NAME | systemd | | Process name
7: 1| PROCESS_ATTR_CPU_UTIL | 0.00 | % | Process CPU utilization
7: 2| PROCESS_ATTR_MEM_VIRT |
15183377 | byte | Process VIRT memory size
7: 3| PROCESS_ATTR_MEM_RSS | 6216822 | byte | Process RSS(Resident Set Size) memory size
7: 4| PROCESS_ATTR_MEM_RSS_PERCENT | 0.00 | % | Process RSS(Resident Set Size) memory percent
7: 5| PROCESS_ATTR_DISK_READ_BPS | 0 | b/s | Process disk read per second
7: 6| PROCESS_ATTR_DISK_WRITE_BPS | 0 | b/s | Process disk write per second
7: 7| PROCESS_ATTR_PGID | 1 | | Process group ID
7: 8| PROCESS_ATTR_PPID | 0 | | Process parent PID(Process ID)
7: 9| PROCESS_ATTR_MEM_PSS | 3757056 | byte | Process PSS(Propotional Set Size) memory size
7:10| PROCESS_ATTR_MEM_SWAP | 311296 | byte | Process Swap memory size
7:11| PROCESS_ATTR_MEM_SWAP_PSS | 186368 | byte | Process Swap PSS(Propotional Set Size) memory size
7:12| PROCESS_ATTR_MEM_GPU | Not Supported | byte | Process GPU memory size
8: 0| PROCESS_GROUP_ATTR_PID_LIST | Not Implemented | | Process-group PID(Process ID) list
8: 1| PROCESS_GROUP_ATTR_NAME_LIST | Not Implemented | | Process-group name list
8: 2| PROCESS_GROUP_ATTR_CPU_UTIL | 0.23 | % | Process-group CPU utilization
8: 3| PROCESS_GROUP_ATTR_DISK_READ_BPS | 0 | b/s | Process-group disk read per second
8: 4| PROCESS_GROUP_ATTR_DISK_WRITE_BPS | 31743 | b/s | Process-group disk write per second
8: 5| PROCESS_GROUP_ATTR_MEM_VIRT |
140541707212 | byte | Process-group VIRT memory size
8: 6| PROCESS_GROUP_ATTR_MEM_RSS |
1378679318 | byte | Process-group RSS(Resident Set Size) memory size
8: 7| PROCESS_GROUP_ATTR_MEM_PSS |
188443648 | byte | Process-group PSS(Propotional Set Size) memory size
8: 8| PROCESS_GROUP_ATTR_MEM_SWAP |
93335552 | byte | Process-group Swap memory size
8: 9| PROCESS_GROUP_ATTR_MEM_SWAP_PSS |
92164096 | byte | Process-group Swap PSS(Propotional Set Size) memory size
8:10| PROCESS_GROUP_ATTR_MEM_GPU | Not Supported | byte | Process-group GPU memory size
Change-Id: I4e227fe451108b51f0a2371ad7104a54e36bb6a8
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 25 Jul 2022 03:44:02 +0000 (12:44 +0900)]
resource: Add disk and network resource driver
Add disk and network resource driver to provide monitoring data.
1. Add disk resource driver to provide the disk bandwidth
and usage with following resource attributes:
- DISK_ATTR_NAME indicates the disk device name
- DISK_ATTR_READ_PER_SEC indicates read bandwidth of specific block like zram0
- DISK_ATTR_WRITE_PER_SEC indicates write bandwidth of specific block like mmcblk0
- DISK_ATTR_READ_TOTAL indicates read kB size of specific block
- DISK_ATTR_WRITE_TOTAL indicates write kB size of specific block
The detailed description[1] of data are from /proc/diskstats and
/sys/class/block/[block name]/stats:
[1] https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
2. Add skeleton of network resource driver with resource name attribute.
- NETWORK_ATTR_NAME indicates the network device name
Change-Id: Ib440ab628ad1edc5a24378b9c18b80b7c9a8367e
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 25 Jul 2022 14:57:51 +0000 (23:57 +0900)]
resource: system: Fix typo
Change-Id: I5c6fce73c5243e7f0a306584f07fcd7b47e03de0
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 22 Jul 2022 07:54:33 +0000 (16:54 +0900)]
lib: resource-monitor: Add attribute to get resource name
[Newly added resource attributes]
- CPU_ATTR_NAME gets CPU resource name
- BUS_ATTR_NAME gets BUS resource name
- GPU_ATTR_NAME gets GPU resource name
- DISPLAY_ATTR_NAME gets Display resource name
[Renamed resource attributes]
- PROCESS_ATTR_COMM -> PROCESS_ATTR_NAME
- PROCESS_GROUP_ATTR_COMM_LIST -> PROCESS_GROUP_ATTR_NAME_LIST
Change-Id: I3f343b3aad2345bb4145fa85ed74d6764d9b43a1
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 22 Jul 2022 04:59:21 +0000 (13:59 +0900)]
pass: parser: Parse new resource type for display/disk/network
Parse new resource type for display/disk/network.
Change-Id: Id5c1a110aa22a825e2f0d0bbcff99707032f2bed
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Thu, 21 Jul 2022 07:28:38 +0000 (16:28 +0900)]
tests: resource-monitor-tests: Rename the test name to PhysicalResourceMonitorTest
The resource-monitor provides the both physical resources like
CPU/BUS/Display etc and logical resources such as process and
process-group. In order to add the logical resource test,
Rename the previous test name to PhysicalResourceMonitorTest.
Change-Id: I49fc0a38cc73bdc0b3a00d23582a874ff72120e6
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Tue, 26 Jul 2022 05:03:13 +0000 (14:03 +0900)]
util: kernel: Check whether adding cpu e/u/stime for TGID taskstat
There are difference with information on TGID taskstat among kernel
version, because e/u/stime for TGID taskstat is only summarized after
commit in mainline linux
8c733420bdd5 ("taskstats: add e/u/stime for TGID command")
is applied.
So, now check TGID taskstat has zero value for e/u/stime at the
initialization, and, if so, those time is calculated by adding values
in PID taskstats.
Change-Id: I8916e754465102a6643aefb8937e763fc5d1ee7a
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Sung-hun Kim [Mon, 25 Jul 2022 05:45:59 +0000 (14:45 +0900)]
util: resource: Assign an unique resource id when a new resouce is created
When PASS-daemon restarted unexpectedly, a pass client which is
survived in spite of PASS-daemon's restart can access resources
by using its own resource id (which is valid for previous PASS
daemon).
To prevent this situation, PASS should assign a unique resource
id for each created resource even if PASS daemon is restarted.
To this end, PASS initializes a global resource id (g_resource_id)
by using the value of gettimeofday(). So, each resource will be
assigned time-reflected resource id, and uniqueness is ensured
unless the number of created resources crosses the time consumed
before restarted.
Change-Id: I0e30addf01a0ee21b1f18aca56010d39d2c90c99
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Chanwoo Choi [Tue, 19 Jul 2022 08:29:37 +0000 (17:29 +0900)]
util: resource: Add detailed error log for debugging
Change-Id: Id740972f6baf00b3675a414b336f7e62cc9a2b63
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Tue, 19 Jul 2022 08:30:05 +0000 (17:30 +0900)]
resource: bus: Replace resource name with 'BUS' instead of 'Memory Bus'
Change-Id: I58cd357e5692149f6ab70b7cd97107ed5a0aa675
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 15 Jul 2022 09:26:01 +0000 (18:26 +0900)]
monitor: request-handler: Add debug log to catch the correct fail point
Add debug log to catch the correct fail point by printing
the correct resource name and resource attribute name.
And add missing error log.
The updated error log as following:
handle_request_set_resource_ctrl(310) > failed to set resource control, client(10) | res:type(MEMORY)id(21) | ctrl:name((null))id(0)val(0)
(snip)
handle_request_get_value_uint64(526) > failed to get uint64 value, client(10) | res:type(MEMORY)id(21) | attr:name(MEMORY_ATTR_TOTAL)id(1)
handle_request_get_value_uint64(526) > failed to get uint64 value, client(10) | res:type(MEMORY)id(21) | attr:name(MEMORY_ATTR_AVAILABLE)id(2)
Change-Id: I693c74f01f32954f4b828448aa3b8c2626fb2730
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Tue, 19 Jul 2022 03:27:22 +0000 (12:27 +0900)]
util: resource: Add get_resource_attr_name and get_resource_controL_name function
Add get_resource_attr_name and get_resource_controL_name function
to get the attribute name and control name.
Function prototype as following:
- const char *get_resource_attr_name(struct resource *resource, u_int64_t attr_id)
- const char *get_resource_control_name(struct resource *resource, u_int64_t ctrl_id)
Change-Id: Id77a7f07f8129fc14d693b32f35f94e8b4c93f3a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Tue, 5 Jul 2022 11:17:48 +0000 (20:17 +0900)]
monitor: request-handler: Remove unneeded local variable
Change-Id: Iff69aa14a7aa97b4db8efa782dc845ba513f2648
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 4 Jul 2022 21:51:41 +0000 (06:51 +0900)]
util: resource: Discard const keyword of struct resource
Discard const keyword when accessing struct resource
by hiding the 'struct resource' from use of 'struct resource'.
Except for 'void *priv' field of struct resource,
the fields of struct resource should be accessed by getter/setter
functions.
Change-Id: I80fe2a7c9df8f6a5c273da9f222668a03ba8e62e
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 4 Jul 2022 21:15:56 +0000 (06:15 +0900)]
resource: Use getter/setter of struct resource for encapsulation
Prevent the direct access of the fields of struct resource
by using getter/setter functiosn of struct resource.
By this change, keep the encapsulation of struct resource
and only communicate via getter/setter functions.
Change-Id: I4c7b92b79197ef67688773a5ef6b7db5e044bc09
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 4 Jul 2022 21:16:35 +0000 (06:16 +0900)]
util: resource: Encapsulate struct resource by hiding from user
Move 'struct resource' into src/util/resource.c for hiding it
and add missing getter/setter for encapsulation to access
the fiels of 'struct resource'.
Change-Id: Ib20b3de6f5ac68f20c14da82dedef38bbe26d2e8
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 8 Jul 2022 07:49:57 +0000 (16:49 +0900)]
lib: resource-monitor: Fix return value of pass_resource_monitor_is_resource_attr_supported
When return minus error value, it is converted to 1. It means that
return 'true' when error happen. So that change the return value
from minus integer value to false.
Fix following issue by this patch:
[ FAILED ] ResourceMonitorTest.pass_resource_monitor_is_resource_attr_supported_invalid
Change-Id: I437644ffbc6b55f9ff0e539ab3af1ceda6878872
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Wed, 6 Jul 2022 09:16:29 +0000 (18:16 +0900)]
monitor: request-handler: Fix wrong hash function when using integer key
The glib hash supports the various hash type. The resource-monitor uses
the integer value of resource id as the key of hash. If want to use
the integer key value, have to use 'g_direct_hash'[1] function
and 'g_direct_equal' function to compare the integer key instead of
pointer key for finding the inserted data.
[1] https://docs.gtk.org/glib/func.direct_hash.html
[2] https://docs.gtk.org/glib/func.direct_equal.html
Fix the following issues by this patch:
[ FAILED ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/0
[ FAILED ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/0
[ FAILED ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/0
Change-Id: I128fd800d44e5709d55d0c7a44a80db94e6d83d8
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 4 Jul 2022 22:37:38 +0000 (07:37 +0900)]
test: intergration-test: Add resource-monitor-tests
In order that test the resource-monitor library and internal logic,
add resource-monitor-tests.
[Example, the result of resource-monitor-tests]
root:~> resource-monitor-tests
[==========] Running 16 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 4 tests from ResourceMonitorTest
[ RUN ] ResourceMonitorTest.pass_resource_monitor_init_and_exit
[ OK ] ResourceMonitorTest.pass_resource_monitor_init_and_exit (0 ms)
[ RUN ] ResourceMonitorTest.pass_resource_monitor_get_resource_count_valid
[ OK ] ResourceMonitorTest.pass_resource_monitor_get_resource_count_valid (2 ms)
[ RUN ] ResourceMonitorTest.pass_resource_monitor_get_resource_count_invalid
[ OK ] ResourceMonitorTest.pass_resource_monitor_get_resource_count_invalid (0 ms)
[ RUN ] ResourceMonitorTest.pass_resource_monitor_is_resource_attr_supported_invalid
[ OK ] ResourceMonitorTest.pass_resource_monitor_is_resource_attr_supported_invalid (1 ms)
[----------] 4 tests from ResourceMonitorTest (6 ms total)
[----------] 12 tests from ResourceMonitorTest/EachResourceMonitorTest
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_create_resource_and_delete/0
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_create_resource_and_delete/0 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_create_resource_and_delete/1
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_create_resource_and_delete/1 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_create_resource_and_delete/2
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_create_resource_and_delete/2 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/0
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/0 (1 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/1
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/1 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/2
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/2 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/0
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/0 (2 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/1
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/1 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/2
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/2 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/0
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/0 (3 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/1
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/1 (0 ms)
[ RUN ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/2
[ OK ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/2 (0 ms)
[----------] 12 tests from ResourceMonitorTest/EachResourceMonitorTest (15 ms total)
[----------] Global test environment tear-down
[==========] 16 tests from 2 test suites ran. (21 ms total)
[ PASSED ] 16 tests.
Change-Id: Id15d6948849decedcbe0f48bee083667afdc996b
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Dongwoo Lee [Tue, 5 Jul 2022 10:09:51 +0000 (19:09 +0900)]
util: kernel: Fix to check memory map info precisely
Since both "Pss:" and "SwapPss:" nodes has "Pss:" as substring, so
just strstr() cannot distinguish them. To fix it, not just check
section including node name, but check section starting with node
name.
Change-Id: Ia113d57b84414b9483b098920634c7f9f4b7461d
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Mon, 4 Jul 2022 06:19:07 +0000 (15:19 +0900)]
resource: process: Add checking support for PROCESS_ATTR_GPU_MEM
Change-Id: Icc7f49ee785f668f8e6afc68c6960a4d4c81c438
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Mon, 4 Jul 2022 02:41:38 +0000 (11:41 +0900)]
resource: process-group: Add checking support for PROCESS_GROUP_ATTR_GPU_MEM
Change-Id: Iefbaa9526f62fe1af5fb054f8cbacbe81863bb9b
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Mon, 4 Jul 2022 02:14:38 +0000 (11:14 +0900)]
util: kernel: gpu-mem: Improve process for finding gpu node
To get rid of redundant gpu node checking at every update, finding gpu
node will be proceeded at once as constructor.
Change-Id: I30c18784f578e224e812c9ee9e0d9a4704cf901a
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Dongwoo Lee [Fri, 1 Jul 2022 05:39:58 +0000 (14:39 +0900)]
util: kernel: gpu-mem: Fix missing header file
Change-Id: Iec6278b4a5cab50315b3f42f28cc12205d5d2ee7
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Chanwoo Choi [Mon, 4 Jul 2022 18:53:39 +0000 (03:53 +0900)]
util: kernel: Remove unused variable to fix build warning
Fix the following warning.
/home/abuild/rpmbuild/BUILD/pass-1.2.0/src/util/kernel.c:
In function 'get_gpu_mem_info':
/home/abuild/rpmbuild/BUILD/pass-1.2.0/src/util/kernel.c:435:6:
warning: variable 'n' set but not used [-Wunused-but-set-variable]
| int n;
Change-Id: Ie763f9bf4f2aa61aa22535ca0209871359306419
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Tue, 5 Jul 2022 10:11:15 +0000 (19:11 +0900)]
pass: parser: Replace with bool data type to prevent mismatched type casting
Until now, even if use DATA_TYPE_BOOLEN, use 'int' variable type.
It might cause the unknown issue by mismatched type casting
on get_property() fucntion. In order to prevent the wrong type casting,
replace with bool data type instead of integer type.
Change-Id: I51791d72579afc97b73b6a67d9a9711c21c033f4
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Mon, 4 Jul 2022 03:32:06 +0000 (12:32 +0900)]
util: common: Replace prototype of json helper functions to get correct value
The get_int_from_object() returns '-EINVAL' when json object doesn't
contain ' key'. But it isn't correct because 'int' value is able
to get the minus value. It means that when get_int_from_object() return -EINVAL,
it is not error on side of user. To fix them, return the error and then
get the value as the parameter. Also, get_double_from_object() has the same issue.
Also, in order that keep the consistent prototype of json helper functions,
changes the functiosn as following:
- int get_int_from_object(json_object *obj, const char *key, int *data);
- int get_double_from_object(json_object *obj, const char *key, double *data);
- int get_boolean_from_object(json_object *obj, const char *key, bool *data);
Change-Id: I0a9b9da36312a0d86920f259b1f702095f104da6
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Sun, 3 Jul 2022 17:20:04 +0000 (02:20 +0900)]
pmqos: parser: Distinguish mandatory property or optional with get_property
Change-Id: Ifef64ee85c00f4c7a2b695aa5edf80ac6e42c824
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Sun, 3 Jul 2022 17:17:18 +0000 (02:17 +0900)]
thermal: parser: Distinguish mandatory property or optional with get_property
Change-Id: I301aefac2dd006b6ba4406b0e813947c949aa490
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 24 Jun 2022 07:35:30 +0000 (16:35 +0900)]
pass: parser: Distinguish mandatory property or optional with get_property
Actually, it is difficult and complicated to specify
whether some property is mandatory or optional even if
it is requied.
Specify either mandatory or optional status of each property
with get_property() function. If some property is mandatory,
just pass the true into 3rd argument of get_property.
In case of mandatory property, get_property returns error
if property is absent. On the other hand, get_property
returns non-zero with debug level log about absent property.
And also, should print the error for non-existent mandatory properteis
in same section at the same time. It helps user to fix
the configuration.
For example,
- 'device_type' and 'device_name' properties are mandatory
and 'thermal_device_name' property is optional property.
ret += get_property(obj, "device_type", DATA_TYPE_STRING,
true, (void *)device_type);
ret += get_property(obj, "device_name", DATA_TYPE_STRING,
true, (void *)device_name);
ret += get_property(obj, "thermal_device_name", DATA_TYPE_STRING,
false, (void *)thermal_device_name);
if (ret < 0) {
_E("Failed to get mandatory properties in device_list\n");
return ret;
}
- result of error log
Failed to get property of 'device_type' (log for mandatory property)
Failed to get property of 'device_name' (log for mandatory property)
There is no property of 'thermal_priority' (log for optional property)
Failed to get mandatory properties in device_list
cannot parse of 0th resource in 'device_list' section
Change-Id: I2e8a87788eadb7550369378af4adfec0774bdc8a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Chanwoo Choi [Fri, 24 Jun 2022 06:13:09 +0000 (15:13 +0900)]
util: common: Add get_property to simplify the property getting operation
There are already helper funciton to get value from json object.
In order to simpilfy the code getting value from json object,
add get_value_from_object function with data type arguemnt.
[Detailed description of get_property]
int get_property(json_object *obj, const char *key,
int type, bool mandatory, void *data)
- json_object *obj : json object
- const char *key : property key
- int type : data type of property
- bool mandatory : if property is mandatory, true.
- void *data : each data will be stored
Change-Id: Ifd217ae5773e11ccb1f2d74850ee1c68fb035ebe
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>