const void *data, int count);
int (*get)(const struct resource *res,
const struct resource_attribute *attr,
- void **data);
+ void *data);
};
struct resource_attribute {
int get_resource_attr_int64(struct resource *resource, u_int64_t attr_id, int64_t *data);
int get_resource_attr_uint(struct resource *resource, u_int64_t attr_id, u_int32_t *data);
int get_resource_attr_uint64(struct resource *resource, u_int64_t attr_id, u_int64_t *data);
-int get_resource_attr_double(struct resource *resource, u_int64_t attr_id, double **data);
-int put_resource_attr_double(struct resource *resource, u_int64_t attr_id);
-int get_resource_attr_string(struct resource *resource, u_int64_t attr_id, char **data);
-int put_resource_attr_string(struct resource *resource, u_int64_t attr_id);
+int get_resource_attr_double(struct resource *resource, u_int64_t attr_id, double *data);
+int get_resource_attr_string(struct resource *resource, u_int64_t attr_id, char *data);
int get_resource_attr_array(struct resource *resource, u_int64_t attr_id,
struct array_value **data);
-int put_resource_attr_array(struct resource *resource, u_int64_t attr_id);
int get_resource_attr_ptr(struct resource *resource, u_int64_t attr_id, void **data);
-int put_resource_attr_ptr(struct resource *resource, u_int64_t attr_id);
void set_resource_attr_interest(struct resource *resource, u_int64_t interest_mask);
void unset_resource_attr_interest(struct resource *resource, u_int64_t interest_mask);
#define PROCESS_CPU_UTIL BIT(0)
#define PROCESS_MEM_VIRT BIT(1)
#define PROCESS_MEM_RSS BIT(2)
-#define PROCESS_MEM_PERCENT BIT(3)
-#define PROCESS_DISK_READ BIT(4)
-#define PROCESS_DISK_WRITE BIT(5)
+#define PROCESS_MEM_RSS_PERCENT BIT(3)
+#define PROCESS_DISK_READ_BPS BIT(4)
+#define PROCESS_DISK_WRITE_BPS BIT(5)
#define PROCESS_COMM BIT(6)
#define PROCESS_CTRL_TGID BIT(0)
static int battery_get_info(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
char *path = NULL;
- int ret, val = 0;
+ int ret;
+ int *val = (int *)data;
if (!res || !attr || !data)
return -EINVAL;
return -EINVAL;
}
- ret = sysfs_get_int(path, &val);
+ ret = sysfs_get_int(path, val);
if (ret < 0)
return ret;
- *data = (void *)(intptr_t)val;
-
return 0;
}
static int battery_get_status(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
- char buf[BUFF_MAX];
+ char *buf = (char *)data;
int ret;
if (!res || !attr || !data)
if (ret < 0)
return ret;
- *data = strdup(buf);
- if (!*data)
- return -ENOMEM;
-
return 0;
}
int index;
};
-static int bus_get_cur_freq(const struct resource *res,
+static int bus_get_value_from_hal_power(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct bus_context *ctx;
- int val;
+ int *val = (int *)data;
+ int _val;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
return -EINVAL;
}
- val = hal_power_dvfs_get_curr_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int bus_get_min_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct bus_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: BUS_CTRL_DEVICE_ID is not yet initialized\n", res->name);
+ switch (attr->id) {
+ case BUS_CUR_FREQ:
+ _val = hal_power_dvfs_get_curr_freq(res->type, ctx->device_name);
+ break;
+ case BUS_MIN_FREQ:
+ _val = hal_power_dvfs_get_min_freq(res->type, ctx->device_name);
+ break;
+ case BUS_MAX_FREQ:
+ _val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
+ break;
+ case BUS_AVAILABLE_MIN_FREQ:
+ _val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
+ break;
+ case BUS_AVAILABLE_MAX_FREQ:
+ _val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
+ break;
+ default:
return -EINVAL;
}
- val = hal_power_dvfs_get_min_freq(res->type, ctx->device_name);
- if (val < 0)
+ if (_val < 0)
return -EINVAL;
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int bus_get_max_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct bus_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: BUS_CTRL_DEVICE_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int bus_get_available_min_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct bus_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: BUS_CTRL_DEVICE_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int bus_get_available_max_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct bus_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: BUS_CTRL_DEVICE_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
+ *val = _val;
return 0;
}
static int bus_get_curr_governor(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct bus_context *ctx;
- char buf[BUFF_MAX];
+ char *buf = (char *)data;
int val;
if (!res || !res->priv || !attr || !data)
if (val < 0)
return -EINVAL;
- *data = strdup(buf);
- if (!*data)
- return -ENOMEM;
-
return 0;
}
.id = BUS_CUR_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = bus_get_cur_freq,
+ .get = bus_get_value_from_hal_power,
},
}, {
.name = "BUS_MIN_FREQ",
.id = BUS_MIN_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = bus_get_min_freq,
+ .get = bus_get_value_from_hal_power,
},
}, {
.name = "BUS_MAX_FREQ",
.id = BUS_MAX_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = bus_get_max_freq,
+ .get = bus_get_value_from_hal_power,
}
}, {
.name = "BUS_AVAILABLE_MIN_FREQ",
.id = BUS_AVAILABLE_MIN_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = bus_get_available_min_freq,
+ .get = bus_get_value_from_hal_power,
}
}, {
.name = "BUS_AVAILABLE_MAX_FREQ",
.id = BUS_AVAILABLE_MAX_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = bus_get_available_max_freq,
+ .get = bus_get_value_from_hal_power,
}
}, {
.name = "BUS_CUR_GOVERNOR",
int index;
};
-static int cpu_get_cur_freq(const struct resource *res,
+static int cpu_get_value_from_hal_power(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct cpu_context *ctx;
- int val;
+ int *val = (int *)data;
+ int _val;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
return -EINVAL;
}
- val = hal_power_dvfs_get_curr_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int cpu_get_min_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct cpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: CPU_CTRL_CLUSTER_ID is not yet initialized\n", res->name);
+ switch (attr->id) {
+ case CPU_CUR_FREQ:
+ _val = hal_power_dvfs_get_curr_freq(res->type, ctx->device_name);
+ break;
+ case CPU_MIN_FREQ:
+ _val = hal_power_dvfs_get_min_freq(res->type, ctx->device_name);
+ break;
+ case CPU_MAX_FREQ:
+ _val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
+ break;
+ case CPU_AVAILABLE_MIN_FREQ:
+ _val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
+ break;
+ case CPU_AVAILABLE_MAX_FREQ:
+ _val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
+ break;
+ default:
return -EINVAL;
}
- val = hal_power_dvfs_get_min_freq(res->type, ctx->device_name);
- if (val < 0)
+ if (_val < 0)
return -EINVAL;
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int cpu_get_max_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct cpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: CPU_CTRL_CLUSTER_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int cpu_get_available_min_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct cpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: CPU_CTRL_CLUSTER_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int cpu_get_available_max_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct cpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: CPU_CTRL_CLUSTER_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
+ *val = _val;
return 0;
}
static int cpu_get_curr_governor(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct cpu_context *ctx;
- char buf[BUFF_MAX];
+ char *buf = (char *)data;
int val;
if (!res || !res->priv || !attr || !data)
if (val < 0)
return -EINVAL;
- *data = strdup(buf);
- if (!*data)
- return -ENOMEM;
-
return 0;
}
static int cpu_get_online_cpu(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
return 0;
}
static int cpu_get_temperature(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
return 0;
}
.id = CPU_CUR_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = cpu_get_cur_freq,
+ .get = cpu_get_value_from_hal_power,
},
}, {
.name = "CPU_MIN_FREQ",
.id = CPU_MIN_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = cpu_get_min_freq,
+ .get = cpu_get_value_from_hal_power,
},
}, {
.name = "CPU_MAX_FREQ",
.id = CPU_MAX_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = cpu_get_max_freq,
+ .get = cpu_get_value_from_hal_power,
}
}, {
.name = "CPU_AVAILABLE_MIN_FREQ",
.id = CPU_AVAILABLE_MIN_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = cpu_get_available_min_freq,
+ .get = cpu_get_value_from_hal_power,
}
}, {
.name = "CPU_AVAILABLE_MAX_FREQ",
.id = CPU_AVAILABLE_MAX_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = cpu_get_available_max_freq,
+ .get = cpu_get_value_from_hal_power,
}
}, {
.name = "CPU_CUR_GOVERNOR",
static int display_get_fps(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
GDBusConnection *conn;
GDBusMessage *msg, *reply;
GError *err = NULL;
struct display_fps_data fps_data;
int *disp_id;
- double *fps;
+ double *fps = (double *)data;
int ret = 0;
if (!res || !res->priv || !attr || !data)
&fps_data.window, &fps_data.fps);
out:
- fps = malloc(sizeof(double));
- if (!fps) {
- ret = -ENOMEM;
- goto err_reply;
- }
-
*fps = fps_data.fps;
- *data = (void *)fps;
err_reply:
g_object_unref(reply);
int index;
};
-static int gpu_get_cur_freq(const struct resource *res,
+static int gpu_get_value_from_hal_power(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct gpu_context *ctx;
- int val;
+ int *val = (int *)data;
+ int _val;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
return -EINVAL;
}
- val = hal_power_dvfs_get_curr_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int gpu_get_min_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct gpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: GPU_CTRL_DEVICE_ID is not yet initialized\n", res->name);
+ switch (attr->id) {
+ case GPU_CUR_FREQ:
+ _val = hal_power_dvfs_get_curr_freq(res->type, ctx->device_name);
+ break;
+ case GPU_MIN_FREQ:
+ _val = hal_power_dvfs_get_min_freq(res->type, ctx->device_name);
+ break;
+ case GPU_MAX_FREQ:
+ _val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
+ break;
+ case GPU_AVAILABLE_MIN_FREQ:
+ _val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
+ break;
+ case GPU_AVAILABLE_MAX_FREQ:
+ _val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
+ break;
+ default:
return -EINVAL;
}
- val = hal_power_dvfs_get_min_freq(res->type, ctx->device_name);
- if (val < 0)
+ if (_val < 0)
return -EINVAL;
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int gpu_get_max_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct gpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: GPU_CTRL_DEVICE_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int gpu_get_available_min_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct gpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: GPU_CTRL_DEVICE_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int gpu_get_available_max_freq(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct gpu_context *ctx;
- int val;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->device_name) {
- _E("%s: GPU_CTRL_DEVICE_ID is not yet initialized\n", res->name);
- return -EINVAL;
- }
-
- val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
- if (val < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
+ *val = _val;
return 0;
}
static int gpu_get_curr_governor(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct gpu_context *ctx;
- char buf[BUFF_MAX];
+ char *buf = (char *)data;
int val;
if (!res || !res->priv || !attr || !data)
if (val < 0)
return -EINVAL;
- *data = strdup(buf);
- if (!*data)
- return -ENOMEM;
-
return 0;
}
static int gpu_get_temperature(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
return 0;
}
.id = GPU_CUR_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = gpu_get_cur_freq,
+ .get = gpu_get_value_from_hal_power,
},
}, {
.name = "GPU_MIN_FREQ",
.id = GPU_MIN_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = gpu_get_min_freq,
+ .get = gpu_get_value_from_hal_power,
},
}, {
.name = "GPU_MAX_FREQ",
.id = GPU_MAX_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = gpu_get_max_freq,
+ .get = gpu_get_value_from_hal_power,
}
}, {
.name = "GPU_AVAILABLE_MIN_FREQ",
.id = GPU_AVAILABLE_MIN_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = gpu_get_available_min_freq,
+ .get = gpu_get_value_from_hal_power,
}
}, {
.name = "GPU_AVAILABLE_MAX_FREQ",
.id = GPU_AVAILABLE_MAX_FREQ,
.type = DATA_TYPE_INT,
.ops = {
- .get = gpu_get_available_max_freq,
+ .get = gpu_get_value_from_hal_power,
}
}, {
.name = "GPU_CUR_GOVERNOR",
#define PROC_MEM_INFO_MEM_AVAILABLE "MemAvailable"
#define PROC_MEM_INFO_MEM_FREE "MemFree"
-static inline int memory_read_val_from_proc_node(uint32_t val_id, u_int64_t *val)
+static int memory_get_memory_info(const struct resource *res,
+ const struct resource_attribute *attr,
+ void *data)
{
+ u_int64_t *val = (u_int64_t *)data;
int ret;
- switch (val_id) {
+ if (!res || !attr || !data)
+ return -EINVAL;
+
+ switch (attr->id) {
case MEMORY_TOTAL:
ret = kernel_get_memory_total(val);
break;
_E("wrong memory resource attribute\n");
ret = -EINVAL;
}
-
- return ret;
-}
-
-static int memory_get_total_memory(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- u_int64_t val;
- int ret;
-
- if (!res || !attr || !data)
- return -EINVAL;
-
- ret = memory_read_val_from_proc_node(attr->id, &val);
if (ret < 0)
return -EINVAL;
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int memory_get_available_memory(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- u_int64_t val;
- int ret;
-
- if (!res || !attr || !data)
- return -EINVAL;
-
- ret = memory_read_val_from_proc_node(attr->id, &val);
- if (ret < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
- return 0;
-}
-
-static int memory_get_free_memory(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- u_int64_t val;
- int ret;
-
- if (!res || !attr || !data)
- return -EINVAL;
-
- ret = memory_read_val_from_proc_node(attr->id, &val);
- if (ret < 0)
- return -EINVAL;
-
- *data = (void *)(intptr_t)val;
-
return 0;
}
.id = MEMORY_TOTAL,
.type = DATA_TYPE_UINT64,
.ops = {
- .get = memory_get_total_memory,
+ .get = memory_get_memory_info,
},
}, {
.name = "MEMORY_AVAILABLE",
.id = MEMORY_AVAILABLE,
.type = DATA_TYPE_UINT64,
.ops = {
- .get = memory_get_available_memory,
+ .get = memory_get_memory_info,
},
}, {
.name = "MEMORY_FREE",
.id = MEMORY_FREE,
.type = DATA_TYPE_UINT64,
.ops = {
- .get = memory_get_free_memory,
+ .get = memory_get_memory_info,
}
},
};
static int process_get_cpu_util(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct process_context *ctx;
struct taskstats *prev, *curr;
- double util = 0.0;
+ double *util = (double *)data;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
curr = &ctx->curr;
if (ctx->cpu_period >= 1E-6) {
- util = (double)(curr->ac_utime + curr->ac_stime);
- util -= (double)(prev->ac_utime + prev->ac_stime);
- util *= (jiffy / (ctx->cpu_period * 10.0));
-
- /*
- * To obtain precision after converting types between double and
- * void pointer, utilization increased 1000 times (0~100000), so
- * value should be divided by 1000 at user-side.
- */
- util = min(util, 100000.0);
+ *util = (double)(curr->ac_utime + curr->ac_stime);
+ *util -= (double)(prev->ac_utime + prev->ac_stime);
+ *util *= (jiffy / (ctx->cpu_period * 10000.0));
+ *util = min(*util, 100.0);
}
- *data = (void *)(intptr_t)(int)util;
-
return 0;
}
static int process_get_mem_virt(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct process_context *ctx;
struct taskstats *curr;
- double virt;
+ u_int64_t *virt = (u_int64_t *)data;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
curr = &ctx->curr;
- virt = (double)curr->virtmem / (double)curr->ac_stime;
- virt *= 1024.0 * 1000.0;
-
- *data = (void *)(uintptr_t)(int)virt;
+ *virt = (curr->virtmem * 1024 * 1024) / curr->ac_stime;
return 0;
}
static int process_get_mem_rss(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct process_context *ctx;
struct taskstats *curr;
- double rss;
+ u_int64_t _rss;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
curr = &ctx->curr;
- rss = (double)curr->coremem / (double)curr->ac_stime;
- rss *= 1024.0 * 1000.0;
+ _rss = (curr->coremem * 1024 * 1024) / curr->ac_stime;
switch (attr->id) {
case PROCESS_MEM_RSS:
- *data = (void *)(intptr_t)(int)rss;
+ {
+ u_int64_t *rss = (u_int64_t *)data;
+
+ *rss = _rss;
break;
- case PROCESS_MEM_PERCENT:
- /* percentage value should be divided by 1000 at user-side */
- *data = (void *)(intptr_t)(int)((rss / ctx->total_memory) * 100000.0);
+ }
+ case PROCESS_MEM_RSS_PERCENT:
+ {
+ double *percent = (double *)data;
+
+ *percent = ((double)_rss / (double)ctx->total_memory) * 100.0;
break;
+ }
default:
return -EINVAL;
}
return 0;
}
-static int process_get_disk_read(const struct resource *res,
+static int process_get_disk_bps(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct process_context *ctx;
struct taskstats *prev, *curr;
u_int64_t period;
- double bps = 0.0;
+ u_int32_t *bps = (u_int32_t *)data;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
curr = &ctx->curr;
period = curr->ac_etime - prev->ac_etime;
- bps = (double)(curr->read_bytes - prev->read_bytes) * 1000000 / period;
- *data = (void *)(intptr_t)(int)bps;
-
- return 0;
-}
-
-static int process_get_disk_write(const struct resource *res,
- const struct resource_attribute *attr,
- void **data)
-{
- struct process_context *ctx;
- struct taskstats *prev, *curr;
- u_int64_t period;
- double bps = 0.0;
-
- if (!res || !res->priv || !attr || !data)
- return -EINVAL;
-
- ctx = res->priv;
-
- if (!ctx->tgid) {
- _E("resource %s is not yet initialized\n", res->name);
+ switch (attr->id) {
+ case PROCESS_DISK_READ_BPS:
+ *bps = (curr->read_bytes - prev->read_bytes) * 1000000 / period;
+ break;
+ case PROCESS_DISK_WRITE_BPS:
+ *bps = (curr->write_bytes - prev->write_bytes) * 1000000 / period;
+ break;
+ default:
return -EINVAL;
}
-
- prev = &ctx->prev;
- curr = &ctx->curr;
-
- period = curr->ac_etime - prev->ac_etime;
-
- bps = (double)(curr->write_bytes - prev->write_bytes) * 1000000 / period;
-
- *data = (void *)(intptr_t)(int)bps;
-
return 0;
}
static int process_get_comm(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct process_context *ctx;
+ char *buf = (char *)data;
if (!res || !res->priv || !attr || !data)
return -EINVAL;
return -EINVAL;
}
- *data = g_strdup(ctx->comm);
+ strncpy(buf, ctx->comm, TS_COMM_LEN);
return 0;
}
{
.name = "PROCESS_CPU_UTIL",
.id = PROCESS_CPU_UTIL,
- .type = DATA_TYPE_INT,
+ .type = DATA_TYPE_DOUBLE,
.ops = {
.get = process_get_cpu_util,
},
{
.name = "PROCESS_MEM_VIRT",
.id = PROCESS_MEM_VIRT,
- .type = DATA_TYPE_INT,
+ .type = DATA_TYPE_UINT64,
.ops = {
.get = process_get_mem_virt,
},
{
.name = "PROCESS_MEM_RSS",
.id = PROCESS_MEM_RSS,
- .type = DATA_TYPE_INT,
+ .type = DATA_TYPE_UINT64,
.ops = {
.get = process_get_mem_rss,
},
},
{
- .name = "PROCESS_MEM_PERCENT",
- .id = PROCESS_MEM_PERCENT,
- .type = DATA_TYPE_INT,
+ .name = "PROCESS_MEM_RSS_PERCENT",
+ .id = PROCESS_MEM_RSS_PERCENT,
+ .type = DATA_TYPE_DOUBLE,
.ops = {
.get = process_get_mem_rss,
},
},
{
- .name = "PROCESS_DISK_READ",
- .id = PROCESS_DISK_READ,
- .type = DATA_TYPE_INT,
+ .name = "PROCESS_DISK_READ_BPS",
+ .id = PROCESS_DISK_READ_BPS,
+ .type = DATA_TYPE_UINT,
.ops = {
- .get = process_get_disk_read,
+ .get = process_get_disk_bps,
},
},
{
- .name = "PROCESS_DISK_WRITE",
- .id = PROCESS_DISK_WRITE,
- .type = DATA_TYPE_INT,
+ .name = "PROCESS_DISK_WRITE_BPS",
+ .id = PROCESS_DISK_WRITE_BPS,
+ .type = DATA_TYPE_UINT,
.ops = {
- .get = process_get_disk_write,
+ .get = process_get_disk_bps,
},
},
{
static int system_get_avg_cpu_util(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct system_resouce_data *sysdata;
- double *util;
+ double *util = (double *)data;
if (!res || !res->priv ||!attr || !data)
return -EINVAL;
- util = malloc(sizeof(double));
- if (!util)
- return -ENOMEM;
-
sysdata = (struct system_resouce_data *)res->priv;
*util = __calculate_cpu_util(attr->id, &sysdata->prev_avg, &sysdata->curr_avg);
- if (util < 0) {
+ if (*util < 0) {
_W("failed to calculate average cpu util (%s: %s)\n", res->name, attr->name);
*util = 0.0;
}
- *data = (void *)util;
return 0;
}
static int system_get_per_cpu_util(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
struct system_resouce_data *sysdata;
- struct array_value *array;
+ struct array_value *array = (struct array_value *)data;
double *utils;
int i;
sysdata = (struct system_resouce_data *)res->priv;
- array = calloc(1, sizeof(*array));
- if (!array)
- return -ENOMEM;
-
array->type = DATA_TYPE_DOUBLE;
array->length = sysdata->num_possible_cpus;
+
+ if (array->data)
+ free(array->data);
+
array->data = calloc(sysdata->num_possible_cpus, sizeof(double));
- if (!array->data) {
- free(array);
+ if (!array->data)
return -ENOMEM;
- }
+
utils = (double *)array->data;
for (i = 0; i < sysdata->num_possible_cpus; i++) {
utils[i] = 0;
}
}
- *data = (void *)array;
return 0;
}
static int system_get_cpu_num(const struct resource *res,
const struct resource_attribute *attr,
- void **data)
+ void *data)
{
- int cpu_num;
+ int *cpu_num = (int *)data;
if (!res || !attr || !data)
return -EINVAL;
switch (attr->id) {
case SYSTEM_POSSIBLE_CPU:
- cpu_num = kernel_get_online_cpu_num();
+ *cpu_num = kernel_get_online_cpu_num();
break;
case SYSTEM_ONLINE_CPU:
- cpu_num = kernel_get_possible_cpu_num();
+ *cpu_num = kernel_get_possible_cpu_num();
break;
default:
return -EINVAL;
}
- *data = (void *)(intptr_t)cpu_num;
-
return 0;
}
return -EINVAL;
attr = &resource->attrs[attr_index];
- attr_value = &resource->attrs_value[attr_index];
if (!attr->ops.get)
return -EINVAL;
- ret = attr->ops.get(resource, attr, &(attr_value->data));
+ attr_value = &resource->attrs_value[attr_index];
+
+ ret = attr->ops.get(resource, attr, attr_value->data);
if (ret < 0)
return ret;
if (!attr_value)
return -EINVAL;
- *data = (int32_t)(intptr_t)attr_value->data;
+ *data = *((int32_t *)attr_value->data);
return 0;
}
if (!attr_value)
return -EINVAL;
- *data = (int64_t)(intptr_t)attr_value->data;
+ *data = *((int64_t *)attr_value->data);
return 0;
}
if (!attr_value)
return -EINVAL;
- *data = (u_int32_t)(intptr_t)attr_value->data;
+ *data = *((u_int32_t *)attr_value->data);
return 0;
}
if (!attr_value)
return -EINVAL;
- *data = (u_int64_t)(intptr_t)attr_value->data;
+ *data = *((u_int64_t *)attr_value->data);
return 0;
}
-int get_resource_attr_double(struct resource *resource, u_int64_t attr_id, double **data)
+int get_resource_attr_double(struct resource *resource, u_int64_t attr_id, double *data)
{
struct resource_attribute_value *attr_value = NULL;
if (!attr_value)
return -EINVAL;
- *data = (double *)attr_value->data;
+ *data = *((double *)attr_value->data);
return 0;
}
-int put_resource_attr_double(struct resource *resource, u_int64_t attr_id)
-{
- struct resource_attribute_value *attr_value = NULL;
-
- if (!check_attr_validate(resource, attr_id, DATA_TYPE_DOUBLE))
- return -EINVAL;
-
- attr_value = get_resource_attr_value(resource, attr_id);
- if (!attr_value)
- return -EINVAL;
-
- free(attr_value->data);
- attr_value->data = NULL;
-
- return 0;
-}
-
-int get_resource_attr_string(struct resource *resource, u_int64_t attr_id, char **data)
+int get_resource_attr_string(struct resource *resource, u_int64_t attr_id, char *data)
{
struct resource_attribute_value *attr_value = NULL;
if (!attr_value)
return -EINVAL;
- *data = (char *)attr_value->data;
-
- return 0;
-}
-
-int put_resource_attr_string(struct resource *resource, u_int64_t attr_id)
-{
- struct resource_attribute_value *attr_value = NULL;
-
- if (!check_attr_validate(resource, attr_id, DATA_TYPE_STRING))
- return -EINVAL;
-
- attr_value = get_resource_attr_value(resource, attr_id);
- if (!attr_value || !attr_value->data)
- return -EINVAL;
-
- free(attr_value->data);
- attr_value->data = NULL;
+ strncpy(data, (char *)attr_value->data, BUFF_MAX);
return 0;
}
return 0;
}
-int put_resource_attr_array(struct resource *resource, u_int64_t attr_id)
-{
- struct resource_attribute_value *attr_value = NULL;
- struct array_value *array;
-
- if (!check_attr_validate(resource, attr_id, DATA_TYPE_ARRAY))
- return -EINVAL;
-
- attr_value = get_resource_attr_value(resource, attr_id);
- if (!attr_value || !attr_value->data)
- return -EINVAL;
-
- array = (struct array_value *)attr_value->data;
- if (array) {
- array->type = 0;
- array->length = 0;
- free(array->data);
- array->data = NULL;
- }
- free(attr_value->data);
- attr_value->data = NULL;
-
- return 0;
-}
-
int get_resource_attr_ptr(struct resource *resource, u_int64_t attr_id, void **data)
{
struct resource_attribute_value *attr_value = NULL;
return 0;
}
-int put_resource_attr_ptr(struct resource *resource, u_int64_t attr_id)
+void set_resource_attr_interest(struct resource *resource, u_int64_t interest_mask)
{
- struct resource_attribute_value *attr_value = NULL;
+ struct resource_attribute_value *attr_value;
+ int i;
- if (!check_attr_validate(resource, attr_id, DATA_TYPE_PTR))
- return -EINVAL;
-
- attr_value = get_resource_attr_value(resource, attr_id);
- if (!attr_value || !attr_value->data)
- return -EINVAL;
+ if (!resource)
+ return;
- free(attr_value->data);
- attr_value->data = NULL;
+ for (i = 0; i < resource->num_attrs; i++) {
+ if (!(resource->attrs[i].id & interest_mask))
+ continue;
- return 0;
-}
+ attr_value = get_resource_attr_value(resource, resource->attrs[i].id);
+ if (!attr_value) {
+ _E("failed to get attribute value: resource: %s, attribute: %s",
+ resource->name, resource->attrs[i].name);
+ return;
+ }
-void set_resource_attr_interest(struct resource *resource, u_int64_t interest_mask)
-{
- if (!resource)
- return;
+ /*
+ * In resource monitor, each resource has a lot of attributes, but
+ * only updated attributes are selected by clients on demand. So,
+ * instead of allocating memory at the resource creation, allocate
+ * at the set interest.
+ */
+ if (!attr_value->data) {
+ switch (attr_value->type) {
+ case DATA_TYPE_INT:
+ attr_value->data = calloc(1, sizeof(int32_t));
+ break;
+ case DATA_TYPE_INT64:
+ attr_value->data = calloc(1, sizeof(int64_t));
+ break;
+ case DATA_TYPE_UINT:
+ attr_value->data = calloc(1, sizeof(u_int32_t));
+ break;
+ case DATA_TYPE_UINT64:
+ attr_value->data = calloc(1, sizeof(u_int64_t));
+ break;
+ case DATA_TYPE_DOUBLE:
+ attr_value->data = calloc(1, sizeof(double));
+ break;
+ case DATA_TYPE_STRING:
+ attr_value->data = calloc(BUFF_MAX, sizeof(char));
+ break;
+ case DATA_TYPE_ARRAY:
+ attr_value->data = calloc(1, sizeof(struct array_value));
+ break;
+ default:
+ _E("Not supported data type: %d", attr_value->type);
+ return;
+ }
+ }
+ }
resource->attr_interest |= interest_mask;
}
void unset_resource_attr_interest(struct resource *resource, u_int64_t interest_mask)
{
+ struct resource_attribute_value *attr_value;
+ int i;
+
if (!resource)
return;
+ for (i = 0; i < resource->num_attrs; i++) {
+ if (!(resource->attrs[i].id & interest_mask))
+ continue;
+
+ attr_value = get_resource_attr_value(resource, resource->attrs[i].id);
+ if (!attr_value) {
+ _E("failed to get attribute value: resource: %s, attribute: %s",
+ resource->name, resource->attrs[i].name);
+ return;
+ }
+
+ if (attr_value->data) {
+ switch (attr_value->type) {
+ case DATA_TYPE_ARRAY:
+ {
+ struct array_value *array = attr_value->data;
+
+ if (array->data) {
+ free(array->data);
+ array->data = NULL;
+ }
+ /* fall through */
+ }
+ case DATA_TYPE_INT:
+ case DATA_TYPE_INT64:
+ case DATA_TYPE_UINT:
+ case DATA_TYPE_UINT64:
+ case DATA_TYPE_DOUBLE:
+ case DATA_TYPE_STRING:
+ free(attr_value->data);
+ attr_value->data = NULL;
+ break;
+ default:
+ _E("Not supported data type: %d", attr_value->type);
+ return;
+ }
+ }
+ }
+
resource->attr_interest &= ~interest_mask;
}