#define MEMORY_ATTR_CACHED BIT(4) /* DATA_TYPE_UINT64 */
#define MEMORY_ATTR_CMA_TOTAL BIT(5) /* DATA_TYPE_UINT64 */
#define MEMORY_ATTR_CMA_FREE BIT(6) /* DATA_TYPE_UINT64 */
+#define MEMORY_ATTR_SWAP_TOTAL BIT(7) /* DATA_TYPE_UINT64 */
+#define MEMORY_ATTR_SWAP_FREE BIT(8) /* DATA_TYPE_UINT64 */
/* Battery Resource */
#define BATTERY_ATTR_CAPACITY BIT(0) /* DATA_TYPE_INT */
#define PROC_MEM_INFO_BUFFER "Buffers"
#define PROC_MEM_INFO_CACHED "Cached"
#define PROC_MEM_INFO_CMA_FREE "CmaFree"
+#define PROC_MEM_INFO_SWAP_FREE "SwapFree"
static int memory_get_cma_total(u_int64_t *val)
{
return 0;
}
+static int memory_get_swap_total(u_int64_t *val)
+{
+ static u_int64_t swap_total = 0;
+ int ret;
+
+ if (!swap_total) {
+ ret = kernel_get_memory_info("SwapTotal", &swap_total);
+ if (ret < 0) {
+ _E("failed to get system SWAP total memory\n");
+ return -EINVAL;
+ }
+ }
+
+ *val = swap_total;
+
+ return 0;
+}
+
static int memory_get_memory_info(const struct resource *res,
const struct resource_attribute *attr,
void *data)
case MEMORY_ATTR_CMA_FREE:
ret = kernel_get_memory_info(PROC_MEM_INFO_CMA_FREE, val);
break;
+ case MEMORY_ATTR_SWAP_TOTAL:
+ ret = memory_get_swap_total(val);
+ break;
+ case MEMORY_ATTR_SWAP_FREE:
+ ret = kernel_get_memory_info(PROC_MEM_INFO_SWAP_FREE, val);
+ break;
default:
_E("wrong memory resource attribute\n");
ret = -EINVAL;
.ops = {
.get = memory_get_memory_info,
}
+ }, {
+ .name = "MEMORY_ATTR_SWAP_TOTAL",
+ .id = MEMORY_ATTR_SWAP_TOTAL,
+ .type = DATA_TYPE_UINT64,
+ .ops = {
+ .get = memory_get_memory_info,
+ }
+ }, {
+ .name = "MEMORY_ATTR_SWAP_FREE",
+ .id = MEMORY_ATTR_SWAP_FREE,
+ .type = DATA_TYPE_UINT64,
+ .ops = {
+ .get = memory_get_memory_info,
+ }
},
};