Each resource are able to have the non-common features.
The resource flag will be used to indicate the characteristics
of resource.
- RESOURCE_FLAG_COUNT_ONLY_ONE
: Some resource's resource count is only one on all board such as system and
memory resources. Add this flag when want to return 1 as resource count.
- RESOURCE_FLAG_PROCESS
: process and process-group are not physical resource like CPU/GPU/Memory.
Sometimes, it should be handled by the different handling. In order to
separate out them, use this flag.
Change-Id: Ic7df2cae2105b14382c0f084c30fbbcde5efdac4
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
#include <glib.h>
#include "common.h"
+/* Resource flags */
+/*
+ * This flags indicates that the resource has the only one resource count
+ * such as system/memory resources.
+ */
+#define RESOURCE_FLAG_COUNT_ONLY_ONE BIT(0)
+
+/*
+ * This flag incidates that resource is either process or process-group
+ * and is not physical h/w resource.
+ */
+#define RESOURCE_FLAG_PROCESS BIT(1)
+
struct resource;
struct resource_attribute;
struct resource_driver {
const char *name;
const int type;
+ const u_int64_t flag;
const int num_attrs;
const struct resource_attribute *attrs;
const int num_ctrls;
static const struct resource_driver memory_resource_driver = {
.name = "MEMORY",
.type = RESOURCE_TYPE_MEMORY,
+ .flag = RESOURCE_FLAG_COUNT_ONLY_ONE,
.attrs = memory_attrs,
.num_attrs = ARRAY_SIZE(memory_attrs),
};
static const struct resource_driver process_group_driver = {
.name = "PROCESS_GROUP",
.type = RESOURCE_TYPE_PROCESS_GROUP,
+ .flag = RESOURCE_FLAG_PROCESS,
.attrs = process_group_attrs,
.num_attrs = ARRAY_SIZE(process_group_attrs),
.ctrls = process_group_ctrls,
static const struct resource_driver process_resource_driver = {
.name = "PROCESS",
.type = RESOURCE_TYPE_PROCESS,
+ .flag = RESOURCE_FLAG_PROCESS,
.attrs = process_attrs,
.num_attrs = ARRAY_SIZE(process_attrs),
.ctrls = process_ctrls,
static const struct resource_driver system_resource_driver = {
.name = "SYSTEM",
.type = RESOURCE_TYPE_SYSTEM,
+ .flag = RESOURCE_FLAG_COUNT_ONLY_ONE,
.attrs = system_attrs,
.num_attrs = ARRAY_SIZE(system_attrs),
.ops = {
return -1;
}
+static const struct resource_driver *find_resource_driver(int resource_type)
+{
+ GList *node;
+
+ node = g_list_find_custom(g_resource_driver_head,
+ &resource_type, __compare_resource_type);
+
+ if (!node)
+ return NULL;
+ return (struct resource_driver *)node->data;
+}
+
void add_resource_driver(const struct resource_driver *driver)
{
if (!driver)
{
GList *node;
struct resource_device *device;
+ const struct resource_driver *driver;
int count = 0;
for (node = g_resource_device_head; node != NULL; node = node->next) {
count++;
}
- return count;
+ if (count > 0)
+ return count;
+
+ driver = find_resource_driver(resource_type);
+ if (!driver)
+ return -EINVAL;
+
+ if (driver->flag & RESOURCE_FLAG_COUNT_ONLY_ONE)
+ return 1;
+ else if (driver->flag & RESOURCE_FLAG_PROCESS)
+ return -EINVAL;
+
+ return 0;
}
const struct resource_device *find_resource_device(int resource_type,
g_list_remove(g_resource_device_head, (gpointer)device);
}
-static const struct resource_driver *find_resource_driver(int resource_type)
-{
- GList *node;
-
- node = g_list_find_custom(g_resource_driver_head,
- &resource_type, __compare_resource_type);
-
- if (!node)
- return NULL;
- return (struct resource_driver *)node->data;
-}
-
static void do_delete_resource(struct resource *resource)
{
if (!resource->name)
RESOURCE_TYPE_GPU,
RESOURCE_TYPE_MEMORY,
RESOURCE_TYPE_BATTERY,
- RESOURCE_TYPE_PROCESS,
RESOURCE_TYPE_DISPLAY,
RESOURCE_TYPE_SYSTEM,
- RESOURCE_TYPE_PROCESS_GROUP,
RESOURCE_TYPE_DISK,
RESOURCE_TYPE_NETWORK,
};
int res_types[] = {
RESOURCE_TYPE_UNKNOWN,
RESOURCE_TYPE_NONSTANDARD,
+ RESOURCE_TYPE_PROCESS,
+ RESOURCE_TYPE_PROCESS_GROUP,
};
int id = pass_resource_monitor_init();
for (i = 0; i < (int)ARRAY_SIZE(res_types); i++) {
int count;
int ret = pass_resource_monitor_get_resource_count(id, res_types[i], &count);
- EXPECT_EQ(ret, 0);
+ EXPECT_NE(ret, 0);
}
int ret = pass_resource_monitor_exit(id);
.ctrl_id = 0,
.attrs = system_attrs,
.num_attrs = ARRAY_SIZE(system_attrs),
- .res_count = 1,
}, {
.type = RESOURCE_TYPE_MEMORY,
.ctrl_id = 0,