Fix excessive CPU usage issue in DNS monitoring 52/325152/3 tizen_9.0
authorJaehyun Kim <jeik01.kim@samsung.com>
Mon, 2 Jun 2025 12:31:56 +0000 (21:31 +0900)
committerhyunsube-lee <hyunsube.lee@samsung.com>
Thu, 5 Jun 2025 03:49:38 +0000 (12:49 +0900)
Change-Id: Ib437bf5ec0996e123fb54c428d3f90a353dc27e7
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
resources/var/lib/inm-manager/settings
src/inm-dns-lookup.c

index a86ff28a03c8f0a80e566f172a1a33a00971fe65..b3e372a4127f0ad0b0bb7654c0da4f89f9fe8d90 100644 (file)
@@ -13,5 +13,5 @@ SupportDnsMonitoring=True
 SupportGatewayMonitoring=True
 SupportRtnlMonitoring=false
 SupportArpMonitoring=True
-SupportIfaceMonitoring=false
+SupportIfaceMonitoring=True
 SupportRetryTxRateMonitoring=false
\ No newline at end of file
index 0883c01dab0d4ff5121232ce9330d0b23606e048..ea7b64f81329a7fa90ec91ada38e169ee8c99890 100644 (file)
@@ -36,6 +36,7 @@
 #define ARES_DEFAULT_TRIAL_TIMEOUT_MS 500
 #define ARES_DEFAULT_TIMEOUT_MS 5000
 #define ARES_DEFAULT_TRY 10
+#define ARES_PROCESS_INTERVAL_USEC 100000
 #define DEFAULT_TEST_URL "www.tizen.org"
 #define DNS_INTERVAL_MIN 1000
 
@@ -129,7 +130,6 @@ static inline void __destroy_default_dns_lookup_data()
 static gboolean __sock_channel_io_cb(GIOChannel *source,
                                        GIOCondition condition, gpointer data)
 {
-       INM_LOGI("");
        inm_gio_channel_s *gio_channel;
        ares_socket_t read_fd = ARES_SOCKET_BAD;
        ares_socket_t write_fd = ARES_SOCKET_BAD;
@@ -157,7 +157,9 @@ static gboolean __sock_channel_io_cb(GIOChannel *source,
 
        if (g_default_dns_lookup_data->is_lookup_finished)
                __destroy_default_dns_lookup_data();
-       INM_LOGI("");
+
+       g_usleep(ARES_PROCESS_INTERVAL_USEC);
+
        return TRUE;
 }
 
@@ -294,33 +296,48 @@ static void __sock_state_cb(void *data, int fd, int read, int write)
        return;
 }
 
-static int __ares_set_opt(inm_dns_lookup_s *lookup_data)
+static int __ares_set_opt(inm_dns_lookup_s *lookup_data, int monitor_interval)
 {
        struct ares_options *p_opts = NULL;
 
        p_opts = g_try_malloc0(sizeof(struct ares_options));
        if (!p_opts) {
-               INM_LOGI("");
+               INM_LOGI("Out of memory");
                return -1;
        }
 
-       p_opts->sock_state_cb = __sock_state_cb;
-       p_opts->sock_state_cb_data = (void *)lookup_data;
-       p_opts->timeout = ARES_DEFAULT_TRIAL_TIMEOUT_MS;
-       p_opts->tries = ARES_DEFAULT_TRY;
+       if (monitor_interval) {
+               int monitor_timeout = ARES_DEFAULT_TIMEOUT_MS;
+
+               if (ARES_DEFAULT_TIMEOUT_MS >= monitor_interval)
+                       monitor_timeout = (int)(monitor_interval * 0.8);
+
+               p_opts->timeout = monitor_timeout;
+               p_opts->sock_state_cb = __sock_state_cb;
+               p_opts->sock_state_cb_data = (void *)lookup_data;
+       } else {
+               p_opts->sock_state_cb = __sock_state_cb;
+               p_opts->sock_state_cb_data = (void *)lookup_data;
+               p_opts->timeout = ARES_DEFAULT_TRIAL_TIMEOUT_MS;
+               p_opts->tries = ARES_DEFAULT_TRY;
+       }
 
        lookup_data->ch_options = p_opts;
 
        return 0;
 }
 
-static inline int __init_ares_channel(inm_dns_lookup_s *dns_lookup_data)
+static inline int __init_ares_channel(inm_dns_lookup_s *dns_lookup_data, int monitor_interval)
 {
        ares_channel ch;
        int opt_mask = 0;
        int ret;
 
-       opt_mask = ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_SOCK_STATE_CB;
+       if (monitor_interval)
+               opt_mask = ARES_OPT_TIMEOUTMS | ARES_OPT_SOCK_STATE_CB;
+       else
+               opt_mask = ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_SOCK_STATE_CB;
+
        ret = ares_init_options(&ch, dns_lookup_data->ch_options, opt_mask);
        if (ret != ARES_SUCCESS) {
                PRINT_LOG("ares_init_options: %s\n", ares_strerror(ret));
@@ -333,26 +350,26 @@ static inline int __init_ares_channel(inm_dns_lookup_s *dns_lookup_data)
        return 0;
 }
 
-static inline int __create_default_dns_lookup_data()
+static inline int __create_default_dns_lookup_data(int monitor_interval)
 {
        inm_dns_lookup_s *dns_lookup_data = NULL;
        int ret;
 
        dns_lookup_data = g_try_malloc0(sizeof(inm_dns_lookup_s));
        if (!dns_lookup_data) {
-               INM_LOGI("");
+               INM_LOGI("Out of memory");
                return -1;
        }
 
-       ret = __ares_set_opt(dns_lookup_data);
+       ret = __ares_set_opt(dns_lookup_data, monitor_interval);
        if (ret != 0) {
-               INM_LOGI("");
+               INM_LOGI("__ares_set_opt() is failed");
                g_free(dns_lookup_data);
                return -1;
        }
-       ret = __init_ares_channel(dns_lookup_data);
+       ret = __init_ares_channel(dns_lookup_data, monitor_interval);
        if (ret != 0) {
-               INM_LOGI("");
+               INM_LOGI("__init_ares_channel() is failed");
                g_free(dns_lookup_data->ch_options);
                g_free(dns_lookup_data);
                return -1;
@@ -492,14 +509,14 @@ int inm_default_dns_state_monitor(void)
                __destroy_default_dns_lookup_data();
        }
 
-       ret = __create_default_dns_lookup_data();
+       interval = __get_dns_check_interval_value();
+
+       ret = __create_default_dns_lookup_data(interval);
        if (ret != 0) {
                INM_LOGI("Operation Failed");
                return INM_DNS_LOOKUP_ERROR_OPERATION_FAILED;
        }
 
-       interval = __get_dns_check_interval_value();
-
        __dns_state_monitor(NULL);
 
        g_default_dns_lookup_data->ares_timer_source_id =
@@ -537,7 +554,7 @@ int inm_default_dns_lookup_start(inm_default_dns_lookup_callback cb, gpointer us
                return INM_DNS_LOOKUP_ERROR_IN_PROGRESS;
        }
 
-       ret = __create_default_dns_lookup_data();
+       ret = __create_default_dns_lookup_data(0);
        if (ret != 0) {
                INM_LOGI("");
                return INM_DNS_LOOKUP_ERROR_OPERATION_FAILED;