]> Devi Nivas Git - cs3210-lab1.git/log
cs3210-lab1.git
18 years agoModel verifying that wakeup really
rsc [Fri, 12 Oct 2007 04:21:04 +0000 (04:21 +0000)]
Model verifying that wakeup really
can be called after release without
causing deadlock.

18 years agoIncorporate new understanding of/with Intel SMP spec.
rsc [Mon, 1 Oct 2007 20:43:15 +0000 (20:43 +0000)]
Incorporate new understanding of/with Intel SMP spec.

Dropped cmpxchg in favor of xchg, to match lecture notes.

Use xchg to release lock, for future protection and to
keep gcc from acting clever.

18 years agoRe: why cpuid() in locking code?
rsc [Sun, 30 Sep 2007 14:30:04 +0000 (14:30 +0000)]
Re: why cpuid() in locking code?

rtm wrote:
> Why does acquire() call cpuid()? Why does release() call cpuid()?

The cpuid in acquire is redundant with the cmpxchg, as you said.
I have removed the cpuid from acquire.

The cpuid in release is actually doing something important,
but not on the hardware.  It keeps gcc from reordering the
lock->locked assignment above the other two during optimization.
(Not that current gcc -O2 would choose to do that, but it is allowed to.)
I have replaced the cpuid in release with a "gcc barrier" that
keeps gcc from moving things around but has no hardware effect.

On a related note, I don't think the cpuid in mpmain is necessary,
for the same reason that the cpuid wasn't needed in release.

As to the question of whether

  acquire();
  x = protected;
  release();

might read protected after release(), I still haven't convinced
myself whether it can.  I'll put the cpuid back into release if
we determine that it can.

Russ

18 years agotricks
rsc [Sun, 30 Sep 2007 14:20:47 +0000 (14:20 +0000)]
tricks

18 years agointerrupts during system calls
rsc [Thu, 27 Sep 2007 21:37:45 +0000 (21:37 +0000)]
interrupts during system calls

"It just works."

18 years agoFinal word on the locking fiasco?
rsc [Thu, 27 Sep 2007 21:25:37 +0000 (21:25 +0000)]
Final word on the locking fiasco?

Change pushcli / popcli so that they can never turn on
interrupts unexpectedly.  That is, if interrupts are on,
then pushcli(); popcli(); turns them off and back on, but
if they are off to begin with, then pushcli(); popcli(); is
a no-op.

I think our fundamental mistake was having a primitive
(release and then popcli nee spllo) that could turn
interrupts on at unexpected moments instead of being
explicit about when we want to start allowing interrupts.

With the new semantics, all the manual fiddling of ncli
to force interrupts off in certain sections goes away.
In return, we must explicitly mark the places where
we want to enable interrupts unconditionally, by calling sti().
There is only one: inside the scheduler loop.

18 years agocleaner
rsc [Thu, 27 Sep 2007 21:02:03 +0000 (21:02 +0000)]
cleaner

18 years agoyank out stack overflow checking ugliness
rsc [Thu, 27 Sep 2007 20:38:53 +0000 (20:38 +0000)]
yank out stack overflow checking ugliness

18 years agookay, that was long enough - revert
rsc [Thu, 27 Sep 2007 20:32:45 +0000 (20:32 +0000)]
okay, that was long enough - revert

18 years agotest: store curproc at top of stack
rsc [Thu, 27 Sep 2007 20:29:50 +0000 (20:29 +0000)]
test: store curproc at top of stack

I don't actually think this is worthwhile, but I figured
I would check it in before reverting it, so that it can
be in the revision history.

Pros:
  * curproc doesn't need to turn on/off interrupts
  * scheduler doesn't have to edit curproc anymore

Cons:
  * it's ugly
  * all the stack computation is more complicated.
  * it doesn't actually simplify anything but curproc,
    and even curproc is harder to follow.

18 years agonit
rsc [Thu, 27 Sep 2007 20:25:32 +0000 (20:25 +0000)]
nit

18 years agorename splhi/spllo to pushcli/popcli
rsc [Thu, 27 Sep 2007 20:09:40 +0000 (20:09 +0000)]
rename splhi/spllo to pushcli/popcli

18 years agooverkill: use segments to catch stack overflow (delete before next year)
rsc [Thu, 27 Sep 2007 19:39:10 +0000 (19:39 +0000)]
overkill: use segments to catch stack overflow (delete before next year)

18 years agonow spllo is okay
rsc [Thu, 27 Sep 2007 19:35:25 +0000 (19:35 +0000)]
now spllo is okay

18 years agobetter lapic writes, suggested by cliff
rsc [Thu, 27 Sep 2007 19:33:46 +0000 (19:33 +0000)]
better lapic writes, suggested by cliff

18 years agouse larger, allocated cpu stacks
rsc [Thu, 27 Sep 2007 19:32:43 +0000 (19:32 +0000)]
use larger, allocated cpu stacks

18 years agodon't call it ss - that's the stack segment
rsc [Thu, 27 Sep 2007 16:47:50 +0000 (16:47 +0000)]
don't call it ss - that's the stack segment

18 years agokernel SMP interruptibility fixes.
rsc [Thu, 27 Sep 2007 12:58:42 +0000 (12:58 +0000)]
kernel SMP interruptibility fixes.

Last year, right before I sent xv6 to the printer, I changed the
SETGATE calls so that interrupts would be disabled on entry to
interrupt handlers, and I added the nlock++ / nlock-- in trap()
so that interrupts would stay disabled while the hw handlers
(but not the syscall handler) did their work.  I did this because
the kernel was otherwise causing Bochs to triple-fault in SMP
mode, and time was short.

Robert observed yesterday that something was keeping the SMP
preemption user test from working.  It turned out that when I
simplified the lapic code I swapped the order of two register
writes that I didn't realize were order dependent.  I fixed that
and then since I had everything paged in kept going and tried
to figure out why you can't leave interrupts on during interrupt
handlers.  There are a few issues.

First, there must be some way to keep interrupts from "stacking
up" and overflowing the stack.  Keeping interrupts off the whole
time solves this problem -- even if the clock tick handler runs
long enough that the next clock tick is waiting when it finishes,
keeping interrupts off means that the handler runs all the way
through the "iret" before the next handler begins.  This is not
really a problem unless you are putting too many prints in trap
-- if the OS is doing its job right, the handlers should run
quickly and not stack up.

Second, if xv6 had page faults, then it would be important to
keep interrupts disabled between the start of the interrupt and
the time that cr2 was read, to avoid a scenario like:

   p1 page faults [cr2 set to faulting address]
   p1 starts executing trapasm.S
   clock interrupt, p1 preempted, p2 starts executing
   p2 page faults [cr2 set to another faulting address]
   p2 starts, finishes fault handler
   p1 rescheduled, reads cr2, sees wrong fault address

Alternately p1 could be rescheduled on the other cpu, in which
case it would still see the wrong cr2.  That said, I think cr2
is the only interrupt state that isn't pushed onto the interrupt
stack atomically at fault time, and xv6 doesn't care.  (This isn't
entirely hypothetical -- I debugged this problem on Plan 9.)

Third, and this is the big one, it is not safe to call cpu()
unless interrupts are disabled.  If interrupts are enabled then
there is no guarantee that, between the time cpu() looks up the
cpu id and the time that it the result gets used, the process
has not been rescheduled to the other cpu.  For example, the
very commonly-used expression curproc[cpu()] (aka the macro cp)
can end up referring to the wrong proc: the code stores the
result of cpu() in %eax, gets rescheduled to the other cpu at
just the wrong instant, and then reads curproc[%eax].

We use curproc[cpu()] to get the current process a LOT.  In that
particular case, if we arranged for the current curproc entry
to be addressed by %fs:0 and just use a different %fs on each
CPU, then we could safely get at curproc even with interrupts
disabled, since the read of %fs would be atomic with the read
of %fs:0.  Alternately, we could have a curproc() function that
disables interrupts while computing curproc[cpu()].  I've done
that last one.

Even in the current kernel, with interrupts off on entry to trap,
interrupts are enabled inside release if there are no locks held.
Also, the scheduler's idle loop must be interruptible at times
so that the clock and disk interrupts (which might make processes
runnable) can be handled.

In addition to the rampant use of curproc[cpu()], this little
snippet from acquire is wrong on smp:

  if(cpus[cpu()].nlock == 0)
    cli();
  cpus[cpu()].nlock++;

because if interrupts are off then we might call cpu(), get
rescheduled to a different cpu, look at cpus[oldcpu].nlock, and
wrongly decide not to disable interrupts on the new cpu.  The
fix is to always call cli().  But this is wrong too:

  if(holding(lock))
    panic("acquire");
  cli();
  cpus[cpu()].nlock++;

because holding looks at cpu().  The fix is:

  cli();
  if(holding(lock))
    panic("acquire");
  cpus[cpu()].nlock++;

I've done that, and I changed cpu() to complain the first time
it gets called with interrupts disabled.  (It gets called too
much to complain every time.)

I added new functions splhi and spllo that are like acquire and
release but without the locking:

  void
  splhi(void)
  {
    cli();
    cpus[cpu()].nsplhi++;
  }

  void
  spllo(void)
  {
    if(--cpus[cpu()].nsplhi == 0)
      sti();
  }

and I've used those to protect other sections of code that refer
to cpu() when interrupts would otherwise be disabled (basically
just curproc and setupsegs).  I also use them in acquire/release
and got rid of nlock.

I'm not thrilled with the names, but I think the concept -- a
counted cli/sti -- is sound.  Having them also replaces the
nlock++/nlock-- in trap.c and main.c, which is nice.

Final note: it's still not safe to enable interrupts in
the middle of trap() between lapic_eoi and returning
to user space.  I don't understand why, but we get a
fault on pop %es because 0x10 is a bad segment
descriptor (!) and then the fault faults trying to go into
a new interrupt because 0x8 is a bad segment descriptor too!
Triple fault.  I haven't debugged this yet.

18 years agouse console lock
rsc [Thu, 27 Sep 2007 12:29:25 +0000 (12:29 +0000)]
use console lock

18 years agomake slow bigdir last test
rsc [Thu, 27 Sep 2007 12:29:06 +0000 (12:29 +0000)]
make slow bigdir last test

18 years agochanges since two days ago:
rsc [Thu, 27 Sep 2007 11:27:04 +0000 (11:27 +0000)]
changes since two days ago:

drop , address=0xf0000 from romimage line.
newer bochs has a 128k bios that it loads elsewhere.
so let bochs decide where the romimage goes.

change cpu quantum to 1 (default is 5, max is 16)
in an attempt to provoke more races.  only provokes
them slightly more frequently, may not be worth
the slowdown.

18 years agouse standard bios location
rsc [Thu, 27 Sep 2007 05:14:25 +0000 (05:14 +0000)]
use standard bios location

18 years agobelieve it or not, this was working
rsc [Thu, 27 Sep 2007 05:13:10 +0000 (05:13 +0000)]
believe it or not, this was working

the macro expansion of "char *cp;" turned into
char *(curproc[cpu()]);  which declares a dynamically
sized array of char* called curproc.

so then &cp == &(curproc[cpu()]) was actually a
stack variable as "expected".  it was one past the
end of the array, but the implicit alloca allocated
more than was necessary.

do not tell me that making cp a #define was a bad idea.
there are worse problems to fix.  more on that later.

18 years agocomment bochs nonsense
rsc [Wed, 26 Sep 2007 23:32:47 +0000 (23:32 +0000)]
comment bochs nonsense

18 years agovarious comment and print tweaks
rsc [Wed, 26 Sep 2007 23:32:00 +0000 (23:32 +0000)]
various comment and print tweaks

18 years agodebugging prints
rsc [Wed, 26 Sep 2007 23:24:23 +0000 (23:24 +0000)]
debugging prints

18 years agoApparently the initial interrupt count lapic[TICR]
rsc [Wed, 26 Sep 2007 20:34:12 +0000 (20:34 +0000)]
Apparently the initial interrupt count lapic[TICR]
must be set *after* initializing the lapic[TIMER] vector.

Doing this, we now get clock interrupts on cpu 1.
(No idea why we always got them on cpu 0.)

Don't write to TCCR - it is read-only.

18 years agooops, interrupts on in syscall traps doesn't work after all
rtm [Tue, 25 Sep 2007 16:15:05 +0000 (16:15 +0000)]
oops, interrupts on in syscall traps doesn't work after all

18 years agotell SETGATE to leave interrupts on for T_SYSCALL
rtm [Tue, 25 Sep 2007 15:23:44 +0000 (15:23 +0000)]
tell SETGATE to leave interrupts on for T_SYSCALL
panic if unknown fault with CPL=0 (i.e. in kernel)

18 years agoThis should fix building on FreeBSD
nelhage [Wed, 19 Sep 2007 23:49:52 +0000 (23:49 +0000)]
This should fix building on FreeBSD

18 years agoFix compilation on 64-bit machines (thanks to andersk for patch)
nelhage [Tue, 18 Sep 2007 00:41:34 +0000 (00:41 +0000)]
Fix compilation on 64-bit machines (thanks to andersk for patch)

18 years agofix comments
rtm [Sat, 15 Sep 2007 20:05:47 +0000 (20:05 +0000)]
fix comments

18 years agosh
rsc [Wed, 5 Sep 2007 15:55:43 +0000 (15:55 +0000)]
sh

18 years agocontinuous quality management
rtm [Fri, 31 Aug 2007 19:55:27 +0000 (19:55 +0000)]
continuous quality management

18 years agosymlink implementation
rsc [Thu, 30 Aug 2007 18:36:38 +0000 (18:36 +0000)]
symlink implementation

18 years agodo not toss .ps
rsc [Thu, 30 Aug 2007 18:33:48 +0000 (18:33 +0000)]
do not toss .ps

18 years agoclumsy cd
rsc [Thu, 30 Aug 2007 18:30:26 +0000 (18:30 +0000)]
clumsy cd

18 years agomake new Homework 8 work
rtm [Thu, 30 Aug 2007 18:21:35 +0000 (18:21 +0000)]
make new Homework 8 work

18 years agooops - broke circular buffer
rsc [Thu, 30 Aug 2007 18:20:53 +0000 (18:20 +0000)]
oops - broke circular buffer

18 years agooops - broke arg counting
rsc [Thu, 30 Aug 2007 18:19:52 +0000 (18:19 +0000)]
oops - broke arg counting

18 years agolongjmp -> swtch in comments
rtm [Thu, 30 Aug 2007 17:39:56 +0000 (17:39 +0000)]
longjmp -> swtch in comments

18 years agotweak
rsc [Thu, 30 Aug 2007 14:12:19 +0000 (14:12 +0000)]
tweak

18 years agoDO NOT MAIL: xv6-rev1
rsc [Thu, 30 Aug 2007 14:11:21 +0000 (14:11 +0000)]
DO NOT MAIL: xv6-rev1

18 years agofinal xv6 for 2007
rsc [Thu, 30 Aug 2007 14:09:14 +0000 (14:09 +0000)]
final xv6 for 2007

18 years agobootothers now in main
rsc [Wed, 29 Aug 2007 19:20:49 +0000 (19:20 +0000)]
bootothers now in main

18 years agospelling
rtm [Wed, 29 Aug 2007 18:18:57 +0000 (18:18 +0000)]
spelling

18 years agofinal nits
rsc [Tue, 28 Aug 2007 19:39:49 +0000 (19:39 +0000)]
final nits

18 years agomatch README
rsc [Tue, 28 Aug 2007 19:30:29 +0000 (19:30 +0000)]
match README

18 years agonits
rsc [Tue, 28 Aug 2007 19:30:23 +0000 (19:30 +0000)]
nits

18 years agonits
rsc [Tue, 28 Aug 2007 19:25:04 +0000 (19:25 +0000)]
nits

18 years agodelete proc_ on proc_exit, proc_wait, proc_kill
rsc [Tue, 28 Aug 2007 19:14:43 +0000 (19:14 +0000)]
delete proc_ on proc_exit, proc_wait, proc_kill

18 years agocomments; rename irq_ to pic_
rsc [Tue, 28 Aug 2007 19:04:36 +0000 (19:04 +0000)]
comments; rename irq_ to pic_

18 years agospaces around else for rtm
rsc [Tue, 28 Aug 2007 18:37:41 +0000 (18:37 +0000)]
spaces around else for rtm

18 years agomore consistent spacing
rsc [Tue, 28 Aug 2007 18:32:08 +0000 (18:32 +0000)]
more consistent spacing

18 years agonits
rsc [Tue, 28 Aug 2007 18:23:48 +0000 (18:23 +0000)]
nits

18 years agofix offsets
rsc [Tue, 28 Aug 2007 18:04:43 +0000 (18:04 +0000)]
fix offsets

18 years agomore cmain -> bootmain
rsc [Tue, 28 Aug 2007 18:02:49 +0000 (18:02 +0000)]
more cmain -> bootmain

18 years agoChange dev read/write functions
rsc [Tue, 28 Aug 2007 17:49:49 +0000 (17:49 +0000)]
Change dev read/write functions
to take inode* instead of minor number.

Unlock console inode during console_read
and console_write.  Otherwise background
processes cannot write to console while the
shell is reading it waiting for input.

18 years agooops
rsc [Tue, 28 Aug 2007 17:48:44 +0000 (17:48 +0000)]
oops

18 years agocmain -> bootmain
rsc [Tue, 28 Aug 2007 13:01:10 +0000 (13:01 +0000)]
cmain -> bootmain

18 years agonit
rsc [Tue, 28 Aug 2007 12:52:14 +0000 (12:52 +0000)]
nit

18 years agoreplace setjmp/longjmp with swtch
rsc [Tue, 28 Aug 2007 12:48:33 +0000 (12:48 +0000)]
replace setjmp/longjmp with swtch

18 years agonever returns!
rsc [Tue, 28 Aug 2007 05:19:45 +0000 (05:19 +0000)]
never returns!

18 years agonits
rsc [Tue, 28 Aug 2007 05:01:04 +0000 (05:01 +0000)]
nits

18 years agoformatting
rsc [Tue, 28 Aug 2007 05:00:53 +0000 (05:00 +0000)]
formatting

18 years agoclumsy blank pages to make some files align better
rsc [Tue, 28 Aug 2007 05:00:39 +0000 (05:00 +0000)]
clumsy blank pages to make some files align better

18 years agorename 8253pit -> timer
rsc [Tue, 28 Aug 2007 04:41:20 +0000 (04:41 +0000)]
rename 8253pit -> timer

18 years agorename 8253pit.c to timer.c
rsc [Tue, 28 Aug 2007 04:40:58 +0000 (04:40 +0000)]
rename 8253pit.c to timer.c

18 years agorunoff
rsc [Tue, 28 Aug 2007 04:26:55 +0000 (04:26 +0000)]
runoff

18 years agoadd grep; add lost echo
rsc [Tue, 28 Aug 2007 04:26:34 +0000 (04:26 +0000)]
add grep; add lost echo

18 years agoavoid double echo
rsc [Tue, 28 Aug 2007 04:26:19 +0000 (04:26 +0000)]
avoid double echo

18 years agoremove _ from pipe; be like file
rsc [Tue, 28 Aug 2007 04:22:35 +0000 (04:22 +0000)]
remove _ from pipe; be like file

18 years agoclean up Makefile; add wc
rsc [Tue, 28 Aug 2007 04:20:40 +0000 (04:20 +0000)]
clean up Makefile; add wc

18 years agoadd struct stat decl
rsc [Tue, 28 Aug 2007 04:20:25 +0000 (04:20 +0000)]
add struct stat decl

18 years agodo not call proc_exit until lock dropped
rsc [Tue, 28 Aug 2007 04:20:13 +0000 (04:20 +0000)]
do not call proc_exit until lock dropped

18 years agooops
rsc [Tue, 28 Aug 2007 04:19:47 +0000 (04:19 +0000)]
oops

18 years agohandle printf("%s\n", 0)
rsc [Tue, 28 Aug 2007 04:15:35 +0000 (04:15 +0000)]
handle printf("%s\n", 0)

18 years agonit
rsc [Tue, 28 Aug 2007 04:14:32 +0000 (04:14 +0000)]
nit

18 years agooops
rsc [Tue, 28 Aug 2007 04:13:40 +0000 (04:13 +0000)]
oops

18 years agonit
rsc [Tue, 28 Aug 2007 04:13:24 +0000 (04:13 +0000)]
nit

18 years agoformatting tweaks
rsc [Tue, 28 Aug 2007 03:46:58 +0000 (03:46 +0000)]
formatting tweaks

18 years agocomment non-check of cp->killed
rsc [Tue, 28 Aug 2007 03:32:49 +0000 (03:32 +0000)]
comment non-check of cp->killed

18 years agoNo one is going to find this inode.
rsc [Tue, 28 Aug 2007 03:31:11 +0000 (03:31 +0000)]
No one is going to find this inode.
There is only one ref to it -- the caller --
and no links to it.

18 years agoNew shell.
rsc [Tue, 28 Aug 2007 03:28:29 +0000 (03:28 +0000)]
New shell.

18 years agoMove keyboard code into kbd.c; add backspace handling.
rsc [Tue, 28 Aug 2007 03:28:13 +0000 (03:28 +0000)]
Move keyboard code into kbd.c; add backspace handling.

18 years agooops
rsc [Tue, 28 Aug 2007 02:39:40 +0000 (02:39 +0000)]
oops

18 years agomove mp.h to low-level
rsc [Mon, 27 Aug 2007 23:55:45 +0000 (23:55 +0000)]
move mp.h to low-level

18 years agono more ioapic.h
rsc [Mon, 27 Aug 2007 23:54:24 +0000 (23:54 +0000)]
no more ioapic.h

18 years agomake code match comment
rsc [Mon, 27 Aug 2007 23:53:50 +0000 (23:53 +0000)]
make code match comment

18 years agomake code match comment
rsc [Mon, 27 Aug 2007 23:53:17 +0000 (23:53 +0000)]
make code match comment

18 years agomake code match comment
rsc [Mon, 27 Aug 2007 23:53:17 +0000 (23:53 +0000)]
make code match comment

18 years agoRename main0 to main.
rsc [Mon, 27 Aug 2007 23:32:16 +0000 (23:32 +0000)]
Rename main0 to main.

18 years agodelete unnecessary #include lines
rsc [Mon, 27 Aug 2007 23:26:33 +0000 (23:26 +0000)]
delete unnecessary #include lines

18 years agoSimplify MP hardware code.
rsc [Mon, 27 Aug 2007 22:53:31 +0000 (22:53 +0000)]
Simplify MP hardware code.
Mainly delete unused constants and code.

Move mp_startthem to main.c as bootothers.

18 years agoClean up lapic code.
rsc [Mon, 27 Aug 2007 16:57:13 +0000 (16:57 +0000)]
Clean up lapic code.

One initialization function now, not three.
Use #defines instead of enums (consistent with other code, but sigh).

Still boots in Bochs in SMP mode.

18 years agonits
rsc [Mon, 27 Aug 2007 16:55:10 +0000 (16:55 +0000)]
nits

18 years agonits
rsc [Mon, 27 Aug 2007 16:12:08 +0000 (16:12 +0000)]
nits

18 years agonits
rsc [Mon, 27 Aug 2007 16:06:19 +0000 (16:06 +0000)]
nits

18 years agooops
rsc [Mon, 27 Aug 2007 16:06:15 +0000 (16:06 +0000)]
oops

18 years agoEdit exec.
rsc [Mon, 27 Aug 2007 15:17:40 +0000 (15:17 +0000)]
Edit exec.

Do not commit to new memory image until
nothing can go wrong, avoiding bad2 case.

Be sure to allocate enough stack space for argv.

Load executable before initializing stack, to
keep ELF loops together.

Make argv loop clearer.