提交 e0780ce4 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

real tlb flush barrier

上级 f336c8cd
#include "mmu.h" #include "mmu.h"
#include "atomic.hh"
struct cilkframe; struct cilkframe;
// extern atomic<u64> tlbflush_req; using std::atomic;
extern atomic<u64> tlbflush_req;
// Per-CPU state // Per-CPU state
struct cpu { struct cpu {
...@@ -13,7 +16,7 @@ struct cpu { ...@@ -13,7 +16,7 @@ struct cpu {
struct context *scheduler; // swtch() here to enter scheduler struct context *scheduler; // swtch() here to enter scheduler
struct cilkframe *cilkframe; struct cilkframe *cilkframe;
int timer_printpc; int timer_printpc;
// atomic<u64> tlbflush_done; // last tlb flush req done on this cpu atomic<u64> tlbflush_done; // last tlb flush req done on this cpu
// Cpu-local storage variables; see below // Cpu-local storage variables; see below
struct cpu *cpu; struct cpu *cpu;
......
...@@ -216,17 +216,18 @@ atomic<u64> tlbflush_req; ...@@ -216,17 +216,18 @@ atomic<u64> tlbflush_req;
void void
tlbflush() tlbflush()
{ {
// u64 myreq = tlbflush_req++; u64 myreq = tlbflush_req++;
cli(); cli();
int myid = mycpu()->id;
lcr3(rcr3()); lcr3(rcr3());
for (int i = 0; i < ncpu; i++) for (int i = 0; i < ncpu; i++)
if (i != mycpu()->id) if (i != myid)
lapic_tlbflush(i); lapic_tlbflush(i);
sti(); sti();
for (int i = 0; i < ncpu; i++) { for (int i = 0; i < ncpu; i++)
if (i != mycpu()->id) { if (i != myid)
// while (cpus[i].tlbflush_done < myreq) /* spin */ ; while (cpus[i].tlbflush_done < myreq)
} /* spin */ ;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "kernel.hh" #include "kernel.hh"
#include "traps.h" #include "traps.h"
#include "bits.h" #include "bits.h"
#include "cpu.hh"
// Local APIC registers, divided by 4 for use as uint[] indices. // Local APIC registers, divided by 4 for use as uint[] indices.
#define ID (0x0020/4) // ID #define ID (0x0020/4) // ID
...@@ -179,9 +180,7 @@ lapic_ipi(int cpu, int ino) ...@@ -179,9 +180,7 @@ lapic_ipi(int cpu, int ino)
void void
lapic_tlbflush(u32 cpu) lapic_tlbflush(u32 cpu)
{ {
cprintf("lapic_tlbflush: to cpu %d\n", cpu);
lapic_ipi(cpu, T_TLBFLUSH); lapic_ipi(cpu, T_TLBFLUSH);
cprintf("lapic_tlbflush: to cpu %d done\n", cpu);
} }
void void
......
...@@ -14,7 +14,7 @@ thr(void *arg) ...@@ -14,7 +14,7 @@ thr(void *arg)
{ {
u64 tid = (u64)arg; u64 tid = (u64)arg;
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 1000; i++) {
volatile char *p = (char*) (0x40000UL + tid * 8 * 4096); volatile char *p = (char*) (0x40000UL + tid * 8 * 4096);
if (map((void *) p, 8 * 4096) < 0) { if (map((void *) p, 8 * 4096) < 0) {
printf(1, "%d: map failed\n", tid); printf(1, "%d: map failed\n", tid);
......
...@@ -95,12 +95,13 @@ trap(struct trapframe *tf) ...@@ -95,12 +95,13 @@ trap(struct trapframe *tf)
cprintf("cpu%d: spurious interrupt at %x:%lx\n", cprintf("cpu%d: spurious interrupt at %x:%lx\n",
mycpu()->id, tf->cs, tf->rip); mycpu()->id, tf->cs, tf->rip);
lapiceoi(); lapiceoi();
case T_TLBFLUSH: case T_TLBFLUSH: {
// nreq = tlbflush_req.load(); u64 nreq = tlbflush_req.load();
lapiceoi(); lapiceoi();
lcr3(rcr3()); lcr3(rcr3());
// mycpu()->tlbflush_done = nreq; mycpu()->tlbflush_done = nreq;
break; break;
}
case T_SAMPCONF: case T_SAMPCONF:
lapiceoi(); lapiceoi();
sampconf(); sampconf();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论