Skip to content

Commit

Permalink
[sgen] Count cards for binary protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed Apr 16, 2014
1 parent 9f6ab33 commit 35f397e
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 12 deletions.
2 changes: 2 additions & 0 deletions mono/metadata/sgen-gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ struct _SgenMajorCollector {
MonoVTable* (*describe_pointer) (char *pointer);
guint8* (*get_cardtable_mod_union_for_object) (char *object);
long long (*get_and_reset_num_major_objects_marked) (void);
void (*count_cards) (long long *num_total_cards, long long *num_marked_cards);
};

extern SgenMajorCollector major_collector;
Expand Down Expand Up @@ -891,6 +892,7 @@ void sgen_los_iterate_objects (IterateObjectCallbackFunc cb, void *user_data) MO
void sgen_los_iterate_live_block_ranges (sgen_cardtable_block_callback callback) MONO_INTERNAL;
void sgen_los_scan_card_table (gboolean mod_union, SgenGrayQueue *queue) MONO_INTERNAL;
void sgen_los_update_cardtable_mod_union (void) MONO_INTERNAL;
void sgen_los_count_cards (long long *num_total_cards, long long *num_marked_cards) MONO_INTERNAL;
void sgen_major_collector_scan_card_table (SgenGrayQueue *queue) MONO_INTERNAL;
gboolean sgen_los_is_valid_object (char *object) MONO_INTERNAL;
gboolean mono_sgen_los_describe_pointer (char *ptr) MONO_INTERNAL;
Expand Down
27 changes: 27 additions & 0 deletions mono/metadata/sgen-los.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,33 @@ sgen_los_scan_card_table (gboolean mod_union, SgenGrayQueue *queue)
}
}

void
sgen_los_count_cards (long long *num_total_cards, long long *num_marked_cards)
{
LOSObject *obj;
long long total_cards = 0;
long long marked_cards = 0;

for (obj = los_object_list; obj; obj = obj->next) {
int i;
guint8 *cards = sgen_card_table_get_card_scan_address ((mword) obj->data);
guint8 *cards_end = sgen_card_table_get_card_scan_address ((mword) obj->data + obj->size - 1);
mword num_cards = (cards_end - cards) + 1;

if (!SGEN_OBJECT_HAS_REFERENCES (obj->data))
continue;

total_cards += num_cards;
for (i = 0; i < num_cards; ++i) {
if (cards [i])
++marked_cards;
}
}

*num_total_cards = total_cards;
*num_marked_cards = marked_cards;
}

void
sgen_los_update_cardtable_mod_union (void)
{
Expand Down
26 changes: 26 additions & 0 deletions mono/metadata/sgen-marksweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,31 @@ major_scan_card_table (gboolean mod_union, SgenGrayQueue *queue)
} END_FOREACH_BLOCK;
}

static void
major_count_cards (long long *num_total_cards, long long *num_marked_cards)
{
MSBlockInfo *block;
long long total_cards = 0;
long long marked_cards = 0;

FOREACH_BLOCK (block) {
guint8 *cards = sgen_card_table_get_card_scan_address ((mword) block->block);
int i;

if (!block->has_references)
continue;

total_cards += CARDS_PER_BLOCK;
for (i = 0; i < CARDS_PER_BLOCK; ++i) {
if (cards [i])
++marked_cards;
}
} END_FOREACH_BLOCK;

*num_total_cards = total_cards;
*num_marked_cards = marked_cards;
}

#ifdef SGEN_HAVE_CONCURRENT_MARK
static void
update_cardtable_mod_union (void)
Expand Down Expand Up @@ -2600,6 +2625,7 @@ sgen_marksweep_fixed_init (SgenMajorCollector *collector)
collector->post_param_init = post_param_init;
collector->is_valid_object = major_is_valid_object;
collector->describe_pointer = major_describe_pointer;
collector->count_cards = major_count_cards;

collector->major_ops.copy_or_mark_object = major_copy_or_mark_object_canonical;
collector->major_ops.scan_object = major_scan_object;
Expand Down
24 changes: 20 additions & 4 deletions mono/metadata/sgen-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,31 @@ binary_protocol_concurrent_update_finish (void)
void
binary_protocol_world_stopping (long long timestamp)
{
SGenProtocolWorldStop entry = { timestamp };
protocol_entry (SGEN_PROTOCOL_WORLD_STOPPING, &entry, sizeof (SGenProtocolWorldStop));
SGenProtocolWorldStopping entry = { timestamp };
protocol_entry (SGEN_PROTOCOL_WORLD_STOPPING, &entry, sizeof (SGenProtocolWorldStopping));
}

void
binary_protocol_world_stopped (long long timestamp, long long total_major_cards,
long long marked_major_cards, long long total_los_cards, long long marked_los_cards)
{
SGenProtocolWorldStopped entry = { timestamp, total_major_cards, marked_major_cards, total_los_cards, marked_los_cards };
protocol_entry (SGEN_PROTOCOL_WORLD_STOPPED, &entry, sizeof (SGenProtocolWorldStopped));
}

void
binary_protocol_world_restarting (int generation, long long timestamp,
long long total_major_cards, long long marked_major_cards, long long total_los_cards, long long marked_los_cards)
{
SGenProtocolWorldRestarting entry = { generation, timestamp, total_major_cards, marked_major_cards, total_los_cards, marked_los_cards };
protocol_entry (SGEN_PROTOCOL_WORLD_RESTARTING, &entry, sizeof (SGenProtocolWorldRestarting));
}

void
binary_protocol_world_restarted (int generation, long long timestamp)
{
SGenProtocolWorldRestart entry = { generation, timestamp };
protocol_entry (SGEN_PROTOCOL_WORLD_RESTARTED, &entry, sizeof (SGenProtocolWorldRestart));
SGenProtocolWorldRestarted entry = { generation, timestamp };
protocol_entry (SGEN_PROTOCOL_WORLD_RESTARTED, &entry, sizeof (SGenProtocolWorldRestarted));
}

void
Expand Down
27 changes: 25 additions & 2 deletions mono/metadata/sgen-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ enum {
SGEN_PROTOCOL_CONCURRENT_START,
SGEN_PROTOCOL_CONCURRENT_UPDATE_FINISH,
SGEN_PROTOCOL_WORLD_STOPPING,
SGEN_PROTOCOL_WORLD_STOPPED,
SGEN_PROTOCOL_WORLD_RESTARTING,
SGEN_PROTOCOL_WORLD_RESTARTED,
SGEN_PROTOCOL_ALLOC,
SGEN_PROTOCOL_COPY,
Expand Down Expand Up @@ -68,12 +70,29 @@ typedef struct {

typedef struct {
long long timestamp;
} SGenProtocolWorldStop;
} SGenProtocolWorldStopping;

typedef struct {
long long timestamp;
long long total_major_cards;
long long marked_major_cards;
long long total_los_cards;
long long marked_los_cards;
} SGenProtocolWorldStopped;

typedef struct {
int generation;
long long timestamp;
long long total_major_cards;
long long marked_major_cards;
long long total_los_cards;
long long marked_los_cards;
} SGenProtocolWorldRestarting;

typedef struct {
int generation;
long long timestamp;
} SGenProtocolWorldRestart;
} SGenProtocolWorldRestarted;

typedef struct {
gpointer obj;
Expand Down Expand Up @@ -215,6 +234,10 @@ void binary_protocol_collection_end (int index, int generation) MONO_INTERNAL;
void binary_protocol_concurrent_start (void) MONO_INTERNAL;
void binary_protocol_concurrent_update_finish (void) MONO_INTERNAL;
void binary_protocol_world_stopping (long long timestamp) MONO_INTERNAL;
void binary_protocol_world_stopped (long long timestamp, long long total_major_cards,
long long marked_major_cards, long long total_los_cards, long long marked_los_cards) MONO_INTERNAL;
void binary_protocol_world_restarting (int generation, long long timestamp,
long long total_major_cards, long long marked_major_cards, long long total_los_cards, long long marked_los_cards) MONO_INTERNAL;
void binary_protocol_world_restarted (int generation, long long timestamp) MONO_INTERNAL;

void binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip) MONO_INTERNAL;
Expand Down
18 changes: 18 additions & 0 deletions mono/metadata/sgen-stw.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ release_gc_locks (void)
UNLOCK_INTERRUPTION;
}

static void
count_cards (long long *major_total, long long *major_marked, long long *los_total, long long *los_marked)
{
sgen_get_major_collector ()->count_cards (major_total, major_marked);
sgen_los_count_cards (los_total, los_marked);
}

static TV_DECLARE (stop_world_time);
static unsigned long max_pause_usec = 0;

Expand Down Expand Up @@ -222,6 +229,11 @@ sgen_stop_world (int generation)
SGEN_LOG (3, "world stopped %d thread(s)", count);
mono_profiler_gc_event (MONO_GC_EVENT_POST_STOP_WORLD, generation);
MONO_GC_WORLD_STOP_END ();
if (binary_protocol_is_enabled ()) {
long long major_total, major_marked, los_total, los_marked;
count_cards (&major_total, &major_marked, &los_total, &los_marked);
binary_protocol_world_stopped (sgen_timestamp (), major_total, major_marked, los_total, los_marked);
}

sgen_memgov_collection_start (generation);
sgen_bridge_reset_data ();
Expand All @@ -239,6 +251,12 @@ sgen_restart_world (int generation, GGTimingInfo *timing)
TV_DECLARE (end_bridge);
unsigned long usec, bridge_usec;

if (binary_protocol_is_enabled ()) {
long long major_total, major_marked, los_total, los_marked;
count_cards (&major_total, &major_marked, &los_total, &los_marked);
binary_protocol_world_restarting (generation, sgen_timestamp (), major_total, major_marked, los_total, los_marked);
}

/* notify the profiler of the leftovers */
/* FIXME this is the wrong spot at we can STW for non collection reasons. */
if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_GC_MOVES))
Expand Down
30 changes: 24 additions & 6 deletions tools/sgen/sgen-grep-binprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ read_entry (FILE *in, void **data)
case SGEN_PROTOCOL_COLLECTION_END: size = sizeof (SGenProtocolCollection); break;
case SGEN_PROTOCOL_CONCURRENT_START: size = 0; break;
case SGEN_PROTOCOL_CONCURRENT_UPDATE_FINISH: size = 0; break;
case SGEN_PROTOCOL_WORLD_STOPPING: size = sizeof (SGenProtocolWorldStop); break;
case SGEN_PROTOCOL_WORLD_RESTARTED: size = sizeof (SGenProtocolWorldRestart); break;
case SGEN_PROTOCOL_WORLD_STOPPING: size = sizeof (SGenProtocolWorldStopping); break;
case SGEN_PROTOCOL_WORLD_STOPPED: size = sizeof (SGenProtocolWorldStopped); break;
case SGEN_PROTOCOL_WORLD_RESTARTING: size = sizeof (SGenProtocolWorldRestarting); break;
case SGEN_PROTOCOL_WORLD_RESTARTED: size = sizeof (SGenProtocolWorldRestarted); break;
case SGEN_PROTOCOL_ALLOC: size = sizeof (SGenProtocolAlloc); break;
case SGEN_PROTOCOL_ALLOC_PINNED: size = sizeof (SGenProtocolAlloc); break;
case SGEN_PROTOCOL_ALLOC_DEGRADED: size = sizeof (SGenProtocolAlloc); break;
Expand Down Expand Up @@ -99,12 +101,26 @@ print_entry (int type, void *data)
break;
}
case SGEN_PROTOCOL_WORLD_STOPPING: {
SGenProtocolWorldStop *entry = data;
SGenProtocolWorldStopping *entry = data;
printf ("%s world stopping timestamp %lld\n", WORKER_PREFIX (type), entry->timestamp);
break;
}
case SGEN_PROTOCOL_WORLD_STOPPED: {
SGenProtocolWorldStopped *entry = data;
long long total = entry->total_major_cards + entry->total_los_cards;
long long marked = entry->marked_major_cards + entry->marked_los_cards;
printf ("%s world stopped timestamp %lld total %lld marked %lld %0.2f%%\n", WORKER_PREFIX (type), entry->timestamp, total, marked, 100.0 * (double) marked / (double) total);
break;
}
case SGEN_PROTOCOL_WORLD_RESTARTING: {
SGenProtocolWorldRestarting *entry = data;
long long total = entry->total_major_cards + entry->total_los_cards;
long long marked = entry->marked_major_cards + entry->marked_los_cards;
printf ("%s world restarting generation %d timestamp %lld total %lld marked %lld %0.2f%%\n", WORKER_PREFIX (type), entry->generation, entry->timestamp, total, marked, 100.0 * (double) marked / (double) total);
break;
}
case SGEN_PROTOCOL_WORLD_RESTARTED: {
SGenProtocolWorldRestart *entry = data;
SGenProtocolWorldRestarted *entry = data;
printf ("%s world restarted generation %d timestamp %lld\n", WORKER_PREFIX (type), entry->generation, entry->timestamp);
break;
}
Expand Down Expand Up @@ -268,6 +284,8 @@ is_match (gpointer ptr, int type, void *data)
case SGEN_PROTOCOL_CONCURRENT_START:
case SGEN_PROTOCOL_CONCURRENT_UPDATE_FINISH:
case SGEN_PROTOCOL_WORLD_STOPPING:
case SGEN_PROTOCOL_WORLD_STOPPED:
case SGEN_PROTOCOL_WORLD_RESTARTING:
case SGEN_PROTOCOL_WORLD_RESTARTED:
case SGEN_PROTOCOL_THREAD_SUSPEND:
case SGEN_PROTOCOL_THREAD_RESTART:
Expand Down Expand Up @@ -446,7 +464,7 @@ main (int argc, char *argv[])
if (pause_times) {
switch (type) {
case SGEN_PROTOCOL_WORLD_STOPPING: {
SGenProtocolWorldStop *entry = data;
SGenProtocolWorldStopping *entry = data;
assert (!pause_times_stopped);
pause_times_concurrent = FALSE;
pause_times_ts = entry->timestamp;
Expand All @@ -458,7 +476,7 @@ main (int argc, char *argv[])
pause_times_concurrent = TRUE;
break;
case SGEN_PROTOCOL_WORLD_RESTARTED: {
SGenProtocolWorldRestart *entry = data;
SGenProtocolWorldRestarted *entry = data;
assert (pause_times_stopped);
printf ("pause-time %d %d %lld %lld\n",
entry->generation,
Expand Down

0 comments on commit 35f397e

Please sign in to comment.