"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

resource.h File Reference

#include <stdio.h>

Include dependency graph for resource.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Compounds

Defines

Functions


Define Documentation

#define MAX_INSTS_PER_CLASS   8
 

Definition at line 81 of file resource.h.

Referenced by res_create_pool(), res_dump(), res_get(), and sim_check_options().

#define MAX_RES_CLASSES   16
 

Definition at line 78 of file resource.h.

Referenced by res_create_pool(), res_dump(), and res_get().


Function Documentation

struct res_pool* res_create_pool char *    name,
struct res_desc   pool,
int    ndesc
 

Definition at line 83 of file resource.c.

References res_desc::busy, res_desc::res_template::class, FALSE, fatal(), res_desc::res_template::master, MAX_INSTS_PER_CLASS, MAX_RES_CLASSES, res_pool::name, res_pool::nents, res_pool::num_resources, res_desc::quantity, res_pool::resources, res_pool::table, and res_desc::x.

Referenced by sim_load_prog().

00084 {
00085   int i, j, k, index, ninsts;
00086   struct res_desc *inst_pool;
00087   struct res_pool *res;
00088 
00089   /* count total instances */
00090   for (ninsts=0,i=0; i<ndesc; i++)
00091     {
00092       if (pool[i].quantity > MAX_INSTS_PER_CLASS)
00093         fatal("too many functional units, increase MAX_INSTS_PER_CLASS");
00094       ninsts += pool[i].quantity;
00095     }
00096 
00097   /* allocate the instance table */
00098   inst_pool = (struct res_desc *)calloc(ninsts, sizeof(struct res_desc));
00099   if (!inst_pool)
00100     fatal("out of virtual memory");
00101 
00102   /* fill in the instance table */
00103   for (index=0,i=0; i<ndesc; i++)
00104     {
00105       for (j=0; j<pool[i].quantity; j++)
00106         {
00107           inst_pool[index] = pool[i];
00108           inst_pool[index].quantity = 1;
00109           inst_pool[index].busy = FALSE;
00110           for (k=0; k<MAX_RES_CLASSES && inst_pool[index].x[k].class; k++)
00111             inst_pool[index].x[k].master = &inst_pool[index];
00112           index++;
00113         }
00114     }
00115   assert(index == ninsts);
00116 
00117   /* allocate the resouce pool descriptor */
00118   res = (struct res_pool *)calloc(1, sizeof(struct res_pool));
00119   if (!res)
00120     fatal("out of virtual memory");
00121   res->name = name;
00122   res->num_resources = ninsts;
00123   res->resources = inst_pool;
00124 
00125   /* fill in the resource table map - slow to build, but fast to access */
00126   for (i=0; i<ninsts; i++)
00127     {
00128       struct res_template *plate;
00129       for (j=0; j<MAX_RES_CLASSES; j++)
00130         {
00131           plate = &res->resources[i].x[j];
00132           if (plate->class)
00133             {
00134               assert(plate->class < MAX_RES_CLASSES);
00135               res->table[plate->class][res->nents[plate->class]++] = plate;
00136             }
00137           else
00138             /* all done with this instance */
00139             break;
00140         }
00141     }
00142 
00143   return res;
00144 }

void res_dump struct res_pool   pool,
FILE *    stream
 

Definition at line 179 of file resource.c.

References MAX_INSTS_PER_CLASS, MAX_RES_CLASSES, res_pool::name, res_pool::nents, res_pool::num_resources, and res_pool::table.

00180 {
00181   int i, j;
00182 
00183   if (!stream)
00184     stream = stderr;
00185 
00186   fprintf(stream, "Resource pool: %s:\n", pool->name);
00187   fprintf(stream, "\tcontains %d resource instances\n", pool->num_resources);
00188   for (i=0; i<MAX_RES_CLASSES; i++)
00189     {
00190       fprintf(stream, "\tclass: %d: %d matching instances\n",
00191               i, pool->nents[i]);
00192       fprintf(stream, "\tmatching: ");
00193       for (j=0; j<MAX_INSTS_PER_CLASS; j++)
00194         {
00195           if (!pool->table[i][j])
00196             break;
00197           fprintf(stream, "\t%s (busy for %d cycles) ",
00198                   pool->table[i][j]->master->name,
00199                   pool->table[i][j]->master->busy);
00200         }
00201       assert(j == pool->nents[i]);
00202       fprintf(stream, "\n");
00203     }
00204 }

struct res_template* res_get struct res_pool   pool,
int    class
 

Definition at line 153 of file resource.c.

References MAX_INSTS_PER_CLASS, MAX_RES_CLASSES, res_get(), and res_pool::table.

Referenced by res_get(), ruu_commit(), and ruu_issue().

00154 {
00155   int i;
00156 
00157   /* must be a valid class */
00158   assert(class < MAX_RES_CLASSES);
00159 
00160   /* must be at least one resource in this class */
00161   assert(pool->table[class][0]);
00162 
00163   for (i=0; i<MAX_INSTS_PER_CLASS; i++)
00164     {
00165       if (pool->table[class][i])
00166         {
00167           if (!pool->table[class][i]->master->busy)
00168             return pool->table[class][i];
00169         }
00170       else
00171         break;
00172     }
00173   /* none found */
00174   return NULL;
00175 }



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214