return MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION;
}
- MM_RM_INFO("Successfully added resource type %d [%s]", type, _mm_resource_manager_get_res_str(type));
+ MM_RM_DEBUG("Successfully added resource type %d [%s]", type, _mm_resource_manager_get_res_str(type));
rset->type = type;
ret = MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION;
} else {
if (rset->mrp_rset->state == MRP_RES_RESOURCE_LOST) {
- MM_RM_INFO("Could not acquire rset %p. Priority is too low.", rset);
+ MM_RM_ERROR("Could not acquire rset %p. Priority is too low.", rset);
ret = MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION;
} else {
- MM_RM_INFO("Acquired rset %p", rset);
+ MM_RM_DEBUG("Acquired rset %p", rset);
ret = MM_RESOURCE_MANAGER_ERROR_NONE;
}
}
MM_RM_ERROR("Timeout elapsed");
ret = MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION;
} else {
- MM_RM_INFO("Released rset %p [%s]", rset, _mm_resource_manager_get_res_str(rset->type));
+ MM_RM_DEBUG("Released rset %p [%s]", rset, _mm_resource_manager_get_res_str(rset->type));
ret = MM_RESOURCE_MANAGER_ERROR_NONE;
}
}
static void _mm_resource_manager_rset_state_callback(mrp_res_context_t *cx, const mrp_res_resource_set_t *rs, void *user_data)
{
- int i = 0;
- mrp_res_resource_t *res = NULL;
mm_resource_manager_rset_s *rset = (mm_resource_manager_rset_s *) user_data;
g_mutex_lock(&rset->lock);
return;
}
- MM_RM_INFO(" -- resource set state (%p) is changed to [%s]", rs, state_str[rs->state]);
- for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
- res = mrp_res_get_resource_by_name(rs, _mm_resource_manager_get_res_str(i));
- if (res == NULL)
- MM_RM_INFO(" -- %s not present in resource set", _mm_resource_manager_get_res_str(i));
- else
- MM_RM_INFO(" -- resource name [%s] -> [%s]'", res->name, state_str[res->state]);
- }
+ MM_RM_DEBUG(" -- resource set state (%p) is changed to [%s]", rs, state_str[rs->state]);
mrp_res_delete_resource_set(rset->mrp_rset);
rset->mrp_rset = mrp_res_copy_resource_set(rs);
switch (rs->state) {
case MRP_RES_RESOURCE_ACQUIRED:
- MM_RM_INFO("rset (%p) is acquired", rset);
+ MM_RM_DEBUG("rset (%p) is acquired", rset);
g_cond_signal(&rset->cond);
break;
case MRP_RES_RESOURCE_AVAILABLE:
- MM_RM_INFO("rset (%p) is released", rset);
+ MM_RM_DEBUG("rset (%p) is released", rset);
g_cond_signal(&rset->cond);
break;
case MRP_RES_RESOURCE_LOST:
- MM_RM_INFO("rset (%p) cannot be acquired", rset);
+ MM_RM_DEBUG("rset (%p) cannot be acquired", rset);
g_cond_signal(&rset->cond);
break;
default:
#include "daemon/backend/mm_resource_manager_backend.h"
#include "common/mm_resource_manager_utils.h"
-
-
#define MM_RESOURCE_MANAGER_RESERVED_RM_ARRAY_SIZE 64 /* preallocated size */
#define MM_RESOURCE_MANAGER_RESERVED_PART_ARRAY_SIZE 4 /* preallocated size */
#define MM_RESOURCE_MANAGER_RESERVED_CALLBACK_ARRAY_SIZE 32 /* preallocated size */
#define MM_RESOURCE_MANGER_NOT_FOUND -1
#define RELEASE_CB_SYNC_TIMEOUT 300 /* miliseconds */
-
+typedef enum {
+ MM_RESOURCE_MANAGER_RES_STATE_FOR_ACQUIRE,
+ MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED,
+ MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE
+} mm_resource_manager_res_state_e;
typedef struct {
- gboolean is_acquired;
+ mm_resource_manager_res_state_e state;
/* NULL means, the resource is acquired fully or is not acquired at all */
GArray *parts;
mm_resource_manager_res_volume volume;
} mm_resource_manager_dmn_release_cb_request_s;
-
+static const char *res_state_str[] = {
+ "FOR ACQUIRE",
+ "ACQUIRED",
+ "FOR RELEASE",
+};
static GPtrArray *managers;
static int res_count[MM_RESOURCE_MANAGER_RES_TYPE_MAX];
static void __handle_release_callbacks(GArray *requests);
static inline void __add_cb_request(GArray *cb_requests, mm_resource_manager_dmn_p mgr,
mm_resource_manager_res_type_e type, mm_resource_manager_res_volume volume);
-static void __release_all_resources(mm_resource_manager_dmn_p manager);
+static void __destroy_all_resources(mm_resource_manager_dmn_p manager);
static gboolean __poll(struct pollfd sync, mm_resource_manager_id id);
static gboolean __wait_for_release_cb_sync(mm_resource_manager_id id);
if (managers) {
for (i = 0; i < managers->len; i++)
- __release_all_resources((mm_resource_manager_dmn_p)managers->pdata[i]);
+ __destroy_all_resources((mm_resource_manager_dmn_p)managers->pdata[i]);
mm_resource_manager_backend_commit_all();
g_ptr_array_free(managers, TRUE);
type = i_mgr->type;
- __release_all_resources(i_mgr);
+ __destroy_all_resources(i_mgr);
mm_resource_manager_backend_commit_all();
g_ptr_array_remove_index_fast(managers, idx);
MM_RM_RETVM_IF(manager->resources[type] == NULL,
MM_RESOURCE_MANAGER_ERROR_NOT_SUPPORTED, "There is no resource %s for the platform", res_name);
- if (manager->resources[type]->is_acquired) {
+ if (manager->resources[type]->state == MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED) {
if (manager->resources[type]->parts == NULL) {
if (releases->volume != MM_RESOURCE_MANAGER_RES_VOLUME_FULL) {
MM_RM_ERROR("Resource %s is acquired fully, but a resource part is tried to be released", res_name);
i_mgr = (mm_resource_manager_dmn_p)managers->pdata[i];
if (i_mgr != manager && conf->priority[i_mgr->app_class] > conf->priority[manager->app_class] &&
- i_mgr->resources[type]->is_acquired) {
+ i_mgr->resources[type]->state == MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED) {
if (i_mgr->resources[type]->parts) {
if (requests->volume == MM_RESOURCE_MANAGER_RES_VOLUME_FULL) {
requests->priority_error = TRUE;
i_mgr = (mm_resource_manager_dmn_p)managers->pdata[i];
if (manager->id == i_mgr->id || conf->priority[i_mgr->app_class] >conf->priority[manager->app_class]) {
- i_mgr->resources[type]->is_acquired = TRUE;
+ i_mgr->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED;
i_mgr->type = type;
i_mgr->volume = volume;
- MM_RM_INFO("Reset the value of acquire in RM #%"PRIu64" (type %s mgr %p)", _mm_rm_hash64(i_mgr->id), res_name, i_mgr);
+ MM_RM_DEBUG("Reset the value of acquire in RM #%"PRIu64" (type %s mgr %p)", _mm_rm_hash64(i_mgr->id), res_name, i_mgr);
if (conf->max_instance[type] > 0)
res_count[type]++;
continue;
mm_resource_manager_backend_release(type);
- MM_RM_INFO("Resource %s will be released (is acquired %d) in RM #%"PRIu64" available volume %d", res_name,
- i_mgr->resources[type]->is_acquired, _mm_rm_hash64(i_mgr->id), conf->max_volume[type]);
+ if (i_mgr->resources[type]->state == MM_RESOURCE_MANAGER_RES_STATE_FOR_ACQUIRE)
+ MM_RM_DEBUG("Resource %s will be released (%s state) in RM #%"PRIu64" available volume %d", res_name,
+ res_state_str[i_mgr->resources[type]->state], _mm_rm_hash64(i_mgr->id), conf->max_volume[type]);
+ else
+ MM_RM_DEBUG("Resource %s will be released (%s state) in RM #%"PRIu64" available volume %d", res_name,
+ res_state_str[i_mgr->resources[type]->state], _mm_rm_hash64(i_mgr->id), conf->max_volume[type]);
}
}
} else {
i_mgr = (mm_resource_manager_dmn_p)managers->pdata[j];
res = i_mgr->resources[type]->parts;
- if (res && i_mgr->resources[type]->is_acquired) {
+ if (res && i_mgr->resources[type]->state == MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED) {
MM_RM_INFO("[#%d] [#%d / #%d] will be released %s in RM #%"PRIu64,
managers->len, i + 1, res->len, res_name, _mm_rm_hash64(i_mgr->id));
if (manager->id == i_mgr->id || conf->priority[i_mgr->app_class] > conf->priority[manager->app_class]) {
if (conf->volume_would_be_checked[type]) {
- if (!i_mgr->resources[type]->is_acquired && conf->max_volume[type] >= 0) {
- i_mgr->resources[type]->is_acquired = TRUE;
+ if (i_mgr->resources[type]->state != MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED && conf->max_volume[type] >= 0) {
+ i_mgr->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED;
i_mgr->type = type;
i_mgr->volume = volume;
conf->max_volume[type] -= volume;
j_mgr = (mm_resource_manager_dmn_p)managers->pdata[j];
res = j_mgr->resources[type]->parts;
- if (!j_mgr->resources[type]->is_acquired)
+ if (j_mgr->resources[type]->state != MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED)
continue;
acquired_volume += g_array_index(res, mm_resource_manager_res_volume, 0);
}
}
- if (i_mgr->resources[type]->is_acquired)
+ if (i_mgr->resources[type]->state == MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED)
res_count[type]++;
- i_mgr->resources[type]->is_acquired = TRUE;
+ i_mgr->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED;
}
}
g_array_append_val(res, requests->volume);
}
}
- manager->resources[type]->is_acquired = TRUE;
+ manager->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED;
mm_resource_manager_backend_acquire(type);
- MM_RM_INFO("RM #%"PRIu64" (type %s mgr %p) is acquired", _mm_rm_hash64(i_mgr->id), res_name, i_mgr);
+ MM_RM_DEBUG("RM #%"PRIu64" (type %s mgr %p) is acquired", _mm_rm_hash64(i_mgr->id), res_name, i_mgr);
}
return cb_requests;
type = request->type;
volume = request->volume;
- if (!mgr->resources[type]->is_acquired)
+ if (mgr->resources[type]->state != MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED)
continue;
id = mgr->id;
MM_RM_HASH64(id);
- if (mgr->type == type && mgr->volume == volume && !mgr->resources[type]->is_acquired) {
- MM_RM_WARNING("Resource (mgr %p) release callback is already completed RM #%"PRIu64" for %s of volume %d",
+ if (mgr->type == type && mgr->volume == volume && mgr->resources[type]->state == MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE) {
+ MM_RM_WARNING("Resource (mgr %p) release callback is already invoked RM #%"PRIu64" for %s of volume %d",
mgr, id, _mm_resource_manager_get_res_str(type), volume);
continue;
}
_mmrm_dmn_dbus_release_callback(id, type, volume);
if (__wait_for_release_cb_sync(id)) {
- MM_RM_INFO("Release callback sync success RM #%"PRIu64, id);
+ MM_RM_INFO("[SYNC] Release callback success RM #%"PRIu64, id);
if (conf->volume_would_be_checked[type] && volume != MM_RESOURCE_MANAGER_RES_VOLUME_FULL) {
conf->max_volume[type] += volume;
- MM_RM_INFO("type %d available volume + %d = %d", type, volume, conf->max_volume[type]);
+ MM_RM_DEBUG("type %d available volume + %d = %d", type, volume, conf->max_volume[type]);
}
if (conf->max_instance[type] > 0 && res_count[type] > 0) {
res_count[type]--;
- MM_RM_INFO("The number of type %d #%d", type, res_count[type]);
+ MM_RM_DEBUG("The number of type %d #%d", type, res_count[type]);
}
- mgr->resources[type]->is_acquired = FALSE;
- MM_RM_INFO("RM #%"PRIu64" (type %s mgr %p) set acquired value as false (%d)",
- id, _mm_resource_manager_get_res_str(type), mgr, mgr->resources[type]->is_acquired);
+ mgr->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE;
+ MM_RM_DEBUG("RM #%"PRIu64" (type %s mgr %p) set acquired value as state (%s)",
+ id, _mm_resource_manager_get_res_str(type), mgr, res_state_str[mgr->resources[type]->state]);
} else {
MM_RM_ERROR("Wait for release callback sync failed RM #%"PRIu64" (type %s)", id, _mm_resource_manager_get_res_str(type));
}
volume = requests->volume;
if (volume == MM_RESOURCE_MANAGER_RES_VOLUME_FULL) {
- manager->resources[type]->is_acquired = FALSE;
+ manager->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE;
} else {
parts = manager->resources[type]->parts;
for (i = 0; i < parts->len && ((mm_resource_manager_res_volume*)parts->data)[i] != volume; i++);
if (parts->len == 0) {
g_array_free(parts, TRUE);
manager->resources[type]->parts = NULL;
- manager->resources[type]->is_acquired = FALSE;
+ manager->resources[type]->state = MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE;
}
}
}
}
-static void __release_all_resources(mm_resource_manager_dmn_p manager)
+static void __destroy_all_resources(mm_resource_manager_dmn_p manager)
{
int i, j;
for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
- if (manager->resources[i] && manager->resources[i]->is_acquired) {
+ if (manager->resources[i] && manager->resources[i]->state == MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED) {
if (manager->resources[i]->parts) {
for (j = 0; j < manager->resources[i]->parts->len; j++)
mm_resource_manager_backend_release(i);
} else {
mm_resource_manager_backend_release(i);
}
- manager->resources[i]->is_acquired = FALSE;
+ manager->resources[i]->state = MM_RESOURCE_MANAGER_RES_STATE_FOR_ACQUIRE;
}
}
}
break;
}
- MM_RM_INFO("[fd %d] RM #%"PRIu64" revents : 0x%x", sync.fd, id, sync.revents);
+ MM_RM_DEBUG("[fd %d] RM #%"PRIu64" revents : 0x%x", sync.fd, id, sync.revents);
return TRUE;
}
*resource_h = resource;
- MM_RM_INFO("Resource %p of type %d with volume %d is marked for acquire in RM #%"PRIu64,
+ MM_RM_DEBUG("Resource %p of type %d with volume %d is marked for acquire in RM #%"PRIu64,
*resource_h, type, volume, _mm_rm_hash64(handle->id));
__mm_resources_unlock(handle);
resource = (mm_resource_manager_res_p)resource_h;
- MM_RM_INFO("[invoked : %d state : %s] Resource %p is marked for release in resource #%"PRIu64,
+ MM_RM_DEBUG("[invoked : %d state : %s] Resource %p is marked for release in resource #%"PRIu64,
handle->release_cb.is_invoked, res_state_str[resource->state], resource_h, handle_id);
if (handle_id != _mm_rm_hash64(resource->handle_id))
- MM_RM_WARNING("handle RM #%"PRIu64" is not resource RM #%"PRIu64, handle_id, _mm_rm_hash64(resource->handle_id));
+ MM_RM_INFO("handle RM #%"PRIu64" is not resource RM #%"PRIu64, handle_id, _mm_rm_hash64(resource->handle_id));
/* FIXME : We should consider resource lock's vulnerability because of using global variable of 'handles_lock' */
if (handle->release_cb.is_invoked) {
ret = __dbus_commit(handle);
if (ret == MM_RESOURCE_MANAGER_ERROR_NONE)
- MM_RM_INFO("Changes in RM #%"PRIu64" have been committed successfully", _mm_rm_hash64(handle->id));
+ MM_RM_DEBUG("Changes in RM #%"PRIu64" have been committed successfully", _mm_rm_hash64(handle->id));
else
MM_RM_ERROR("Dbus commit request failed");
__mm_resources_unlock(handle);
handle_id = handle->id;
MM_RM_HASH64(handle_id);
- MM_RM_INFO("Release callback is invoked for %s of volume %d in handle RM #%"PRIu64" input RM #%"PRIu64,
+ MM_RM_DEBUG("Release callback is invoked for %s of volume %d in handle RM #%"PRIu64" input RM #%"PRIu64,
_mm_resource_manager_get_res_str(type), volume, handle_id, id);
if (handle_id == id) {
g_ptr_array_remove_index_fast(handle->resources, idx);
- MM_RM_INFO("resource length %d => %d", prev_len, handle->resources->len);
+ MM_RM_DEBUG("resource length %d => %d", prev_len, handle->resources->len);
break;
}
mm_resource_manager_res_p i_res;
int i;
- MM_RM_INFO("[RM #%"PRIu64" type : %d] resource (#%d) for the platform", _mm_rm_hash64(rm->id), type, local_volume);
+ MM_RM_DEBUG("[RM #%"PRIu64" type : %d] resource (#%d) for the platform", _mm_rm_hash64(rm->id), type, local_volume);
if (volume > 0) {
for (i = 0; i < rm->resources->len; i++) {
MM_RM_RETM_IF(sync_fd == -1, "Sync FIFO cannot be opened [errno %d]", errno);
if (write(sync_fd, &id, sizeof(id)) == sizeof(id))
- MM_RM_DEBUG("Sync message is sent successfully RM #%"PRIu64, _mm_rm_hash64(id));
+ MM_RM_INFO("[SYNC] message is sent successfully RM #%"PRIu64, _mm_rm_hash64(id));
else
- MM_RM_ERROR("Sync message cannot be sent RM #%"PRIu64, _mm_rm_hash64(id));
+ MM_RM_ERROR("[SYNC] message cannot be sent RM #%"PRIu64, _mm_rm_hash64(id));
close(sync_fd);
}