Julian Seward [Sat, 14 Dec 2002 23:59:09 +0000 (23:59 +0000)]
Merge patch from JeremyF:
66-illegal-instr
When translation encounters an illegal instruction, emit a call to an
illegal instruction rather than giving up altogether. Some programs
check for CPU capabilities by actually trying them out, so we want to
match a dumb Pentium's behaviour a little better.
It still prints the message, so it won't hide actual illegal or
mis-parsed instructions. I was hoping this might make the Nvidia
drivers realize they're running on a pre-MMX P5, but apparently they
just won't take that as an answer. It does make the virtual CPU
behave a little more like a real CPU though.
Julian Seward [Thu, 12 Dec 2002 23:42:48 +0000 (23:42 +0000)]
Merge patch from JeremyF:
72-jump
Add some codegen infrastructure to make it easier to generate local
jumps. If you want to generate a local backwards jump, use
VG_(init_target)(&tgt) to initialize the target descriptor, then
VG_(emit_target_back)(&tgt) just before emitting the target
instruction. Then, when emitting the delta for the jump, call
VG_(emit_delta)(&tgt).
Forward jumps are analogous, except that you call VG_(emit_delta)()
then VG_(emit_target_forward)().
The new emit function, VG_(emit_jcondshort_target)() takes a target
pointer rather than a delta.
Julian Seward [Thu, 12 Dec 2002 23:13:21 +0000 (23:13 +0000)]
Merge patch from JeremyF. This is a fixed version of the original
69-simple-jlo, which takes account of the fact that the P flag is set
only from the lowest 8 bits of the result, a problem causing the
original version of this patch not to work right.
Also fixes a call to new_emit.
69-simple-jlo
For Jlo and Jnlo, which test S == O or S != O, when generating special
test sequences which don't require the simulated flags in the real
flags, generate a test and parity test to see if both bits are equal
(even parity) or not equal (odd parity).
Julian Seward [Mon, 9 Dec 2002 19:20:00 +0000 (19:20 +0000)]
Merge patch from JeremyF:
69-simple-jlo
For Jlo and Jnlo, which test S == O or S != O, when generating special
test sequences which don't require the simulated flags in the real
flags, generate a test and parity test to see if both bits are equal
(even parity) or not equal (odd parity).
Julian Seward [Sun, 8 Dec 2002 22:24:59 +0000 (22:24 +0000)]
Get rid of the flag --fast-jcc; it's wired-on by default. Assumes that
pushf/popf is catastrophically expensive on most target CPUs, which is
certainly true for P3 and Athlon and I assume (but not checked) P4.
Julian Seward [Sun, 8 Dec 2002 22:14:11 +0000 (22:14 +0000)]
Merge patch from JeremyF:
65-fix-ldt
Fix LDT handling in threaded programs. do__apply_in_new_thread() was
failing to set up the child thread's LDT inherited from the parent,
and was triggering an assert in VG_(save_thread_state)() when trying
to copy the parent's thread state to the child.
Julian Seward [Sun, 8 Dec 2002 18:20:01 +0000 (18:20 +0000)]
Merge patches from JeremyF, to do lazy eflags updating:
- D flag is seperated from the rest (OSZCAP)
- Minimise transfers between real and simulated %eflags since these
are very expensive.
61-special-d
Make the D flag special. Store it separately in the baseblock rather
than in EFLAGs. This is because it is used almost completely unlike
the other flags, and mashing them together just makes maintaining
eflags hard.
62-lazy-eflags
Implements lazy eflags save and restore. Helps a lot.
Julian Seward [Sun, 1 Dec 2002 19:40:49 +0000 (19:40 +0000)]
Change the way INCEIP is done. Instead of emitting add insns, keep
track of the current %EIP value and write it to memory at an INCEIP.
Uses JeremyF's idea of only writing the lowest 8 bits if the upper 24
are unchanged since the previous write. [might this cause probls
to do with write combining on high-performance CPUs? To be checked
out.]
On a simple program running a small inner loop, this gets about 2/3
the benefits of removing INCEIPs altogether, compared with the add-insn
scheme.
I tried a much more complex scheme too, in which we do analysis to
remove as many INCEIPs as possible if it is possible to show that
there will be no EIP reads in between them. This seemed to make
almost no improvement on real programs (kate, xedit) and adds some
code and slows down the code generator, so I don't think it's worth
the hassle.
Julian Seward [Sun, 1 Dec 2002 02:07:08 +0000 (02:07 +0000)]
Merge patch from JeremyF:
56-chained-accounting
Fix accounting for chained blocks, by only counting real unchain
events, rather than the unchains used to establish the initial call to
VG_(patch_me) at the jump site.
Also a minor cleanup of the jump delta calculation in synth_jcond_lit.
Julian Seward [Sat, 30 Nov 2002 15:01:01 +0000 (15:01 +0000)]
Merge patch from JeremyF:
50-fast-cond
Implement Julian's idea for fast conditional jumps. Rather than fully
restoring the eflags register with an expensive push-popf pair, just
test the flag bits directly out of the base block. Faster, and smaller
code too!
Julian Seward [Sat, 30 Nov 2002 14:00:47 +0000 (14:00 +0000)]
Merge in a somewhat modified patch version of Jeremy Fitzhardinge's
translation chaining patch.
47-chained-bb
This implements basic-block chaining. Rather than always going through
the dispatch loop, a BB may jump directly to a successor BB if it is
present in the translation cache.
When the BB's code is first generated, the jumps to the successor BBs
are filled with undefined instructions. When the BB is inserted into
the translation cache, the undefined instructions are replaced with a
call to VG_(patch_me). When VG_(patch_me) is called, it looks up the
desired target address in the fast translation cache. If present, it
backpatches the call to patch_me with a jump to the translated target
BB. If the fast lookup fails, it falls back into the normal dispatch
loop.
When the parts of the translation cache are discarded, all translations
are unchained, so as to ensure we don't have direct jumps to code which
has been thrown away.
This optimisation only has effect on direct jumps; indirect jumps
(including returns) still go through the dispatch loop. The -v stats
indicate a worst-case rate of about 16% of jumps having to go via the
slow mechanism. This will be a combination of function returns and
genuine indirect jumps.
Certain parts of the dispatch loop's actions have to be moved into
each basic block; namely: updating the virtual EIP and keeping track
of the basic block counter.
At present, basic block chaining seems to improve performance by up to
25% with --skin=none. Gains for skins adding more instrumentation
will be correspondingly smaller.
There is a command line option: --chain-bb=yes|no (defaults to yes).
Julian Seward [Sat, 30 Nov 2002 12:35:42 +0000 (12:35 +0000)]
Merge patch from JeremyF (with a little added paranoia, for this one
could potentially cause hard-to-find code generation bugs):
00-lazy-fp
This patch implements lazy FPU state save and restore, which improves
the performance of FPU-intensive code by a factor of 15 or so. [when
running without any instrumentatation, that is.]
Julian Seward [Sat, 30 Nov 2002 00:49:43 +0000 (00:49 +0000)]
Complete integration of the new code management (sectored FIFO) story.
This commit adds stats gathering / printing (use -v -v), and selection
of sector size decided by asking skins, via
VG_(details).avg_translation_sizeB, the average size of their
translations.
Julian Seward [Fri, 29 Nov 2002 01:02:45 +0000 (01:02 +0000)]
Complete overhaul of the storage of translations to properly support
translation chaining. The old LRU system has gone, since it required
marking each translation each time it was used -- simulating a
reference bit. This is unacceptably expensive.
New scheme uses FIFO discard. TC is split into a variable number
(currently 8) parts. When all 8 parts are full, the oldest is
discarded and reused for allocation. This somewhat guards against
discarding recently-made translations and performs well in practice.
TT entries are simplified: the orig and trans size fields are now
stored in the TC, not in the TT. The TC entries are "self
describing", so it is possible to scan forwards through the TC entries
and rebuild the TT from them. TC entries are now word-aligned.
VG_(tt_fast) entries now point to TC entries, not TT entries.
The main dispatch loop now is 2 insns shorter since there's no need to
mark the current epoch on each TT entry as it is used. For that
matter, there's no longer any need for the notion of a current epoch
anyway.
It's all a great deal simpler than the old scheme, and it seems
significantly faster too.
Julian Seward [Wed, 20 Nov 2002 08:17:16 +0000 (08:17 +0000)]
A small tool to help documentation writers. Copies docs out of an
installation tree (`pwd`/Inst) back to the build tree since it is a
lot easier to edit them in the installation tree. Use with care!
- For all except `trivialleak', expected output lines like this:
by 0x........: __libc_start_main@@GLIBC_2.0 (...libc...)
were changed to look like this:
by 0x........: (within /.../tests/supp2)
This change was caused by a change about 3 weeks ago, but we couldn't work
out exactly which one. It does not seem unreasonable, though.
- For `malloc1' and `trivialleak', one of the line numbers changed -- they
are now correct instead of off by one -- thanks to Jeremy F's recent patch
which subtracts one from return addresses (for exactly this reason).
Now they all pass again except `tronical', as expected.
Overview:
- Factored out a lot of commonality between AddrCheck and MemCheck. Basic
idea is that common code goes into a single file in MemCheck, and AddrCheck
peeks in and "borrows" it.
More or less, only identical code or identical-with-respect-to-subtypes
code was factored out.
Identical-with-respect-to-subtypes means that some enum types (SuppKind,
ErrorKind, etc) were merged because they were identical except that
MemCheck had some extra constants. So some of the code borrowed by
AddrCheck contains cases it never needs. But that's not so bad, avoiding
the duplication is IMHO more important.
Removed:
- ac_include.h, it wasn't necessary
- All the old debugging stuff from ac_main.c (printing shadow regs, not
applicable for AddrCheck).
- MANUAL_DEPS from memcheck/Makefile.am because it wasn't doing anything
- Some unnecessary crud from addrcheck/Makefile.am
Added:
- memcheck/mc_common.{c,h}
- memcheck/mc_constants.h
- addrcheck/ac_common.c, which simply #includes memcheck/mc_common.c. This
hack was required because there is no way (that I could work out) to tell
Automake that it should build ../memcheck/mc_common.o before building
AddrCheck.
Changed:
- a lot of prefixes from SK_ to MC_; only core/skin interface functions are
prefixed with SK_ now. This makes it clear which functions are from the
core/skin interface, and for AddrCheck it's clear which functions are
shared with/borrowed from MemCheck. Changed some related prefixes for
consistency.
- Also factored out some duplication within AddrCheck -- some accessibility
checking was needlessly split up into separate read and write checks that
did the same thing.
Unchanged:
- I considered moving the leak detector out of core into mc_common.c, but
didn't, because it constantly accesses ShadowChunk fields and converting to
get/set methods would have been a total pain.
- Left old debugging stuff in for MemCheck, although I seriously doubt it
would still work.
Julian Seward [Sat, 16 Nov 2002 11:06:50 +0000 (11:06 +0000)]
Merge patch from JeremyF:
27-nvalgrind
Make valgrind.h pay attention to the preprocessor symbol NVALGRIND. If
defined, it compiles out the Valgrind magic sequence and just assigns
the result with the default return. This is analogous to NDEBUG's
effect on assert().
Julian Seward [Thu, 14 Nov 2002 23:16:58 +0000 (23:16 +0000)]
Merge patch from JeremyF:
41-linefix
When working out the source:line information for a stack backtrace,
subtract 1 from return addresses in the hope that this points to the
line of the caller rather than the line after the caller.
Lots of changes to future-proof the core/skin interface, making it less likely
that changes will cause binary incompatibilities. Mostly done by hiding naked
structs with function calls.
Structs hidden in this way were: UCodeBlock, SkinSupp and SkinError (which were
merged back with CoreSupp and CoreError into single types Supp and Error),
ShadowChunk, VgDetails, VgNeeds and VgTrackEvents. The last three are the most
important ones, as they are (I think) the most likely to change.
Suitable get()/set() methods were defined for each one. The way UCodeBlocks
are copied for instrumentation by skins is a little different now, using
setup_UCodeBlock. Had to add a few other functions here n there. Changed
how SK_(complete_shadow_chunk) works a bit.
Added a file coregrind/vg_needs.c which contains all the get/set functions.
It's pretty simple.
The changes are not totally ideal -- eg. ShadowChunks has get()/set() methods
for its `next' field which arguably shouldn't be exposed (betraying the fact
that it's a linked list), and the get()/set() methods are a bit cumbersome at
times, esp. for `Error' because the fields are accessed quite a few times, and
the treatment of Supps and Errors is a bit inconsistent (but they are used in
different ways), and sizeof_shadow_blocks is still a hack. But still better
than naked structs. And one advantage is that a bit of sanity checking can be
performed by the get()/set() methods, as is done for VG_({get,set}_sc_extra)()
to make sure no reading/writing occurs outside the allowed area.
I didn't do it for UInstr, because its fields are accessed directly in lots and
lots of spots, which would have been a great big pain and I was a little
worried about overhead of calling lots of extra functions, although in practice
translation times are small enough that it probably doesn't matter.
Updated the example skin and the docs, too, hurrah.
Julian Seward [Wed, 13 Nov 2002 22:43:26 +0000 (22:43 +0000)]
Merge patch from JeremyF:
40-hg-tidstate
HELGRIND: record more information when a memory location changes
state. Now also records the thread ID and the previous state at that
point (so now a "possible race" error message tells you the moment we
entered an error state from an OK state, and where we entered that OK
state and from what).
Julian Seward [Wed, 13 Nov 2002 22:42:13 +0000 (22:42 +0000)]
Merge patch from JeremyF:
39-lock-prefix
Add a new UInstr LOCK to represent a "lock" prefix in the instruction
stream. This has the same semantics as NOP, but allows a skin to tell
whether a group of UInstrs associated with an x86 instruction are
meant to be locked.
HELGRIND: uses the LOCK UInstr to automatically take and release a
special __BUS_HARDWARE_LOCK__ around locked instructions. This only
works properly if all instructions touching a given address are locked
(even reads).
Julian Seward [Wed, 13 Nov 2002 22:37:41 +0000 (22:37 +0000)]
Merge patch from JeremyF:
38-hg-lazy-lasttouch
HELGRIND: rather than recording the last access, record the last state
change. This is more interesting and useful, and uses up a lot less
memory when using (now inaccurately named) --show-last-access=all.
Julian Seward [Wed, 13 Nov 2002 22:35:55 +0000 (22:35 +0000)]
Merge patch from JeremyF:
37-hg-private-stack
HELGRIND: by default, assume that thread stacks are thread-local. This
means that they are always initalized to be exclusively owned by their
thread (rather than virgin), and no access checks are generated for
stack-relative memory references (ie, relative off ESP or EBP). This
saves about 70% (statically) of checks on memory accesses.
This is enabled by default, but can be disabled with
--private-stacks=no
Julian Seward [Wed, 13 Nov 2002 22:29:34 +0000 (22:29 +0000)]
Merge patch from JeremyF:
33-pre_mutex_lock
HELGRIND: two updates: add a pre_mutex_lock tracking function, so the
skin can do something before the thread blocks. This allows us to do
lock ordering tests before the thread blocks in the deadlock we'd like
to report...
Julian Seward [Wed, 13 Nov 2002 22:25:51 +0000 (22:25 +0000)]
Merge patch from JeremyF:
32-hg-lifetime-segments
HELGRIND: implement the algorithm described in "Runtime Checking of
Multithreaded Applications with Visual Threads". Rather than working
with thread IDs, this algorithm breaks the lifetime of a thread up
into thread lifetime segments, and arranges them in an interference
graph.
If a memory location is in exclusive state and it is touched by
another thread, it compares the TLSs of the old owner and the new
thread. If the two TLSs can't possibly overlap in time (for example,
one TLS is the parent before a child thread is created, and the other
TLS is the child thread) the memory location's ownership is
transferred rather than moving it into a shared state. This allows a
parent thread to set up some memory and then create a new child,
handing ownership of that memory to the child, without generating
spurious errors.
At present the only synchonization events used to create new TLSs are
thread create and thread join, though in principle any synchronization
event would work.
Julian Seward [Wed, 13 Nov 2002 22:22:25 +0000 (22:22 +0000)]
Merge patch from JeremyF:
31-hg-shadow-execontext
HELGRIND: Add option to record ExeContext for every word access. This
is probably very slow and memory hungry, but it helps make the error
reports more useful. Defaults to off.
Julian Seward [Wed, 13 Nov 2002 22:11:53 +0000 (22:11 +0000)]
Merge patch from JeremyF:
26-hg-client-reqs
HELGRIND: first client requests. Adds a request to return memory to
its virginal state (useful for allocators which recycle memory), and
one to put memory into an error state (useful for suppressing errors
from known races).
Julian Seward [Wed, 13 Nov 2002 21:57:52 +0000 (21:57 +0000)]
Merge patch from JeremyF:
22-mutex-destroy-unlock:
It seems that glibc assumes in its internal use of pthreads that
destroying a lock implicity unlocks it. This patch handles this case
so that lock ownership tracking is accurate.
Also handles the case of the dyanmic linker wanting to do locking
before Valgrind has started up. vg_libpthread now implements toy
lock/unlock functions to keep it happy and leave the locks in a
sensible state. Implements some untested code to handle the case where
a lock is taken before Valgrind is running but released afterwards.
Julian Seward [Wed, 13 Nov 2002 21:51:10 +0000 (21:51 +0000)]
Merge patch from JeremyF:
03a-open-nonblock
Implement open of FIFOs for threaded programs, so that everything
doesn't block when we try to open a FIFO file in a non-blocking way.
Julian Seward [Wed, 13 Nov 2002 21:46:34 +0000 (21:46 +0000)]
Merge patch from JeremyF:
21-hg-hashed-lockset
HELGRIND: New implementation of LockSets. This changes the
lockset_table into a hash, and changes the representation of each
LockSet from a list into an array. This improves performance (mainly
because of the hash, but the arrays are more cache friendly too), and
simplifies the code.
Julian Seward [Wed, 13 Nov 2002 21:24:57 +0000 (21:24 +0000)]
Just call me Mr Brain-Dead Moron. Move the documentation sources to
where I _should_ have put them in the first place, and fix up the
Makefile.am's accordingly. 'make' and 'make install' now work.
Julian Seward [Mon, 11 Nov 2002 00:20:07 +0000 (00:20 +0000)]
Add documentation back in, in its new form. Still all very rough and
totally borked, but pretty much all the duplication is gone, and there
is a good start on a common core section in
coregrind/coregrind_core.html. At least I know where I'm going with
all this now.
The Makefile.am's need to be fixed up.
Basic idea is that, when put together in a single directory, these
files make a coherent manual, starting at manual.html. Fortunately
:-) "make install" does exactly that -- copies them to a single
directory.
After redundancy removal, there's more that 38000 words of
documentation here, according to wc. Amazing.
Julian Seward [Sat, 9 Nov 2002 10:24:01 +0000 (10:24 +0000)]
Clean up; add command-line spec of port # and request to exit when number
of connections falls to zero. Also, handle SIGINT, and print time
at start/exit.
Added a basic core/skin interface versioning system. Each skin must use the
macro VG_DETERMINE_INTERFACE_VERSION exactly once. If the X.Y core and skin
versions don't have a matching X (indicating binary incompatibility), Valgrind
will abort execution immediately at startup.