提交 b01e8a94 创建 作者: Austin Clements's avatar Austin Clements

De-duplicate myid and mycpuid

Apparently we wound up with two equivalent functions for getting the current CPU's id. Switch to just myid since that was more common and is implemented as a static inline instead of an extern.
上级 d175a882
...@@ -102,7 +102,7 @@ class xns : public rcu_freed { ...@@ -102,7 +102,7 @@ class xns : public rcu_freed {
e->next = root.load(); e->next = root.load();
if (cmpxch(&table[i].chain, e->next.load(), e)) { if (cmpxch(&table[i].chain, e->next.load(), e)) {
int c = mycpuid(); int c = myid();
acquire(&percore_lock[c]); acquire(&percore_lock[c]);
e->percore_c = c; e->percore_c = c;
e->percore_next = percore[c].load(); e->percore_next = percore[c].load();
...@@ -180,7 +180,7 @@ class xns : public rcu_freed { ...@@ -180,7 +180,7 @@ class xns : public rcu_freed {
template<class CB> template<class CB>
void enumerate(CB cb) { void enumerate(CB cb) {
scoped_gc_epoch gc; scoped_gc_epoch gc;
int cpuoffset = mycpuid(); int cpuoffset = myid();
for (int i = 0; i < NCPU; i++) { for (int i = 0; i < NCPU; i++) {
auto e = percore[(i + cpuoffset) % NCPU].load(); auto e = percore[(i + cpuoffset) % NCPU].load();
while (e) { while (e) {
......
#pragma once #pragma once
extern int mycpuid(void); #include "cpu.hh"
template <typename T> template <typename T>
struct percpu { struct percpu {
...@@ -11,15 +11,15 @@ struct percpu { ...@@ -11,15 +11,15 @@ struct percpu {
percpu &operator=(const percpu &o) = delete; percpu &operator=(const percpu &o) = delete;
T* get() const { T* get() const {
return cpu(mycpuid()); return cpu(myid());
} }
T* operator->() const { T* operator->() const {
return cpu(mycpuid()); return cpu(myid());
} }
T& operator*() const { T& operator*() const {
return *cpu(mycpuid()); return *cpu(myid());
} }
T& operator[](int id) const { T& operator[](int id) const {
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "uwq.hh" #include "uwq.hh"
#include "wqtypes.hh" #include "wqtypes.hh"
int mycpuid(void);
uwq_ipcbuf* allocipc(void); uwq_ipcbuf* allocipc(void);
static inline void* static inline void*
......
...@@ -191,7 +191,7 @@ ialloc(u32 dev, short type) ...@@ -191,7 +191,7 @@ ialloc(u32 dev, short type)
struct superblock sb; struct superblock sb;
readsb(dev, &sb); readsb(dev, &sb);
for (int k = mycpuid()*IPB; k < sb.ninodes; k += (NCPU*IPB)) { for (int k = myid()*IPB; k < sb.ninodes; k += (NCPU*IPB)) {
for(int inum = k; inum < k+IPB && inum < sb.ninodes; inum++){ for(int inum = k; inum < k+IPB && inum < sb.ninodes; inum++){
if (inum == 0) if (inum == 0)
continue; continue;
......
...@@ -141,7 +141,7 @@ cmain(u64 mbmagic, u64 mbaddr) ...@@ -141,7 +141,7 @@ cmain(u64 mbmagic, u64 mbaddr)
initmp(); initmp();
inittls(); // thread local storage inittls(); // thread local storage
// Some global constructors require mycpu()->id (via mycpuid()) // Some global constructors require mycpu()->id (via myid())
// which we setup in inittls // which we setup in inittls
extern const uptr sctors[], ectors[]; extern const uptr sctors[], ectors[];
for (const uptr *ctorva = ectors; ctorva > sctors; ) { for (const uptr *ctorva = ectors; ctorva > sctors; ) {
......
...@@ -21,12 +21,6 @@ proc::hash(const u32 &p) ...@@ -21,12 +21,6 @@ proc::hash(const u32 &p)
return p; return p;
} }
int
mycpuid(void)
{
return mycpu()->id;
}
xns<u32, proc*, proc::hash> *xnspid __mpalign__; xns<u32, proc*, proc::hash> *xnspid __mpalign__;
struct proc *bootproc __mpalign__; struct proc *bootproc __mpalign__;
......
...@@ -174,7 +174,7 @@ trap(struct trapframe *tf) ...@@ -174,7 +174,7 @@ trap(struct trapframe *tf)
// In user space, assume process misbehaved. // In user space, assume process misbehaved.
uerr.println("pid ", myproc()->pid, ' ', myproc()->name, uerr.println("pid ", myproc()->pid, ' ', myproc()->name,
": trap ", (u64)tf->trapno, " err ", (u32)tf->err, ": trap ", (u64)tf->trapno, " err ", (u32)tf->err,
" on cpu ", mycpuid(), " rip ", shex(tf->rip), " on cpu ", myid(), " rip ", shex(tf->rip),
" rsp ", shex(tf->rsp), " addr ", shex(rcr2()), " rsp ", shex(tf->rsp), " addr ", shex(rcr2()),
"--kill proc"); "--kill proc");
myproc()->killed = 1; myproc()->killed = 1;
......
...@@ -28,7 +28,7 @@ uwq_trywork(void) ...@@ -28,7 +28,7 @@ uwq_trywork(void)
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU; u64 j = (i+k) % NCPU;
if (j == mycpuid()) if (j == myid())
continue; continue;
struct cpu *c = &cpus[j]; struct cpu *c = &cpus[j];
...@@ -199,7 +199,7 @@ uwq::tryworker(void) ...@@ -199,7 +199,7 @@ uwq::tryworker(void)
proc* p = w->proc_; proc* p = w->proc_;
acquire(&p->lock); acquire(&p->lock);
p->cpuid = mycpuid(); p->cpuid = myid();
release(&p->lock); release(&p->lock);
w->running_ = true; w->running_ = true;
...@@ -226,7 +226,7 @@ again: ...@@ -226,7 +226,7 @@ again:
w->running_ = true; w->running_ = true;
acquire(&p->lock); acquire(&p->lock);
p->cpuid = mycpuid(); p->cpuid = myid();
addrun(p); addrun(p);
release(&p->lock); release(&p->lock);
......
...@@ -31,7 +31,7 @@ int ...@@ -31,7 +31,7 @@ int
wq_push(work *w) wq_push(work *w)
{ {
assert(wq_); assert(wq_);
return wq_->push(w, mycpuid()); return wq_->push(w, myid());
} }
void void
......
...@@ -158,7 +158,7 @@ wq::trywork(bool dosteal) ...@@ -158,7 +158,7 @@ wq::trywork(bool dosteal)
// A "random" victim CPU // A "random" victim CPU
k = rdtsc(); k = rdtsc();
w = pop(mycpuid()); w = pop(myid());
if (w != nullptr) { if (w != nullptr) {
w->run(); w->run();
return 1; return 1;
...@@ -170,7 +170,7 @@ wq::trywork(bool dosteal) ...@@ -170,7 +170,7 @@ wq::trywork(bool dosteal)
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU; u64 j = (i+k) % NCPU;
if (j == mycpuid()) if (j == myid())
continue; continue;
w = steal(j); w = steal(j);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论