Add new API for getting physical memory size 00/117500/4 accepted/tizen/common/20170316.161534 accepted/tizen/ivi/20170316.101447 accepted/tizen/mobile/20170316.101338 accepted/tizen/tv/20170316.101358 accepted/tizen/unified/20170316.101457 accepted/tizen/wearable/20170316.101429 submit/tizen/20170316.010706
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 6 Mar 2017 07:56:44 +0000 (16:56 +0900)
committerKwon <k_c.kwon@samsung.com>
Wed, 15 Mar 2017 04:43:06 +0000 (21:43 -0700)
- /proc/meminfo supports the memory size except kernel reserved memory
- However, somebody want to get physical(total) memory size
- Therefore, we have to support two kinds of memory size
- Physical memory size = number of page * page size

Change-Id: I72711f1980dc8ade60578edb0ab7360f2d3f8aa5
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
include/runtime_info.h
src/runtime_info_usage.c

index 6aa5143..1abb9b4 100644 (file)
@@ -412,6 +412,18 @@ int runtime_info_get_processor_current_frequency(int core_idx, int *cpu_freq);
 int runtime_info_get_processor_max_frequency(int core_idx, int *cpu_freq);
 
 /**
+ * @brief  Gets the physical memory size.
+ * @since_tizen 4.0
+ *
+ * @param[out]  size Physical memory size (KiB)
+ *
+ * @retval  #RUNTIME_INFO_ERROR_NONE  Successful
+ * @retval  #RUNTIME_INFO_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #RUNTIME_INFO_ERROR_IO_ERROR  An I/O error occurred (during file open operation)
+ */
+int runtime_info_get_physical_memory_size(int *size);
+
+/**
  * @}
  */
 
index 4a05400..2699e2b 100644 (file)
@@ -196,29 +196,6 @@ API int runtime_info_get_system_memory_info(runtime_memory_info_s *info)
        info->used = mem_available ? (info->total - mem_available) : (info->total - info->free - info->cache);
        info->swap = kBtoKiB(((swap_total > swap_free) ? (int)(swap_total - swap_free) : 0));
 
-       /*
-        * Get total memory size from zoneinfo
-        *
-        * meminfo show the total memory size
-        * except kernel reserved memory
-        *
-        * Therefore, we will use (the number of page * page size)
-        */
-       fp = fopen("/proc/zoneinfo", "r");
-       if (fp == NULL) {
-               _E("IO_ERROR(0x%08x) : failed to open file to read memory size",
-                               RUNTIME_INFO_ERROR_IO_ERROR);
-               return RUNTIME_INFO_ERROR_IO_ERROR;
-       }
-
-       info->total = 0;
-       while (fgets(buf, sizeof(buf), fp) != NULL)
-               if (sscanf(buf, " spanned %lu", &value) == 1)
-                       info->total += value;
-       info->total = pagetoKiB(info->total);
-
-       fclose(fp);
-
        return RUNTIME_INFO_ERROR_NONE;
 }
 
@@ -552,3 +529,33 @@ API int runtime_info_get_processor_max_frequency(int core_idx, int *cpu_freq)
 
        return RUNTIME_INFO_ERROR_NONE;
 }
+
+API int runtime_info_get_physical_memory_size(int *size)
+{
+       char buf[256];
+       unsigned long value;
+       int sum;
+       FILE *fp = fopen("/proc/zoneinfo", "r");
+       if (!fp) {
+               _E("IO_ERROR(0x%08x) : failed to open file to read memory size",
+                               RUNTIME_INFO_ERROR_IO_ERROR);
+               return RUNTIME_INFO_ERROR_IO_ERROR;
+       }
+
+       if (!size) {
+               _E("INVALID PARAMETER(0x%08x) : invalid output parameter",
+                               RUNTIME_INFO_ERROR_INVALID_PARAMETER);
+               fclose(fp);
+               return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
+       }
+
+       sum = 0;
+       while (fgets(buf, sizeof(buf), fp) != NULL)
+               if (sscanf(buf, " spanned %lu", &value) == 1)
+                       sum += value;
+       *size = pagetoKiB(sum);
+
+       fclose(fp);
+
+       return RUNTIME_INFO_ERROR_NONE;
+}