pclass.h 3.43 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1 2
/*
 * EMULAB-COPYRIGHT
3
 * Copyright (c) 2000-2006 University of Utah and the Flux Group.
Robert Ricci's avatar
Robert Ricci committed
4 5 6
 * All rights reserved.
 */

7 8 9
#ifndef __PCLASS_H
#define __PCLASS_H

10 11
#include<map>

12 13 14
// Declared in assign.cc - indicated whether or not we should use pclasses
extern bool use_pclasses;

15 16 17 18
// tb pnode list is a data structure that acts like list but has
// O(1) removal.  It is a list of tb_pnode*.
class tb_pnodelist {
public:
19 20 21 22 23
  typedef list<tb_pnode*> pnode_list;
  typedef pnode_list::iterator list_iter;
  pnode_list L;
  typedef hash_map<tb_pnode*,list_iter,hashptr<tb_pnode*> > pnode_iter_map;
  pnode_iter_map D;
24

25 26 27 28
  list_iter push_front(tb_pnode *p) {
    L.push_front(p);
    list_iter it = L.begin();
    D[p]=it;
29 30
    return it;
  };
31 32 33 34 35
  list_iter push_back(tb_pnode *p) {
    L.push_back(p);
    list_iter it = L.end();
    it--;
    D[p]=it;
36 37 38 39
    return it;
  };
  int remove(tb_pnode *p) {
    if (exists(p)) {
40 41 42
      pnode_iter_map::iterator dit = D.find(p);
      L.erase((*dit).second);
      D.erase(dit);
43 44 45 46 47 48
      return 0;
    } else {
      return 1;
    }
  };
  int exists(tb_pnode *p) {
49
    return (D.find(p) != D.end());
50 51
  }
  tb_pnode *front() {
52
    return (L.empty() ? NULL : L.front());
53
  };
54

55 56 57 58
  int size() {
      return L.size();
  };

59 60 61 62 63 64 65 66
  friend ostream &operator<<(ostream &o, const tb_pnodelist& l)
  {
    pnode_list::const_iterator lit;
    for (lit=l.L.begin();lit!=l.L.end();++lit) {
      o << "    " << (*lit)->name << endl;
    }
    return o;
  }
67 68 69 70
};

class tb_pclass {
public:
71
  tb_pclass() : name(), size(0), used_members(0), disabled(false), refcount(0),
72
    is_dynamic(false) {;}
73

74
  typedef map<fstring,tb_pnodelist*> pclass_members_map;
75
  typedef hash_set<tb_pnode*,hashptr<tb_pnode*> > tb_pnodeset;
76
  typedef hash_map<fstring,tb_pnodeset*> pclass_members_set;
77

78
  int add_member(tb_pnode *p, bool is_own_class);
79

80
  fstring name;			// purely for debugging
81
  int size;
82
  int used_members;
83 84 85 86 87
  pclass_members_map members;
#ifdef SMART_UNMAP
  pclass_members_set used_members;
#endif

88 89
  bool disabled;

Robert Ricci's avatar
Robert Ricci committed
90 91 92 93
  // A count of how many nodes can use this pclass
  // For use with PRUNE_PCLASSES
  int refcount;

94 95
  // Is this a dynamic plcass? If false, it's a "real" one
  bool is_dynamic;
Robert Ricci's avatar
Robert Ricci committed
96

97 98
  friend ostream &operator<<(ostream &o, const tb_pclass& p)
  {
99
    o << p.name << " size=" << p.size <<
100 101
      " used_members=" << p.used_members << " disabled=" << p.disabled <<
      " is_dynamic=" << p.is_dynamic << "\n";
102 103 104 105 106 107 108 109
    pclass_members_map::const_iterator dit;
    for (dit=p.members.begin();dit!=p.members.end();++dit) {
      o << "  " << (*dit).first << ":\n";
      o << *((*dit).second) << endl;
    }
    o << endl;
    return o;
  }
110 111 112
};

typedef list<tb_pclass*> pclass_list;
113 114
typedef vector<tb_pclass*> pclass_vector;
typedef pair<int,pclass_vector*> tt_entry;
115
typedef hash_map<fstring,tt_entry> pclass_types;
116 117 118 119 120 121 122 123

/* Constants */
#define PCLASS_BASE_WEIGHT 1
#define PCLASS_NEIGHBOR_WEIGHT 1
#define PCLASS_UTIL_WEIGHT 1
#define PCLASS_FDS_WEIGHT 2

/* routines defined in pclass.cc */
124 125 126 127
// Sets pclasses and type_table globals -
// Takes two arguments - a physical graph, and a flag indicating whether or not
// each physical node should get its own pclass (effectively disabling
// pclasses)
128 129
int generate_pclasses(tb_pgraph &PG, bool pclass_for_each_pnode,
	bool dynamic_pclasses);
130 131 132

/* The following two routines sets and remove mappings in pclass
   datastructures */
133 134
int pclass_set(tb_vnode *v,tb_pnode *p);
int pclass_unset(tb_pnode *p);
135

136
void pclass_debug();
137

138 139
int count_enabled_pclasses();

140
#endif