const struct resource_attribute_ops ops;
};
+struct resource_control;
+
+struct resource_control_ops {
+ const int (*set)(const struct resource *res,
+ const struct resource_control *ctrl,
+ const void *data);
+ const int (*get)(const struct resource *res,
+ const struct resource_control *ctrl,
+ void **data);
+};
+
+struct resource_control {
+ const char name[BUFF_MAX];
+ const u_int64_t id;
+ const struct resource_control_ops ops;
+};
+
struct resource_driver_ops {
int (*init)(struct resource *res);
void (*exit)(struct resource *res);
int (*prepare_update)(struct resource *res);
};
-/* resource driver flags */
-#define RESOURCE_DRIVER_NO_DEVICE BIT32(1)
-
struct resource_driver {
const char *name;
const int type;
- const int flags;
const int num_attrs;
const struct resource_attribute *attrs;
+ const int num_ctrls;
+ const struct resource_control *ctrls;
const struct resource_driver_ops ops;
};
char *name;
const struct resource_driver *driver;
int type;
- int index;
- void *user_data;
void *priv;
int num_attrs;
const struct resource_attribute *attrs;
struct resource_attribute_value *attrs_value;
+ int num_ctrls;
+ const struct resource_control *ctrls;
u_int64_t attr_interest;
};
void remove_resource_device(struct resource_device *resource_device);
/* Create/delete resource instance */
-struct resource *create_resource(int resource_type, int resource_index, void *user_data);
+struct resource *create_resource(int resource_type);
void delete_resource(struct resource *resource);
+/* Handle resource control */
+int set_resource_control(struct resource *resource, u_int64_t ctrl_id, const void *data);
+
/* Handle resource attribute */
int update_resource_attrs(struct resource *resource);
const struct resource_attribute *get_resource_attr(struct resource *resource, u_int64_t attr_id);
#define CPU_ONLINE_CPU BIT(6)
#define CPU_TEMPERATURE BIT(7)
+#define CPU_CTRL_CLUSTER_ID BIT(0)
+
#define BUS_CUR_FREQ BIT(0)
#define BUS_MIN_FREQ BIT(1)
#define BUS_MAX_FREQ BIT(2)
#define BUS_AVAILABLE_MAX_FREQ BIT(4)
#define BUS_CUR_GOVERNOR BIT(5)
+#define BUS_CTRL_DEVICE_ID BIT(0)
+
#define GPU_CUR_FREQ BIT(0)
#define GPU_MIN_FREQ BIT(1)
#define GPU_MAX_FREQ BIT(2)
#define GPU_CUR_GOVERNOR BIT(5)
#define GPU_TEMPERATURE BIT(6)
+#define GPU_CTRL_DEVICE_ID BIT(0)
+
#define MEMORY_TOTAL BIT(0)
#define MEMORY_AVAILABLE BIT(1)
#define MEMORY_FREE BIT(2)
#define DISPLAY_FPS BIT(0)
+#define DISPLAY_CTRL_DEVICE_ID BIT(0)
+
#define SYSTEM_CPU_UTIL BIT(0)
#define SYSTEM_CPU_USER_UTIL BIT(1)
#define SYSTEM_CPU_SYS_UTIL BIT(2)
#define PROCESS_DISK_WRITE BIT(5)
#define PROCESS_COMM BIT(6)
+#define PROCESS_CTRL_TGID BIT(0)
+
/**
* @brief Initialize the tizen monitor
* @param[in] Timer period (unit: millisecond, minimum value is 100ms)
.type = RESOURCE_TYPE_BATTERY,
.attrs = battery_attrs,
.num_attrs = ARRAY_SIZE(battery_attrs),
- .flags = RESOURCE_DRIVER_NO_DEVICE,
};
RESOURCE_DRIVER_REGISTER(&battery_resource_driver)
#include <tmonitor/tmonitor.h>
+struct bus_context {
+ char *device_name;
+ int index;
+};
+
static int bus_get_cur_freq(const struct resource *res,
const struct resource_attribute *attr,
void **data)
{
+ struct bus_context *ctx;
int val;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
- val = hal_power_dvfs_get_curr_freq(res->type, res->name);
+ 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_curr_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct bus_context *ctx;
int val;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
- val = hal_power_dvfs_get_min_freq(res->type, res->name);
+ 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_min_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct bus_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct bus_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct bus_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct bus_context *ctx;
char buf[BUFF_MAX];
int val;
- if (!res || !attr || !data)
+ 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_curr_governor(res->type, res->name, buf);
+ val = hal_power_dvfs_get_curr_governor(res->type, ctx->device_name, buf);
if (val < 0)
return -EINVAL;
},
};
+static int bus_setup_device_id(const struct resource *res,
+ const struct resource_control *ctrl,
+ const void *data)
+{
+ struct bus_context *ctx;
+ const struct resource_device *device;
+ int device_id = (int)(intptr_t)data;
+
+ if (!res || !res->priv || !ctrl)
+ return -EINVAL;
+
+ device = find_resource_device(res->type, device_id);
+ if (!device) {
+ _E("Not available resource: type: %s, index: %d\n",
+ res->name, device_id);
+ return -EINVAL;
+ }
+
+ ctx = res->priv;
+
+ if (ctx->device_name)
+ free(ctx->device_name);
+
+ ctx->device_name = g_strdup(device->name);
+ ctx->index = device_id;
+
+ return 0;
+}
+
+static const struct resource_control bus_ctrls[] = {
+ {
+ .name = "BUS_CTRL_DEVICE_ID",
+ .id = BUS_CTRL_DEVICE_ID,
+ .ops = {
+ .set = bus_setup_device_id,
+ },
+ },
+};
+
+static int bus_init(struct resource *res)
+{
+ struct bus_context *ctx;
+
+ ctx = calloc(1, sizeof(struct bus_context));
+ if (!ctx)
+ return -ENOMEM;
+
+ res->priv = ctx;
+
+ return 0;
+}
+
+static void bus_exit(struct resource *res)
+{
+ struct bus_context *ctx;
+
+ if (res && res->priv) {
+ ctx = res->priv;
+ if (ctx->device_name) {
+ free(ctx->device_name);
+ ctx->device_name = NULL;
+ }
+ free(ctx);
+ res->priv = NULL;
+ }
+}
+
static const struct resource_driver bus_resource_driver = {
.name = "Memory Bus",
.type = RESOURCE_TYPE_BUS,
.attrs = bus_attrs,
.num_attrs = ARRAY_SIZE(bus_attrs),
+ .ctrls = bus_ctrls,
+ .num_ctrls = ARRAY_SIZE(bus_ctrls),
+ .ops = {
+ .init = bus_init,
+ .exit = bus_exit,
+ },
};
RESOURCE_DRIVER_REGISTER(&bus_resource_driver)
+
#include <tmonitor/tmonitor.h>
+struct cpu_context {
+ char *device_name;
+ int index;
+};
+
static int cpu_get_cur_freq(const struct resource *res,
const struct resource_attribute *attr,
void **data)
{
+ struct cpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
- val = hal_power_dvfs_get_curr_freq(res->type, res->name);
+ 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_curr_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct cpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
- val = hal_power_dvfs_get_min_freq(res->type, res->name);
+ 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_min_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct cpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_max_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct cpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct cpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct cpu_context *ctx;
char buf[BUFF_MAX];
int val;
- if (!res || !attr || !data)
+ 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_curr_governor(res->type, res->name, buf);
+ val = hal_power_dvfs_get_curr_governor(res->type, ctx->device_name, buf);
if (val < 0)
return -EINVAL;
},
};
+static int cpu_setup_cluster_id(const struct resource *res,
+ const struct resource_control *ctrl,
+ const void *data)
+{
+ struct cpu_context *ctx;
+ const struct resource_device *device;
+ int resource_index = (int)(intptr_t)data;
+
+ if (!res || !res->priv || !ctrl)
+ return -EINVAL;
+
+ device = find_resource_device(res->type, resource_index);
+ if (!device) {
+ _E("Not available resource: type: %s, index: %d\n",
+ res->name, resource_index);
+ return -EINVAL;
+ }
+
+ ctx = res->priv;
+
+ if (ctx->device_name)
+ free(ctx->device_name);
+
+ ctx->device_name = g_strdup(device->name);
+ ctx->index = resource_index;
+
+ return 0;
+}
+
+static const struct resource_control cpu_ctrls[] = {
+ {
+ .name = "CPU_CTRL_CLUSTER_ID",
+ .id = CPU_CTRL_CLUSTER_ID,
+ .ops = {
+ .set = cpu_setup_cluster_id,
+ },
+ },
+};
+
+static int cpu_init(struct resource *res)
+{
+ struct cpu_context *ctx;
+
+ ctx = calloc(1, sizeof(struct cpu_context));
+ if (!ctx)
+ return -ENOMEM;
+
+ res->priv = ctx;
+
+ return 0;
+}
+
+static void cpu_exit(struct resource *res)
+{
+ struct cpu_context *ctx;
+
+ if (res && res->priv) {
+ ctx = res->priv;
+ if (ctx->device_name) {
+ free(ctx->device_name);
+ ctx->device_name = NULL;
+ }
+ free(ctx);
+ res->priv = NULL;
+ }
+}
+
static const struct resource_driver cpu_resource_driver = {
.name = "CPU",
.type = RESOURCE_TYPE_CPU,
.attrs = cpu_attrs,
.num_attrs = ARRAY_SIZE(cpu_attrs),
+ .ctrls = cpu_ctrls,
+ .num_ctrls = ARRAY_SIZE(cpu_ctrls),
+ .ops = {
+ .init = cpu_init,
+ .exit = cpu_exit,
+ },
};
RESOURCE_DRIVER_REGISTER(&cpu_resource_driver)
+
GVariant *result, *value;
GError *err = NULL;
struct display_fps_data fps_data;
+ int *disp_id;
int ret = 0;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
+ disp_id = res->priv;
+
+ if (*disp_id < 0) {
+ _E("%s: DISPLAY_CTRL_DEVICE_ID is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
/* Connect dbus interface and receive message */
conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
if (err) {
/* Parse the received data */
result = g_variant_get_child_value(g_dbus_message_get_body(reply), 0);
- if (g_variant_n_children(result) <= res->index) {
+ if (g_variant_n_children(result) == 0) {
fps_data.fps = 0.0;
goto out;
}
/* Get the fps information according to the index of resource_device */
- value = g_variant_get_child_value(result, res->index);
+ value = g_variant_get_child_value(result, *disp_id);
g_variant_get(value, "(usiud)",
&fps_data.type, fps_data.output, &fps_data.zpos,
&fps_data.window, &fps_data.fps);
},
};
+static int display_setup_device_id(const struct resource *res,
+ const struct resource_control *ctrl,
+ const void *data)
+{
+ int *disp_id;
+
+ if (!res || !res->priv || !ctrl)
+ return -EINVAL;
+
+ disp_id = res->priv;
+
+ *disp_id = (int)(intptr_t)data;
+
+ return 0;
+}
+
+static const struct resource_control display_ctrls[] = {
+ {
+ .name = "DISPLAY_CTRL_DEVICE_ID",
+ .id = DISPLAY_CTRL_DEVICE_ID,
+ .ops = {
+ .set = display_setup_device_id,
+ },
+ },
+};
+
+static int display_init(struct resource *res)
+{
+ int *disp_id;
+
+ disp_id = malloc(sizeof(int));
+ if (!disp_id)
+ return -ENOMEM;
+
+ *disp_id = -1;
+
+ res->priv = disp_id;
+
+ return 0;
+}
+
+static void display_exit(struct resource *res)
+{
+ if (res && res->priv)
+ free(res->priv);
+}
static const struct resource_driver display_resource_driver = {
.name = "DISPLAY",
.type = RESOURCE_TYPE_DISPLAY,
.attrs = display_attrs,
.num_attrs = ARRAY_SIZE(display_attrs),
- .flags = RESOURCE_DRIVER_NO_DEVICE,
+ .ctrls = display_ctrls,
+ .num_ctrls = ARRAY_SIZE(display_ctrls),
+ .ops = {
+ .init = display_init,
+ .exit = display_exit,
+ },
};
RESOURCE_DRIVER_REGISTER(&display_resource_driver)
#include <tmonitor/tmonitor.h>
+struct gpu_context {
+ char *device_name;
+ int index;
+};
+
static int gpu_get_cur_freq(const struct resource *res,
const struct resource_attribute *attr,
void **data)
{
+ struct gpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
- val = hal_power_dvfs_get_curr_freq(res->type, res->name);
+ 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_curr_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct gpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ if (!res || !res->priv || !attr || !data)
return -EINVAL;
- val = hal_power_dvfs_get_min_freq(res->type, res->name);
+ 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_min_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct gpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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_max_freq(res->type, res->name);
+ val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct gpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_available_min_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct gpu_context *ctx;
int val;
- if (!res || !attr || !data)
+ 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, res->name);
+ val = hal_power_dvfs_get_available_max_freq(res->type, ctx->device_name);
if (val < 0)
return -EINVAL;
const struct resource_attribute *attr,
void **data)
{
+ struct gpu_context *ctx;
char buf[BUFF_MAX];
int val;
- if (!res || !attr || !data)
+ 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_curr_governor(res->type, res->name, buf);
+ val = hal_power_dvfs_get_curr_governor(res->type, ctx->device_name, buf);
if (val < 0)
return -EINVAL;
},
};
+static int gpu_setup_device_id(const struct resource *res,
+ const struct resource_control *ctrl,
+ const void *data)
+{
+ struct gpu_context *ctx;
+ const struct resource_device *device;
+ int resource_index = (int)(intptr_t)data;
+
+ if (!res || !res->priv || !ctrl)
+ return -EINVAL;
+
+ device = find_resource_device(res->type, resource_index);
+ if (!device) {
+ _E("Not available resource: type: %s, index: %d\n",
+ res->name, resource_index);
+ return -EINVAL;
+ }
+
+ ctx = res->priv;
+
+ if (ctx->device_name)
+ free(ctx->device_name);
+
+ ctx->device_name = g_strdup(device->name);
+ ctx->index = resource_index;
+
+ return 0;
+}
+
+static const struct resource_control gpu_ctrls[] = {
+ {
+ .name = "GPU_CTRL_DEVICE_ID",
+ .id = GPU_CTRL_DEVICE_ID,
+ .ops = {
+ .set = gpu_setup_device_id,
+ },
+ },
+};
+
+static int gpu_init(struct resource *res)
+{
+ struct gpu_context *ctx;
+
+ ctx = calloc(1, sizeof(struct gpu_context));
+ if (!ctx)
+ return -ENOMEM;
+
+ res->priv = ctx;
+
+ return 0;
+}
+
+static void gpu_exit(struct resource *res)
+{
+ struct gpu_context *ctx;
+
+ if (res && res->priv) {
+ ctx = res->priv;
+ if (ctx->device_name) {
+ free(ctx->device_name);
+ ctx->device_name = NULL;
+ }
+ free(ctx);
+ res->priv = NULL;
+ }
+}
+
static const struct resource_driver gpu_resource_driver = {
.name = "GPU",
.type = RESOURCE_TYPE_GPU,
.attrs = gpu_attrs,
.num_attrs = ARRAY_SIZE(gpu_attrs),
+ .ctrls = gpu_ctrls,
+ .num_ctrls = ARRAY_SIZE(gpu_ctrls),
+ .ops = {
+ .init = gpu_init,
+ .exit = gpu_exit,
+ },
};
RESOURCE_DRIVER_REGISTER(&gpu_resource_driver)
+
.type = RESOURCE_TYPE_MEMORY,
.attrs = memory_attrs,
.num_attrs = ARRAY_SIZE(memory_attrs),
- .flags = RESOURCE_DRIVER_NO_DEVICE,
};
RESOURCE_DRIVER_REGISTER(&memory_resource_driver)
#include <tmonitor/tmonitor.h>
struct process_context {
- pid_t pid;
+ pid_t tgid;
char comm[TS_COMM_LEN];
struct taskstats prev;
struct taskstats curr;
return -EINVAL;
ctx = res->priv;
+
+ if (!ctx->tgid) {
+ _E("resource %s is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
prev = &ctx->prev;
curr = &ctx->curr;
return -EINVAL;
ctx = res->priv;
+
+ if (!ctx->tgid) {
+ _E("resource %s is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
curr = &ctx->curr;
virt = (double)curr->virtmem / (double)curr->ac_stime;
return -EINVAL;
ctx = res->priv;
+
+ if (!ctx->tgid) {
+ _E("resource %s is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
curr = &ctx->curr;
rss = (double)curr->coremem / (double)curr->ac_stime;
return -EINVAL;
ctx = res->priv;
+
+ if (!ctx->tgid) {
+ _E("resource %s is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
prev = &ctx->prev;
curr = &ctx->curr;
return -EINVAL;
ctx = res->priv;
+
+ if (!ctx->tgid) {
+ _E("resource %s is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
prev = &ctx->prev;
curr = &ctx->curr;
return -EINVAL;
ctx = res->priv;
+
+ if (!ctx->tgid) {
+ _E("resource %s is not yet initialized\n", res->name);
+ return -EINVAL;
+ }
+
*data = g_strdup(ctx->comm);
return 0;
memset(curr, 0, sizeof(struct taskstats));
- sprintf(task_dir_path, "/proc/%d/task/", ctx->pid);
+ sprintf(task_dir_path, "/proc/%d/task/", ctx->tgid);
task_dir = opendir(task_dir_path);
if (!task_dir)
return 0;
}
+static int process_setup_tgid(const struct resource *res,
+ const struct resource_control *ctrl,
+ const void *data)
+{
+ struct taskstats stats;
+ struct process_context *ctx;
+ u_int64_t total_memory;
+ int ret;
+
+ if (!res || !res->priv || !ctrl)
+ return -EINVAL;
+
+ ctx = res->priv;
+
+ total_memory = ctx->total_memory;
+ memset(ctx, 0, sizeof(*ctx));
+
+ ctx->total_memory = total_memory;
+ ctx->tgid = (pid_t)(intptr_t)data;
+ ctx->prev_total_time = get_total_cpu_time();
+
+ /* update initial status */
+ ret = update_taskstats(ctx);
+ if (ret < 0)
+ return -EINVAL;
+
+ ret = query_taskstats(&stats, TASKSTATS_CMD_ATTR_PID, ctx->tgid);
+ if (ret < 0)
+ return -EINVAL;
+
+ memcpy(ctx->comm, stats.ac_comm, TS_COMM_LEN);
+
+ return 0;
+}
+
+static const struct resource_control process_ctrls[] = {
+ {
+ .name = "PROCESS_CTRL_TGID",
+ .id = PROCESS_CTRL_TGID,
+ .ops = {
+ .set = process_setup_tgid,
+ },
+ },
+};
+
static int process_prepare_update(struct resource *res)
{
struct process_context *ctx = res->priv;
static int process_init(struct resource *res)
{
- struct taskstats stats;
struct process_context *ctx;
int ret;
if (!ctx)
return -ENOMEM;
- ctx->prev_total_time = get_total_cpu_time();
- ctx->pid = (pid_t)(intptr_t)res->user_data;
-
ret = kernel_get_memory_total(&ctx->total_memory);
if (ret < 0) {
free(ctx);
return -EINVAL;
}
- /* update initial status */
- ret = update_taskstats(ctx);
- if (ret < 0) {
- free(ctx);
- return -EINVAL;
- }
-
- ret = query_taskstats(&stats, TASKSTATS_CMD_ATTR_PID, ctx->pid);
- if (ret < 0) {
- free(ctx);
- return -EINVAL;
- }
- memcpy(ctx->comm, stats.ac_comm, TS_COMM_LEN);
-
res->priv = ctx;
return 0;
.name = "PROCESS",
.type = RESOURCE_TYPE_PROCESS,
.attrs = process_attrs,
- .flags = RESOURCE_DRIVER_NO_DEVICE,
.num_attrs = ARRAY_SIZE(process_attrs),
+ .ctrls = process_ctrls,
+ .num_ctrls = ARRAY_SIZE(process_ctrls),
.ops = {
.init = process_init,
.exit = process_exit,
util = __calculate_cpu_util(attr->id, &sysdata->prev_avg, &sysdata->curr_avg);
if (util < 0) {
- _W("failed to calculate average cpu util (%s.%d: %s)\n",
- res->name, res->index, attr->name);
+ _W("failed to calculate average cpu util (%s: %s)\n", res->name, attr->name);
util = 0;
}
*data = (void *)(intptr_t)util;
&sysdata->prev_cpus[i],
&sysdata->curr_cpus[i]);
if (utils[i] < 0) {
- _W("failed to calculate per-cpu util (%s.%d: %s)\n",
- res->name, res->index, attr->name);
+ _W("failed to calculate per-cpu util (%s: %s)\n", res->name, attr->name);
utils[i] = 0;
}
}
ret = kernel_get_possible_cpu_num();
if (ret < 0) {
- _I("failed to get possible cpu on system driver (%s.%d)\n",
- res->name, res->index);
+ _I("failed to get possible cpu on system driver (%s)\n", res->name);
goto err;
}
sysdata->num_possible_cpus = ret;
sysdata->prev_cpus = calloc(sysdata->num_possible_cpus,
sizeof(struct cpu_stat));
if (!sysdata->prev_cpus) {
- _I("failed to allocate memory of prev_cpus (%s.%d)\n",
- res->name, res->index);
+ _I("failed to allocate memory of prev_cpus (%s)\n", res->name);
ret = -ENOMEM;
goto err;
}
sysdata->curr_cpus = calloc(sysdata->num_possible_cpus,
sizeof(struct cpu_stat));
if (!sysdata->curr_cpus) {
- _I("failed to allocate memory of curr_cpus (%s.%d)\n",
- res->name, res->index);
+ _I("failed to allocate memory of curr_cpus (%s)\n", res->name);
ret = -ENOMEM;
goto err_prev_cpus;
}
memcpy(&sysdata->prev_avg, &sysdata->curr_avg, sizeof(sysdata->prev_avg));
ret = kernel_get_total_cpu_stat(&sysdata->curr_avg);
if (ret < 0) {
- _I("failed to calculate average cpu util (%s:%d)\n",
- res->name, res->index);
+ _I("failed to calculate average cpu util (%s)\n", res->name);
return ret;
}
sysdata->num_possible_cpus,
&sysdata->num_online_cpus);
if (ret < 0) {
- _I("failed to calculate per-cpu util (%s:%d)\n",
- res->name, res->index);
+ _I("failed to calculate per-cpu util (%s)\n", res->name);
return ret;
}
.type = RESOURCE_TYPE_SYSTEM,
.attrs = system_attrs,
.num_attrs = ARRAY_SIZE(system_attrs),
- .flags = RESOURCE_DRIVER_NO_DEVICE,
.ops = {
.init = system_driver_init,
.exit = system_driver_exit,
#include <util/log.h>
#define RESOURCE_ATTR_MASK (ULLONG_MAX)
-#define RESOURCE_ATTR_INDEX(id) (63 - __builtin_clzll(id))
+#define BIT64_INDEX(id) (63 - __builtin_clzll(id))
+#define RESOURCE_ATTR_INDEX(id) BIT64_INDEX(id)
+#define RESOURCE_CTRL_INDEX(id) BIT64_INDEX(id)
static GList *g_resource_driver_head;
static GList *g_resource_device_head;
do_delete_resource(resource);
}
-struct resource *create_resource(int resource_type, int resource_index,
- void *user_data)
+struct resource *create_resource(int resource_type)
{
- const struct resource_device *device = NULL;
const struct resource_driver *driver = NULL;
struct resource *resource = NULL;
int i, ret;
if (!driver)
return NULL;
- if (!(driver->flags & RESOURCE_DRIVER_NO_DEVICE)) {
- device = find_resource_device(resource_type, resource_index);
- if (!device) {
- _E("Not available resource: type: %d, index: %d\n",
- resource_type, resource_index);
- return NULL;
- }
- }
-
resource = calloc(1, sizeof(*resource));
if (!resource)
return NULL;
- if (device) {
- resource->type = device->type;
- resource->name = g_strdup(device->name);
- resource->index = device->index;
- } else {
- resource->type = resource_type;
- resource->name = g_strdup(driver->name);
- resource->index = resource_index;
- }
+ resource->type = resource_type;
+ resource->name = g_strdup(driver->name);
resource->driver = driver;
- resource->user_data = user_data;
resource->num_attrs = driver->num_attrs;
resource->attrs = driver->attrs;
resource->attrs_value = calloc(resource->num_attrs,
for (i = 0; i < resource->num_attrs; i++)
resource->attrs_value[i].type = driver->attrs[i].type;
+ resource->ctrls = driver->ctrls;
+ resource->num_ctrls = driver->num_ctrls;
+
if (driver->ops.init) {
ret = driver->ops.init(resource);
if (ret < 0) {
return resource;
}
+int set_resource_control(struct resource *resource, u_int64_t ctrl_id, const void *data)
+{
+ const struct resource_control *ctrl;
+ int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
+ int ret;
+
+ if (!resource)
+ return -EINVAL;
+
+ ctrl = &resource->ctrls[ctrl_index];
+ if (!ctrl->ops.set)
+ return -ENOTSUP;
+
+ ret = ctrl->ops.set(resource, ctrl, data);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
static int update_resource_attr(struct resource *resource, u_int64_t attr_id)
{
int attr_index = RESOURCE_ATTR_INDEX(attr_id);