peter [Sat, 24 May 2003 20:58:47 +0000 (20:58 +0000)]
Add a temporary indirect patch for gcc when targeting amd64. This is to
give the cvs tree a surviving a 'make world'. One of the two diff chunks
is already in gcc-3.3, the other has been committed to gcc's HEAD and
is in the pipeline for gcc-3.3.1 (but has not been committed yet).
The first chunk simplifies an excessively complex assembler statement
when generating switch jump tables. The use of '.' causes as(1) to choke
on big files. Use a simpler form instead. This is only an issue for
TARGET_64BIT mode.
The second chunk fixes an internal compiler error when compiling
libc/stdio/vfprinf.c. While this is supposedly only an issue for
64 bit mode, it does touch the 32 bit i386 code paths, so this patch
is only applied for TARGET_ARCH == amd64 to keep the risks down.
Breaking gcc at the 11th hour would suck.
This will be removed when it is time to import gcc-3.3.
marcel [Sat, 24 May 2003 20:51:55 +0000 (20:51 +0000)]
Unconditionally restore ar.k7 (memory stack) and ar.k6 (register stack)
when returning from an interrupt. Both registers are used on interrupt
to switch to the right kernel stack, but other than that they are not
used. This means we only have to make sure they contain proper values
while in user mode. As such, we conditionally restored these registers
based on whether we returned to userland or not. A nice property of
conditionally restoring ar.k6 and ar.k7 is that it introduces two
invariants: ar.k6 always points to the bottom of the kernel stack and
ar.k7 always points to the top of the kernel stack (immediately below
the PCB we have there).
However, the EPC syscall path introduces an irregularity: there's no
"thin red line" between user and kernel. There's a grey area that's a
couple of instructions wide. Any interruption in that grey area is
bound to see an inconsistent state. One such state is that we're in
kernel space for all practical purposes, but we still need to have
ar.k6 and ar.k7 restored as if we're in userland.
Thus: restore ar.k6 and ar.k7 unconditionally at the cost of losing
a valuable invariant. Both registers now hold the extend of the
usable portion of the kernel stack at any interrupt nesting, which
when in userland mean the bottom and the top of the kstack.
peter [Sat, 24 May 2003 19:38:18 +0000 (19:38 +0000)]
libstdc++.so breaks on amd64 due to bogons in our build, so prevent the
shared library being built for amd64. The problem is that libstdc++.so
is produced with 'cc -shared'. This has an internal -lgcc, which is
not PIC. libstdc++.so uses exceptions and the dwarf2 unwinder, which
are in libgcc.a. As a result, non-PIC code gets pulled into libstdc++.so.
This is fatal on amd64 when certain relocation types cannot be used in
PIC mode. The official FSF solution to this is to have libgcc.so with
internal ELF symbol versioning to solve the ABI problem, but I dont want
to fight that battle yet. I tried making libgcc_pic.a (which worked
fine), but thats not something for the 11th hour before a release.
hmp [Sat, 24 May 2003 18:28:18 +0000 (18:28 +0000)]
Get usb(4) manual page closer to reality:
- update ``struct usb_device_info''
- add information about new fields in about struct
- document USB_EVENT_IS_ATTACH() and USB_EVENT_IS_DETACH()
- update URL of the USB.ORG developer documentation
PR: docs/41580 (original patch)
Reviewed by: n_hibma
Approved by: des (mentor), re (bmah)
peter [Sat, 24 May 2003 17:37:51 +0000 (17:37 +0000)]
Initial pass at supporting shared libraries on amd64. There are still
a few missing relocation types in amd64/reloc.c, but I have not found
any of them in use yet. :-)
deischen [Sat, 24 May 2003 02:29:25 +0000 (02:29 +0000)]
Change low-level locking a bit so that we can tell if
a lock is being waitied on.
Fix a races in join and cancellation.
When trying to wait on a CV and the library is not yet
threaded, make it threaded so that waiting actually works.
When trying to nanosleep() and we're not threaded, just
call the system call nanosleep instead of adding the thread
to the wait queue.
Clean up adding/removing new threads to the "all threads queue",
assigning them unique ids, and tracking how many active threads
there are. Do it all when the thread is added to the scheduling
queue instead of making pthread_create() know how to do it.
Fix a race where a thread could be marked for signal delivery
but it could be exited before we actually add the signal to it.
Other minor cleanups and bug fixes.
Submitted by: davidxu
Approved by: re@ (blanket for libpthread)
mtm [Sat, 24 May 2003 01:02:16 +0000 (01:02 +0000)]
Lock the cond queue (condition variables):
Access to the thread's flags and state is protected by
_thread_critical_enter/exit(). When a thread is signaled with a condition
its state must be protected by locking it and disabling
signals before it is taken of the waiters' queue.
Move the implementation of pthread_cond_signal() and pthread_cond_broadcast()
into one function, cond_signal(). Its behaviour is determined by the
last argument, int broadcast. If this is set to 1 it will remove all
waiters, otherwise it will wake up only the first waiter thread.
Remove an extraneous call to pthread_testcancel().
marcel [Sat, 24 May 2003 00:17:34 +0000 (00:17 +0000)]
Fix an alpha inheritance bug:
On alpha, PAL is involved in context management and after wiring
the CPU (in alpha_init()) a context switch was performed to tell
PAL about the context. This was bogusly brought over to ia64
where it introduced bugs, because we restored the context from
a mostly uninitialized PCB.
The cleanup constitutes:
o Remove the unused arguments from ia64_init().
o Don't return from ia64_init(), but instead call mi_startup()
directly. This reduces the amount of muckery in assembly and
also allows for the next bullet:
o Save our currect context prior to calling mi_startup(). The
reason for this is that many threads are created from thread0
by cloning the PCB. By saving our context in the PCB, we have
something sane to clone. It also ensures that a cloned thread
that does not alter the context in any way will return to
the saved context, where we're ready for the eventuality with
a nice, user unfriendly panic().
The cleanup fixes at least the following bugs:
o Entering mi_startup() with the RSE in enforced lazy mode.
o Re-execution of ia64_init() in certain "lab" conditions.
While here, add proper unwind directives to __start() so that
the unwind knows it has reached the bottom of the (call) stack.
marcel [Fri, 23 May 2003 23:55:31 +0000 (23:55 +0000)]
Fix a (new) source of instability:
When interrupting a kernel context, we don't need to switch stacks
(memory nor register). As such, we were also not restoring the
register stack pointer (ar.bspstore). This, however, fails to be
valid in 1 situation: when we interrupt a register stack switch as
is being done in restorectx(). The problem is that restorectx()
needs to have ar.bsp == ar.bspstore before it can assign the new
value to ar.bspstore. This is achieved by doing a loadrs prior to
assigning to ar.bspstore. If we take an interrupt in between the
loadrs and the assignment and we don't make sure we restore the
ar.bspstore prior to returning from the interrupt, we switch
stacks with possibly non-zero dirty registers, which means that
the new frame pointer (ar.bsp) will be invalid.
So, instead of jumping over the restoration of the register frame
pointer and related registers, we conditionalize it based on whether
we return to kernel context or user context. A future performance
tweak is possible by only restoring ar.bspstore when returning to
kernel mode *and* when the RSE is in enforced lazy mode. One cannot
assume ar.bsp == ar.bspstore if the RSE is not in enforced lazy mode
anyway.
While here (well, not quite) don't unconditionally assign to
ar.bspstore in exception_save. Only do that when we actually switch
stacks. It can only harm us to do it unconditionally.
mtm [Fri, 23 May 2003 23:39:31 +0000 (23:39 +0000)]
Add two functions: _spinlock_pthread() and _spinunlock_pthread()
that take the address of a struct pthread as their first argument.
_spin[un]lock() just become wrappers arround these two functions.
These new functions are for use in situations where curthread can't be
used. One example is _thread_retire(), where we invalidate the array index
curthread uses to get its pointer..
marcel [Fri, 23 May 2003 23:16:43 +0000 (23:16 +0000)]
In swapctx(), put the RSE in enforced lazy mode before we flush the
register stack. There's nothing really wrong with flushing before
putting the RSE in enforced lazy mode, provided you don't depend on
ar.bspstore being equal to ar.bsp when the RSE has been put in
enforced lazy more. The small window between the flush and setting
the RSE may be sufficient to have the RSE eagerly increase the dirty
region (and hence cause ar.bspstore != ar.bsp) or have an interrupt
that may even get the laziest RSE to do something.
Anyway: we don't depend on ar.bspstore being equal to ar.bsp, so
nothing was and is broken. But the code was non-intuitive and
easily confuses. This is a source of future bugs.
Note: the advantage of not depending on ar.bspstore is that there's
some recilience against an interrupted flushrs. Clobbering is limited
to stacked register contents only, not to RSE address clobbering.
alc [Fri, 23 May 2003 19:54:02 +0000 (19:54 +0000)]
Make the maximum number of vnodes a function of both the physical memory
size and the kernel's heap size, specifically, vm_kmem_size. This
function allows a maximum of 40% of the vm_kmem_size to be used for
vnodes and vm objects. This is a conservative bound based upon recent
problem reports. (In other words, a slight increase in this percentage
may be safe.)
Finally, machines with less than ~3GB of RAM should be unaffected
by this change, i.e., the maximum number of vnodes should remain
the same. If necessary, machines with 3GB or more of RAM can increase
the maximum number of vnodes by increasing vm_kmem_size.
Desired by: scottl
Tested by: jake
Approved by: re (rwatson,scottl)
mtm [Fri, 23 May 2003 10:28:13 +0000 (10:28 +0000)]
EDOOFUS
Prevent one thread from messing up another thread's saved signal
mask by saving it in struct pthread instead of leaving it as a
global variable. D'oh!
mtm [Fri, 23 May 2003 09:48:20 +0000 (09:48 +0000)]
Make WARNS2 clean. The fixes mostly included:
o removed unused variables
o explicit inclusion of header files
o prototypes for externally defined functions
peter [Fri, 23 May 2003 06:35:45 +0000 (06:35 +0000)]
Update comments. Note that the kernel is at -1GB, not -2GB as erroniously
implied by the previous commit. KVM is still only 1GB until
pmap_growkernel() learns about the extra page table level.
peter [Fri, 23 May 2003 06:31:56 +0000 (06:31 +0000)]
As suggested by the gdb folks, pad the 'struct fpreg' to a full 512 bytes
to match the native fxsave/fxrstor object size since thats apparently what
the Linux/NetBSD folks do.
peter [Fri, 23 May 2003 06:08:28 +0000 (06:08 +0000)]
Add amd64 to the MACHINE_ARCH list of systems that link bsdlabel to
disklabel. I just got burnt again by having an old disklabel binary
kicking around.
Discussed with: phk
Approved by: re (safe amd64 stuff)
peter [Fri, 23 May 2003 05:10:49 +0000 (05:10 +0000)]
Low risk amd64 fix. Use a vm_offset_t for the virtual location of the
buffer space instead of a u_int32_t. Otherwise the upper 32 bits of
the address space get truncated and syscons blows up.
peter [Fri, 23 May 2003 05:07:33 +0000 (05:07 +0000)]
Deal with the user VM space expanding. 32 bit applications do not like
having their stack at the 512GB mark. Give 4GB of user VM space for 32
bit apps. Note that this is significantly more than on i386 which gives
only about 2.9GB of user VM to a process (1GB for kernel, plus page
table pages which eat user VM space).
peter [Fri, 23 May 2003 05:04:54 +0000 (05:04 +0000)]
Major pmap rework to take advantage of the larger address space on amd64
systems. Of note:
- Implement a direct mapped region using 2MB pages. This eliminates the
need for temporary mappings when getting ptes. This supports up to
512GB of physical memory for now. This should be enough for a while.
- Implement a 4-tier page table system. Most of the infrastructure is
there for 128TB of userland virtual address space, but only 512GB is
presently enabled due to a mystery bug somewhere. The design of this
was heavily inspired by the alpha pmap.c.
- The kernel is moved into the negative address space(!).
- The kernel has 2GB of KVM available.
- Provide a uma memory allocator to use the direct map region to take
advantage of the 2MB TLBs.
- Fixed some assumptions in the bus_space macros about the ability
to fit virtual addresses in an 'int'.
Notable missing things:
- pmap_growkernel() should be able to grow to 512GB of KVM by expanding
downwards below kernbase. The kernel must be at the top 2GB of the
negative address space because of gcc code generation strategies.
- need to fix the >512GB user vm code.
grog [Fri, 23 May 2003 01:15:55 +0000 (01:15 +0000)]
Change the way the plex lock mutexes work. Previously they were part
of the struct plex, which tore apart the mutex linked lists when the
plex table was expanded. Now we maintain a pool of mutexes (currently
32) to be shared by all plexes. This is still a lot better than the
splhigh() method used in other architectures.
expand_table: Add parameters file and line if we're debugging.
grog [Fri, 23 May 2003 01:15:30 +0000 (01:15 +0000)]
Change the way the plex lock mutexes work. Previously they were part
of the struct plex, which tore apart the mutex linked lists when the
plex table was expanded. Now we maintain a pool of mutexes (currently
32) to be shared by all plexes. This is still a lot better than the
splhigh() method used in other architectures.
grog [Fri, 23 May 2003 01:14:35 +0000 (01:14 +0000)]
Change the way the plex lock mutexes work. Previously they were part
of the struct plex, which tore apart the mutex linked lists when the
plex table was expanded. Now we maintain a pool of mutexes (currently
32) to be shared by all plexes. This is still a lot better than the
splhigh() method used in other architectures.
grog [Fri, 23 May 2003 01:13:43 +0000 (01:13 +0000)]
Change the way the plex lock mutexes work. Previously they were part
of the struct plex, which tore apart the mutex linked lists when the
plex table was expanded. Now we maintain a pool of mutexes (currently
32) to be shared by all plexes. This is still a lot better than the
splhigh() method used in other architectures.
grog [Fri, 23 May 2003 01:13:10 +0000 (01:13 +0000)]
Change many strcpys to strlcpys, etc.
Submitted by: Ted Unangst <tedu@stanford.edu>
Correct some inaccurate and badly formatted comments.
config_subdisk: If our drive is down, ensure that the subdisk is
crashed. Previously it was possible for the subdisk
to be up when the drive was down.
Change the way the plex lock mutexes work. Previously they were part
of the struct plex, which tore apart the mutex linked lists when the
plex table was expanded. Now we maintain a pool of mutexes (currently
32) to be shared by all plexes. This is still a lot better than the
splhigh() method used in other architectures.
bmah [Fri, 23 May 2003 00:02:10 +0000 (00:02 +0000)]
Modified release note: Note code generation problems with the base
system GCC using -march=pentium4, and the local workaround in our
Makefile infrastructure.
imp [Thu, 22 May 2003 23:58:50 +0000 (23:58 +0000)]
o Document the tunables that acpi allows. (mdoc gurus please comment
on and fix if neceeary).
o Note that acpi is available on i386-ia32, ia64 and amd64, not just 'intel'
platforms. Intel has had nothing to do with amd64.
dougb [Thu, 22 May 2003 18:38:54 +0000 (18:38 +0000)]
When newfs'ing a partition with UFS2 that had previously been newfs'ed
with UFS1, the UFS1 superblocks were not deleted. This allowed any
RELENG_4 (or other non-UFS2-aware) fsck to think it knew how to "fix"
the file system, resulting in severe data scrambling.
This patch is a more advanced version than the one originally submitted.
Lukas improved it based on feedback from Kirk, and testing by me. It
blanks all UFS1 superblocks (if any) during a UFS2 newfs, thereby causing
fsck's that are not UFS2 aware to generate the "SEARCH FOR ALTERNATE
SUPER-BLOCK FAILED" message, and exit without damaging the fs.
anholt [Thu, 22 May 2003 16:56:46 +0000 (16:56 +0000)]
Change -march=pentium4 to -march=pentium3 when CPUTYPE==p4, because gcc 3.2 is
known to produce broken code with -march=pentium4. Add a note explaining this.
This should be removed when we update to gcc 3.3 or the bug is otherwise fixed.
julian [Wed, 21 May 2003 18:53:25 +0000 (18:53 +0000)]
When we are spilling threads out of the run queue during panic, make sure we
keep the thread state variable consistent with its real state.
i.e. Don't say it's on the run queue when it isn't.
ru [Wed, 21 May 2003 15:52:43 +0000 (15:52 +0000)]
mdoc(7) fixes.
This manpage should really have only one short description (.Nd);
if anyone could come up with a wording suitable for both conversion
and decoding/encoding functions, that would unbreak the whatis(1)
output for this manpage.
ru [Wed, 21 May 2003 13:26:37 +0000 (13:26 +0000)]
Fixed catman(1) so that if the source files are compressed,
the preformatted files are compressed with the same program
as the source, and if the source files are uncompressed, the
preformatted files are also uncompressed.
mtm [Wed, 21 May 2003 08:21:24 +0000 (08:21 +0000)]
o Make the defenition of _set_curthread() match its declaration
in thr_private.h
o Lock down the ldt_entries array and ldt_free, which points to
the next free slot. As noted in the comments, it's necessary
to special case the initial_thread because %gs is not setup
for it yet. This is ok because that early in the program there
won't be any reentrancy issues anyways.
mtm [Wed, 21 May 2003 03:41:07 +0000 (03:41 +0000)]
Insert a debugging aid:
When in either the mutex or cond queue we notice that the thread
is already on one of the queues, don't just simply abort(). Print
out the thread's identifiers and what queue it was on.
mtm [Wed, 21 May 2003 03:34:54 +0000 (03:34 +0000)]
Re-enable the garbage collector thread in anticipation of further
locking work. I can't see anything obviously wrong with it (other than
the need to update the locking).
mtm [Wed, 21 May 2003 03:29:18 +0000 (03:29 +0000)]
When a thread exits it does not return from the kernel unless it
is the *only* remaining thread in the application, in which case we
should not core dump, and instead exit gracefully.
jhb [Tue, 20 May 2003 20:50:33 +0000 (20:50 +0000)]
The per-CPU spinlocks list is only maintained when WITNESS is enabled.
Thus, treat all page faults while in a critical section as fatal rather
than just those that occur with a non-empty spinlocks list. All such page
faults are fatal anyways. Calling trap_fatal() earlier increases the
chances of getting more useful panic messages and a possible DDB prompt.
marcel [Tue, 20 May 2003 06:57:20 +0000 (06:57 +0000)]
o Fix a definite bogon: the dirty bity fault, instruction access
failt and data access fault install the PTE in question into
the VHPT table. However, a post-increment was missing and we
wrote the raw PTE data into the pagesize/access key field.
This leaves a corrupt VHPT entry.
o While here, remove the explicit cache purge. Insertion into
the translation implicitly purges any overlapping entries.
o Make sure there's a cycle break between the itc and the rfi.
o Whitespace fixes.