Skip to content

Commit

Permalink
Synchronization in system calls without global locks across all syste…
Browse files Browse the repository at this point in the history
…m calls?
  • Loading branch information
wilkie committed Jan 19, 2010
1 parent ef4f99c commit aedacc5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
72 changes: 38 additions & 34 deletions kernel/core/syscall.d
Expand Up @@ -39,18 +39,20 @@ public:
return SyscallError.OK;
}

synchronized SyscallError allocPage(out int ret, AllocPageArgs* params) {
Environment* current = Scheduler.current();
SyscallError allocPage(out int ret, AllocPageArgs* params) {
synchronized {
Environment* current = Scheduler.current();

if (current.alloc(params.virtualAddress, 4096, true) == ErrorVal.Fail) {
ret = -1;
kprintfln!("allocPage({}): FAIL")(params.virtualAddress);
return SyscallError.Failcopter;
}
if (current.alloc(params.virtualAddress, 4096, true) == ErrorVal.Fail) {
ret = -1;
kprintfln!("allocPage({}): FAIL")(params.virtualAddress);
return SyscallError.Failcopter;
}

ret = 0;
ret = 0;

return SyscallError.OK;
return SyscallError.OK;
}
}

// void exit(ulong retval)
Expand Down Expand Up @@ -83,32 +85,34 @@ public:
// return SyscallError.OK;
// }

synchronized SyscallError perfPoll(PerfPollArgs* params) {
static ulong[256] value;
static ulong numTimes = 0;
static ulong overall;

numTimes++;
bool firstTime = false;

//params.value = PerfMon.pollEvent(params.event) - params.value;
if (numTimes == 1) {
firstTime = true;
SyscallError perfPoll(PerfPollArgs* params) {
synchronized {
static ulong[256] value;
static ulong numTimes = 0;
static ulong overall;

numTimes++;
bool firstTime = false;

//params.value = PerfMon.pollEvent(params.event) - params.value;
if (numTimes == 1) {
firstTime = true;
}

value[Cpu.identifier] = PerfMon.pollEvent(params.event) - value[Cpu.identifier];

if (numTimes == 1) {
overall = PerfMon.pollEvent(params.event);
}
else if (numTimes == 8) {
overall = value[0];
overall += value[1];
overall += value[2];
overall += value[3];
}

return SyscallError.OK;
}

value[Cpu.identifier] = PerfMon.pollEvent(params.event) - value[Cpu.identifier];

if (numTimes == 1) {
overall = PerfMon.pollEvent(params.event);
}
else if (numTimes == 8) {
overall = value[0];
overall += value[1];
overall += value[2];
overall += value[3];
}

return SyscallError.OK;
}

}
Expand Down
15 changes: 15 additions & 0 deletions kernel/runtime/dstubs.d
Expand Up @@ -95,6 +95,21 @@ void _d_monitorexit(Object h){
mon.unlock();
}

// XXX: Also magical.

struct D_CRITICAL_SECTION {
D_CRITICAL_SECTION* next;
Mutex mtx;
}

void _d_criticalenter(D_CRITICAL_SECTION* dcs) {
dcs.mtx.lock();
}

void _d_criticalexit(D_CRITICAL_SECTION* dcs) {
dcs.mtx.unlock();
}

/**************************************************
Random stubs (they'll go somewhere eventually)
**************************************************/
Expand Down

0 comments on commit aedacc5

Please sign in to comment.