MPS issue job001969

TitleMPS gc-start and -end messages give no idea of timing
Assigned userRichard Kistruck
DescriptionMPS gc-start and -end messages give no idea of timing.

  mps_message_clock() -- new function in mps.h

Related jobs:
job001968: "MPS clients get no synchronous alert of collection begin/end"

RHSK 2008-11-12
The messages are asynchronous (and therefore have no implicit
timestamp), and they have no explicit timestamp.
AnalysisRHSK 2008-11-12
Give gc-start and -end messages an explicit timestamp as they are
posted with MessagePost(). Use the mps_clock() plinth facility (see

Client accesses timestamp with new accessor mps_message_clock().

Note: gc messages are not very numerous, so calling mps_clock as
they are posted is fine. Whereas finalization messages might be
extremely numerous (although I have no numbers to hand), and would
not benefit from timestamps -- there is nothing very useful about
the time the MPS happens to discovers that an object is finalizable.
Therefore, to avoid risk of performance regression due to excessive
library calls to mps_clock(), do not set the timestamp on
finalization messages.

MPS uses two sorts of time values:

mps_clock_t: a plinth-supplied arithmetic type, with values
>= 0, modelled on ISO C time.h's clock(). mps_clock()'s return
value signifies absolute CPU time since process start. We also use
mps_clock_t for relative clock values. Convert to/from seconds
with factor mps_clocks_per_sec().

double (seconds): time interval in seconds (including fractions of
a second).

mps_clock_t is sometimes stored in and treated as a Word (both have
underlying type "unsigned long" in C on all platforms, currently).

This is rather a mess, so clear it up:

new internal type Clock; new wrappers for mps_clock and

(optional) new internal type Timespan, with TimespanClock() and
ClockTimespan() converters; call mps_clocks_per_sec once in
ArenaInit and store the result in ArenaStruct to avoid calling
mps_clocks_per_sec() all over the place!

RHSK 2008-11-12
Concern: I added the postedClock field to MessageStruct, so it
imposes a memory cost for finalization messages that never use the
field, which means a additional memory cost for every object for which
the client calls mps_finalize. This memory cost is a regression.

It could be cured by making mps_message_clock() dispatch on message
type. Methods for gc-start and -end messages would use storage
specific to those message types.

RHSK 2008-11-24
Fix concern: regain previous small size by moving "MessageType type"
field from MessageStruct to MessageClassStruct. This also usefully
simplifies the relationship between message types and message
How foundunknown
Observed in1.108.2
Created byRichard Kistruck
Created on2008-11-12 15:35:51
Last modified byGareth Rees
Last modified on2010-10-06 22:15:39
History2008-11-12 RHSK Created.
2008-11-12 RHSK Concern: the current implementation has added a additional memory cost to finalized objects.
2008-11-24 RHSK Fix concern: regain previous small size.
2009-02-17 RHSK (update name of related job001968)


Change Effect Date User Description
166809 closed 2008-11-25 12:56:15 Richard Kistruck MPS br/timing: RefMan: add entry for mps_message_clock()
166796 closed 2008-11-24 16:20:35 Richard Kistruck MPS br/timing: design/message:
Write new .class.type: each class now implements exactly one type.
.class.not-type is now false; mark it as obsolete.
166795 closed 2008-11-24 15:44:27 Richard Kistruck MPS br/timing: move field "MessageType type" out of MessageStruct
and into MessageClassStruct.
166702 closed 2008-11-12 10:02:52 Richard Kistruck MPS br/timing: MessageClocked(), used in MessageCheck and to prevent
numerous messages (namely: finalization messages) being timestamped.
166701 open 2008-11-12 09:26:48 Richard Kistruck MPS br/timing: new ClockNow() wrapper for mps_clock(), ClocksPerSec();
use Clock in arena step (not Word).
166697 open 2008-11-11 16:57:30 Richard Kistruck MPS br/timing: new type "Clock", internal equivalent of mps_clock_t.
Used for a field in messages. (More uses to follow).
166696 open 2008-11-11 16:22:26 Richard Kistruck MPS br/timing: mpsi_check(): Check that external and internal messsage types match.
166695 open 2008-11-11 15:28:28 Richard Kistruck MPS br/timing: finalcv.c: verify that message clock is 0 (unset)
for finalization messages.
166690 open 2008-11-11 10:39:53 Richard Kistruck MPS br/timing: Do not set postedClock for finalization msgs.
166689 open 2008-11-11 10:31:48 Richard Kistruck MPS br/timing: amcss output changes:
- Keep counts of both collection start messages and collection end
  messages. Upon receipt of these messages, format the collection
  start/end reports as 'brackets' (makes it easier to see whether
  allocation continues during the collection or not).
- If mps_collections has changed, report() messages before doing
  anything else.
- (source code clarity) Guess that the naked "4" in the
  mps_arena_has_addr test means "hitsWanted", and label it.
166677 open 2008-11-07 16:11:37 Richard Kistruck MPS br/timing:
  message.c: maintain postedClock field, set it with mps_clock() at post time;
  amcss.c: call and display mps_message_clock() on _gc_start & _gc messages.
166676 open 2008-11-07 15:22:24 Richard Kistruck MPS br/timing: (cosmetic) re-format report()'s switch on message type
to comply with design/cstyle.