Author: tobias@masterthesis-vm Branch: c8-efficient-serial-execution Changeset: r2019:87f8a688298c Date: 2017-03-02 16:44 +0100 http://bitbucket.org/pypy/stmgc/changeset/87f8a688298c/
Log: Refactor timing event function to accept general payloads diff --git a/c8/stm/marker.c b/c8/stm/marker.c --- a/c8/stm/marker.c +++ b/c8/stm/marker.c @@ -3,6 +3,9 @@ # include "core.h" // silence flymake #endif +#define payload(marker) stm_timing_event_payload_data_t data = { &marker }; \ + stm_timing_event_payload_t payload = { \ + STM_EVENT_PAYLOAD_MARKER, data }; static bool marker_fetch(stm_thread_local_t *tl, stm_loc_marker_t *out_marker) { @@ -92,19 +95,16 @@ stm_loc_marker_t marker; marker_fetch_obj_write(start, contention, &marker); + payload(marker) stmcb_timing_event(STM_SEGMENT->running_thread, - STM_CONTENTION_WRITE_READ, &marker); + STM_CONTENTION_WRITE_READ, &payload); } static void _timing_become_inevitable(void) { stm_loc_marker_t marker; marker_fetch(STM_SEGMENT->running_thread, &marker); + payload(marker) stmcb_timing_event(STM_SEGMENT->running_thread, - STM_BECOME_INEVITABLE, &marker); + STM_BECOME_INEVITABLE, &payload); } - - -void (*stmcb_timing_event)(stm_thread_local_t *tl, /* the local thread */ - enum stm_event_e event, - stm_loc_marker_t *marker); diff --git a/c8/stm/prof.c b/c8/stm/prof.c --- a/c8/stm/prof.c +++ b/c8/stm/prof.c @@ -6,37 +6,45 @@ static char *profiling_basefn = NULL; static stm_expand_marker_fn profiling_expand_marker; -#define MARKER_LEN_MAX 160 +#define EXTRA_LEN_MAX 160 static bool close_timing_log(void); /* forward */ static void _stm_profiling_event(stm_thread_local_t *tl, enum stm_event_e event, - stm_loc_marker_t *marker) + stm_timing_event_payload_t *payload) { struct buf_s { uint32_t tv_sec; uint32_t tv_nsec; uint32_t thread_num; uint8_t event; - uint8_t marker_length; - char extra[MARKER_LEN_MAX+1]; + uint8_t extra_length; + char extra[EXTRA_LEN_MAX+1]; } __attribute__((packed)); struct buf_s buf; struct timespec t; buf.thread_num = tl->thread_local_counter; buf.event = event; - buf.marker_length = 0; + buf.extra_length = 0; - if (marker != NULL && marker->odd_number != 0) { - buf.marker_length = profiling_expand_marker(get_segment_base(0), - marker, - buf.extra, MARKER_LEN_MAX); + if (payload != NULL) { + if (payload->type == STM_EVENT_PAYLOAD_MARKER) { + stm_loc_marker_t *marker = payload->data.loc_marker; + if (marker != NULL && marker->odd_number != 0) { + buf.extra_length = profiling_expand_marker(get_segment_base(0), + marker, + buf.extra, EXTRA_LEN_MAX); + } + } else if (payload->type == STM_EVENT_PAYLOAD_DURATION) { + uint32_t duration = payload->data.duration; + buf.extra_length = sprintf(buf.extra, "%u", duration); + } } - size_t result, outsize = offsetof(struct buf_s, extra) + buf.marker_length; + size_t result, outsize = offsetof(struct buf_s, extra) + buf.extra_length; FILE *f = profiling_file; if (f == NULL) return; @@ -146,3 +154,7 @@ profiling_basefn = strdup(profiling_file_name); return 0; } + +void (*stmcb_timing_event)(stm_thread_local_t *tl, /* the local thread */ + enum stm_event_e event, + stm_timing_event_payload_t *payload); diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -596,6 +596,7 @@ "gc minor done", \ "gc major start", \ "gc major done" + /* TODO names for new duration events */ /* The markers pushed in the shadowstack are an odd number followed by a regular object pointer. */ @@ -616,12 +617,12 @@ } stm_timing_event_payload_data_t; /* Wrapper for payload holding data type and data. */ typedef struct { - enum stm_payload_type_e payload_type; - stm_timing_event_payload_data_t payload_data; + enum stm_payload_type_e type; + stm_timing_event_payload_data_t data; } stm_timing_event_payload_t; extern void (*stmcb_timing_event)(stm_thread_local_t *tl, /* the local thread */ enum stm_event_e event, - stm_loc_marker_t *marker); + stm_timing_event_payload_t *payload); /* Calling this sets up a stmcb_timing_event callback that will produce a binary file called 'profiling_file_name'. Call it with @@ -634,6 +635,7 @@ the given position and with the given maximum length. */ typedef int (*stm_expand_marker_fn)(char *seg_base, stm_loc_marker_t *marker, char *output, int output_size); +/* TODO generalize expand function */ int stm_set_timing_log(const char *profiling_file_name, int fork_mode, stm_expand_marker_fn expand_marker); _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit