[m-rev.] diff: mercury_threadscope.[ch]
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon May 2 17:54:51 AEST 2011
runtime/mercury_threadscope.[ch]:
Remove unnecessary mechanism for managing a non-existent module
of hand-translated-to-C Mercury code.
Fix deviations from our programming style.
Zoltan.
cvs diff: Diffing .
Index: mercury_threadscope.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_threadscope.c,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_threadscope.c
--- mercury_threadscope.c 13 Apr 2011 13:19:42 -0000 1.11
+++ mercury_threadscope.c 1 May 2011 03:56:24 -0000
@@ -2,10 +2,6 @@
** vim: ts=4 sw=4 expandtab
*/
/*
-INIT mercury_sys_init_threadscope
-ENDINIT
-*/
-/*
** Copyright (C) 2009-2011 The University of Melbourne.
** Copyright (C) 2008-2009 The GHC Team.
**
@@ -16,10 +12,9 @@
/*
** Event log format
**
-** The log format is designed to be extensible: old tools should be
-** able to parse (but not necessarily understand all of) new versions
-** of the format, and new tools will be able to understand old log
-** files.
+** The log format is designed to be extensible: old tools should be able
+** to parse (but not necessarily understand) new versions of the format,
+** and new tools will be able to understand old log files.
**
** Each event has a specific format. If you add new events, give them
** new numbers: we never re-use old event numbers.
@@ -29,8 +24,8 @@
**
** - The format is extensible:
**
-** - The header describes each event type and its length. Tools
-** that don't recognise a particular event type can skip those events.
+** - The header describes each event type and its length. Tools that
+** don't recognise a particular event type can skip those events.
**
** - There is room for extra information in the event type
** specification, which can be ignored by older tools.
@@ -69,7 +64,7 @@
** [Word16] -- length of the rest (for variable-sized events only)
** ... extra event-specific info ...
**
-** All values a packed, no attempt is made to align them.
+** All values are packed, no attempt is made to align them.
**
** New events must be registered with GHC. These are kept in the GHC-events
** package.
@@ -77,9 +72,7 @@
*/
#include "mercury_imp.h"
-
#include "mercury_threadscope.h"
-
#include "mercury_atomic_ops.h"
#include <stdio.h>
@@ -140,8 +133,8 @@
/* 23, 24 used by eden */
/*
-** Capsets or capability sets are groups of engines with some association, for
-** instance a group of threads in a process.
+** Capsets or capability sets are groups of engines with some association,
+** for instance a group of threads in a process.
*/
#define MR_TS_EVENT_CAPSET_CREATE 25 /* (capset, capset_type) */
#define MR_TS_EVENT_CAPSET_DELETE 26 /* (capset) */
@@ -168,10 +161,11 @@
#define MR_TS_MER_EVENT_START_PAR_CONJ 100 /* (int id, memo'd string id) */
#define MR_TS_MER_EVENT_STOP_PAR_CONJ 101 /* (int id) */
#define MR_TS_MER_EVENT_STOP_PAR_CONJUNCT 102 /* (int id) */
+
/*
-** Creating sparks is not specifically mercury, but conjunct IDs are,
-** If other systems wish to use this event they can move it to the main events
-** section.
+** Creating sparks is not specifically mercury, but conjunct IDs are.
+** If other systems wish to use this event, they can move it
+** to the main events section.
*/
#define MR_TS_MER_EVENT_SPARKING 103 /* (int id, spark id) */
@@ -190,10 +184,10 @@
#endif
/*
- * Engine set type values for EVENT_CAPSET_CREATE
- */
+** Engine set type values for EVENT_CAPSET_CREATE.
+*/
#define MR_TS_ENGSET_TYPE_CUSTOM 1 /* reserved for end-user applications */
-#define MR_TS_ENGSET_TYPE_OSPROCESS 2 /* engines belong to the same OS process */
+#define MR_TS_ENGSET_TYPE_OSPROCESS 2 /* engines belong to same OS process */
#define MR_TS_ENGSET_TYPE_CLOCKDOMAIN 3 /* engines share a local clock/time */
/*
@@ -228,8 +222,9 @@
MR_Integer MR_tsbuffer_block_open_pos;
/*
- ** True if the engine's current context is stopped and therefore stop and
- ** start events should not be posted from the GC callback procedures.
+ ** True if the engine's current context is stopped, and therefore
+ ** stop and start events should not be posted from the GC callback
+ ** procedures.
*/
MR_bool MR_tsbuffer_ctxt_is_stopped;
@@ -238,8 +233,8 @@
};
/*
-** We define some types and functions to write them. These types are set
-** carefully to match the ones that GHC uses.
+** We define some types and functions to write them.
+** These types are set carefully to match the ones that GHC uses.
*/
typedef MR_uint_least16_t EventType;
typedef MR_uint_least64_t Time;
@@ -252,7 +247,7 @@
typedef struct {
EventType etd_event_type;
- const char* etd_description;
+ const char *etd_description;
MR_int_least16_t etd_size;
} EventTypeDesc;
@@ -274,8 +269,8 @@
static EventTypeDesc event_type_descs[] = {
{
/*
- ** The startup event informs threadscope of the number of engines we're
- ** using. It should be given outside of a block.
+ ** The startup event informs threadscope of the number of engines
+ ** we are using. It should be given outside of a block.
*/
MR_TS_EVENT_STARTUP,
"Startup (num_engines)",
@@ -291,7 +286,7 @@
},
{
/*
- ** A block of events belonging to the named engine follows,
+ ** A block of events belonging to the named engine follows.
** The length of this block is given including the block message
** itself, the time that this block finishes is also given.
** Blocks _must not_ exist within other blocks.
@@ -318,7 +313,7 @@
},
{
/*
- ** The named context begun executing a spark from it's local stack.
+ ** The named context has begun executing a spark from its local stack.
*/
MR_TS_EVENT_RUN_SPARK,
"Run a spark from the local stack",
@@ -326,7 +321,7 @@
},
{
/*
- ** The named context begun executing a spark from another engine's
+ ** The named context has begun executing a spark from another engine's
** stack.
*/
MR_TS_EVENT_STEAL_SPARK,
@@ -335,8 +330,8 @@
},
{
/*
- ** The named context begun executing on the engine named by the current
- ** block.
+ ** The named context has begun executing on the engine
+ ** named by the current block.
*/
MR_TS_EVENT_RUN_THREAD,
"Run context",
@@ -344,8 +339,8 @@
},
{
/*
- ** The named context finished executing on the engine named by the
- ** current block. The reason why the context stopped is given.
+ ** The named context has stopped executing on the engine named by
+ ** the current block. The reason why the context stopped is given.
*/
MR_TS_EVENT_STOP_THREAD,
"Context stopped",
@@ -361,12 +356,12 @@
},
{
MR_TS_EVENT_LOG_MSG,
- "A user-provided log messagei",
+ "A user-provided log message",
-1 /* Variable length */
},
{
/*
- ** Start a garbage collection run
+ ** Start a garbage collection run.
*/
MR_TS_EVENT_GC_START,
"Start GC",
@@ -374,7 +369,7 @@
},
{
/*
- ** Stop a garbage collection run
+ ** Stop a garbage collection run.
*/
MR_TS_EVENT_GC_END,
"Stop GC",
@@ -382,8 +377,8 @@
},
{
/*
- ** The runtime system registers a string and an ID for it so that the
- ** ID represents the string in future messages.
+ ** The runtime system registers a string and an ID for it
+ ** so that the ID represents the string in future messages.
*/
MR_TS_EVENT_STRING,
"Register an id->string mapping",
@@ -391,8 +386,8 @@
},
{
/*
- ** The runtime system is about to call main/2. This message has no
- ** parameters.
+ ** The runtime system is about to call main/2.
+ ** This message has no parameters.
*/
MR_TS_EVENT_CALL_MAIN,
"About to call main/2",
@@ -436,15 +431,15 @@
{
MR_TS_EVENT_OSPROCESS_PID,
"The pid and parent pid of this process",
- 2*SZ_PID
+ 2 * SZ_PID
},
{
MR_TS_MER_EVENT_SPARKING,
"A spark is being created",
SZ_DYN_CONJ_ID + SZ_SPARK_ID
/*
- * Note that the dynamic conj ID is only useful for Mercury. other
- * implementors may want different attributes here.
+ ** Note that the dynamic conj ID is only useful for Mercury.
+ ** Other implementors may want different attributes here.
*/
},
{
@@ -464,8 +459,8 @@
},
{
/*
- * The dynamic conjunction id can be inferred from contact, it is the
- * next conjunction started after this event.
+ ** The dynamic conjunction id can be inferred from context;
+ ** it is the next conjunction started after this event.
*/
MR_TS_MER_EVENT_FUT_CREATE,
"Create a future (future id)",
@@ -473,7 +468,7 @@
},
{
MR_TS_MER_EVENT_FUT_WAIT_NOSUSPEND,
- "Wait on a future without suspending (no waiting) (future id)",
+ "Wait on a future without suspending (future id)",
SZ_FUTURE_ID
},
{
@@ -493,19 +488,21 @@
},
{
MR_TS_MER_EVENT_WORK_STEALING,
- "Engine begins attempting to steal work",
+ "Engine begins attempt to steal work",
0
},
{
/* Mark the end of this array. */
- MR_TS_NUM_EVENT_TAGS, NULL, 0
+ MR_TS_NUM_EVENT_TAGS,
+ NULL,
+ 0
}
};
/*
** These tables are filled in when the header of the log file is written.
-** While they can be inferred from the event_type_desc structure they allow for
-** constant time lookup.
+** While they can be inferred from the event_type_desc structure,
+** they allow for constant time lookup.
*/
static MR_int_least16_t event_type_sizes[MR_TS_NUM_EVENT_TAGS];
static MR_int_least16_t event_type_sizes_mercury[MR_TS_NUM_MER_EVENTS];
@@ -539,8 +536,8 @@
get_next_engset_id(void)
{
/*
- * This is a seperate function as I may have to add locking or atomic ops
- * later.
+ ** This is a seperate function as I may have to add locking or atomic ops
+ ** later.
*/
return next_engset_id++;
}
@@ -565,29 +562,31 @@
}
/*
-** Is there enough room for this statically sized event in the current engine's
-** buffer _and_ enough room for the block marker event.
+** Is there enough room in the current engine's buffer
+** for this statically sized event _and_ for the block marker event.
*/
MR_STATIC_INLINE MR_bool
-enough_room_for_event(
- struct MR_threadscope_event_buffer *buffer,
+enough_room_for_event(struct MR_threadscope_event_buffer *buffer,
EventType event_type)
{
- return (buffer->MR_tsbuffer_pos + event_type_size(event_type) +
+ int needed =
+ buffer->MR_tsbuffer_pos +
+ event_type_size(event_type) +
event_type_size(MR_TS_EVENT_BLOCK_MARKER) +
((2 + 8) * 2)) /* (EventType, Time) * 2 */
- < MR_TS_BUFFERSIZE;
+ return needed < MR_TS_BUFFERSIZE;
}
MR_STATIC_INLINE MR_bool
-enough_room_for_variable_size_event(
- struct MR_threadscope_event_buffer *buffer,
+enough_room_for_variable_size_event(struct MR_threadscope_event_buffer *buffer,
MR_Unsigned length)
{
- return (buffer->MR_tsbuffer_pos + length +
+ int needed =
+ buffer->MR_tsbuffer_pos +
+ length +
event_type_size(MR_TS_EVENT_BLOCK_MARKER) +
(2 + 8) * 2) /* (EventType, Time) * 2 */
- < MR_TS_BUFFERSIZE;
+ return needed < MR_TS_BUFFERSIZE;
}
/*
@@ -602,39 +601,34 @@
/*
** Put words into the current engine's buffer in big endian order.
*/
-MR_STATIC_INLINE void put_byte(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_byte(struct MR_threadscope_event_buffer *buffer,
int byte)
{
buffer->MR_tsbuffer_data[buffer->MR_tsbuffer_pos++] = byte;
}
-MR_STATIC_INLINE void put_be_int16(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_be_int16(struct MR_threadscope_event_buffer *buffer,
MR_int_least16_t word)
{
put_byte(buffer, (word >> 8) & 0xFF);
put_byte(buffer, word & 0xFF);
}
-MR_STATIC_INLINE void put_be_uint16(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_be_uint16(struct MR_threadscope_event_buffer *buffer,
MR_uint_least16_t word)
{
put_byte(buffer, (word >> 8) & 0xFF);
put_byte(buffer, word & 0xFF);
}
-MR_STATIC_INLINE void put_be_uint32(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_be_uint32(struct MR_threadscope_event_buffer *buffer,
MR_uint_least32_t word)
{
put_be_uint16(buffer, (word >> 16) & 0xFFFF);
put_be_uint16(buffer, word & 0xFFFF);
}
-MR_STATIC_INLINE void put_be_uint64(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_be_uint64(struct MR_threadscope_event_buffer *buffer,
MR_uint_least64_t word)
{
put_be_uint32(buffer, (word >> 32) & 0xFFFFFFFF);
@@ -643,8 +637,7 @@
MR_STATIC_INLINE void put_raw_string(
struct MR_threadscope_event_buffer *buffer,
- const char *string,
- unsigned len)
+ const char *string, unsigned len)
{
unsigned i;
for (i = 0; i < len; i++) {
@@ -653,12 +646,11 @@
}
/*
-** Put a string in the given buffer, The string will be preceeded by a 16 bit
-** integer giving the string's length.
+** Put a string in the given buffer. The string will be preceeded
+** by a 16 bit integer giving the string's length.
*/
MR_STATIC_INLINE void put_string_size16(
- struct MR_threadscope_event_buffer *buffer,
- const char *string)
+ struct MR_threadscope_event_buffer *buffer, const char *string)
{
unsigned i, len;
@@ -668,12 +660,11 @@
}
/*
-** Put a string in the given buffer, The string will be preceeded by a 32 bit
-** integer giving the string's length.
+** Put a string in the given buffer. The string will be preceeded
+** by a 32 bit integer giving the string's length.
*/
MR_STATIC_INLINE void put_string_size32(
- struct MR_threadscope_event_buffer *buffer,
- const char *string)
+ struct MR_threadscope_event_buffer *buffer, const char *string)
{
unsigned i, len;
@@ -682,16 +673,14 @@
put_raw_string(buffer, string, len);
}
-MR_STATIC_INLINE void put_timestamp(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_timestamp(struct MR_threadscope_event_buffer *buffer,
Time timestamp)
{
put_be_uint64(buffer, timestamp);
}
MR_STATIC_INLINE void put_eventlog_offset(
- struct MR_threadscope_event_buffer *buffer,
- EventlogOffset offset)
+ struct MR_threadscope_event_buffer *buffer, EventlogOffset offset)
{
put_be_uint32(buffer, offset);
}
@@ -704,64 +693,55 @@
put_timestamp(buffer, timestamp);
}
-MR_STATIC_INLINE void put_engine_id(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_engine_id(struct MR_threadscope_event_buffer *buffer,
MR_EngineId engine_num)
{
put_be_uint16(buffer, engine_num);
}
MR_STATIC_INLINE void put_context_id(
- struct MR_threadscope_event_buffer *buffer,
- MR_ContextId context_id)
+ struct MR_threadscope_event_buffer *buffer, MR_ContextId context_id)
{
put_be_uint32(buffer, context_id);
}
MR_STATIC_INLINE void put_stop_reason(
- struct MR_threadscope_event_buffer *buffer,
- MR_ContextStopReason reason)
+ struct MR_threadscope_event_buffer *buffer, MR_ContextStopReason reason)
{
put_be_uint16(buffer, reason);
}
-MR_STATIC_INLINE void put_string_id(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_string_id(struct MR_threadscope_event_buffer *buffer,
MR_TS_StringId id)
{
put_be_uint32(buffer, id);
}
MR_STATIC_INLINE void put_par_conj_dynamic_id(
- struct MR_threadscope_event_buffer *buffer,
- MR_Word* id)
+ struct MR_threadscope_event_buffer *buffer, MR_Word* id)
{
put_be_uint64(buffer, (MR_Word)id);
}
-MR_STATIC_INLINE void put_spark_id(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_spark_id(struct MR_threadscope_event_buffer *buffer,
MR_SparkId spark_id)
{
put_be_uint32(buffer, spark_id);
}
-MR_STATIC_INLINE void put_engset_id(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_engset_id(struct MR_threadscope_event_buffer *buffer,
MR_EngSetId engset_id)
{
put_be_uint32(buffer, engset_id);
}
MR_STATIC_INLINE void put_engset_type(
- struct MR_threadscope_event_buffer *buffer,
- MR_EngSetType type)
+ struct MR_threadscope_event_buffer *buffer, MR_EngSetType type)
{
put_be_uint16(buffer, type);
}
-MR_STATIC_INLINE void put_future_id(
- struct MR_threadscope_event_buffer *buffer,
+MR_STATIC_INLINE void put_future_id(struct MR_threadscope_event_buffer *buffer,
MR_Future* id)
{
put_be_uint64(buffer, (MR_Word)id);
@@ -769,30 +749,24 @@
/***************************************************************************/
-static struct MR_threadscope_event_buffer*
-MR_create_event_buffer(void);
+static struct MR_threadscope_event_buffer* MR_create_event_buffer(void);
/*
-** The prelude is everything up to and including the 'DATA_BEGIN' marker
+** The prelude is everything up to and including the 'DATA_BEGIN' marker.
*/
-static void
-MR_open_output_file_and_write_prelude(void);
+static void MR_open_output_file_and_write_prelude(void);
-static void
-MR_close_output_file(void);
+static void MR_close_output_file(void);
-static void
-put_event_type(struct MR_threadscope_event_buffer *buffer,
+static void put_event_type(struct MR_threadscope_event_buffer *buffer,
EventTypeDesc *event_type);
-static MR_bool
-flush_event_buffer(struct MR_threadscope_event_buffer *buffer);
+static MR_bool flush_event_buffer(struct MR_threadscope_event_buffer *buffer);
-static void
-maybe_close_block(struct MR_threadscope_event_buffer *buffer);
+static void maybe_close_block(struct MR_threadscope_event_buffer *buffer);
-static void
-open_block(struct MR_threadscope_event_buffer *buffer, MR_Unsigned eng_id);
+static void open_block(struct MR_threadscope_event_buffer *buffer,
+ MR_Unsigned eng_id);
/***************************************************************************/
@@ -800,50 +774,43 @@
MR_threadscope_register_string(const char *string);
/*
-** These four events are used to create and manage engine sets. Haskell calls
-** these cap sets.
+** These four events are used to create and manage engine sets.
+** Haskell calls these cap sets.
**
** The first two work on the global event buffer and are not thread safe.
*/
-static void
-MR_threadscope_post_create_engset(MR_EngSetId id, MR_EngSetType type);
+static void MR_threadscope_post_create_engset(MR_EngSetId id,
+ MR_EngSetType type);
-static void
-MR_threadscope_post_destroy_engset(MR_EngSetId id);
+static void MR_threadscope_post_destroy_engset(MR_EngSetId id);
-static void
-MR_threadscope_post_engset_add(struct MR_threadscope_event_buffer *buffer,
+static void MR_threadscope_post_engset_add(
+ struct MR_threadscope_event_buffer *buffer,
MR_EngSetId id, MR_EngineId eng);
-static void
-MR_threadscope_post_engset_remove(MR_EngSetId id, MR_EngineId eng);
+static void MR_threadscope_post_engset_remove(MR_EngSetId id, MR_EngineId eng);
/*
** Post the name and version of the runtime system to the log file.
**
-** Note that this is the name of the implementation (mmc), not the name of the
-** language (mercury).
+** Note that this is the name of the implementation (mmc),
+** not the name of the language (mercury).
**
** The name and version are separated by a '-'.
*/
-static void
-MR_threadscope_post_runtime_identifier(MR_EngSetId id, const char *ident);
+static void MR_threadscope_post_runtime_identifier(MR_EngSetId id,
+ const char *ident);
/***************************************************************************/
-static void
-start_gc_callback(void);
-static void
-stop_gc_callback(void);
-static void
-pause_thread_gc_callback(void);
-static void
-resume_thread_gc_callback(void);
+static void start_gc_callback(void);
+static void stop_gc_callback(void);
+static void pause_thread_gc_callback(void);
+static void resume_thread_gc_callback(void);
/***************************************************************************/
-static MR_uint_least64_t
-get_current_time_nanosecs(void);
+static MR_uint_least64_t get_current_time_nanosecs(void);
/***************************************************************************/
@@ -853,12 +820,12 @@
MR_DO_THREADSCOPE_DEBUG(
fprintf(stderr, "In setup threadscope thread: 0x%lx\n", pthread_self())
);
- /* This value is used later when setting up the primordial engine */
+ /* This value is used later when setting up the primordial engine. */
MR_primordial_first_tsc = MR_read_cpu_tsc();
/*
- ** These variables are used for TSC synchronization which is not used. See
- ** below.
+ ** These variables are used for TSC synchronization which is not used.
+ ** See below.
**
pthread_mutex_init(&MR_tsc_sync_slave_lock, MR_MUTEX_ATTR);
MR_US_COND_CLEAR(&MR_tsc_sync_slave_entry_cond);
@@ -903,7 +870,8 @@
MR_finalize_threadscope(void)
{
MR_DO_THREADSCOPE_DEBUG(
- fprintf(stderr, "In finalize threadscope thread: 0x%lx\n", pthread_self())
+ fprintf(stderr, "In finalize threadscope thread: 0x%lx\n",
+ pthread_self())
);
MR_threadscope_post_destroy_engset(process_engset_id);
@@ -916,7 +884,8 @@
MR_threadscope_setup_engine(MercuryEngine *eng)
{
MR_DO_THREADSCOPE_DEBUG(
- fprintf(stderr, "In threadscope setup engine thread: 0x%lx\n", pthread_self())
+ fprintf(stderr, "In threadscope setup engine thread: 0x%lx\n",
+ pthread_self())
);
eng->MR_eng_next_spark_id = 0;
@@ -942,7 +911,8 @@
struct MR_threadscope_event_buffer *buffer = eng->MR_eng_ts_buffer;
MR_DO_THREADSCOPE_DEBUG(
- fprintf(stderr, "In threadscope finalize engine thread: 0x%lx\n", pthread_self())
+ fprintf(stderr, "In threadscope finalize engine thread: 0x%lx\n",
+ pthread_self())
);
MR_threadscope_post_engset_remove(process_engset_id, eng->MR_eng_id);
@@ -965,8 +935,8 @@
#if 0
/*
** It looks like we don't need this on modern CPUs including multi-socket
-** systems (goliath). If we find systems where this is needed we can enable it
-** via a runtime check.
+** systems (goliath). If we find systems where this is needed, we can
+** enable it via a runtime check.
*/
/*
** The synchronization of TSCs operates as follows:
@@ -993,31 +963,24 @@
volatile static MR_Us_Cond MR_tsc_sync_t1;
static Time MR_tsc_sync_master_time;
-static int
-compare_time_delay_offset_by_delay(const void *a, const void *b);
+static int compare_time_delay_offset_by_delay(const void *a, const void *b);
void
MR_threadscope_sync_tsc_master(void)
{
unsigned i;
- /*
- ** Wait for a slave to enter.
- */
+ /* Wait for a slave to enter. */
MR_US_COND_SET(&MR_tsc_sync_master_entry_cond);
MR_US_SPIN_COND(&MR_tsc_sync_slave_entry_cond);
MR_US_COND_CLEAR(&MR_tsc_sync_slave_entry_cond);
for (i = 0; i < MR_TSC_SYNC_NUM_ROUNDS; i++) {
- /*
- ** Wait to receive the message from the slave at T0
- */
+ /* Wait to receive the message from the slave at T0. */
MR_US_SPIN_COND(&MR_tsc_sync_t0);
MR_US_COND_CLEAR(&MR_tsc_sync_t0);
- /*
- ** Read our TSC and send the slave a message.
- */
+ /* Read our TSC and send the slave a message. */
MR_tsc_sync_master_time = MR_read_cpu_tsc();
MR_US_COND_SET(&MR_tsc_sync_t1);
}
@@ -1032,13 +995,12 @@
Timedelta total_offset;
MercuryEngine *eng = MR_thread_engine_base;
- /*
- ** Only one slave may enter at a time.
- */
+ /* Only one slave may enter at a time. */
MR_LOCK(&MR_tsc_sync_slave_lock, "MR_threadscope_sync_tsc_slave");
/*
- ** Tell the master we're ready to begin and wait for it to tell us it's ready.
+ ** Tell the master we are ready to begin, and wait for it to tell us
+ ** it is ready.
*/
MR_US_COND_SET(&MR_tsc_sync_slave_entry_cond);
MR_US_SPIN_COND(&MR_tsc_sync_master_entry_cond);
@@ -1055,8 +1017,8 @@
MR_US_COND_SET(&MR_tsc_sync_t0);
/*
- ** Wait for the master to reply, the master handles T=1, here we
- ** proceed to T=2.
+ ** Wait for the master to reply, the master handles T=1,
+ ** here we proceed to T=2.
*/
MR_US_SPIN_COND(&MR_tsc_sync_t1);
slave_tsc_at_t2 = MR_read_cpu_tsc();
@@ -1065,33 +1027,37 @@
/*
** Here are Cristian's formulas. Delay is the round trip time,
** slave_tsc_at_t0 + delay/2 is the time on the slave's clock that the
- ** master processed the slaves message and sent it's own. This is
+ ** master processed the slaves message and sent its own. This is
** accurate if the communication delays in either direction are
** uniform, that is communication latency is synchronous.
*/
delay_offset[i].delay = slave_tsc_at_t2 - slave_tsc_at_t0;
- delay_offset[i].offset =
- MR_tsc_sync_master_time - (slave_tsc_at_t0 + delay_offset[i].delay/2);
+ delay_offset[i].offset = MR_tsc_sync_master_time -
+ (slave_tsc_at_t0 + delay_offset[i].delay/2);
}
- /* By now the master thread will return and continue with it's normal work. */
+
+ /*
+ ** By now the master thread will return,
+ ** and continue with its normal work.
+ */
/*
** We do this debugging output while holding the lock, so that the output
** is reasonable.
*/
MR_DO_THREADSCOPE_DEBUG({
- fprintf(stderr, "TSC Synchronization for thread 0x%x\n", pthread_self());
+ fprintf(stderr, "TSC Synchronization for thread 0x%x\n",
+ pthread_self());
for (i = 0; i < MR_TSC_SYNC_NUM_ROUNDS; i++) {
- fprintf(stderr, "delay: %ld offset (local + global = total) %ld + %ld = %ld\n",
+ fprintf(stderr,
+ "delay: %ld offset (local + global = total) %ld + %ld = %ld\n",
delay_offset[i].delay, delay_offset[i].offset, MR_global_offset,
delay_offset[i].offset + MR_global_offset);
}
});
MR_UNLOCK(&MR_tsc_sync_slave_lock, "MR_threadscope_sync_tsc_slave");
- /*
- ** Now to average the best offsets.
- */
+ /* Now to average the best offsets. */
qsort(&delay_offset, MR_TSC_SYNC_NUM_ROUNDS, sizeof(TimeDelayOffset),
compare_time_delay_offset_by_delay);
total_offset = 0;
@@ -1138,7 +1104,8 @@
open_block(buffer, MR_ENGINE(MR_eng_id));
}
- put_event_header(buffer, MR_TS_EVENT_CREATE_THREAD, get_current_time_nanosecs());
+ put_event_header(buffer, MR_TS_EVENT_CREATE_THREAD,
+ get_current_time_nanosecs());
put_context_id(buffer, context->MR_ctxt_num_id);
MR_US_UNLOCK(&(buffer->MR_tsbuffer_lock));
@@ -1179,7 +1146,8 @@
open_block(buffer, MR_ENGINE(MR_eng_id));
}
- put_event_header(buffer, MR_TS_EVENT_THREAD_RUNNABLE, get_current_time_nanosecs());
+ put_event_header(buffer, MR_TS_EVENT_THREAD_RUNNABLE,
+ get_current_time_nanosecs());
put_context_id(buffer, context->MR_ctxt_num_id);
MR_US_UNLOCK(&(buffer->MR_tsbuffer_lock));
@@ -1187,8 +1155,7 @@
static void
MR_threadscope_post_run_context_locked(
- struct MR_threadscope_event_buffer *buffer,
- MR_Context *context)
+ struct MR_threadscope_event_buffer *buffer, MR_Context *context)
{
if (!enough_room_for_event(buffer, MR_TS_EVENT_RUN_THREAD)) {
flush_event_buffer(buffer);
@@ -1224,8 +1191,7 @@
static void
MR_threadscope_post_stop_context_locked(
struct MR_threadscope_event_buffer *buffer,
- MR_Context *context,
- MR_ContextStopReason reason)
+ MR_Context *context, MR_ContextStopReason reason)
{
if (!enough_room_for_event(buffer, MR_TS_EVENT_STOP_THREAD)) {
flush_event_buffer(buffer);
@@ -1234,7 +1200,8 @@
open_block(buffer, MR_thread_engine_base->MR_eng_id);
}
- put_event_header(buffer, MR_TS_EVENT_STOP_THREAD, get_current_time_nanosecs());
+ put_event_header(buffer, MR_TS_EVENT_STOP_THREAD,
+ get_current_time_nanosecs());
put_context_id(buffer, context->MR_ctxt_num_id);
put_stop_reason(buffer, reason);
}
@@ -1316,7 +1283,7 @@
/*
** The engine that created the spark (which may not be whom it was stolen
** from if different work-stealking algorithms are implemented) can be
- ** derrived from the spark id.
+ ** derived from the spark id.
*/
engine_id = (spark_id & 0xFF000000) >> 24;
put_be_uint16(buffer, engine_id);
@@ -1346,7 +1313,8 @@
}
void
-MR_threadscope_post_calling_main(void) {
+MR_threadscope_post_calling_main(void)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
@@ -1363,12 +1331,14 @@
}
void
-MR_threadscope_post_looking_for_global_context(void) {
+MR_threadscope_post_looking_for_global_context(void)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
if (!enough_room_for_event(buffer,
- MR_TS_MER_EVENT_LOOKING_FOR_GLOBAL_CONTEXT)) {
+ MR_TS_MER_EVENT_LOOKING_FOR_GLOBAL_CONTEXT))
+ {
flush_event_buffer(buffer);
open_block(buffer, MR_ENGINE(MR_eng_id));
} else if (!block_is_open(buffer)) {
@@ -1381,7 +1351,8 @@
}
void
-MR_threadscope_post_work_stealing(void) {
+MR_threadscope_post_work_stealing(void)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
@@ -1399,7 +1370,8 @@
void
MR_threadscope_post_start_par_conj(MR_Word* dynamic_id,
- MR_TS_StringId static_id) {
+ MR_TS_StringId static_id)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
@@ -1419,7 +1391,8 @@
}
void
-MR_threadscope_post_stop_par_conj(MR_Word *dynamic_id) {
+MR_threadscope_post_stop_par_conj(MR_Word *dynamic_id)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
@@ -1438,7 +1411,8 @@
}
void
-MR_threadscope_post_stop_par_conjunct(MR_Word *dynamic_id) {
+MR_threadscope_post_stop_par_conjunct(MR_Word *dynamic_id)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
@@ -1472,7 +1446,8 @@
** +4 for the string id.
*/
if (!enough_room_for_variable_size_event(&global_buffer, strlen(string)
- + 2 + 4)) {
+ + 2 + 4))
+ {
flush_event_buffer(&global_buffer);
}
@@ -1487,7 +1462,8 @@
void
MR_threadscope_register_strings_array(MR_Threadscope_String *array,
- unsigned size) {
+ unsigned size)
+{
unsigned i;
for (i = 0; i < size; i++) {
@@ -1499,7 +1475,8 @@
}
void
-MR_threadscope_post_log_msg(const char *message) {
+MR_threadscope_post_log_msg(const char *message)
+{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
@@ -1556,8 +1533,8 @@
}
/*
- ** When this event occurs the engine hasn't been setup yet. Even though we
- ** use the engine's buffer we cannot use get_current_time_nanosecs()
+ ** When this event occurs the engine hasn't been setup yet. Even though
+ ** we use the engine's buffer, we cannot use get_current_time_nanosecs().
*/
put_event_header(buffer, MR_TS_EVENT_CAPSET_ASSIGN_CAP, 0);
put_engset_id(buffer, id);
@@ -1714,8 +1691,8 @@
progname_base = basename(progname_copy);
/*
- ** This is an over-approximation on the amount of space needed for this
- ** filename.
+ ** This is an over-approximation on the amount of space needed
+ ** for this filename.
*/
filename_len = strlen(progname_base) + strlen(MR_TS_FILENAME_FORMAT) + 1;
MR_threadscope_output_filename = MR_GC_NEW_ARRAY(char, filename_len);
@@ -1733,9 +1710,10 @@
put_be_uint32(&global_buffer, MR_TS_EVENT_HEADER_BEGIN);
put_be_uint32(&global_buffer, MR_TS_EVENT_HET_BEGIN);
- for ( i = 0;
+ for (i = 0;
event_type_descs[i].etd_event_type != MR_TS_NUM_EVENT_TAGS;
- i++) {
+ i++)
+ {
put_event_type(&global_buffer, &event_type_descs[i]);
}
put_be_uint32(&global_buffer, MR_TS_EVENT_HET_END);
@@ -1767,15 +1745,14 @@
MR_int_least16_t size;
EventType event_type;
- /*
- * This also fills in our tables of event sizes.
- */
+ /* This also fills in our tables of event sizes. */
event_type = event_type_desc->etd_event_type;
size = event_type_desc->etd_size;
if (event_type < MR_TS_NUM_EVENT_TAGS) {
event_type_sizes[event_type] = size;
} else if ((event_type < (MR_TS_MER_EVENT_START + MR_TS_NUM_MER_EVENTS))
- && (event_type >= MR_TS_MER_EVENT_START)) {
+ && (event_type >= MR_TS_MER_EVENT_START))
+ {
event_type_sizes_mercury[event_type - MR_TS_MER_EVENT_START] = size;
} else {
fprintf(stderr, "Unknown event type %d\n", event_type);
@@ -1805,7 +1782,8 @@
*/
if (MR_threadscope_output_file && buffer->MR_tsbuffer_pos) {
if (0 == fwrite(buffer->MR_tsbuffer_data, buffer->MR_tsbuffer_pos, 1,
- MR_threadscope_output_file)) {
+ MR_threadscope_output_file))
+ {
perror(MR_threadscope_output_filename);
MR_threadscope_output_file = NULL;
MR_threadscope_output_filename = NULL;
@@ -1826,7 +1804,8 @@
saved_pos = buffer->MR_tsbuffer_pos;
buffer->MR_tsbuffer_pos = buffer->MR_tsbuffer_block_open_pos +
sizeof(EventType) + sizeof(Time);
- put_eventlog_offset(buffer, saved_pos - buffer->MR_tsbuffer_block_open_pos);
+ put_eventlog_offset(buffer,
+ saved_pos - buffer->MR_tsbuffer_block_open_pos);
put_timestamp(buffer, get_current_time_nanosecs());
buffer->MR_tsbuffer_block_open_pos = -1;
@@ -1840,12 +1819,13 @@
maybe_close_block(buffer);
/*
- ** Save the old position, close block uses this so that it knows where the
- ** block maker is that it should write into.
+ ** Save the old position. Close block uses this so that it knows
+ ** where the block maker is that it should write into.
*/
buffer->MR_tsbuffer_block_open_pos = buffer->MR_tsbuffer_pos;
- put_event_header(buffer, MR_TS_EVENT_BLOCK_MARKER, get_current_time_nanosecs());
+ put_event_header(buffer, MR_TS_EVENT_BLOCK_MARKER,
+ get_current_time_nanosecs());
/* Skip over the next two fields, they are filled in by close_block */
buffer->MR_tsbuffer_pos += sizeof(EventlogOffset) + sizeof(Time);
@@ -1921,7 +1901,8 @@
open_block(buffer, MR_thread_engine_base->MR_eng_id);
}
- put_event_header(buffer, MR_TS_EVENT_GC_END, get_current_time_nanosecs());
+ put_event_header(buffer, MR_TS_EVENT_GC_END,
+ get_current_time_nanosecs());
context = MR_thread_engine_base->MR_eng_this_context;
if (!buffer->MR_tsbuffer_ctxt_is_stopped && context) {
@@ -1938,7 +1919,8 @@
MR_Context *context;
MR_DO_THREADSCOPE_DEBUG(
- fprintf(stderr, "In gc pause thread callback thread: 0x%lx\n", pthread_self())
+ fprintf(stderr, "In gc pause thread callback thread: 0x%lx\n",
+ pthread_self())
);
if (MR_thread_engine_base == NULL) return;
buffer = MR_thread_engine_base->MR_eng_ts_buffer;
@@ -1964,7 +1946,8 @@
MR_Context *context;
MR_DO_THREADSCOPE_DEBUG(
- fprintf(stderr, "In gc resume thread callback thread: 0x%lx\n", pthread_self());
+ fprintf(stderr, "In gc resume thread callback thread: 0x%lx\n",
+ pthread_self());
);
if (MR_thread_engine_base == NULL) return;
buffer = MR_thread_engine_base->MR_eng_ts_buffer;
@@ -1995,10 +1978,7 @@
if (MR_cpu_cycles_per_sec == 0) {
return current_tsc + eng->MR_eng_cpu_clock_ticks_offset;
} else {
- /*
- ** The large constant (10^9) here converts seconds into
- ** nanoseconds.
- */
+ /* The large constant (10^9) here converts seconds into nanoseconds. */
return (current_tsc + eng->MR_eng_cpu_clock_ticks_offset) /
(MR_cpu_cycles_per_sec / 1000000000);
}
@@ -2007,31 +1987,3 @@
/***************************************************************************/
#endif /* MR_THREADSCOPE */
-
-/* forward decls to suppress gcc warnings */
-void mercury_sys_init_threadscope_init(void);
-void mercury_sys_init_threadscope_init_type_tables(void);
-#ifdef MR_DEEP_PROFILING
-void mercury_sys_init_threadscope_write_out_proc_statics(FILE *fp);
-#endif
-
-void mercury_sys_init_threadscope_init(void)
-{
-#ifndef MR_HIGHLEVEL_CODE
-/* XXX: What does this do? Why do other modules have a call like this.
- threadscope_module();
-*/
-#endif
-}
-
-void mercury_sys_init_threadscope_init_type_tables(void)
-{
- /* no types to register */
-}
-
-#ifdef MR_DEEP_PROFILING
-void mercury_sys_init_threadscope_write_out_proc_statics(FILE *fp)
-{
- /* no proc_statics to write out */
-}
-#endif
Index: mercury_threadscope.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_threadscope.h,v
retrieving revision 1.8
diff -u -b -r1.8 mercury_threadscope.h
--- mercury_threadscope.h 13 Apr 2011 13:19:42 -0000 1.8
+++ mercury_threadscope.h 2 May 2011 07:32:48 -0000
@@ -53,17 +53,13 @@
** This must be called by the primordial thread before starting any other
** threads but after the primordial thread has been pinned.
*/
-extern void
-MR_setup_threadscope(void);
+extern void MR_setup_threadscope(void);
-extern void
-MR_finalize_threadscope(void);
+extern void MR_finalize_threadscope(void);
-extern void
-MR_threadscope_setup_engine(MercuryEngine *eng);
+extern void MR_threadscope_setup_engine(MercuryEngine *eng);
-extern void
-MR_threadscope_finalize_engine(MercuryEngine *eng);
+extern void MR_threadscope_finalize_engine(MercuryEngine *eng);
#if 0
/*
@@ -81,10 +77,8 @@
** synchronize only one at a time. Only the primordial thread may call
** MR_threadscope_sync_tsc_master().
*/
-extern void
-MR_threadscope_sync_tsc_master(void);
-extern void
-MR_threadscope_sync_tsc_slave(void);
+extern void MR_threadscope_sync_tsc_master(void);
+extern void MR_threadscope_sync_tsc_slave(void);
#endif
/*
@@ -100,128 +94,112 @@
** Using the MR_Context typedef here requires the inclusion of
** mercury_context.h, creating a circular dependency
*/
-extern void
-MR_threadscope_post_create_context(struct MR_Context_Struct *context);
+extern void MR_threadscope_post_create_context(
+ struct MR_Context_Struct *context);
/*
** The given context was created in order to execute a spark. It's an
** alternative to the above event.
*/
-extern void
-MR_threadscope_post_create_context_for_spark(struct MR_Context_Struct *ctxt);
+extern void MR_threadscope_post_create_context_for_spark(
+ struct MR_Context_Struct *ctxt);
/*
** This message says the context is now ready to run. Such as it's being
** placed on the run queue after being blocked
*/
-extern void
-MR_threadscope_post_context_runnable(struct MR_Context_Struct *context);
+extern void MR_threadscope_post_context_runnable(
+ struct MR_Context_Struct *context);
/*
** This message says we're now running the current context
*/
-extern void
-MR_threadscope_post_run_context(void);
+extern void MR_threadscope_post_run_context(void);
/*
** This message says we've stopped executing the current context,
** a reason why should be provided.
*/
-extern void
-MR_threadscope_post_stop_context(MR_ContextStopReason reason);
+extern void MR_threadscope_post_stop_context(MR_ContextStopReason reason);
/*
** This message says we're about to execute a spark from our local stack.
*/
-extern void
-MR_threadscope_post_run_spark(MR_SparkId spark_id);
+extern void MR_threadscope_post_run_spark(MR_SparkId spark_id);
/*
** This message says that we're about to execute a spark that was stolen from
** another's stack.
*/
-extern void
-MR_threadscope_post_steal_spark(MR_SparkId spark_id);
+extern void MR_threadscope_post_steal_spark(MR_SparkId spark_id);
/*
** This message says that a spark is being created for the given computation.
** The spark's ID is given as an argument.
*/
-extern void
-MR_threadscope_post_sparking(MR_Word* dynamic_conj_id, MR_SparkId spark_id);
+extern void MR_threadscope_post_sparking(MR_Word* dynamic_conj_id,
+ MR_SparkId spark_id);
/*
** Post this message just before invoking the main/2 predicate.
*/
-extern void
-MR_threadscope_post_calling_main(void);
+extern void MR_threadscope_post_calling_main(void);
/*
** Post this message when a thread begins looking for a context to run.
*/
-extern void
-MR_threadscope_post_looking_for_global_context(void);
+extern void MR_threadscope_post_looking_for_global_context(void);
/*
** Post this message when a thread is about to attempt work stealing.
*/
-extern void
-MR_threadscope_post_work_stealing(void);
+extern void MR_threadscope_post_work_stealing(void);
/*
** Post this message before a parallel conjunction starts.
*/
-extern void
-MR_threadscope_post_start_par_conj(MR_Word* dynamic_id, MR_TS_StringId static_id);
+extern void MR_threadscope_post_start_par_conj(MR_Word* dynamic_id,
+ MR_TS_StringId static_id);
/*
** Post this message after a parallel conjunction stops.
*/
-extern void
-MR_threadscope_post_stop_par_conj(MR_Word* dynamic_id);
+extern void MR_threadscope_post_stop_par_conj(MR_Word* dynamic_id);
/*
** Post this message when a parallel conjunct calls the bariier code.
*/
-extern void
-MR_threadscope_post_stop_par_conjunct(MR_Word* dynamic_id);
+extern void MR_threadscope_post_stop_par_conjunct(MR_Word* dynamic_id);
/*
** Post this message when a future is created, this establishes the conjuction
** id to future id mapping. The conjunction id is inferred by context.
*/
-extern void
-MR_threadscope_post_new_future(MR_Future* future_id);
+extern void MR_threadscope_post_new_future(MR_Future* future_id);
/*
** Post either of these messages when waiting on a future. THe first if the
** context had to be suspended because the future was not available, and the
** second when the context did not need to be suspended.
*/
-extern void
-MR_threadscope_post_wait_future_nosuspend(MR_Future* future_id);
-
-extern void
-MR_threadscope_post_wait_future_suspended(MR_Future* future_id);
+extern void MR_threadscope_post_wait_future_nosuspend(MR_Future* future_id);
+extern void MR_threadscope_post_wait_future_suspended(MR_Future* future_id);
/*
** Post this event when signaling the production of a future.
*/
-extern void
-MR_threadscope_post_signal_future(MR_Future* future_id);
+extern void MR_threadscope_post_signal_future(MR_Future* future_id);
/*
** Register all the strings in an array and save their IDs in the array.
*/
-extern void
-MR_threadscope_register_strings_array(MR_Threadscope_String *array,
+extern void MR_threadscope_register_strings_array(MR_Threadscope_String *array,
unsigned size);
/*
** Post a user-defined log message.
*/
-extern void
-MR_threadscope_post_log_msg(const char *message);
+extern void MR_threadscope_post_log_msg(const char *message);
#endif /* MR_THREADSCOPE */
cvs diff: Diffing GETOPT
cvs diff: Diffing machdeps
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list