32 #include "QuManager.h"
38 QuManager::QuManager(
int nL1,
int nP1,
int nQ1,
int maxppl1,
39 PacketStore *ps1, StatsModule *sm1)
40 : nL(nL1), nP(nP1), nQ(nQ1),
41 maxppl(maxppl1),
ps(ps1), sm(sm1) {
42 queues =
new ListSet(nP,nQ);
43 active =
new Dheap<uint64_t>(nL);
44 vactive =
new Dheap<uint64_t>(nL);
45 quInfo =
new QuInfo[nQ+1];
46 lnkInfo =
new LinkInfo[nL+1];
47 hset =
new DheapSet<uint64_t>(nQ,nL);
51 for (
int lnk = 1; lnk <= nL; lnk++) {
52 lnkInfo[lnk].vt = 0; setLinkRates(lnk, rs);
56 for (
int qid = 1; qid < nQ; qid++) {
57 quInfo[qid].lnk = qid+1;
58 quInfo[qid].pktLim = -1;
61 quInfo[nQ].lnk = 0; free = 1;
65 QuManager::~QuManager() {
76 if (
free == 0)
return 0;
77 int qid =
free;
free = quInfo[qid].lnk;
78 quInfo[qid].lnk = lnk;
79 quInfo[qid].pktLim = 0;
96 quInfo[qid].pktLim = -1;
108 unique_lock lck(
mtx);
110 QuInfo& q = quInfo[qid];
int lnk = q.
lnk;
114 if (
sm->getLinkQlen(lnk) >=
maxppl ||
116 sm->getQbytes(qid) + pleng > q.
byteLim) {
122 if (!
active->member(lnk)) {
124 if (vactive->member(lnk)) {
125 d = vactive->key(lnk);
126 if (now >= d) d = now;
127 vactive->remove(lnk);
140 if (!
hset->insert(qid,q.
vft,lnk)) {
141 cerr <<
"enq attempt to insert in hset failed qid="
142 << qid <<
" lnk=" << lnk <<
" hset="
143 <<
hset->toString(lnk);
149 sm->incQlen(qid,lnk,pleng);
161 unique_lock lck(
mtx);
164 int vl = vactive->findmin(); uint64_t d = vactive->key(vl);
165 while (vl != 0 && now >= d) {
167 vl = vactive->findmin(); d = vactive->key(vl);
170 if (
active->empty())
return 0;
172 if (now < d)
return 0;
175 int qid =
hset->findMin(lnk);
176 pktx px =
queues->removeFirst(qid);
178 sm->decQlen(qid,lnk,pleng);
184 hset->deleteMin(lnk);
190 int npx =
queues->first(qid);
196 hset->changeKeyMin(q.
vft, lnk);
207 if (
hset->empty(lnk)) {
209 vactive->insert(lnk,t);