Esempio n. 1
0
void print_resource (struct resource *r, int pad)
{
    struct resource *c;

    fprintf (stdout, "%*s/%s=%d/%d\n", pad, "", rdl_resource_name (r),
            (int) rdl_resource_available (r),
            (int) rdl_resource_size (r));

    rdl_resource_iterator_reset (r);
    while ((c = rdl_resource_next_child (r))) {
        print_resource (c, pad+1);
        rdl_resource_destroy (c);
    }
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
int main (int argc, char *argv[])
{
    struct rdllib *l;
    struct rdl *rdl1, *rdl2;
    struct rdl_accumulator *a;
    struct resource *r, *c;
    int64_t val;
    const char *h = NULL;

    const char *filename = argv[1];

    log_init (basename (argv[0]));
    rdllib_set_default_errf (NULL, &perr);

    if (!(l = rdllib_open ()))
        log_err_exit ("rdllib_open");

    if (filename == NULL || *filename == '\0')
        filename = getenv ("TESTRDL_INPUT_FILE");

    if (!(rdl1 = rdl_loadfile (l, filename)))
        log_err_exit ("loadfile: %s", filename);

    while ((h = rdl_next_hierarchy (rdl1, h)))
        fprintf (stderr, "%s\n", h);

    if (!(rdl2 = rdl_copy (rdl1)))
        log_err_exit ("copy");

    r = rdl_resource_get (rdl1, "default");
    if (rdl_resource_set_int (r, "test-tag", 5959) < 0)
        exit (1);
    rdl_resource_get_int (r, "test-tag", &val);
    if (val != 5959)
        exit (1);
     rdl_resource_delete_tag (r, "test-tag");

    c = rdl_resource_next_child (r);

    a = rdl_accumulator_create (rdl1);
    if (rdl_accumulator_add (a, c) < 0)
        exit (1);

    rdl2 = rdl_accumulator_copy (a);
    rdl_accumulator_destroy (a);

    print_resource (rdl_resource_get (rdl2, "default"), 0);

    /*
     *  Test find
     */
    json_t *args = Jnew ();
    Jadd_str (args, "type", "node");
    Jadd_int (args, "id", 300);
    rdl2 = rdl_find (rdl1, args);
    if (rdl2 == NULL)
        log_err_exit ("rdl_find");
    json_decref (args);
    r = rdl_resource_get (rdl2, "default");
    if (r == NULL)
        exit (1);

    c = rdl_resource_next_child (r);
    printf ("found %s\n", rdl_resource_name (c));

    rdl_resource_destroy (r);
    rdl_destroy (rdl2);

    r = rdl_resource_get (rdl1, "default:/hype/hype300/socket0/memory");
    if (r == NULL)
        exit (1);

    print_resource (r, 0);
    rdl_resource_alloc (r, 1024);
    printf ("After alloc:\n");
    print_resource (r, 0);
    rdl_resource_free (r, 1024);
    printf ("After free:\n");
    print_resource (r, 0);

    rdllib_close (l);

    log_fini ();

    return 0;
}