Delete dlclose() and Move dlopen() 28/276628/5 accepted/tizen/unified/20220622.133907 submit/tizen/20220622.073052
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 22 Jun 2022 04:37:47 +0000 (13:37 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 22 Jun 2022 07:28:45 +0000 (16:28 +0900)
do not call dlopen()/dlclose() on constructor/destructor respectively.
Instead, delete dlcose() and move dlopen() from constructor to APIs.

Change-Id: Id9f75d2dc2749321e96d6504c45ec06973995190
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/cpu-boosting.c
src/plugin/plugin.c
tests/main.c

index 1acd074..d417192 100644 (file)
@@ -30,15 +30,23 @@ static void *plugin_handle = NULL;
 
 #define CPU_BOOSTING_PLUGIN_PATH             PLUGIN_PATH"/libcapi-system-resource-plugin.so"
 
-static void open_cpu_boosting_plugin(void)
+static int open_cpu_boosting_plugin(void)
 {
-    if (access(CPU_BOOSTING_PLUGIN_PATH, F_OK) != 0) {
+       if (plugin_handle)
+               return RESOURCE_ERROR_NONE;
+
+       if (access(CPU_BOOSTING_PLUGIN_PATH, F_OK) != 0) {
                _E("[CPU-BOOSTING] Cannot find a plugin file");
-    }
+               return RESOURCE_ERROR_NO_SUCH_FILE;
+       }
        else {
                plugin_handle = dlopen(CPU_BOOSTING_PLUGIN_PATH, RTLD_NOW);
-               if (!plugin_handle)
+               if (!plugin_handle) {
                        _E("[CPU-BOOSTING] Failed to load %s", CPU_BOOSTING_PLUGIN_PATH);
+                       return RESOURCE_ERROR_NOT_SUPPORTED;
+               }
+
+               return RESOURCE_ERROR_NONE;
        }
 }
 
@@ -48,8 +56,9 @@ API int resource_set_cpu_boosting (resource_pid_t pid,
        int ret;
        int (*func)(resource_pid_t pid, cpu_boosting_level_e level, int timeout_msec) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_set_cpu_boosting");
        if (!func) {
@@ -71,8 +80,9 @@ API int resource_clear_cpu_boosting (resource_pid_t pid)
        int ret;
        int (*func)(resource_pid_t pid) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_clear_cpu_boosting");
        if (!func) {
@@ -95,8 +105,9 @@ API int resource_get_cpu_boosting_level (resource_pid_t pid,
        int ret;
        int (*func)(resource_pid_t pid, cpu_boosting_level_info_t *level) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_get_cpu_boosting_level");
        if (!func) {
@@ -118,8 +129,9 @@ API int resource_set_cpu_inheritance (int source_tid, char *dest_process, int ti
        int ret;
        int (*func)(int source_tid, char *dest_process, int timeout_msec) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_set_cpu_inheritance");
        if (!func) {
@@ -141,8 +153,9 @@ API int resource_clear_cpu_inheritance (int source_tid, char *dest_process)
        int ret;
        int (*func)(int source_tid, char *dest_process) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_clear_cpu_inheritance");
        if (!func) {
@@ -164,8 +177,9 @@ API int resource_register_cpu_inheritance_destination (char *dest_process, resou
        int ret;
        int (*func)(char *dest_process, resource_pid_t pid) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_register_cpu_inheritance_destination");
        if (!func) {
@@ -187,8 +201,9 @@ API int resource_unregister_cpu_inheritance_destination (char *dest_process)
        int ret;
        int (*func)(char *dest_process) = NULL;
 
-       if (!plugin_handle)
-               return RESOURCE_ERROR_NO_SUCH_FILE;
+       ret = open_cpu_boosting_plugin();
+       if (ret != RESOURCE_ERROR_NONE)
+               return ret;
 
        func = dlsym(plugin_handle, "resource_unregister_cpu_inheritance_destination");
        if (!func) {
@@ -207,16 +222,8 @@ API int resource_unregister_cpu_inheritance_destination (char *dest_process)
 
 static void __CONSTRUCTOR__ cpu_boosting_init(void)
 {
-       open_cpu_boosting_plugin();
-       if (!plugin_handle)
-               _E("[CPU-BOOSTING] Failed to open CPU boosting plugin");
-       else
-               _D("[CPU-BOOSTING] plugin handle (open) = %p", plugin_handle);
 }
 
 static void __DESTRUCTOR__ cpu_boosting_exit(void)
 {
-       _D("[CPU-BOOSTING] plugin handle (close) = %p", plugin_handle);
-       if (plugin_handle)
-               dlclose(plugin_handle);
 }
index ecab651..8f083ab 100644 (file)
@@ -27,9 +27,6 @@ API int resource_set_cpu_boosting (resource_pid_t pid,
                cpu_boosting_level_e level, int timeout_msec)
 {
        _D("[CPU-BOOSTING-PLUGIN] %s called", __func__);
-       for (int i = 0; i < pid.tid_count; i++) {
-               _D("[CPU-BOOSTING-PLUGIN] pid = %d, tid = %d", pid.pid, pid.tid[i]);
-       }
 
        return 0;
 }
@@ -37,9 +34,6 @@ API int resource_set_cpu_boosting (resource_pid_t pid,
 API int resource_clear_cpu_boosting (resource_pid_t pid)
 {
        _D("[CPU-BOOSTING-PLUGIN] %s called", __func__);
-       for (int i = 0; i < pid.tid_count; i++) {
-               _D("[CPU-BOOSTING-PLUGIN] pid = %d, tid = %d", pid.pid, pid.tid[i]);
-       }
 
        return 0;
 }
@@ -48,9 +42,6 @@ API int resource_get_cpu_boosting_level (resource_pid_t pid,
                cpu_boosting_level_info_t *level)
 {
        _D("[CPU-BOOSTING-PLUGIN] %s called", __func__);
-       for (int i = 0; i < pid.tid_count; i++) {
-               _D("[CPU-BOOSTING-PLUGIN] pid = %d, tid = %d", pid.pid, pid.tid[i]);
-       }
 
        return 0;
 }
index 77bfccc..0757a18 100644 (file)
@@ -198,6 +198,8 @@ static void one_process_all_thread_test(int tid_count)
 
 int main (void)
 {
+       _D("[CPU-BOOSTING-TEST] Start");
+
        /* Case 1: Boosting a process with a single thread */
        _D("[CPU-BOOSTING-TEST] <<<<<<<<<< One Process One Thread >>>>>>>>>>");
        one_process_one_thread_test();