On 12/01/2015 13:00, Pavel Dovgalyuk wrote:
> +/*! Reads next clock event from the input. */
> +int64_t replay_read_clock(unsigned int kind)
> +{
> + if (kind >= REPLAY_CLOCK_COUNT) {
> + fprintf(stderr, "invalid clock ID %d for replay\n", kind);
> + exit(1);
> + }
> +
> + replay_exec_instructions();
> +
> + if (replay_file) {
> + if (skip_async_events(EVENT_CLOCK + kind)) {
> + replay_read_next_clock(kind);
> + }
> + int64_t ret = replay_state.cached_clock[kind];
> +
> + return ret;
> + }
> +
> + fprintf(stderr, "REPLAY INTERNAL ERROR %d\n", __LINE__);
> + exit(1);
> +}
Is this thread safe? Please introduce the record/replay QemuMutex in
patch 4, and all along the series document which variables it protects.
Paolo
> diff --git a/replay/replay.h b/replay/replay.h
> index 90a949b..1c18c0e 100755
> --- a/replay/replay.h
> +++ b/replay/replay.h
> @@ -16,6 +16,16 @@
> #include <stdint.h>
> #include "qapi-types.h"
>
> +/* replay clock kinds */
> +/* rdtsc */
> +#define REPLAY_CLOCK_REAL_TICKS 0
> +/* host_clock */
> +#define REPLAY_CLOCK_HOST 1
> +/* virtual_rt_clock */
> +#define REPLAY_CLOCK_VIRTUAL_RT 2
> +
> +#define REPLAY_CLOCK_COUNT 3
> +
> extern ReplayMode replay_mode;
> extern char *replay_image_suffix;
>
> @@ -47,6 +57,19 @@ bool replay_interrupt(void);
> Returns true, when interrupt request is pending */
> bool replay_has_interrupt(void);
>
> +/* Processing clocks and other time sources */
> +
> +/*! Save the specified clock */
> +int64_t replay_save_clock(unsigned int kind, int64_t clock);
> +/*! Read the specified clock from the log or return cached data */
> +int64_t replay_read_clock(unsigned int kind);
> +/*! Saves or reads the clock depending on the current replay mode. */
> +#define REPLAY_CLOCK(clock, value) \
> + (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \
> + : replay_mode == REPLAY_MODE_RECORD \
> + ? replay_save_clock((clock), (value)) \
> + : (value))
> +
Inline functions please, not macros.