예제 #1
0
static resrc_flow_t *resrc_flow_add_rdl (resrc_flow_t *parent,
                                         struct resource *r)
{
    json_t *o = NULL;
    resrc_flow_t *resrc_flow = NULL;
    struct resource *c;

    o = rdl_resource_json (r);
    resrc_flow = resrc_flow_new_from_json (o, parent);

    while ((c = rdl_resource_next_child (r))) {
        (void) resrc_flow_add_rdl (resrc_flow, c);
        rdl_resource_destroy (c);
    }

    Jput (o);
    return resrc_flow;
}
예제 #2
0
static void determine_all_min_bandwidth_helper (struct resource *r,
                                                double curr_min_bandwidth,
                                                zhash_t *job_hash)
{
    struct resource *curr_child;
    int64_t job_id;
    double total_requested_bandwidth, curr_average_bandwidth,
        child_alloc_bandwidth, total_used_bandwidth, this_max_bandwidth,
        num_children, this_alloc_bandwidth;
    json_t *o;
    zlist_t *child_list;
    const char *type = NULL;

    // Check if leaf node in hierarchy (base case)
    rdl_resource_iterator_reset (r);
    curr_child = rdl_resource_next_child (r);
    if (curr_child == NULL) {
        // Check if allocated to a job
        if (rdl_resource_get_int (r, "lwj", &job_id) == 0) {
            // Determine which is less, the bandwidth currently available to
            // this resource, or the bandwidth allocated to it by the job
            // This assumes that jobs cannot share leaf nodes in the hierarchy
            this_alloc_bandwidth = get_alloc_bandwidth (r);
            curr_min_bandwidth = (curr_min_bandwidth < this_alloc_bandwidth)
                                     ? curr_min_bandwidth
                                     : this_alloc_bandwidth;
            double *job_min_bw = get_job_min_from_hash (job_hash, job_id);
            if (job_min_bw != NULL && curr_min_bandwidth < *job_min_bw) {
                *job_min_bw = curr_min_bandwidth;
            }  // if job_min_bw is NULL, the tag still exists in the RDL, but
               // the job completed
        }
        return;
    }  // else

    // Sum the bandwidths of the parent's children
    total_requested_bandwidth = 0;
    child_list = zlist_new ();
    while (curr_child != NULL) {
        o = rdl_resource_json (curr_child);
        Jget_str (o, "type", &type);
        // TODO: clean up this hardcoded value, should go away once we switch to
        // the real
        // rdl implementation (storing a bandwidth resource at every level)
        if (strcmp (type, "memory") != 0) {
            total_requested_bandwidth += get_alloc_bandwidth (curr_child);
            zlist_append (child_list, curr_child);
        }
        Jput (o);
        curr_child = rdl_resource_next_child (r);
    }
    rdl_resource_iterator_reset (r);

    // Sort child list based on alloc bw
    zlist_sort (child_list, compare_resource_alloc_bw);

    // const char *resource_string = Jtostr(o);
    // Loop over all of the children
    this_max_bandwidth = get_max_bandwidth (r);
    total_used_bandwidth = (total_requested_bandwidth > this_max_bandwidth)
                               ? this_max_bandwidth
                               : total_requested_bandwidth;
    total_used_bandwidth = (total_used_bandwidth > curr_min_bandwidth)
                               ? curr_min_bandwidth
                               : total_used_bandwidth;
    while (zlist_size (child_list) > 0) {
        // Determine the amount of bandwidth to allocate to each child
        num_children = zlist_size (child_list);
        curr_average_bandwidth = (total_used_bandwidth / num_children);
        curr_child = (struct resource *)zlist_pop (child_list);
        child_alloc_bandwidth = get_alloc_bandwidth (curr_child);
        if (child_alloc_bandwidth > 0) {
            if (child_alloc_bandwidth > curr_average_bandwidth)
                child_alloc_bandwidth = curr_average_bandwidth;

            // Subtract the allocated bandwidth from the parent's total
            total_used_bandwidth -= child_alloc_bandwidth;
            // Recurse on the child
            determine_all_min_bandwidth_helper (curr_child,
                                                child_alloc_bandwidth,
                                                job_hash);
        }
        rdl_resource_destroy (curr_child);
    }

    // Cleanup
    zlist_destroy (
        &child_list);  // no need to rdl_resource_destroy, done in above loop

    return;
}