提交 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 {
e->next = root.load();
if (cmpxch(&table[i].chain, e->next.load(), e)) {
int c = mycpuid();
int c = myid();
acquire(&percore_lock[c]);
e->percore_c = c;
e->percore_next = percore[c].load();
......@@ -180,7 +180,7 @@ class xns : public rcu_freed {
template<class CB>
void enumerate(CB cb) {
scoped_gc_epoch gc;
int cpuoffset = mycpuid();
int cpuoffset = myid();
for (int i = 0; i < NCPU; i++) {
auto e = percore[(i + cpuoffset) % NCPU].load();
while (e) {
......
#pragma once
extern int mycpuid(void);
#include "cpu.hh"
template <typename T>
struct percpu {
......@@ -11,15 +11,15 @@ struct percpu {
percpu &operator=(const percpu &o) = delete;
T* get() const {
return cpu(mycpuid());
return cpu(myid());
}
T* operator->() const {
return cpu(mycpuid());
return cpu(myid());
}
T& operator*() const {
return *cpu(mycpuid());
return *cpu(myid());
}
T& operator[](int id) const {
......
......@@ -5,7 +5,6 @@
#include "uwq.hh"
#include "wqtypes.hh"
int mycpuid(void);
uwq_ipcbuf* allocipc(void);
static inline void*
......
......@@ -191,7 +191,7 @@ ialloc(u32 dev, short type)
struct superblock 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++){
if (inum == 0)
continue;
......
......@@ -141,7 +141,7 @@ cmain(u64 mbmagic, u64 mbaddr)
initmp();
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
extern const uptr sctors[], ectors[];
for (const uptr *ctorva = ectors; ctorva > sctors; ) {
......
......@@ -21,12 +21,6 @@ proc::hash(const u32 &p)
return p;
}
int
mycpuid(void)
{
return mycpu()->id;
}
xns<u32, proc*, proc::hash> *xnspid __mpalign__;
struct proc *bootproc __mpalign__;
......
......@@ -174,7 +174,7 @@ trap(struct trapframe *tf)
// In user space, assume process misbehaved.
uerr.println("pid ", myproc()->pid, ' ', myproc()->name,
": 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()),
"--kill proc");
myproc()->killed = 1;
......
......@@ -28,7 +28,7 @@ uwq_trywork(void)
for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU;
if (j == mycpuid())
if (j == myid())
continue;
struct cpu *c = &cpus[j];
......@@ -199,7 +199,7 @@ uwq::tryworker(void)
proc* p = w->proc_;
acquire(&p->lock);
p->cpuid = mycpuid();
p->cpuid = myid();
release(&p->lock);
w->running_ = true;
......@@ -226,7 +226,7 @@ again:
w->running_ = true;
acquire(&p->lock);
p->cpuid = mycpuid();
p->cpuid = myid();
addrun(p);
release(&p->lock);
......
......@@ -31,7 +31,7 @@ int
wq_push(work *w)
{
assert(wq_);
return wq_->push(w, mycpuid());
return wq_->push(w, myid());
}
void
......
......@@ -158,7 +158,7 @@ wq::trywork(bool dosteal)
// A "random" victim CPU
k = rdtsc();
w = pop(mycpuid());
w = pop(myid());
if (w != nullptr) {
w->run();
return 1;
......@@ -170,7 +170,7 @@ wq::trywork(bool dosteal)
for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU;
if (j == mycpuid())
if (j == myid())
continue;
w = steal(j);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论