From patchwork Wed Sep 6 18:19:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 9941171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 73C18602CC for ; Wed, 6 Sep 2017 18:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6169528C33 for ; Wed, 6 Sep 2017 18:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0821828C04; Wed, 6 Sep 2017 18:20:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5E95528C24 for ; Wed, 6 Sep 2017 18:20:24 +0000 (UTC) Received: from localhost ([::1]:37405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpevt-0003iT-E9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Sep 2017 14:20:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpevA-0003i3-Tx for qemu-devel@nongnu.org; Wed, 06 Sep 2017 14:19:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpev6-0005w3-Sr for qemu-devel@nongnu.org; Wed, 06 Sep 2017 14:19:28 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:39560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpev6-0005vr-Hn for qemu-devel@nongnu.org; Wed, 06 Sep 2017 14:19:24 -0400 Received: from correu-2.ac.upc.es (correu-2.ac.upc.es [147.83.30.92]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id v86IJLWp005042; Wed, 6 Sep 2017 20:19:21 +0200 Received: from localhost (unknown [31.210.187.58]) by correu-2.ac.upc.es (Postfix) with ESMTPSA id A8DFF1DF; Wed, 6 Sep 2017 20:19:15 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 21:19:14 +0300 Message-Id: <150472195416.24907.15859962605541218107.stgit@frigg.lan> X-Mailer: git-send-email 2.14.1 In-Reply-To: <150471856141.24907.274176769201097378.stgit@frigg.lan> References: <150471856141.24907.274176769201097378.stgit@frigg.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id v86IJLWp005042 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v4 14/20] instrument: Add event 'guest_cpu_reset' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Emilio G. Cota" , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: LluĂ­s Vilanova --- instrument/control.c | 9 +++++++++ instrument/events.h | 3 +++ instrument/events.inc.h | 11 +++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 9 +++++++++ qom/cpu.c | 2 ++ stubs/instrument.c | 1 + 7 files changed, 36 insertions(+) diff --git a/instrument/control.c b/instrument/control.c index 09ba682483..3cec1028e5 100644 --- a/instrument/control.c +++ b/instrument/control.c @@ -66,3 +66,12 @@ QI_VPUBLIC void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu)) ERROR_IF(!instr_get_state(), "called outside instrumentation"); instr_set_event(guest_cpu_exit, fn); } + + +void (*instr_event__guest_cpu_reset)(QICPU vcpu); + +QI_VPUBLIC void qi_event_set_guest_cpu_reset(void (*fn)(QICPU vcpu)) +{ + ERROR_IF(!instr_get_state(), "called outside instrumentation"); + instr_set_event(guest_cpu_reset, fn); +} diff --git a/instrument/events.h b/instrument/events.h index c743cb8180..4a0560490a 100644 --- a/instrument/events.h +++ b/instrument/events.h @@ -39,6 +39,9 @@ static inline void instr_guest_cpu_enter(CPUState *vcpu); extern void (*instr_event__guest_cpu_exit)(QICPU vcpu); static inline void instr_guest_cpu_exit(CPUState *vcpu); +extern void (*instr_event__guest_cpu_reset)(QICPU vcpu); +static inline void instr_guest_cpu_reset(CPUState *vcpu); + #include "instrument/events.inc.h" diff --git a/instrument/events.inc.h b/instrument/events.inc.h index bcbf0cb32a..2f2cd324aa 100644 --- a/instrument/events.inc.h +++ b/instrument/events.inc.h @@ -31,3 +31,14 @@ static inline void instr_guest_cpu_exit(CPUState *vcpu) instr_set_state(INSTR_STATE_DISABLE); } } + +static inline void instr_guest_cpu_reset(CPUState *vcpu) +{ + void (*cb)(QICPU vcpu) = instr_get_event(guest_cpu_reset); + if (cb) { + QICPU vcpu_ = instr_cpu_set(vcpu); + instr_set_state(INSTR_STATE_ENABLE); + (*cb)(vcpu_); + instr_set_state(INSTR_STATE_DISABLE); + } +} diff --git a/instrument/load.c b/instrument/load.c index 63b7d564ec..d9310d1979 100644 --- a/instrument/load.c +++ b/instrument/load.c @@ -150,6 +150,7 @@ InstrUnloadError instr_unload(int64_t handle_id) instr_set_event(fini_fn, NULL); instr_set_event(guest_cpu_enter, NULL); instr_set_event(guest_cpu_exit, NULL); + instr_set_event(guest_cpu_reset, NULL); /* this should never fail */ if (dlclose(handle->dlhandle) < 0) { diff --git a/instrument/qemu-instr/control.h b/instrument/qemu-instr/control.h index c37a380ab0..238ea63301 100644 --- a/instrument/qemu-instr/control.h +++ b/instrument/qemu-instr/control.h @@ -89,6 +89,15 @@ void qi_event_set_guest_cpu_enter(void (*fn)(QICPU vcpu)); */ void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu)); +/* + * Reset the state of a virtual (guest) CPU. + * + * Mode: user, softmmu + * Targets: all + * Time: exec + */ +void qi_event_set_guest_cpu_reset(void (*fn)(QICPU vcpu)); + #ifdef __cplusplus } #endif diff --git a/qom/cpu.c b/qom/cpu.c index 4f38db0dac..d09cf583eb 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -19,6 +19,7 @@ */ #include "qemu/osdep.h" +#include "instrument/events.h" #include "qapi/error.h" #include "qemu-common.h" #include "qom/cpu.h" @@ -271,6 +272,7 @@ void cpu_reset(CPUState *cpu) (*klass->reset)(cpu); } + instr_guest_cpu_reset(cpu); trace_guest_cpu_reset(cpu); } diff --git a/stubs/instrument.c b/stubs/instrument.c index ea8df6d467..74935975da 100644 --- a/stubs/instrument.c +++ b/stubs/instrument.c @@ -13,3 +13,4 @@ __thread InstrState instr_cur_state; void (*instr_event__guest_cpu_enter)(QICPU *vcpu); void (*instr_event__guest_cpu_exit)(QICPU *vcpu); +void (*instr_event__guest_cpu_reset)(QICPU *vcpu);