osutil: Added a function that get the number of host processors.
authorKitae Kim <kt920.kim@samsung.com>
Wed, 4 Sep 2013 03:03:41 +0000 (12:03 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Wed, 11 Sep 2013 05:21:33 +0000 (14:21 +0900)
Separate the implementation from print_system_info_os function,
because the function could be useful when creating threads.

Change-Id: Ibb6d937b810c68505a64097c0b1f539b3ace45dd
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/osutil-darwin.c
tizen/src/osutil-linux.c
tizen/src/osutil-win32.c
tizen/src/osutil.h

index c47ee89..0b3ee7c 100644 (file)
@@ -137,6 +137,27 @@ void set_bin_path_os(gchar * exec_argv)
     free(data);
 }
 
+int get_number_of_processors(void)
+{
+    int mib[2], sys_num = 0;
+    size_t len;
+
+    mib[0] = CTL_HW;
+    mib[1] = HW_AVAILCPU;
+
+    sysctl(mib, 2, &sys_num, &len, NULL, 0);
+    if (num_processor < 1) {
+        mib[1] = HW_NCPU;
+        sysctl(mib, 2, &sys_num, &len, NULL, 0);
+
+        if (sys_num < 1) {
+            sys_num = 1;
+        }
+    }
+    INFO("* Number of processors : %d\n", sys_num);
+
+    return sys_num;
+}
 
 void print_system_info_os(void)
 {
@@ -175,12 +196,15 @@ void print_system_info_os(void)
     }
     free(sys_info);
 
+#if 0
     mib[0] = CTL_HW;
     mib[1] = HW_NCPU;
     len = sizeof(sys_num);
     if (sysctl(mib, 2, &sys_num, &len, NULL, 0) >= 0) {
         INFO("* Number of processors : %d\n", sys_num);
     }
+#endif
+    get_number_of_processors();
 
     mib[0] = CTL_HW;
     mib[1] = HW_PHYSMEM;
index f7fd45d..91ca6c7 100644 (file)
@@ -1,9 +1,9 @@
-/* 
+/*
  * Emulator
  *
  * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  * SeokYeon Hwang <syeon.hwang@samsung.com>
  * MunKyu Im <munkyu.im@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
@@ -165,6 +165,19 @@ void set_bin_path_os(gchar * exec_argv)
     g_strlcat(bin_path, "/", PATH_MAX);
 }
 
+int get_number_of_processors(void)
+{
+    int num_processors = 0;
+
+    num_processors = sysconf(_SC_NPROCESSORS_ONLN);
+    if (num_processors < 1) {
+        num_processors = 1;
+    }
+    TRACE("Number of processors : %d\n", num_processors);
+
+    return num_processors;
+}
+
 void print_system_info_os(void)
 {
     INFO("* Linux\n");
@@ -274,7 +287,7 @@ static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy,
             ERR("pac file is not wrong! It could be the wrong pac address or pac file format\n");
             fclose(fp_pacfile);
         }
-    } 
+    }
     else {
         ERR("fail to get pacfile fp\n");
     return -1;
@@ -300,7 +313,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
         snprintf(buf_proxy, MAXLEN, "%s", buf);
     }
     pclose(output);
-    
+
     output = popen(gproxycmds[GNOME_PROXY_HTTP_PORT][gproxytool], "r");
     if(fscanf(output, "%s", buf_port) <= 0) {
         //for abnormal case: if can't find the key of http port, get from environment value.
@@ -394,7 +407,7 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
     }
     if (ret > 0) {
         process_string(buf);
-        //priority : auto > manual > none       
+        //priority : auto > manual > none
         if (strcmp(buf, "auto") == 0) {
             INFO("AUTO PROXY MODE\n");
             get_auto_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
index 35e40be..d650641 100644 (file)
@@ -1,9 +1,9 @@
-/* 
+/*
  * Emulator
  *
  * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  * SeokYeon Hwang <syeon.hwang@samsung.com>
  * MunKyu Im <munkyu.im@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
@@ -142,6 +142,23 @@ void set_bin_path_os(gchar * exec_argv)
     g_strlcat(bin_path, "\\", PATH_MAX);
 }
 
+int get_number_of_processors(void)
+{
+    SYSTEM_INFO sysi;
+    int num_processors = 0;
+
+    GetSystemInfo(&sysi);
+    TRACE("Processor type: %d, Core number: %d\n",
+        sysi.dwProcessorType, sysi.dwNumberOfProcessors);
+
+    num_processors = sysi.dwNumberOfProcessors;
+    if (num_processors < 1) {
+        num_processors = 1;
+    }
+
+    return num_processors;
+}
+
 void print_system_info_os(void)
 {
     INFO("* Windows\n");
@@ -164,9 +181,12 @@ void print_system_info_os(void)
     SYSTEM_INFO sysi;
     ZeroMemory(&sysi, sizeof(SYSTEM_INFO));
 
+#if 0
     GetSystemInfo(&sysi);
     INFO("* Processor type : %d, Number of processors : %d\n",
             sysi.dwProcessorType, sysi.dwNumberOfProcessors);
+#endif
+    get_number_of_processors();
 
     MEMORYSTATUSEX memInfo;
     memInfo.dwLength = sizeof(MEMORYSTATUSEX);
@@ -217,7 +237,7 @@ static int get_auto_proxy(BYTE *url, char *http_proxy, char *https_proxy, char *
             ERR("pac file is not wrong! It could be the wrong pac address or pac file format\n");
             fclose(fp_pacfile);
         }
-    } 
+    }
     else {
         ERR("fail to get pacfile fp\n");
         return -1;
@@ -264,7 +284,7 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
             lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, url, &dwLength);
             if (lRet == ERROR_SUCCESS && dwLength != 0) {
                 get_auto_proxy(url, http_proxy, https_proxy, ftp_proxy, socks_proxy);
-                RegCloseKey(hKey);      
+                RegCloseKey(hKey);
                 return 0;
             }
         }
@@ -294,7 +314,7 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
     }
     if (*(char*)proxyenable == 0) {
         free(proxyenable);
-        RegCloseKey(hKey);      
+        RegCloseKey(hKey);
         return 0;
     }
 
@@ -303,14 +323,14 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
     if (lRet != ERROR_SUCCESS && dwLength == 0) {
         ERR("Failed to query value from from %s\n",
                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
-        RegCloseKey(hKey);      
+        RegCloseKey(hKey);
         return 0;
     }
 
     proxyserver = (BYTE*)malloc(dwLength);
     if (proxyserver == NULL) {
         ERR( "Failed to allocate a buffer\n");
-        RegCloseKey(hKey);      
+        RegCloseKey(hKey);
         return 0;
     }
 
@@ -323,11 +343,11 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
         RegCloseKey(hKey);
         return 0;
     }
-    
+
     if((char*)proxyserver != NULL) {
         INFO("proxy value: %s\n", (char*)proxyserver);
         real_proxy = malloc(MAXLEN);
-        
+
         for(p = strtok((char*)proxyserver, ";"); p; p = strtok(NULL, ";")){
             if(strstr(p, HTTP_PROTOCOL)) {
                 remove_string(p, real_proxy, HTTP_PROTOCOL);
index f90527a..032d483 100644 (file)
@@ -72,5 +72,7 @@ void download_url(char *);
 size_t write_data(void *, size_t, size_t, FILE *);
 void remove_string(char *, char *, const char *);
 
+int get_number_of_processors(void);
+
 #endif // __OS_UTIL_H__