Exemple #1
0
void mtapi_group_set_attribute(
  MTAPI_IN mtapi_group_hndl_t group,
  MTAPI_IN mtapi_uint_t attribute_num,
  MTAPI_OUT void* attribute,
  MTAPI_IN mtapi_size_t attribute_size,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
  embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
  embb_mtapi_group_t* local_group;

  embb_mtapi_log_trace("mtapi_group_set_attribute() called\n");

  if (embb_mtapi_node_is_initialized()) {
    if (embb_mtapi_group_pool_is_handle_valid(node->group_pool, group)) {
      local_group = embb_mtapi_group_pool_get_storage_for_handle(
        node->group_pool, group);
      mtapi_groupattr_set(&local_group->attributes, attribute_num,
        attribute, attribute_size, &local_status);
    } else {
      local_status = MTAPI_ERR_GROUP_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
}
Exemple #2
0
void mtapi_action_enable(
  MTAPI_IN mtapi_action_hndl_t action,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  embb_mtapi_log_trace("mtapi_action_enable() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    if (embb_mtapi_action_pool_is_handle_valid(node->action_pool, action)) {
      embb_mtapi_action_t* local_action =
        embb_mtapi_action_pool_get_storage_for_handle(
          node->action_pool, action);
      local_action->enabled = MTAPI_TRUE;
      local_status = MTAPI_SUCCESS;
    } else {
      local_status = MTAPI_ERR_ACTION_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
}
Exemple #3
0
void mtapi_action_set_attribute(
  MTAPI_IN mtapi_action_hndl_t action,
  MTAPI_IN mtapi_uint_t attribute_num,
  MTAPI_IN void* attribute,
  MTAPI_IN mtapi_size_t attribute_size,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  embb_mtapi_log_trace("mtapi_action_set_attribute() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    if (embb_mtapi_action_pool_is_handle_valid(node->action_pool, action)) {
      embb_mtapi_action_t* local_action =
        embb_mtapi_action_pool_get_storage_for_handle(
          node->action_pool, action);
      mtapi_actionattr_set(
        &local_action->attributes,
        attribute_num,
        attribute,
        attribute_size,
        &local_status);
    } else {
      local_status = MTAPI_ERR_ACTION_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
}
void embb_mtapi_id_pool_deallocate(
  embb_mtapi_id_pool_t * that,
  mtapi_uint_t id) {
  assert(MTAPI_NULL != that);

  if (embb_mtapi_spinlock_acquire(&that->lock)) {
    if (that->capacity > that->ids_availabe) {
      /* acquire position to put id to */
      mtapi_uint_t id_position = that->put_id_position;
      that->put_id_position++;
      if (that->capacity <= that->put_id_position) {
        that->put_id_position = 0;
      }

      /* put id back into buffer */
      that->id_buffer[id_position] = id;

      /* make it available */
      that->ids_availabe++;
    }
    embb_mtapi_spinlock_release(&that->lock);
  } else {
    embb_mtapi_log_error(
      "could not acquire lock in embb_mtapi_IdPool_deallocate\n");
  }
}
Exemple #5
0
void mtapi_action_get_attribute(
  MTAPI_IN mtapi_action_hndl_t action,
  MTAPI_IN mtapi_uint_t attribute_num,
  MTAPI_OUT void* attribute,
  MTAPI_IN mtapi_size_t attribute_size,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  embb_mtapi_log_trace("mtapi_action_get_attribute() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    if (embb_mtapi_action_pool_is_handle_valid(node->action_pool, action)) {
      embb_mtapi_action_t* local_action =
        embb_mtapi_action_pool_get_storage_for_handle(
          node->action_pool, action);

      if (MTAPI_NULL == attribute) {
        local_status = MTAPI_ERR_PARAMETER;
      } else {
        switch (attribute_num) {
        case MTAPI_ACTION_GLOBAL:
          local_status = embb_mtapi_attr_get_mtapi_boolean_t(
            &local_action->attributes.global, attribute, attribute_size);
          break;

        case MTAPI_ACTION_AFFINITY:
          local_status = embb_mtapi_attr_get_mtapi_affinity_t(
            &local_action->attributes.affinity, attribute, attribute_size);
          break;

        case MTAPI_ACTION_DOMAIN_SHARED:
          local_status = embb_mtapi_attr_get_mtapi_boolean_t(
            &local_action->attributes.domain_shared,
            attribute,
            attribute_size);
          break;

        default:
          /* attribute unknown */
          local_status = MTAPI_ERR_ATTR_NUM;
          break;
        }
      }
    } else {
      local_status = MTAPI_ERR_ACTION_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
}
mtapi_boolean_t embb_mtapi_thread_context_start(
  embb_mtapi_thread_context_t* that,
  embb_mtapi_scheduler_t * scheduler) {
  int err;
  embb_mtapi_scheduler_worker_func_t * worker_func;
  embb_core_set_t core_set;

  assert(MTAPI_NULL != that);
  assert(MTAPI_NULL != scheduler);

  worker_func = embb_mtapi_scheduler_worker_func(scheduler);

  /* pin thread to core */
  embb_core_set_init(&core_set, 0);
  embb_core_set_add(&core_set, that->core_num);

  /* create thread */
  if (that->is_main_thread) {
    /* reuse main thread */
    that->thread = embb_thread_current();
    err = embb_tss_create(&that->tss_id);
    if (EMBB_SUCCESS != err) {
      /* report error to scheduler */
      embb_atomic_store_int(&that->run, -1);
      return MTAPI_FALSE;
    }
    embb_tss_set(&(that->tss_id), that);
    embb_atomic_store_int(&that->run, 1);
  } else {
    err = embb_thread_create_with_priority(
      &that->thread, &core_set, that->thread_priority, worker_func, that);
    if (EMBB_SUCCESS != err) {
      embb_mtapi_log_error(
        "embb_mtapi_ThreadContext_initializeWithNodeAndCoreNumber() could not "
        "create thread %d on core %d\n", that->worker_index, that->core_num);
      return MTAPI_FALSE;
    }
    /* wait for worker to come up */
    while (0 == embb_atomic_load_int(&that->run)) {
      embb_thread_yield();
    }
  }

  if (0 < embb_atomic_load_int(&that->run)) {
    return MTAPI_TRUE;
  } else {
    return MTAPI_FALSE;
  }
}
Exemple #7
0
void mtapi_group_get_attribute(
  MTAPI_IN mtapi_group_hndl_t group,
  MTAPI_IN mtapi_uint_t attribute_num,
  MTAPI_OUT void* attribute,
  MTAPI_IN mtapi_size_t attribute_size,
  MTAPI_OUT mtapi_status_t* status ) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  EMBB_UNUSED(attribute_num);
  EMBB_UNUSED(attribute_size);

  embb_mtapi_log_trace("mtapi_group_get_attribute() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    if (embb_mtapi_group_pool_is_handle_valid(node->group_pool, group)) {
      /* the following is not needed for now, since there are no attributes

      embb_mtapi_group_t* local_group =
        embb_mtapi_group_pool_get_storage_for_handle(
          node->group_pool, group); */

      if (MTAPI_NULL == attribute) {
        local_status = MTAPI_ERR_PARAMETER;
      } else {
        /* switch is not needed for now, since there are no attributes
        switch (attribute_num) {
        default: */
          local_status = MTAPI_ERR_ATTR_NUM;
        /*  break;
        }*/
      }
    } else {
      local_status = MTAPI_ERR_GROUP_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
}
Exemple #8
0
mtapi_group_hndl_t mtapi_group_create(
  MTAPI_IN mtapi_group_id_t group_id,
  MTAPI_IN mtapi_group_attributes_t* attributes,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
  embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
  mtapi_group_hndl_t group_hndl = { 0, EMBB_MTAPI_IDPOOL_INVALID_ID };
  embb_mtapi_group_t* group = NULL;

  embb_mtapi_log_trace("mtapi_group_create() called\n");

  if (embb_mtapi_node_is_initialized()) {
    group = embb_mtapi_group_pool_allocate(node->group_pool);
    if (MTAPI_NULL != group) {
      embb_mtapi_group_initialize_with_node(group, node);
      group->group_id = group_id;
      if (MTAPI_NULL != attributes) {
        group->attributes = *attributes;
        local_status = MTAPI_SUCCESS;
      } else {
        mtapi_groupattr_init(&group->attributes, &local_status);
      }
      if (MTAPI_SUCCESS == local_status) {
        group_hndl = group->handle;
      } else {
        embb_mtapi_group_finalize(group);
        embb_mtapi_group_pool_deallocate(node->group_pool, group);
      }
    } else {
      local_status = MTAPI_ERR_GROUP_LIMIT;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
  return group_hndl;
}
Exemple #9
0
void mtapi_action_disable(
  MTAPI_IN mtapi_action_hndl_t action,
  MTAPI_IN mtapi_timeout_t timeout,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  embb_mtapi_log_trace("mtapi_action_disable() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    if (embb_mtapi_action_pool_is_handle_valid(node->action_pool, action)) {
      embb_mtapi_action_t* local_action =
        embb_mtapi_action_pool_get_storage_for_handle(
          node->action_pool, action);
      local_action->enabled = MTAPI_FALSE;

      embb_mtapi_thread_context_t * context = NULL;

      embb_duration_t wait_duration;
      embb_time_t end_time;
      if (MTAPI_INFINITE < timeout) {
        embb_duration_set_milliseconds(
          &wait_duration, (unsigned long long)timeout);
        embb_time_in(&end_time, &wait_duration);
      }

      /* cancel all tasks */
      embb_mtapi_scheduler_process_tasks(
        node->scheduler, embb_mtapi_action_disable_visitor, local_action);

      /* find out on which thread we are */
      context = embb_mtapi_scheduler_get_current_thread_context(
        node->scheduler);

      local_status = MTAPI_SUCCESS;
      while (embb_atomic_load_int(&local_action->num_tasks)) {
        if (MTAPI_INFINITE < timeout) {
          embb_time_t current_time;
          embb_time_now(&current_time);
          if (embb_time_compare(&current_time, &end_time) > 0) {
            /* timeout! */
            local_status = MTAPI_TIMEOUT;
            break;
          }
        }

        /* do other work if applicable */
        embb_mtapi_scheduler_execute_task_or_yield(
          node->scheduler,
          node,
          context);
      }
    } else {
      local_status = MTAPI_ERR_ACTION_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
}
Exemple #10
0
mtapi_action_hndl_t mtapi_action_create(
  MTAPI_IN mtapi_job_id_t job_id,
  MTAPI_IN mtapi_action_function_t action_function,
  MTAPI_IN void* node_local_data,
  MTAPI_IN mtapi_size_t node_local_data_size,
  MTAPI_IN mtapi_action_attributes_t* attributes,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
  mtapi_action_hndl_t action_handle = { 0, EMBB_MTAPI_IDPOOL_INVALID_ID };

  embb_mtapi_log_trace("mtapi_action_create() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    /* check if job is valid */
    if (embb_mtapi_job_is_id_valid(node, job_id)) {
      embb_mtapi_job_t* job = embb_mtapi_job_get_storage_for_id(node, job_id);
      embb_mtapi_action_t* new_action =
        embb_mtapi_action_pool_allocate(node->action_pool);
      if (MTAPI_NULL != new_action) {
        new_action->domain_id = node->domain_id;
        new_action->node_id = node->node_id;
        new_action->job_id = job_id;
        new_action->node_local_data = node_local_data;
        new_action->node_local_data_size = node_local_data_size;
        new_action->enabled = MTAPI_TRUE;
        new_action->is_plugin_action = MTAPI_FALSE;
        embb_atomic_store_int(&new_action->num_tasks, 0);

        new_action->action_function = action_function;

        /* set defaults if no attributes were given */
        if (MTAPI_NULL != attributes) {
          new_action->attributes = *attributes;
          local_status = MTAPI_SUCCESS;
        } else {
          /* use the default */
          mtapi_actionattr_init(&new_action->attributes, &local_status);
        }

        /* check if affinity is sane */
        if (0 == new_action->attributes.affinity) {
          local_status = MTAPI_ERR_PARAMETER;
        }

        if (MTAPI_SUCCESS == local_status) {
          action_handle = new_action->handle;
          embb_mtapi_job_add_action(job, new_action);
        } else {
          embb_mtapi_action_pool_deallocate(node->action_pool, new_action);
        }
      } else {
        /* no more space left in action pool */
        local_status = MTAPI_ERR_ACTION_LIMIT;
      }
    } else {
      local_status = MTAPI_ERR_JOB_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
  return action_handle;
}
Exemple #11
0
void mtapi_group_wait_any(
  MTAPI_IN mtapi_group_hndl_t group,
  MTAPI_OUT void** result,
  MTAPI_IN mtapi_timeout_t timeout,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  embb_mtapi_log_trace("mtapi_group_wait_any() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    if (embb_mtapi_group_pool_is_handle_valid(node->group_pool, group)) {
      embb_mtapi_group_t* local_group =
        embb_mtapi_group_pool_get_storage_for_handle(
          node->group_pool, group);

      embb_mtapi_task_t* local_task;
      /* are there any tasks left? */
      if (0 == embb_atomic_load_int(&local_group->num_tasks)) {
        /* group becomes invalid, so delete it */
        mtapi_group_delete(group, &local_status);
        local_status = MTAPI_GROUP_COMPLETED;
      } else {
        embb_mtapi_thread_context_t * context = NULL;

        embb_duration_t wait_duration;
        embb_time_t end_time;
        if (MTAPI_INFINITE < timeout) {
          embb_duration_set_milliseconds(
            &wait_duration, (unsigned long long)timeout);
          embb_time_in(&end_time, &wait_duration);
        }

        /* find out on which thread we are */
        context = embb_mtapi_scheduler_get_current_thread_context(
          node->scheduler);

        /* wait for any task to arrive */
        local_status = MTAPI_SUCCESS;
        local_task = embb_mtapi_task_queue_pop(&local_group->queue);
        while (MTAPI_NULL == local_task) {
          if (MTAPI_INFINITE < timeout) {
            embb_time_t current_time;
            embb_time_now(&current_time);
            if (embb_time_compare(&current_time, &end_time) > 0) {
              /* timeout! */
              local_status = MTAPI_TIMEOUT;
              break;
            }
          }

          /* do other work if applicable */
          embb_mtapi_scheduler_execute_task_or_yield(
            node->scheduler,
            node,
            context);

          /* try to pop a task from the group queue */
          local_task = embb_mtapi_task_queue_pop(&local_group->queue);
        }
        /* was there a timeout, or is there a result? */
        if (MTAPI_NULL != local_task) {
          /* store result */
          if (MTAPI_NULL != result) {
            *result = local_task->result_buffer;
          }

          /* return error code set by the task */
          local_status = local_task->error_code;

          /* delete task */
          embb_mtapi_task_delete(local_task, node->task_pool);
          embb_atomic_fetch_and_add_int(&local_group->num_tasks, -1);
        }
      }
    } else {
      local_status = MTAPI_ERR_GROUP_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
  embb_mtapi_log_trace("mtapi_group_wait_any() returns\n");
}