apply boost for server start and directory scan 72/302472/1
authorsamsung2013 <yuzhi.he@samsung.com>
Thu, 7 Dec 2023 09:28:23 +0000 (17:28 +0800)
committersamsung2013 <yuzhi.he@samsung.com>
Thu, 7 Dec 2023 09:28:23 +0000 (17:28 +0800)
Change-Id: I6e4edf7dcb66939c3b7407b63d7c0f0e1ec3cef0

Makefile.am
lib/media-util-db.c
packaging/media-server.spec
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner-v2/media-scanner-v2.c
src/server/media-server-main.c

index 0ba8952..5f616dc 100755 (executable)
@@ -130,7 +130,7 @@ media_server_LDFLAGS = -pie
 media_server_LDADD = $(SQLITE3_LIBS) \
                     $(COMMON_LDADD) \
                     $(PHONESTATUS_LIBS) \
-                    $(SYSTEM_INFO_LIBS)
+                    $(SYSTEM_INFO_LIBS) -lcapi-system-resource
 
 media_server_LDADD += $(SECURITY_LIBS) \
                              $(USB_DEVICE_LIBS) \
@@ -189,7 +189,7 @@ media_scanner_v2_LDADD = $(COMMON_LDADD)
 
 media_scanner_v2_LDADD += $(USB_DEVICE_LIBS) \
                           $(POWER_DEFS_LIBS) \
-                          $(POWER_TV_LIBS)
+                          $(POWER_TV_LIBS) -lcapi-system-resource
 endif
 ######################################################
 #mediadb_udpate
index ef21077..af8728d 100755 (executable)
@@ -129,7 +129,7 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo
        int ret = SQLITE_OK;
        char *db_path = NULL;
        char *sql = NULL;
-
+       MSAPI_DBG_ERR("need_write[%d]", need_write);
        ret = ms_user_get_media_db_path(uid, &db_path);
        MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_INTERNAL, "ms_user_get_media_db_path failed");
 
@@ -185,7 +185,7 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo
 
        /* Set for localized collate */
        sqlite3_collation_needed(*db_handle, NULL, __media_db_collation_cb);
-
+       MSAPI_DBG_ERR("Finish");
        return MS_MEDIA_ERR_NONE;
 }
 
index 2781301..1d63ae5 100755 (executable)
@@ -24,6 +24,7 @@ BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(capi-system-device)
+BuildRequires: pkgconfig(capi-system-resource)
 %if 0%{?gtests:1}
 BuildRequires:  pkgconfig(gmock)
 %endif
index 9668a5e..de1c6e7 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #include <malloc.h>
-
+#include <cpu-boosting.h>
 #include "media-util.h"
 #include "media-server-ipc.h"
 #include "media-common-utils.h"
@@ -287,12 +287,23 @@ gpointer msc_storage_extract_thread(gpointer data)
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
        int end_flag = NORMAL_EVENT;
 
+       resource_pid_t stResource = {};
+       stResource.pid = getpid();
+
+       if(0 != resource_set_cpu_boosting(stResource, CPU_BOOSTING_LEVEL_MEDIUM, (cpu_boosting_flag_e)0, -1)) {
+               MS_DBG_ERR("Start CPU Boost 0 Failed[%d]", stResource.pid);
+       }
+       else {
+               MS_DBG_ERR("Start CPU Boost 0, pid[%d]", stResource.pid);
+       }
+
        while (1) {
                __msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
                extract_data = g_async_queue_pop(storage_extract_queue);
                if (extract_data->pid == POWEROFF) {
                        MS_DBG_ERR("power off");
                        MS_SAFE_FREE(extract_data);
+                       resource_clear_cpu_boosting(stResource);
                        return NULL;
                }
 
@@ -402,6 +413,7 @@ NEXT:
 _POWEROFF:
        MS_SAFE_FREE(extract_data);
        ms_disconnect_db(handle);
+       resource_clear_cpu_boosting(stResource);
 
        return NULL;
 }
index 3cfbe6e..60931a5 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <malloc.h>
 #include <dirent.h>
-
+#include <cpu-boosting.h>
 #include "media-util.h"
 #include "media-server-ipc.h"
 #include "media-common-utils.h"
@@ -137,7 +137,7 @@ static int __msc_check_stop_status(ms_msg_type_e msg_type, const char *start_pat
        if (msg_type == MS_MSG_DIRECTORY_SCANNING || msg_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
                g_mutex_lock(&scan_req_mutex2);
                /* check cancel path */
-               //MS_DBG_ERR("__msc_check_stop_status...");
+               MS_DBG_ERR("__msc_check_stop_status...");
                if ((cancel_scan_item != NULL) && (cancel_scan_item->path != NULL)) {
                        MS_DBG_SWARN("check blocked storage [%s][%s]", cancel_scan_item->path, start_path);
                        if ((strncmp(cancel_scan_item->path, start_path, strlen(cancel_scan_item->path)) == 0)
@@ -256,6 +256,7 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch
                sleep_count = 0;
 
                dir = opendir(current_path);
+               MS_DBG_ERR("opendir[%s]", current_path);
                if (dir == NULL) {
                        MS_DBG_ERR("g_dir_open fails [%s]", current_path);
                        MS_SAFE_FREE(current_path);
@@ -378,6 +379,8 @@ END_SCAN:
        if (ret != MS_MEDIA_ERR_NONE)
                MS_DBG_INFO("ret : %d", ret);
 
+       MS_DBG_ERR("End scan");
+
        return ret;
 }
 
@@ -597,6 +600,8 @@ END_SCAN:
        if (ret != MS_MEDIA_ERR_NONE)
                MS_DBG_INFO("ret : %d", ret);
 
+       MS_DBG_ERR("End scan");
+
        return ret;
 }
 
@@ -707,6 +712,16 @@ static int __msc_db_update(sqlite3 *handle, const char *storage_id, const ms_com
        int err = MS_MEDIA_ERR_NONE;
        char *start_path = NULL;
 
+       resource_pid_t stResource = {};
+       stResource.pid = getpid();
+
+       if(0 != resource_set_cpu_boosting(stResource, CPU_BOOSTING_LEVEL_MEDIUM, (cpu_boosting_flag_e)0, -1)) {
+               MS_DBG_ERR("Start CPU Boost 0 Failed[%d]", stResource.pid);
+       }
+       else {
+               MS_DBG_ERR("Start CPU Boost 0, pid[%d]", stResource.pid);
+       }
+
        if (scan_data->msg_type != MS_MSG_STORAGE_INVALID) {
                MS_DBG_WARN("INSERT");
                start_path = g_strdup(scan_data->msg);
@@ -723,7 +738,10 @@ static int __msc_db_update(sqlite3 *handle, const char *storage_id, const ms_com
                msc_remove_extract_request(scan_data);
        }
 
+       MS_DBG_ERR("start to sync[%d]", stResource.pid);
        sync();
+       MS_DBG_ERR("end sync[%d]", stResource.pid);
+       resource_clear_cpu_boosting(stResource);
 
        return err;
 }
index 32ba130..9e09fbe 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <cpu-boosting.h>
 
 #include "media-common-utils.h"
 #include "media-common-external-storage.h"
@@ -85,6 +86,14 @@ int main(int argc, char **argv)
        int err = -1;
        int fd = -1;
 
+       resource_pid_t stResource = {};
+       stResource.pid = getpid();
+       if(0 != resource_set_cpu_boosting(stResource, CPU_BOOSTING_LEVEL_MEDIUM, (cpu_boosting_flag_e)0, -1)) {
+               MS_DBG_ERR("Start CPU Boost 0 Failed[%d]", stResource.pid);
+       } else {
+               MS_DBG_ERR("Start CPU Boost 0, pid[%d]", stResource.pid);
+       }
+
        MS_DBG_INFO("Scanner-V2 start");
 
        __msc_add_event_receiver();
@@ -113,12 +122,14 @@ int main(int argc, char **argv)
        err = mkfifo(MS_SCANNER_FIFO_PATH_REQ, MS_SCANNER_FIFO_MODE);
        if (err != 0) {
                MS_DBG_STRERROR("mkfifo failed");
+               resource_clear_cpu_boosting(stResource);
                return MS_MEDIA_ERR_INTERNAL;
        }
 
        fd = open(MS_SCANNER_FIFO_PATH_REQ, O_RDWR);
        if (fd < 0) {
                MS_DBG_STRERROR("fifo open failed");
+               resource_clear_cpu_boosting(stResource);
                return MS_MEDIA_ERR_INTERNAL;
        }
 
@@ -140,6 +151,8 @@ int main(int argc, char **argv)
        msc_send_ready();
        MS_DBG_INFO("Scanner-V2 is running");
 
+       resource_clear_cpu_boosting(stResource);
+
        /*Set VIP Process*/
        ms_set_vip_process();
 
@@ -162,6 +175,7 @@ int main(int argc, char **argv)
        ms_unload_functions();
 
 EXIT:
+       resource_clear_cpu_boosting(stResource);
        MS_DBG_INFO("Scanner-V2 is shutting down");
        return 0;
 }
index 2394509..b824b39 100644 (file)
@@ -24,6 +24,7 @@
 #include <malloc.h>
 #include <vconf.h>
 #include <iniparser.h>
+#include <cpu-boosting.h>
 
 #include "media-util.h"
 #include "media-common-utils.h"
@@ -275,9 +276,18 @@ int main(int argc, char **argv)
        int ret = 0;
        int sockfd = -1;
 
+       resource_pid_t stResource = {};
+       stResource.pid = getpid();
+       if(0 != resource_set_cpu_boosting(stResource, CPU_BOOSTING_LEVEL_MEDIUM, (cpu_boosting_flag_e)0, -1)) {
+               MS_DBG_ERR("Start CPU Boost 0 Failed[%d]", stResource.pid);
+       } else {
+               MS_DBG_ERR("Start CPU Boost 0, pid[%d]", stResource.pid);
+       }
+
        ret = ms_load_functions();
        if (ret != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("ms_load_functions failed [%d]", ret);
+               resource_clear_cpu_boosting(stResource);
                return -1;
        }
 
@@ -313,6 +323,7 @@ int main(int argc, char **argv)
        if (ms_cynara_initialize() != MS_MEDIA_ERR_NONE) {
                ms_unload_functions();
                MS_DBG_ERR("Failed to initialize cynara");
+               resource_clear_cpu_boosting(stResource);
                return -1;
        }
 
@@ -321,6 +332,7 @@ int main(int argc, char **argv)
 
        if (ms_ipc_create_server_socket(MS_SCANNER_PORT, &sockfd) != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("Failed to create socket");
+               resource_clear_cpu_boosting(stResource);
                return -1;
        }
 
@@ -363,6 +375,7 @@ int main(int argc, char **argv)
        /*Set VIP Process*/
        ms_set_vip_process();
 #endif
+       resource_clear_cpu_boosting(stResource);
 
        g_main_loop_run(mainloop);