From: Kitae Kim Date: Wed, 4 Sep 2013 03:03:41 +0000 (+0900) Subject: osutil: Added a function that get the number of host processors. X-Git-Tag: TizenStudio_2.0_p2.3~622 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06023889558a8e4c302953c6bd3b1435d0cb0270;p=sdk%2Femulator%2Fqemu.git osutil: Added a function that get the number of host processors. 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 --- diff --git a/tizen/src/osutil-darwin.c b/tizen/src/osutil-darwin.c index c47ee89..0b3ee7c 100644 --- a/tizen/src/osutil-darwin.c +++ b/tizen/src/osutil-darwin.c @@ -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; diff --git a/tizen/src/osutil-linux.c b/tizen/src/osutil-linux.c index f7fd45d..91ca6c7 100644 --- a/tizen/src/osutil-linux.c +++ b/tizen/src/osutil-linux.c @@ -1,9 +1,9 @@ -/* +/* * Emulator * * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: + * Contact: * SeokYeon Hwang * MunKyu Im * GiWoong Kim @@ -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); diff --git a/tizen/src/osutil-win32.c b/tizen/src/osutil-win32.c index 35e40be..d650641 100644 --- a/tizen/src/osutil-win32.c +++ b/tizen/src/osutil-win32.c @@ -1,9 +1,9 @@ -/* +/* * Emulator * * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: + * Contact: * SeokYeon Hwang * MunKyu Im * GiWoong Kim @@ -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); diff --git a/tizen/src/osutil.h b/tizen/src/osutil.h index f90527a..032d483 100644 --- a/tizen/src/osutil.h +++ b/tizen/src/osutil.h @@ -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__