Received: from eggs.gnu.org ([2001:4830:134:3::10]:45590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YC1sg-0006Bz-9G for qemu-devel@nongnu.org; Fri, 16 Jan 2015 03:03:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YC1sb-0004bS-GM for qemu-devel@nongnu.org; Fri, 16 Jan 2015 03:03:45 -0500 Received: from mail.ispras.ru ([83.149.199.45]:58202) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YC1sb-0004bC-7n for qemu-devel@nongnu.org; Fri, 16 Jan 2015 03:03:41 -0500 From: "Pavel Dovgaluk" References: <20150112115944.3504.66763.stgit@PASHA-ISP> <20150112120054.3504.35220.stgit@PASHA-ISP> <54B3BA89.6080705@redhat.com> <000501d02f12$61177b30$23467190$@Dovgaluk@ispras.ru> <54B4E79C.5010201@redhat.com> In-Reply-To: <54B4E79C.5010201@redhat.com> Date: Fri, 16 Jan 2015 11:03:44 +0300 Message-ID: <000101d03162$f2d2ed50$d878c7f0$@Dovgaluk@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-Language: ru Subject: Re: [Qemu-devel] [RFC PATCH v7 12/21] replay: recording and replaying clock ticks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: 'Paolo Bonzini' , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, alex.bennee@linaro.org, mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru, maria.klimushenkova@ispras.ru, afaerber@suse.de, fred.konrad@greensocs.com > From: Paolo Bonzini [mailto:pbonzini@redhat.com] > On 13/01/2015 10:21, Pavel Dovgaluk 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? > > It is, because order of main_loop and cpu_exec executions is protected > > by global mutex. > > > > Please document exactly which globals are protected by the rr QemuMutex, > and which by the global mutex. But I think as many variables as > possible should be protected by the rr QemuMutex, for two reasons: > > 1) people are working on threaded TCG. While SMP record/replay is a > whole different story, even UP TCG will be multithreaded. > > 2) in the end it makes reviewing the code simpler. There is one problem with protecting log file inside the replay code. We probably should have the following sequence of calls: lock_replay_mutex replay_save_events replay_run_event unlock_replay_mutex But replay_run_event can also generate some log events and we will have deadlock here. That is why we rely on global mutex. Pavel Dovgalyuk