More usched

上级 98c1ea02
...@@ -14,6 +14,11 @@ typedef uint64_t u64; ...@@ -14,6 +14,11 @@ typedef uint64_t u64;
#include "percpu.hh" #include "percpu.hh"
#include "sched.hh" #include "sched.hh"
#include "queue.h" #include "queue.h"
#include "uscopedperf.hh"
#include "intelctr.hh"
static auto perfgroup = ctrgroup(&intelctr::tsc);
static int nprocs = NCPU; static int nprocs = NCPU;
static int the_time = 5; static int the_time = 5;
...@@ -64,13 +69,14 @@ public: ...@@ -64,13 +69,14 @@ public:
proc* steal(bool nonexec); proc* steal(bool nonexec);
void dump(); void dump();
volatile u64 ncansteal_ __mpalign__;
sched_stat stats_; sched_stat stats_;
u64 ncansteal_;
volatile bool cansteal_ __mpalign__;
private: private:
pthread_spinlock_t lock_; pthread_spinlock_t lock_;
sched_link head_; sched_link head_ __mpalign__;;
}; };
percpu<schedule> schedule_; percpu<schedule> schedule_;
...@@ -109,6 +115,7 @@ schedule::schedule(void) ...@@ -109,6 +115,7 @@ schedule::schedule(void)
head_.next = &head_; head_.next = &head_;
head_.prev = &head_; head_.prev = &head_;
ncansteal_ = 0; ncansteal_ = 0;
cansteal_ = false;
pthread_spin_init(&lock_, 0); pthread_spin_init(&lock_, 0);
} }
...@@ -123,7 +130,8 @@ schedule::enq(proc* p) ...@@ -123,7 +130,8 @@ schedule::enq(proc* p)
head_.prev->next = entry; head_.prev->next = entry;
head_.prev = entry; head_.prev = entry;
if (cansteal((proc*)entry, true)) if (cansteal((proc*)entry, true))
ncansteal_++; if (ncansteal_++ == 0)
cansteal_ = true;
stats_.enqs++; stats_.enqs++;
pthread_spin_unlock(&lock_); pthread_spin_unlock(&lock_);
} }
...@@ -131,6 +139,8 @@ schedule::enq(proc* p) ...@@ -131,6 +139,8 @@ schedule::enq(proc* p)
proc* proc*
schedule::deq(void) schedule::deq(void)
{ {
ANON_REGION("deq", &perfgroup);
if (head_.next == &head_) if (head_.next == &head_)
return nullptr; return nullptr;
...@@ -145,7 +155,8 @@ schedule::deq(void) ...@@ -145,7 +155,8 @@ schedule::deq(void)
entry->next->prev = entry->prev; entry->next->prev = entry->prev;
entry->prev->next = entry->next; entry->prev->next = entry->next;
if (cansteal((proc*)entry, true)) if (cansteal((proc*)entry, true))
--ncansteal_; if (--ncansteal_ == 0)
cansteal_ = false;
stats_.deqs++; stats_.deqs++;
pthread_spin_unlock(&lock_); pthread_spin_unlock(&lock_);
return (proc*)entry; return (proc*)entry;
...@@ -154,14 +165,15 @@ schedule::deq(void) ...@@ -154,14 +165,15 @@ schedule::deq(void)
proc* proc*
schedule::steal(bool nonexec) schedule::steal(bool nonexec)
{ {
if (ncansteal_ == 0 || pthread_spin_trylock(&lock_)) if (!cansteal_ || pthread_spin_trylock(&lock_))
return nullptr; return nullptr;
for (sched_link* ptr = head_.next; ptr != &head_; ptr = ptr->next) for (sched_link* ptr = head_.next; ptr != &head_; ptr = ptr->next)
if (cansteal((proc*)ptr, nonexec)) { if (cansteal((proc*)ptr, nonexec)) {
ptr->next->prev = ptr->prev; ptr->next->prev = ptr->prev;
ptr->prev->next = ptr->next; ptr->prev->next = ptr->next;
--ncansteal_; if (--ncansteal_ == 0)
cansteal_ = false;
++stats_.steals; ++stats_.steals;
pthread_spin_unlock(&lock_); pthread_spin_unlock(&lock_);
return (proc*)ptr; return (proc*)ptr;
...@@ -187,6 +199,7 @@ stealit(void) ...@@ -187,6 +199,7 @@ stealit(void)
{ {
proc* p; proc* p;
ANON_REGION("stealit", &perfgroup);
for (int i = 0; i < NCPU; i++) { for (int i = 0; i < NCPU; i++) {
if (i == myid_) if (i == myid_)
continue; continue;
...@@ -269,5 +282,6 @@ main(int ac, char** av) ...@@ -269,5 +282,6 @@ main(int ac, char** av)
sleep(1); sleep(1);
worker((void*)0); worker((void*)0);
scopedperf::perfsum_base::printall();
return 0; return 0;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论