#include #include #include #include "common.h" #include "litmus.h" #include #include #include void bail_out(const char* msg) { perror(msg); exit(-1 * errno); } void request_resources(int task_colors, int avg_ways) { const gsl_rng *way_rng = gsl_rng_alloc(gsl_rng_taus); struct control_page *page = get_ctrl_page(); int color, ways, rem = task_colors; float random; char taken[NUM_COLORS]; memset(page->requests, 0, NUM_COLORS*sizeof(*page->requests)); gsl_rng_set(way_rng, rand()); memset(taken, 0, NUM_COLORS); srand(getpid()); gsl_rng_set(way_rng, getpid()); while (rem) { /* select a random unchosen color */ do { color = rand() % NUM_COLORS; } while (taken[color]); if (rand() % NUM_COLORS <= task_colors) { taken[color] = 1; rem --; random = gsl_ran_exponential(way_rng, avg_ways + 1); ways = 1 + (int)random; ways = (ways < 1) ? 1 : ways; ways = (ways > NUM_WAYS) ? NUM_WAYS : ways; page->requests[color] = ways; } } }