* [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
2012-10-15 23:22 ` Igor Mammedov
2012-10-16 16:02 ` Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 2/7] apic: Store X86CPU in APICCommonState Andreas Färber
` (5 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber
This prepares for changing the variable type from void*.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Igor Mammedov <imammedo@redhat.com>
---
hw/apic_common.c | 1 -
target-i386/cpu.c | 5 ++++-
2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
diff --git a/hw/apic_common.c b/hw/apic_common.c
index 371f95d..a26a631 100644
--- a/hw/apic_common.c
+++ b/hw/apic_common.c
@@ -368,7 +368,6 @@ static const VMStateDescription vmstate_apic_common = {
static Property apic_properties_common[] = {
DEFINE_PROP_UINT8("id", APICCommonState, id, -1),
- DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env),
DEFINE_PROP_BIT("vapic", APICCommonState, vapic_control, VAPIC_ENABLE_BIT,
true),
DEFINE_PROP_END_OF_LIST(),
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e307b4e..0cce910 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -41,6 +41,7 @@
#ifndef CONFIG_USER_ONLY
#include "hw/xen.h"
#include "hw/sysbus.h"
+#include "hw/apic_internal.h"
#endif
/* feature flags taken from "Intel Processor Identification and the CPUID
@@ -1884,6 +1885,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
#ifndef CONFIG_USER_ONLY
static int apic_mapped;
CPUX86State *env = &cpu->env;
+ APICCommonState *apic;
const char *apic_type = "apic";
if (kvm_irqchip_in_kernel()) {
@@ -1902,7 +1904,8 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
OBJECT(env->apic_state), NULL);
qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
/* TODO: convert to link<> */
- qdev_prop_set_ptr(env->apic_state, "cpu_env", env);
+ apic = APIC_COMMON(env->apic_state);
+ apic->cpu_env = env;
if (qdev_init(env->apic_state)) {
error_setg(errp, "APIC device '%s' could not be initialized",
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting Andreas Färber
@ 2012-10-15 23:22 ` Igor Mammedov
2012-10-16 16:02 ` Andreas Färber
1 sibling, 0 replies; 18+ messages in thread
From: Igor Mammedov @ 2012-10-15 23:22 UTC (permalink / raw)
To: Andreas Färber; +Cc: qemu-devel
On Fri, 12 Oct 2012 03:26:37 +0200
Andreas Färber <afaerber@suse.de> wrote:
> This prepares for changing the variable type from void*.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> Cc: Igor Mammedov <imammedo@redhat.com>
> ---
> hw/apic_common.c | 1 -
> target-i386/cpu.c | 5 ++++-
> 2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
>
> diff --git a/hw/apic_common.c b/hw/apic_common.c
> index 371f95d..a26a631 100644
> --- a/hw/apic_common.c
> +++ b/hw/apic_common.c
> @@ -368,7 +368,6 @@ static const VMStateDescription vmstate_apic_common = {
>
> static Property apic_properties_common[] = {
> DEFINE_PROP_UINT8("id", APICCommonState, id, -1),
> - DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env),
> DEFINE_PROP_BIT("vapic", APICCommonState, vapic_control, VAPIC_ENABLE_BIT,
> true),
> DEFINE_PROP_END_OF_LIST(),
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index e307b4e..0cce910 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -41,6 +41,7 @@
> #ifndef CONFIG_USER_ONLY
> #include "hw/xen.h"
> #include "hw/sysbus.h"
> +#include "hw/apic_internal.h"
> #endif
>
> /* feature flags taken from "Intel Processor Identification and the CPUID
> @@ -1884,6 +1885,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
> #ifndef CONFIG_USER_ONLY
> static int apic_mapped;
> CPUX86State *env = &cpu->env;
> + APICCommonState *apic;
> const char *apic_type = "apic";
>
> if (kvm_irqchip_in_kernel()) {
> @@ -1902,7 +1904,8 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
> OBJECT(env->apic_state), NULL);
> qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
> /* TODO: convert to link<> */
> - qdev_prop_set_ptr(env->apic_state, "cpu_env", env);
> + apic = APIC_COMMON(env->apic_state);
> + apic->cpu_env = env;
>
> if (qdev_init(env->apic_state)) {
> error_setg(errp, "APIC device '%s' could not be initialized",
> --
> 1.7.10.4
>
Reviewed-By: Igor Mammedov <imammedo@redhat.com>
--
Regards,
Igor
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting Andreas Färber
2012-10-15 23:22 ` Igor Mammedov
@ 2012-10-16 16:02 ` Andreas Färber
2012-10-16 16:04 ` Paolo Bonzini
2012-10-17 12:50 ` Jan Kiszka
1 sibling, 2 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-16 16:02 UTC (permalink / raw)
To: Paolo Bonzini, Jan Kiszka; +Cc: Igor Mammedov, qemu-devel
Am 12.10.2012 03:26, schrieb Andreas Färber:
> This prepares for changing the variable type from void*.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> Cc: Igor Mammedov <imammedo@redhat.com>
Paolo, are you happy with getting rid of the pointer property this way?
Jan, are you okay with accessing APICCommonState in target-i386/cpu.c as
an interim solution?
Andreas
> ---
> hw/apic_common.c | 1 -
> target-i386/cpu.c | 5 ++++-
> 2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
>
> diff --git a/hw/apic_common.c b/hw/apic_common.c
> index 371f95d..a26a631 100644
> --- a/hw/apic_common.c
> +++ b/hw/apic_common.c
> @@ -368,7 +368,6 @@ static const VMStateDescription vmstate_apic_common = {
>
> static Property apic_properties_common[] = {
> DEFINE_PROP_UINT8("id", APICCommonState, id, -1),
> - DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env),
> DEFINE_PROP_BIT("vapic", APICCommonState, vapic_control, VAPIC_ENABLE_BIT,
> true),
> DEFINE_PROP_END_OF_LIST(),
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index e307b4e..0cce910 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -41,6 +41,7 @@
> #ifndef CONFIG_USER_ONLY
> #include "hw/xen.h"
> #include "hw/sysbus.h"
> +#include "hw/apic_internal.h"
> #endif
>
> /* feature flags taken from "Intel Processor Identification and the CPUID
> @@ -1884,6 +1885,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
> #ifndef CONFIG_USER_ONLY
> static int apic_mapped;
> CPUX86State *env = &cpu->env;
> + APICCommonState *apic;
> const char *apic_type = "apic";
>
> if (kvm_irqchip_in_kernel()) {
> @@ -1902,7 +1904,8 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
> OBJECT(env->apic_state), NULL);
> qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
> /* TODO: convert to link<> */
> - qdev_prop_set_ptr(env->apic_state, "cpu_env", env);
> + apic = APIC_COMMON(env->apic_state);
> + apic->cpu_env = env;
>
> if (qdev_init(env->apic_state)) {
> error_setg(errp, "APIC device '%s' could not be initialized",
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting
2012-10-16 16:02 ` Andreas Färber
@ 2012-10-16 16:04 ` Paolo Bonzini
2012-10-17 12:50 ` Jan Kiszka
1 sibling, 0 replies; 18+ messages in thread
From: Paolo Bonzini @ 2012-10-16 16:04 UTC (permalink / raw)
To: Andreas Färber; +Cc: Igor Mammedov, Jan Kiszka, qemu-devel
Il 16/10/2012 18:02, Andreas Färber ha scritto:
> Am 12.10.2012 03:26, schrieb Andreas Färber:
>> This prepares for changing the variable type from void*.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>
> Paolo, are you happy with getting rid of the pointer property this way?
I wouldn't call it "getting rid of the pointer property", more like
sweeping it under a rug... :) But it is okay with the TODO comment.
Paolo
> Jan, are you okay with accessing APICCommonState in target-i386/cpu.c as
> an interim solution?
>
> Andreas
>
>> ---
>> hw/apic_common.c | 1 -
>> target-i386/cpu.c | 5 ++++-
>> 2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
>>
>> diff --git a/hw/apic_common.c b/hw/apic_common.c
>> index 371f95d..a26a631 100644
>> --- a/hw/apic_common.c
>> +++ b/hw/apic_common.c
>> @@ -368,7 +368,6 @@ static const VMStateDescription vmstate_apic_common = {
>>
>> static Property apic_properties_common[] = {
>> DEFINE_PROP_UINT8("id", APICCommonState, id, -1),
>> - DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env),
>> DEFINE_PROP_BIT("vapic", APICCommonState, vapic_control, VAPIC_ENABLE_BIT,
>> true),
>> DEFINE_PROP_END_OF_LIST(),
>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index e307b4e..0cce910 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
>> @@ -41,6 +41,7 @@
>> #ifndef CONFIG_USER_ONLY
>> #include "hw/xen.h"
>> #include "hw/sysbus.h"
>> +#include "hw/apic_internal.h"
>> #endif
>>
>> /* feature flags taken from "Intel Processor Identification and the CPUID
>> @@ -1884,6 +1885,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
>> #ifndef CONFIG_USER_ONLY
>> static int apic_mapped;
>> CPUX86State *env = &cpu->env;
>> + APICCommonState *apic;
>> const char *apic_type = "apic";
>>
>> if (kvm_irqchip_in_kernel()) {
>> @@ -1902,7 +1904,8 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
>> OBJECT(env->apic_state), NULL);
>> qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
>> /* TODO: convert to link<> */
>> - qdev_prop_set_ptr(env->apic_state, "cpu_env", env);
>> + apic = APIC_COMMON(env->apic_state);
>> + apic->cpu_env = env;
>>
>> if (qdev_init(env->apic_state)) {
>> error_setg(errp, "APIC device '%s' could not be initialized",
>>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting
2012-10-16 16:02 ` Andreas Färber
2012-10-16 16:04 ` Paolo Bonzini
@ 2012-10-17 12:50 ` Jan Kiszka
1 sibling, 0 replies; 18+ messages in thread
From: Jan Kiszka @ 2012-10-17 12:50 UTC (permalink / raw)
To: Andreas Färber; +Cc: Paolo Bonzini, qemu-devel, Igor Mammedov
[-- Attachment #1: Type: text/plain, Size: 2430 bytes --]
On 2012-10-16 18:02, Andreas Färber wrote:
> Am 12.10.2012 03:26, schrieb Andreas Färber:
>> This prepares for changing the variable type from void*.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>
> Paolo, are you happy with getting rid of the pointer property this way?
>
> Jan, are you okay with accessing APICCommonState in target-i386/cpu.c as
> an interim solution?
Yes, I don't see it as a problem.
Jan
>
> Andreas
>
>> ---
>> hw/apic_common.c | 1 -
>> target-i386/cpu.c | 5 ++++-
>> 2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
>>
>> diff --git a/hw/apic_common.c b/hw/apic_common.c
>> index 371f95d..a26a631 100644
>> --- a/hw/apic_common.c
>> +++ b/hw/apic_common.c
>> @@ -368,7 +368,6 @@ static const VMStateDescription vmstate_apic_common = {
>>
>> static Property apic_properties_common[] = {
>> DEFINE_PROP_UINT8("id", APICCommonState, id, -1),
>> - DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env),
>> DEFINE_PROP_BIT("vapic", APICCommonState, vapic_control, VAPIC_ENABLE_BIT,
>> true),
>> DEFINE_PROP_END_OF_LIST(),
>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index e307b4e..0cce910 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
>> @@ -41,6 +41,7 @@
>> #ifndef CONFIG_USER_ONLY
>> #include "hw/xen.h"
>> #include "hw/sysbus.h"
>> +#include "hw/apic_internal.h"
>> #endif
>>
>> /* feature flags taken from "Intel Processor Identification and the CPUID
>> @@ -1884,6 +1885,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
>> #ifndef CONFIG_USER_ONLY
>> static int apic_mapped;
>> CPUX86State *env = &cpu->env;
>> + APICCommonState *apic;
>> const char *apic_type = "apic";
>>
>> if (kvm_irqchip_in_kernel()) {
>> @@ -1902,7 +1904,8 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
>> OBJECT(env->apic_state), NULL);
>> qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
>> /* TODO: convert to link<> */
>> - qdev_prop_set_ptr(env->apic_state, "cpu_env", env);
>> + apic = APIC_COMMON(env->apic_state);
>> + apic->cpu_env = env;
>>
>> if (qdev_init(env->apic_state)) {
>> error_setg(errp, "APIC device '%s' could not be initialized",
>>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH qom-cpu v2 2/7] apic: Store X86CPU in APICCommonState
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
2012-10-15 23:28 ` Igor Mammedov
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 3/7] target-i386: Pass X86CPU to cpu_x86_load_seg_cache_sipi() Andreas Färber
` (4 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber
Prepares for using a link<> property to connect APIC with CPU and for
changing the CPU APIs to CPUState.
Resolve Coding Style warnings by moving the closing parenthesis of
foreach_apic() macro to next line.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Igor Mammedov <imammedo@redhat.com>
---
hw/apic.c | 38 +++++++++++++++++++++-----------------
hw/apic_common.c | 4 ++--
hw/apic_internal.h | 3 ++-
hw/kvm/apic.c | 8 ++++----
target-i386/cpu.c | 2 +-
5 Dateien geändert, 30 Zeilen hinzugefügt(+), 25 Zeilen entfernt(-)
diff --git a/hw/apic.c b/hw/apic.c
index 385555e..f1f804d 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type)
length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
if (sync_type & SYNC_TO_VAPIC) {
- assert(qemu_cpu_is_self(s->cpu_env));
+ assert(qemu_cpu_is_self(&s->cpu->env));
vapic_state.tpr = s->tpr;
vapic_state.enabled = 1;
@@ -151,15 +151,15 @@ static void apic_local_deliver(APICCommonState *s, int vector)
switch ((lvt >> 8) & 7) {
case APIC_DM_SMI:
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SMI);
+ cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_SMI);
break;
case APIC_DM_NMI:
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_NMI);
+ cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_NMI);
break;
case APIC_DM_EXTINT:
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
break;
case APIC_DM_FIXED:
@@ -187,7 +187,7 @@ void apic_deliver_pic_intr(DeviceState *d, int level)
reset_bit(s->irr, lvt & 0xff);
/* fall through */
case APIC_DM_EXTINT:
- cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
break;
}
}
@@ -248,18 +248,22 @@ static void apic_bus_deliver(const uint32_t *deliver_bitmask,
case APIC_DM_SMI:
foreach_apic(apic_iter, deliver_bitmask,
- cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_SMI) );
+ cpu_interrupt(&apic_iter->cpu->env, CPU_INTERRUPT_SMI)
+ );
return;
case APIC_DM_NMI:
foreach_apic(apic_iter, deliver_bitmask,
- cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_NMI) );
+ cpu_interrupt(&apic_iter->cpu->env, CPU_INTERRUPT_NMI)
+ );
return;
case APIC_DM_INIT:
/* normal INIT IPI sent to processors */
foreach_apic(apic_iter, deliver_bitmask,
- cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_INIT) );
+ cpu_interrupt(&apic_iter->cpu->env,
+ CPU_INTERRUPT_INIT)
+ );
return;
case APIC_DM_EXTINT:
@@ -293,7 +297,7 @@ static void apic_set_base(APICCommonState *s, uint64_t val)
/* if disabled, cannot be enabled again */
if (!(val & MSR_IA32_APICBASE_ENABLE)) {
s->apicbase &= ~MSR_IA32_APICBASE_ENABLE;
- cpu_clear_apic_feature(s->cpu_env);
+ cpu_clear_apic_feature(&s->cpu->env);
s->spurious_vec &= ~APIC_SV_ENABLE;
}
}
@@ -362,10 +366,10 @@ static void apic_update_irq(APICCommonState *s)
if (!(s->spurious_vec & APIC_SV_ENABLE)) {
return;
}
- if (!qemu_cpu_is_self(s->cpu_env)) {
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_POLL);
+ if (!qemu_cpu_is_self(&s->cpu->env)) {
+ cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
} else if (apic_irq_pending(s) > 0) {
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
}
}
@@ -472,18 +476,18 @@ static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask,
static void apic_startup(APICCommonState *s, int vector_num)
{
s->sipi_vector = vector_num;
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
+ cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_SIPI);
}
void apic_sipi(DeviceState *d)
{
APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
- cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
+ cpu_reset_interrupt(&s->cpu->env, CPU_INTERRUPT_SIPI);
if (!s->wait_for_sipi)
return;
- cpu_x86_load_seg_cache_sipi(s->cpu_env, s->sipi_vector);
+ cpu_x86_load_seg_cache_sipi(&s->cpu->env, s->sipi_vector);
s->wait_for_sipi = 0;
}
@@ -672,7 +676,7 @@ static uint32_t apic_mem_readl(void *opaque, target_phys_addr_t addr)
case 0x08:
apic_sync_vapic(s, SYNC_FROM_VAPIC);
if (apic_report_tpr_access) {
- cpu_report_tpr_access(s->cpu_env, TPR_ACCESS_READ);
+ cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_READ);
}
val = s->tpr;
break;
@@ -774,7 +778,7 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
break;
case 0x08:
if (apic_report_tpr_access) {
- cpu_report_tpr_access(s->cpu_env, TPR_ACCESS_WRITE);
+ cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_WRITE);
}
s->tpr = val;
apic_sync_vapic(s, SYNC_TO_VAPIC);
diff --git a/hw/apic_common.c b/hw/apic_common.c
index a26a631..7e5af39 100644
--- a/hw/apic_common.c
+++ b/hw/apic_common.c
@@ -103,7 +103,7 @@ void apic_handle_tpr_access_report(DeviceState *d, target_ulong ip,
{
APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
- vapic_report_tpr_access(s->vapic, s->cpu_env, ip, access);
+ vapic_report_tpr_access(s->vapic, &s->cpu->env, ip, access);
}
void apic_report_irq_delivered(int delivered)
@@ -217,7 +217,7 @@ static void apic_reset_common(DeviceState *d)
APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
bool bsp;
- bsp = cpu_is_bsp(x86_env_get_cpu(s->cpu_env));
+ bsp = cpu_is_bsp(s->cpu);
s->apicbase = 0xfee00000 |
(bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE;
diff --git a/hw/apic_internal.h b/hw/apic_internal.h
index 4d8ff49..983671b 100644
--- a/hw/apic_internal.h
+++ b/hw/apic_internal.h
@@ -95,8 +95,9 @@ typedef struct APICCommonClass
struct APICCommonState {
SysBusDevice busdev;
+
MemoryRegion io_memory;
- void *cpu_env;
+ X86CPU *cpu;
uint32_t apicbase;
uint8_t id;
uint8_t arb_id;
diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
index 80e3e48..fddb5ca 100644
--- a/hw/kvm/apic.c
+++ b/hw/kvm/apic.c
@@ -104,7 +104,7 @@ static void kvm_apic_enable_tpr_reporting(APICCommonState *s, bool enable)
.enabled = enable
};
- kvm_vcpu_ioctl(s->cpu_env, KVM_TPR_ACCESS_REPORTING, &ctl);
+ kvm_vcpu_ioctl(&s->cpu->env, KVM_TPR_ACCESS_REPORTING, &ctl);
}
static void kvm_apic_vapic_base_update(APICCommonState *s)
@@ -114,7 +114,7 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
};
int ret;
- ret = kvm_vcpu_ioctl(s->cpu_env, KVM_SET_VAPIC_ADDR, &vapid_addr);
+ ret = kvm_vcpu_ioctl(&s->cpu->env, KVM_SET_VAPIC_ADDR, &vapid_addr);
if (ret < 0) {
fprintf(stderr, "KVM: setting VAPIC address failed (%s)\n",
strerror(-ret));
@@ -125,7 +125,7 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
static void do_inject_external_nmi(void *data)
{
APICCommonState *s = data;
- CPUX86State *env = s->cpu_env;
+ CPUX86State *env = &s->cpu->env;
uint32_t lvt;
int ret;
@@ -143,7 +143,7 @@ static void do_inject_external_nmi(void *data)
static void kvm_apic_external_nmi(APICCommonState *s)
{
- run_on_cpu(s->cpu_env, do_inject_external_nmi, s);
+ run_on_cpu(&s->cpu->env, do_inject_external_nmi, s);
}
static uint64_t kvm_apic_mem_read(void *opaque, target_phys_addr_t addr,
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0cce910..6a9cacf 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1905,7 +1905,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
/* TODO: convert to link<> */
apic = APIC_COMMON(env->apic_state);
- apic->cpu_env = env;
+ apic->cpu = cpu;
if (qdev_init(env->apic_state)) {
error_setg(errp, "APIC device '%s' could not be initialized",
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 2/7] apic: Store X86CPU in APICCommonState
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 2/7] apic: Store X86CPU in APICCommonState Andreas Färber
@ 2012-10-15 23:28 ` Igor Mammedov
0 siblings, 0 replies; 18+ messages in thread
From: Igor Mammedov @ 2012-10-15 23:28 UTC (permalink / raw)
To: Andreas Färber; +Cc: qemu-devel
On Fri, 12 Oct 2012 03:26:38 +0200
Andreas Färber <afaerber@suse.de> wrote:
> Prepares for using a link<> property to connect APIC with CPU and for
> changing the CPU APIs to CPUState.
>
> Resolve Coding Style warnings by moving the closing parenthesis of
> foreach_apic() macro to next line.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> Cc: Igor Mammedov <imammedo@redhat.com>
> ---
> hw/apic.c | 38 +++++++++++++++++++++-----------------
> hw/apic_common.c | 4 ++--
> hw/apic_internal.h | 3 ++-
> hw/kvm/apic.c | 8 ++++----
> target-i386/cpu.c | 2 +-
> 5 Dateien geändert, 30 Zeilen hinzugefügt(+), 25 Zeilen entfernt(-)
>
> diff --git a/hw/apic.c b/hw/apic.c
> index 385555e..f1f804d 100644
> --- a/hw/apic.c
> +++ b/hw/apic.c
> @@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type)
> length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
>
> if (sync_type & SYNC_TO_VAPIC) {
> - assert(qemu_cpu_is_self(s->cpu_env));
> + assert(qemu_cpu_is_self(&s->cpu->env));
>
> vapic_state.tpr = s->tpr;
> vapic_state.enabled = 1;
> @@ -151,15 +151,15 @@ static void apic_local_deliver(APICCommonState *s, int vector)
>
> switch ((lvt >> 8) & 7) {
> case APIC_DM_SMI:
> - cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SMI);
> + cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_SMI);
> break;
>
> case APIC_DM_NMI:
> - cpu_interrupt(s->cpu_env, CPU_INTERRUPT_NMI);
> + cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_NMI);
> break;
>
> case APIC_DM_EXTINT:
> - cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
> + cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
> break;
>
> case APIC_DM_FIXED:
> @@ -187,7 +187,7 @@ void apic_deliver_pic_intr(DeviceState *d, int level)
> reset_bit(s->irr, lvt & 0xff);
> /* fall through */
> case APIC_DM_EXTINT:
> - cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
> + cpu_reset_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
> break;
> }
> }
> @@ -248,18 +248,22 @@ static void apic_bus_deliver(const uint32_t *deliver_bitmask,
>
> case APIC_DM_SMI:
> foreach_apic(apic_iter, deliver_bitmask,
> - cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_SMI) );
> + cpu_interrupt(&apic_iter->cpu->env, CPU_INTERRUPT_SMI)
> + );
> return;
>
> case APIC_DM_NMI:
> foreach_apic(apic_iter, deliver_bitmask,
> - cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_NMI) );
> + cpu_interrupt(&apic_iter->cpu->env, CPU_INTERRUPT_NMI)
> + );
> return;
>
> case APIC_DM_INIT:
> /* normal INIT IPI sent to processors */
> foreach_apic(apic_iter, deliver_bitmask,
> - cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_INIT) );
> + cpu_interrupt(&apic_iter->cpu->env,
> + CPU_INTERRUPT_INIT)
> + );
> return;
>
> case APIC_DM_EXTINT:
> @@ -293,7 +297,7 @@ static void apic_set_base(APICCommonState *s, uint64_t val)
> /* if disabled, cannot be enabled again */
> if (!(val & MSR_IA32_APICBASE_ENABLE)) {
> s->apicbase &= ~MSR_IA32_APICBASE_ENABLE;
> - cpu_clear_apic_feature(s->cpu_env);
> + cpu_clear_apic_feature(&s->cpu->env);
> s->spurious_vec &= ~APIC_SV_ENABLE;
> }
> }
> @@ -362,10 +366,10 @@ static void apic_update_irq(APICCommonState *s)
> if (!(s->spurious_vec & APIC_SV_ENABLE)) {
> return;
> }
> - if (!qemu_cpu_is_self(s->cpu_env)) {
> - cpu_interrupt(s->cpu_env, CPU_INTERRUPT_POLL);
> + if (!qemu_cpu_is_self(&s->cpu->env)) {
> + cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
> } else if (apic_irq_pending(s) > 0) {
> - cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
> + cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
> }
> }
>
> @@ -472,18 +476,18 @@ static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask,
> static void apic_startup(APICCommonState *s, int vector_num)
> {
> s->sipi_vector = vector_num;
> - cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
> + cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_SIPI);
> }
>
> void apic_sipi(DeviceState *d)
> {
> APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
>
> - cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
> + cpu_reset_interrupt(&s->cpu->env, CPU_INTERRUPT_SIPI);
>
> if (!s->wait_for_sipi)
> return;
> - cpu_x86_load_seg_cache_sipi(s->cpu_env, s->sipi_vector);
> + cpu_x86_load_seg_cache_sipi(&s->cpu->env, s->sipi_vector);
> s->wait_for_sipi = 0;
> }
>
> @@ -672,7 +676,7 @@ static uint32_t apic_mem_readl(void *opaque, target_phys_addr_t addr)
> case 0x08:
> apic_sync_vapic(s, SYNC_FROM_VAPIC);
> if (apic_report_tpr_access) {
> - cpu_report_tpr_access(s->cpu_env, TPR_ACCESS_READ);
> + cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_READ);
> }
> val = s->tpr;
> break;
> @@ -774,7 +778,7 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
> break;
> case 0x08:
> if (apic_report_tpr_access) {
> - cpu_report_tpr_access(s->cpu_env, TPR_ACCESS_WRITE);
> + cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_WRITE);
> }
> s->tpr = val;
> apic_sync_vapic(s, SYNC_TO_VAPIC);
> diff --git a/hw/apic_common.c b/hw/apic_common.c
> index a26a631..7e5af39 100644
> --- a/hw/apic_common.c
> +++ b/hw/apic_common.c
> @@ -103,7 +103,7 @@ void apic_handle_tpr_access_report(DeviceState *d, target_ulong ip,
> {
> APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
>
> - vapic_report_tpr_access(s->vapic, s->cpu_env, ip, access);
> + vapic_report_tpr_access(s->vapic, &s->cpu->env, ip, access);
> }
>
> void apic_report_irq_delivered(int delivered)
> @@ -217,7 +217,7 @@ static void apic_reset_common(DeviceState *d)
> APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
> bool bsp;
>
> - bsp = cpu_is_bsp(x86_env_get_cpu(s->cpu_env));
> + bsp = cpu_is_bsp(s->cpu);
> s->apicbase = 0xfee00000 |
> (bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE;
>
> diff --git a/hw/apic_internal.h b/hw/apic_internal.h
> index 4d8ff49..983671b 100644
> --- a/hw/apic_internal.h
> +++ b/hw/apic_internal.h
> @@ -95,8 +95,9 @@ typedef struct APICCommonClass
>
> struct APICCommonState {
> SysBusDevice busdev;
> +
> MemoryRegion io_memory;
> - void *cpu_env;
> + X86CPU *cpu;
> uint32_t apicbase;
> uint8_t id;
> uint8_t arb_id;
> diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
> index 80e3e48..fddb5ca 100644
> --- a/hw/kvm/apic.c
> +++ b/hw/kvm/apic.c
> @@ -104,7 +104,7 @@ static void kvm_apic_enable_tpr_reporting(APICCommonState *s, bool enable)
> .enabled = enable
> };
>
> - kvm_vcpu_ioctl(s->cpu_env, KVM_TPR_ACCESS_REPORTING, &ctl);
> + kvm_vcpu_ioctl(&s->cpu->env, KVM_TPR_ACCESS_REPORTING, &ctl);
> }
>
> static void kvm_apic_vapic_base_update(APICCommonState *s)
> @@ -114,7 +114,7 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
> };
> int ret;
>
> - ret = kvm_vcpu_ioctl(s->cpu_env, KVM_SET_VAPIC_ADDR, &vapid_addr);
> + ret = kvm_vcpu_ioctl(&s->cpu->env, KVM_SET_VAPIC_ADDR, &vapid_addr);
> if (ret < 0) {
> fprintf(stderr, "KVM: setting VAPIC address failed (%s)\n",
> strerror(-ret));
> @@ -125,7 +125,7 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
> static void do_inject_external_nmi(void *data)
> {
> APICCommonState *s = data;
> - CPUX86State *env = s->cpu_env;
> + CPUX86State *env = &s->cpu->env;
> uint32_t lvt;
> int ret;
>
> @@ -143,7 +143,7 @@ static void do_inject_external_nmi(void *data)
>
> static void kvm_apic_external_nmi(APICCommonState *s)
> {
> - run_on_cpu(s->cpu_env, do_inject_external_nmi, s);
> + run_on_cpu(&s->cpu->env, do_inject_external_nmi, s);
> }
>
> static uint64_t kvm_apic_mem_read(void *opaque, target_phys_addr_t addr,
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 0cce910..6a9cacf 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1905,7 +1905,7 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
> qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
> /* TODO: convert to link<> */
> apic = APIC_COMMON(env->apic_state);
> - apic->cpu_env = env;
> + apic->cpu = cpu;
>
> if (qdev_init(env->apic_state)) {
> error_setg(errp, "APIC device '%s' could not be initialized",
> --
> 1.7.10.4
>
>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
--
Regards,
Igor
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH qom-cpu v2 3/7] target-i386: Pass X86CPU to cpu_x86_load_seg_cache_sipi()
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 1/7] target-i386: Inline APIC cpu_env property setting Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 2/7] apic: Store X86CPU in APICCommonState Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
2012-10-15 23:29 ` Igor Mammedov
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self() Andreas Färber
` (3 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber
Simplifies the call in apic_sipi() again and needed for moving halted
field to CPUState.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/apic.c | 2 +-
target-i386/cpu.h | 4 +++-
2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
diff --git a/hw/apic.c b/hw/apic.c
index f1f804d..ccf2819 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -487,7 +487,7 @@ void apic_sipi(DeviceState *d)
if (!s->wait_for_sipi)
return;
- cpu_x86_load_seg_cache_sipi(&s->cpu->env, s->sipi_vector);
+ cpu_x86_load_seg_cache_sipi(s->cpu, s->sipi_vector);
s->wait_for_sipi = 0;
}
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 871c270..e54596f 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -907,9 +907,11 @@ static inline void cpu_x86_load_seg_cache(CPUX86State *env,
}
}
-static inline void cpu_x86_load_seg_cache_sipi(CPUX86State *env,
+static inline void cpu_x86_load_seg_cache_sipi(X86CPU *cpu,
int sipi_vector)
{
+ CPUX86State *env = &cpu->env;
+
env->eip = 0;
cpu_x86_load_seg_cache(env, R_CS, sipi_vector << 8,
sipi_vector << 12,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 3/7] target-i386: Pass X86CPU to cpu_x86_load_seg_cache_sipi()
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 3/7] target-i386: Pass X86CPU to cpu_x86_load_seg_cache_sipi() Andreas Färber
@ 2012-10-15 23:29 ` Igor Mammedov
0 siblings, 0 replies; 18+ messages in thread
From: Igor Mammedov @ 2012-10-15 23:29 UTC (permalink / raw)
To: Andreas Färber; +Cc: qemu-devel
On Fri, 12 Oct 2012 03:26:39 +0200
Andreas Färber <afaerber@suse.de> wrote:
> Simplifies the call in apic_sipi() again and needed for moving halted
> field to CPUState.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
> hw/apic.c | 2 +-
> target-i386/cpu.h | 4 +++-
> 2 Dateien geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
>
> diff --git a/hw/apic.c b/hw/apic.c
> index f1f804d..ccf2819 100644
> --- a/hw/apic.c
> +++ b/hw/apic.c
> @@ -487,7 +487,7 @@ void apic_sipi(DeviceState *d)
>
> if (!s->wait_for_sipi)
> return;
> - cpu_x86_load_seg_cache_sipi(&s->cpu->env, s->sipi_vector);
> + cpu_x86_load_seg_cache_sipi(s->cpu, s->sipi_vector);
> s->wait_for_sipi = 0;
> }
>
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 871c270..e54596f 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -907,9 +907,11 @@ static inline void cpu_x86_load_seg_cache(CPUX86State *env,
> }
> }
>
> -static inline void cpu_x86_load_seg_cache_sipi(CPUX86State *env,
> +static inline void cpu_x86_load_seg_cache_sipi(X86CPU *cpu,
> int sipi_vector)
> {
> + CPUX86State *env = &cpu->env;
> +
> env->eip = 0;
> cpu_x86_load_seg_cache(env, R_CS, sipi_vector << 8,
> sipi_vector << 12,
> --
> 1.7.10.4
>
>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
--
Regards,
Igor
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self()
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
` (2 preceding siblings ...)
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 3/7] target-i386: Pass X86CPU to cpu_x86_load_seg_cache_sipi() Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
2012-10-16 0:49 ` Igor Mammedov
2012-10-30 20:33 ` Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 5/7] cpus: Pass CPUState to qemu_cpu_kick_thread() Andreas Färber
` (2 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel
Cc: Marcelo Tosatti, Andreas Färber, open list:Overall,
Avi Kivity
Change return type to bool, move to include/qemu/cpu.h and
add documentation.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
cpus.c | 10 ++++------
exec.c | 3 ++-
hw/apic.c | 6 ++++--
include/qemu/cpu.h | 10 ++++++++++
kvm-all.c | 4 +++-
qemu-common.h | 1 -
target-i386/kvm.c | 6 ++++--
7 Dateien geändert, 27 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)
diff --git a/cpus.c b/cpus.c
index 750a76f..849ea8a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -638,9 +638,10 @@ void qemu_init_cpu_loop(void)
void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data)
{
+ CPUState *cpu = ENV_GET_CPU(env);
struct qemu_work_item wi;
- if (qemu_cpu_is_self(env)) {
+ if (qemu_cpu_is_self(cpu)) {
func(data);
return;
}
@@ -855,7 +856,7 @@ static void qemu_cpu_kick_thread(CPUArchState *env)
exit(1);
}
#else /* _WIN32 */
- if (!qemu_cpu_is_self(env)) {
+ if (!qemu_cpu_is_self(cpu)) {
SuspendThread(cpu->hThread);
cpu_signal(0);
ResumeThread(cpu->hThread);
@@ -890,11 +891,8 @@ void qemu_cpu_kick_self(void)
#endif
}
-int qemu_cpu_is_self(void *_env)
+bool qemu_cpu_is_self(CPUState *cpu)
{
- CPUArchState *env = _env;
- CPUState *cpu = ENV_GET_CPU(env);
-
return qemu_thread_is_self(cpu->thread);
}
diff --git a/exec.c b/exec.c
index 7899042..e21be32 100644
--- a/exec.c
+++ b/exec.c
@@ -1685,6 +1685,7 @@ static void cpu_unlink_tb(CPUArchState *env)
/* mask must never be zero, except for A20 change call */
static void tcg_handle_interrupt(CPUArchState *env, int mask)
{
+ CPUState *cpu = ENV_GET_CPU(env);
int old_mask;
old_mask = env->interrupt_request;
@@ -1694,7 +1695,7 @@ static void tcg_handle_interrupt(CPUArchState *env, int mask)
* If called from iothread context, wake the target cpu in
* case its halted.
*/
- if (!qemu_cpu_is_self(env)) {
+ if (!qemu_cpu_is_self(cpu)) {
qemu_cpu_kick(env);
return;
}
diff --git a/hw/apic.c b/hw/apic.c
index ccf2819..1b4cd2f 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type)
length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
if (sync_type & SYNC_TO_VAPIC) {
- assert(qemu_cpu_is_self(&s->cpu->env));
+ assert(qemu_cpu_is_self(CPU(s->cpu)));
vapic_state.tpr = s->tpr;
vapic_state.enabled = 1;
@@ -363,10 +363,12 @@ static int apic_irq_pending(APICCommonState *s)
/* signal the CPU if an irq is pending */
static void apic_update_irq(APICCommonState *s)
{
+ CPUState *cpu = CPU(s->cpu);
+
if (!(s->spurious_vec & APIC_SV_ENABLE)) {
return;
}
- if (!qemu_cpu_is_self(&s->cpu->env)) {
+ if (!qemu_cpu_is_self(cpu)) {
cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
} else if (apic_irq_pending(s) > 0) {
cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index ad706a6..7be983d 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -78,5 +78,15 @@ struct CPUState {
*/
void cpu_reset(CPUState *cpu);
+/**
+ * qemu_cpu_is_self:
+ * @cpu: The vCPU to check against.
+ *
+ * Checks whether the caller is executing on the vCPU thread.
+ *
+ * Returns: %true if called from @cpu's thread, %false otherwise.
+ */
+bool qemu_cpu_is_self(CPUState *cpu);
+
#endif
diff --git a/kvm-all.c b/kvm-all.c
index 92a7137..db01aeb 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -854,9 +854,11 @@ static MemoryListener kvm_memory_listener = {
static void kvm_handle_interrupt(CPUArchState *env, int mask)
{
+ CPUState *cpu = ENV_GET_CPU(env);
+
env->interrupt_request |= mask;
- if (!qemu_cpu_is_self(env)) {
+ if (!qemu_cpu_is_self(cpu)) {
qemu_cpu_kick(env);
}
}
diff --git a/qemu-common.h b/qemu-common.h
index b54612b..2094742 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -326,7 +326,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id);
/* Unblock cpu */
void qemu_cpu_kick(void *env);
void qemu_cpu_kick_self(void);
-int qemu_cpu_is_self(void *env);
/* work queue */
struct qemu_work_item {
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5b18383..cf3d2f1 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1552,9 +1552,10 @@ static int kvm_get_debugregs(CPUX86State *env)
int kvm_arch_put_registers(CPUX86State *env, int level)
{
+ CPUState *cpu = ENV_GET_CPU(env);
int ret;
- assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
+ assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
ret = kvm_getput_regs(env, 1);
if (ret < 0) {
@@ -1609,9 +1610,10 @@ int kvm_arch_put_registers(CPUX86State *env, int level)
int kvm_arch_get_registers(CPUX86State *env)
{
+ CPUState *cpu = ENV_GET_CPU(env);
int ret;
- assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
+ assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
ret = kvm_getput_regs(env, 0);
if (ret < 0) {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self()
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self() Andreas Färber
@ 2012-10-16 0:49 ` Igor Mammedov
2012-10-30 20:08 ` Andreas Färber
2012-10-30 20:33 ` Andreas Färber
1 sibling, 1 reply; 18+ messages in thread
From: Igor Mammedov @ 2012-10-16 0:49 UTC (permalink / raw)
To: Andreas Färber
Cc: Marcelo Tosatti, qemu-devel, open list:Overall, Avi Kivity
On Fri, 12 Oct 2012 03:26:40 +0200
Andreas Färber <afaerber@suse.de> wrote:
> Change return type to bool, move to include/qemu/cpu.h and
> add documentation.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
> cpus.c | 10 ++++------
> exec.c | 3 ++-
> hw/apic.c | 6 ++++--
> include/qemu/cpu.h | 10 ++++++++++
> kvm-all.c | 4 +++-
> qemu-common.h | 1 -
> target-i386/kvm.c | 6 ++++--
> 7 Dateien geändert, 27 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)
>
> diff --git a/cpus.c b/cpus.c
> index 750a76f..849ea8a 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -638,9 +638,10 @@ void qemu_init_cpu_loop(void)
>
> void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data)
> {
> + CPUState *cpu = ENV_GET_CPU(env);
> struct qemu_work_item wi;
>
> - if (qemu_cpu_is_self(env)) {
> + if (qemu_cpu_is_self(cpu)) {
> func(data);
> return;
> }
> @@ -855,7 +856,7 @@ static void qemu_cpu_kick_thread(CPUArchState *env)
> exit(1);
> }
> #else /* _WIN32 */
> - if (!qemu_cpu_is_self(env)) {
> + if (!qemu_cpu_is_self(cpu)) {
> SuspendThread(cpu->hThread);
> cpu_signal(0);
> ResumeThread(cpu->hThread);
> @@ -890,11 +891,8 @@ void qemu_cpu_kick_self(void)
> #endif
> }
>
> -int qemu_cpu_is_self(void *_env)
> +bool qemu_cpu_is_self(CPUState *cpu)
> {
> - CPUArchState *env = _env;
> - CPUState *cpu = ENV_GET_CPU(env);
> -
> return qemu_thread_is_self(cpu->thread);
> }
>
> diff --git a/exec.c b/exec.c
> index 7899042..e21be32 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1685,6 +1685,7 @@ static void cpu_unlink_tb(CPUArchState *env)
> /* mask must never be zero, except for A20 change call */
> static void tcg_handle_interrupt(CPUArchState *env, int mask)
> {
> + CPUState *cpu = ENV_GET_CPU(env);
Is there any chance to get rid of expensive cast on this call path?
> int old_mask;
>
> old_mask = env->interrupt_request;
> @@ -1694,7 +1695,7 @@ static void tcg_handle_interrupt(CPUArchState *env, int mask)
> * If called from iothread context, wake the target cpu in
> * case its halted.
> */
> - if (!qemu_cpu_is_self(env)) {
> + if (!qemu_cpu_is_self(cpu)) {
> qemu_cpu_kick(env);
> return;
> }
> diff --git a/hw/apic.c b/hw/apic.c
> index ccf2819..1b4cd2f 100644
> --- a/hw/apic.c
> +++ b/hw/apic.c
> @@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type)
> length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
>
> if (sync_type & SYNC_TO_VAPIC) {
> - assert(qemu_cpu_is_self(&s->cpu->env));
> + assert(qemu_cpu_is_self(CPU(s->cpu)));
>
> vapic_state.tpr = s->tpr;
> vapic_state.enabled = 1;
> @@ -363,10 +363,12 @@ static int apic_irq_pending(APICCommonState *s)
> /* signal the CPU if an irq is pending */
> static void apic_update_irq(APICCommonState *s)
> {
> + CPUState *cpu = CPU(s->cpu);
> +
> if (!(s->spurious_vec & APIC_SV_ENABLE)) {
> return;
> }
> - if (!qemu_cpu_is_self(&s->cpu->env)) {
> + if (!qemu_cpu_is_self(cpu)) {
> cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
> } else if (apic_irq_pending(s) > 0) {
> cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
> diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
> index ad706a6..7be983d 100644
> --- a/include/qemu/cpu.h
> +++ b/include/qemu/cpu.h
> @@ -78,5 +78,15 @@ struct CPUState {
> */
> void cpu_reset(CPUState *cpu);
>
> +/**
> + * qemu_cpu_is_self:
> + * @cpu: The vCPU to check against.
> + *
> + * Checks whether the caller is executing on the vCPU thread.
> + *
> + * Returns: %true if called from @cpu's thread, %false otherwise.
> + */
> +bool qemu_cpu_is_self(CPUState *cpu);
> +
>
> #endif
> diff --git a/kvm-all.c b/kvm-all.c
> index 92a7137..db01aeb 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -854,9 +854,11 @@ static MemoryListener kvm_memory_listener = {
>
> static void kvm_handle_interrupt(CPUArchState *env, int mask)
> {
> + CPUState *cpu = ENV_GET_CPU(env);
> +
> env->interrupt_request |= mask;
>
> - if (!qemu_cpu_is_self(env)) {
> + if (!qemu_cpu_is_self(cpu)) {
> qemu_cpu_kick(env);
> }
> }
> diff --git a/qemu-common.h b/qemu-common.h
> index b54612b..2094742 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -326,7 +326,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id);
> /* Unblock cpu */
> void qemu_cpu_kick(void *env);
> void qemu_cpu_kick_self(void);
> -int qemu_cpu_is_self(void *env);
>
> /* work queue */
> struct qemu_work_item {
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 5b18383..cf3d2f1 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -1552,9 +1552,10 @@ static int kvm_get_debugregs(CPUX86State *env)
>
> int kvm_arch_put_registers(CPUX86State *env, int level)
> {
> + CPUState *cpu = ENV_GET_CPU(env);
> int ret;
>
> - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
> + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
>
> ret = kvm_getput_regs(env, 1);
> if (ret < 0) {
> @@ -1609,9 +1610,10 @@ int kvm_arch_put_registers(CPUX86State *env, int level)
>
> int kvm_arch_get_registers(CPUX86State *env)
> {
> + CPUState *cpu = ENV_GET_CPU(env);
> int ret;
>
> - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
> + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
>
> ret = kvm_getput_regs(env, 0);
> if (ret < 0) {
> --
> 1.7.10.4
>
>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
--
Regards,
Igor
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self()
2012-10-16 0:49 ` Igor Mammedov
@ 2012-10-30 20:08 ` Andreas Färber
0 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-30 20:08 UTC (permalink / raw)
To: Igor Mammedov
Cc: Alexander Graf, Marcelo Tosatti, qemu-devel, kvm, Avi Kivity
Am 16.10.2012 02:49, schrieb Igor Mammedov:
> On Fri, 12 Oct 2012 03:26:40 +0200
> Andreas Färber <afaerber@suse.de> wrote:
>
>> Change return type to bool, move to include/qemu/cpu.h and
>> add documentation.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> ---
>> cpus.c | 10 ++++------
>> exec.c | 3 ++-
>> hw/apic.c | 6 ++++--
>> include/qemu/cpu.h | 10 ++++++++++
>> kvm-all.c | 4 +++-
>> qemu-common.h | 1 -
>> target-i386/kvm.c | 6 ++++--
>> 7 Dateien geändert, 27 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)
>>
>> diff --git a/cpus.c b/cpus.c
>> index 750a76f..849ea8a 100644
>> --- a/cpus.c
>> +++ b/cpus.c
>> @@ -638,9 +638,10 @@ void qemu_init_cpu_loop(void)
>>
>> void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data)
>> {
>> + CPUState *cpu = ENV_GET_CPU(env);
>> struct qemu_work_item wi;
>>
>> - if (qemu_cpu_is_self(env)) {
>> + if (qemu_cpu_is_self(cpu)) {
>> func(data);
>> return;
>> }
>> @@ -855,7 +856,7 @@ static void qemu_cpu_kick_thread(CPUArchState *env)
>> exit(1);
>> }
>> #else /* _WIN32 */
>> - if (!qemu_cpu_is_self(env)) {
>> + if (!qemu_cpu_is_self(cpu)) {
>> SuspendThread(cpu->hThread);
>> cpu_signal(0);
>> ResumeThread(cpu->hThread);
>> @@ -890,11 +891,8 @@ void qemu_cpu_kick_self(void)
>> #endif
>> }
>>
>> -int qemu_cpu_is_self(void *_env)
>> +bool qemu_cpu_is_self(CPUState *cpu)
>> {
>> - CPUArchState *env = _env;
>> - CPUState *cpu = ENV_GET_CPU(env);
>> -
>> return qemu_thread_is_self(cpu->thread);
>> }
>>
>> diff --git a/exec.c b/exec.c
>> index 7899042..e21be32 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -1685,6 +1685,7 @@ static void cpu_unlink_tb(CPUArchState *env)
>> /* mask must never be zero, except for A20 change call */
>> static void tcg_handle_interrupt(CPUArchState *env, int mask)
>> {
>> + CPUState *cpu = ENV_GET_CPU(env);
> Is there any chance to get rid of expensive cast on this call path?
I've spent some time investigating this and it would be rather complicated:
* We can't change the argument to CPUState yet (pushing the
responsibility to the caller) since interrupt_request is being accessed
til the not-yet-committable end of original part 4 series, the TB is
being flushed, icount being handled, and it is being used for the first
if, so not movable to a deeper block.
* A pointer to this function (or the KVM version below) is stored as
cpu_interrupt_handler and accessed through cpu_interrupt(), which for
softmmu calls the handler and for *-user does something similar to the
TCG version. This function is being used in a lot of places, so adding a
CPUState argument in addition to the CPUArchState would touch a lot of
places for an interim solution.
* QOM makes no guarantees about subclass layout (.env placement), so
going from CPUState to CPUArchState involves quite some ugly #ifdef'fery
that I am trying to avoid, going only the I-know-my-type direction.
I'll therefore accept your Reviewed-by to apply this and will keep
working during the Soft Freeze on the follow-ups that allow changing
this and others completely over to CPUState. Alex has just given green
light for the ppc prerequisites so I can apply them together with xtensa
to qom-cpu and post the next batch if I haven't already.
Regards,
Andreas
>
>> int old_mask;
>>
>> old_mask = env->interrupt_request;
>> @@ -1694,7 +1695,7 @@ static void tcg_handle_interrupt(CPUArchState *env, int mask)
>> * If called from iothread context, wake the target cpu in
>> * case its halted.
>> */
>> - if (!qemu_cpu_is_self(env)) {
>> + if (!qemu_cpu_is_self(cpu)) {
>> qemu_cpu_kick(env);
>> return;
>> }
>> diff --git a/hw/apic.c b/hw/apic.c
>> index ccf2819..1b4cd2f 100644
>> --- a/hw/apic.c
>> +++ b/hw/apic.c
>> @@ -107,7 +107,7 @@ static void apic_sync_vapic(APICCommonState *s, int sync_type)
>> length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
>>
>> if (sync_type & SYNC_TO_VAPIC) {
>> - assert(qemu_cpu_is_self(&s->cpu->env));
>> + assert(qemu_cpu_is_self(CPU(s->cpu)));
>>
>> vapic_state.tpr = s->tpr;
>> vapic_state.enabled = 1;
>> @@ -363,10 +363,12 @@ static int apic_irq_pending(APICCommonState *s)
>> /* signal the CPU if an irq is pending */
>> static void apic_update_irq(APICCommonState *s)
>> {
>> + CPUState *cpu = CPU(s->cpu);
>> +
>> if (!(s->spurious_vec & APIC_SV_ENABLE)) {
>> return;
>> }
>> - if (!qemu_cpu_is_self(&s->cpu->env)) {
>> + if (!qemu_cpu_is_self(cpu)) {
>> cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
>> } else if (apic_irq_pending(s) > 0) {
>> cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
>> diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
>> index ad706a6..7be983d 100644
>> --- a/include/qemu/cpu.h
>> +++ b/include/qemu/cpu.h
>> @@ -78,5 +78,15 @@ struct CPUState {
>> */
>> void cpu_reset(CPUState *cpu);
>>
>> +/**
>> + * qemu_cpu_is_self:
>> + * @cpu: The vCPU to check against.
>> + *
>> + * Checks whether the caller is executing on the vCPU thread.
>> + *
>> + * Returns: %true if called from @cpu's thread, %false otherwise.
>> + */
>> +bool qemu_cpu_is_self(CPUState *cpu);
>> +
>>
>> #endif
>> diff --git a/kvm-all.c b/kvm-all.c
>> index 92a7137..db01aeb 100644
>> --- a/kvm-all.c
>> +++ b/kvm-all.c
>> @@ -854,9 +854,11 @@ static MemoryListener kvm_memory_listener = {
>>
>> static void kvm_handle_interrupt(CPUArchState *env, int mask)
>> {
>> + CPUState *cpu = ENV_GET_CPU(env);
>> +
>> env->interrupt_request |= mask;
>>
>> - if (!qemu_cpu_is_self(env)) {
>> + if (!qemu_cpu_is_self(cpu)) {
>> qemu_cpu_kick(env);
>> }
>> }
>> diff --git a/qemu-common.h b/qemu-common.h
>> index b54612b..2094742 100644
>> --- a/qemu-common.h
>> +++ b/qemu-common.h
>> @@ -326,7 +326,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id);
>> /* Unblock cpu */
>> void qemu_cpu_kick(void *env);
>> void qemu_cpu_kick_self(void);
>> -int qemu_cpu_is_self(void *env);
>>
>> /* work queue */
>> struct qemu_work_item {
>> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
>> index 5b18383..cf3d2f1 100644
>> --- a/target-i386/kvm.c
>> +++ b/target-i386/kvm.c
>> @@ -1552,9 +1552,10 @@ static int kvm_get_debugregs(CPUX86State *env)
>>
>> int kvm_arch_put_registers(CPUX86State *env, int level)
>> {
>> + CPUState *cpu = ENV_GET_CPU(env);
>> int ret;
>>
>> - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
>> + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
>>
>> ret = kvm_getput_regs(env, 1);
>> if (ret < 0) {
>> @@ -1609,9 +1610,10 @@ int kvm_arch_put_registers(CPUX86State *env, int level)
>>
>> int kvm_arch_get_registers(CPUX86State *env)
>> {
>> + CPUState *cpu = ENV_GET_CPU(env);
>> int ret;
>>
>> - assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
>> + assert(cpu_is_stopped(env) || qemu_cpu_is_self(cpu));
>>
>> ret = kvm_getput_regs(env, 0);
>> if (ret < 0) {
>> --
>> 1.7.10.4
>>
>>
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self()
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self() Andreas Färber
2012-10-16 0:49 ` Igor Mammedov
@ 2012-10-30 20:33 ` Andreas Färber
1 sibling, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-30 20:33 UTC (permalink / raw)
To: qemu-devel
Am 12.10.2012 03:26, schrieb Andreas Färber:
> Change return type to bool, move to include/qemu/cpu.h and
> add documentation.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
Applied to qom-cpu branch with the following build fix:
diff --git a/cpus.c b/cpus.c
index 3b1bfec..1f3ac91 100644
--- a/cpus.c
+++ b/cpus.c
@@ -898,7 +898,7 @@ bool qemu_cpu_is_self(CPUState *cpu)
static bool qemu_in_vcpu_thread(void)
{
- return cpu_single_env && qemu_cpu_is_self(cpu_single_env);
+ return cpu_single_env && qemu_cpu_is_self(ENV_GET_CPU(cpu_single_env));
}
void qemu_mutex_lock_iothread(void)
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH qom-cpu v2 5/7] cpus: Pass CPUState to qemu_cpu_kick_thread()
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
` (3 preceding siblings ...)
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 4/7] cpus: Pass CPUState to qemu_cpu_is_self() Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
2012-10-16 0:53 ` Igor Mammedov
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 6/7] cpu: Move created field to CPUState Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 7/7] cpu: Move stop " Andreas Färber
6 siblings, 1 reply; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber
CPUArchState is no longer needed there.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
cpus.c | 9 ++++-----
1 Datei geändert, 4 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
diff --git a/cpus.c b/cpus.c
index 849ea8a..54b765e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -844,9 +844,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
return NULL;
}
-static void qemu_cpu_kick_thread(CPUArchState *env)
+static void qemu_cpu_kick_thread(CPUState *cpu)
{
- CPUState *cpu = ENV_GET_CPU(env);
#ifndef _WIN32
int err;
@@ -871,7 +870,7 @@ void qemu_cpu_kick(void *_env)
qemu_cond_broadcast(env->halt_cond);
if (!tcg_enabled() && !cpu->thread_kicked) {
- qemu_cpu_kick_thread(env);
+ qemu_cpu_kick_thread(cpu);
cpu->thread_kicked = true;
}
}
@@ -883,7 +882,7 @@ void qemu_cpu_kick_self(void)
CPUState *cpu_single_cpu = ENV_GET_CPU(cpu_single_env);
if (!cpu_single_cpu->thread_kicked) {
- qemu_cpu_kick_thread(cpu_single_env);
+ qemu_cpu_kick_thread(cpu_single_cpu);
cpu_single_cpu->thread_kicked = true;
}
#else
@@ -903,7 +902,7 @@ void qemu_mutex_lock_iothread(void)
} else {
iothread_requesting_mutex = true;
if (qemu_mutex_trylock(&qemu_global_mutex)) {
- qemu_cpu_kick_thread(first_cpu);
+ qemu_cpu_kick_thread(ENV_GET_CPU(first_cpu));
qemu_mutex_lock(&qemu_global_mutex);
}
iothread_requesting_mutex = false;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Qemu-devel] [PATCH qom-cpu v2 5/7] cpus: Pass CPUState to qemu_cpu_kick_thread()
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 5/7] cpus: Pass CPUState to qemu_cpu_kick_thread() Andreas Färber
@ 2012-10-16 0:53 ` Igor Mammedov
0 siblings, 0 replies; 18+ messages in thread
From: Igor Mammedov @ 2012-10-16 0:53 UTC (permalink / raw)
To: Andreas Färber; +Cc: qemu-devel
On Fri, 12 Oct 2012 03:26:41 +0200
Andreas Färber <afaerber@suse.de> wrote:
> CPUArchState is no longer needed there.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
> cpus.c | 9 ++++-----
> 1 Datei geändert, 4 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
>
> diff --git a/cpus.c b/cpus.c
> index 849ea8a..54b765e 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -844,9 +844,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
> return NULL;
> }
>
> -static void qemu_cpu_kick_thread(CPUArchState *env)
> +static void qemu_cpu_kick_thread(CPUState *cpu)
> {
> - CPUState *cpu = ENV_GET_CPU(env);
> #ifndef _WIN32
> int err;
>
> @@ -871,7 +870,7 @@ void qemu_cpu_kick(void *_env)
>
> qemu_cond_broadcast(env->halt_cond);
> if (!tcg_enabled() && !cpu->thread_kicked) {
> - qemu_cpu_kick_thread(env);
> + qemu_cpu_kick_thread(cpu);
> cpu->thread_kicked = true;
> }
> }
> @@ -883,7 +882,7 @@ void qemu_cpu_kick_self(void)
> CPUState *cpu_single_cpu = ENV_GET_CPU(cpu_single_env);
>
> if (!cpu_single_cpu->thread_kicked) {
> - qemu_cpu_kick_thread(cpu_single_env);
> + qemu_cpu_kick_thread(cpu_single_cpu);
> cpu_single_cpu->thread_kicked = true;
> }
> #else
> @@ -903,7 +902,7 @@ void qemu_mutex_lock_iothread(void)
> } else {
> iothread_requesting_mutex = true;
> if (qemu_mutex_trylock(&qemu_global_mutex)) {
> - qemu_cpu_kick_thread(first_cpu);
> + qemu_cpu_kick_thread(ENV_GET_CPU(first_cpu));
> qemu_mutex_lock(&qemu_global_mutex);
> }
> iothread_requesting_mutex = false;
> --
> 1.7.10.4
>
>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
--
Regards,
Igor
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH qom-cpu v2 6/7] cpu: Move created field to CPUState
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
` (4 preceding siblings ...)
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 5/7] cpus: Pass CPUState to qemu_cpu_kick_thread() Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 7/7] cpu: Move stop " Andreas Färber
6 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber
Change its type to bool.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
cpu-defs.h | 1 -
cpus.c | 13 +++++++------
include/qemu/cpu.h | 2 ++
3 Dateien geändert, 9 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)
diff --git a/cpu-defs.h b/cpu-defs.h
index 4018b88..ae95158 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -205,7 +205,6 @@ typedef struct CPUWatchpoint {
/* user data */ \
void *opaque; \
\
- uint32_t created; \
uint32_t stop; /* Stop request */ \
uint32_t stopped; /* Artificially stopped */ \
struct QemuCond *halt_cond; \
diff --git a/cpus.c b/cpus.c
index 54b765e..18fa6a9 100644
--- a/cpus.c
+++ b/cpus.c
@@ -746,7 +746,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
qemu_kvm_init_cpu_signals(env);
/* signal CPU creation */
- env->created = 1;
+ cpu->created = true;
qemu_cond_signal(&qemu_cpu_cond);
while (1) {
@@ -781,7 +781,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
sigaddset(&waitset, SIG_IPI);
/* signal CPU creation */
- env->created = 1;
+ cpu->created = true;
qemu_cond_signal(&qemu_cpu_cond);
cpu_single_env = env;
@@ -818,8 +818,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
/* signal CPU creation */
qemu_mutex_lock(&qemu_global_mutex);
for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ cpu = ENV_GET_CPU(env);
env->thread_id = qemu_get_thread_id();
- env->created = 1;
+ cpu->created = true;
}
qemu_cond_signal(&qemu_cpu_cond);
@@ -991,7 +992,7 @@ static void qemu_tcg_init_vcpu(void *_env)
#ifdef _WIN32
cpu->hThread = qemu_thread_get_handle(cpu->thread);
#endif
- while (env->created == 0) {
+ while (!cpu->created) {
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
}
tcg_cpu_thread = cpu->thread;
@@ -1010,7 +1011,7 @@ static void qemu_kvm_start_vcpu(CPUArchState *env)
qemu_cond_init(env->halt_cond);
qemu_thread_create(cpu->thread, qemu_kvm_cpu_thread_fn, env,
QEMU_THREAD_JOINABLE);
- while (env->created == 0) {
+ while (!cpu->created) {
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
}
}
@@ -1024,7 +1025,7 @@ static void qemu_dummy_start_vcpu(CPUArchState *env)
qemu_cond_init(env->halt_cond);
qemu_thread_create(cpu->thread, qemu_dummy_cpu_thread_fn, env,
QEMU_THREAD_JOINABLE);
- while (env->created == 0) {
+ while (!cpu->created) {
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
}
}
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 7be983d..3ab2e25 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -54,6 +54,7 @@ typedef struct CPUClass {
/**
* CPUState:
+ * @created: Indicates whether the CPU thread has been successfully created.
*
* State of one CPU core or thread.
*/
@@ -67,6 +68,7 @@ struct CPUState {
HANDLE hThread;
#endif
bool thread_kicked;
+ bool created;
/* TODO Move common fields from CPUArchState here. */
};
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH qom-cpu v2 7/7] cpu: Move stop field to CPUState
2012-10-12 1:26 [Qemu-devel] [PATCH qom-cpu v2 0/7] QOM CPUState, part 4a: CPU_COMMON, continued Andreas Färber
` (5 preceding siblings ...)
2012-10-12 1:26 ` [Qemu-devel] [PATCH qom-cpu v2 6/7] cpu: Move created field to CPUState Andreas Färber
@ 2012-10-12 1:26 ` Andreas Färber
6 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2012-10-12 1:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber
Change its type to bool.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
cpu-defs.h | 1 -
cpus.c | 27 ++++++++++++++++++---------
include/qemu/cpu.h | 2 ++
3 Dateien geändert, 20 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)
diff --git a/cpu-defs.h b/cpu-defs.h
index ae95158..c93371e 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -205,7 +205,6 @@ typedef struct CPUWatchpoint {
/* user data */ \
void *opaque; \
\
- uint32_t stop; /* Stop request */ \
uint32_t stopped; /* Artificially stopped */ \
struct QemuCond *halt_cond; \
struct qemu_work_item *queued_work_first, *queued_work_last; \
diff --git a/cpus.c b/cpus.c
index 18fa6a9..89fd714 100644
--- a/cpus.c
+++ b/cpus.c
@@ -64,7 +64,9 @@ static CPUArchState *next_cpu;
static bool cpu_thread_is_idle(CPUArchState *env)
{
- if (env->stop || env->queued_work_first) {
+ CPUState *cpu = ENV_GET_CPU(env);
+
+ if (cpu->stop || env->queued_work_first) {
return false;
}
if (env->stopped || !runstate_is_running()) {
@@ -448,7 +450,9 @@ static void do_vm_stop(RunState state)
static int cpu_can_run(CPUArchState *env)
{
- if (env->stop) {
+ CPUState *cpu = ENV_GET_CPU(env);
+
+ if (cpu->stop) {
return 0;
}
if (env->stopped || !runstate_is_running()) {
@@ -687,8 +691,8 @@ static void qemu_wait_io_event_common(CPUArchState *env)
{
CPUState *cpu = ENV_GET_CPU(env);
- if (env->stop) {
- env->stop = 0;
+ if (cpu->stop) {
+ cpu->stop = false;
env->stopped = 1;
qemu_cond_signal(&qemu_pause_cond);
}
@@ -936,7 +940,8 @@ void pause_all_vcpus(void)
qemu_clock_enable(vm_clock, false);
while (penv) {
- penv->stop = 1;
+ CPUState *pcpu = ENV_GET_CPU(penv);
+ pcpu->stop = true;
qemu_cpu_kick(penv);
penv = penv->next_cpu;
}
@@ -945,7 +950,8 @@ void pause_all_vcpus(void)
cpu_stop_current();
if (!kvm_enabled()) {
while (penv) {
- penv->stop = 0;
+ CPUState *pcpu = ENV_GET_CPU(penv);
+ pcpu->stop = 0;
penv->stopped = 1;
penv = penv->next_cpu;
}
@@ -969,7 +975,8 @@ void resume_all_vcpus(void)
qemu_clock_enable(vm_clock, true);
while (penv) {
- penv->stop = 0;
+ CPUState *pcpu = ENV_GET_CPU(penv);
+ pcpu->stop = false;
penv->stopped = 0;
qemu_cpu_kick(penv);
penv = penv->next_cpu;
@@ -1049,7 +1056,8 @@ void qemu_init_vcpu(void *_env)
void cpu_stop_current(void)
{
if (cpu_single_env) {
- cpu_single_env->stop = 0;
+ CPUState *cpu_single_cpu = ENV_GET_CPU(cpu_single_env);
+ cpu_single_cpu->stop = false;
cpu_single_env->stopped = 1;
cpu_exit(cpu_single_env);
qemu_cond_signal(&qemu_pause_cond);
@@ -1131,6 +1139,7 @@ static void tcg_exec_all(void)
}
for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) {
CPUArchState *env = next_cpu;
+ CPUState *cpu = ENV_GET_CPU(env);
qemu_clock_enable(vm_clock,
(env->singlestep_enabled & SSTEP_NOTIMER) == 0);
@@ -1141,7 +1150,7 @@ static void tcg_exec_all(void)
cpu_handle_guest_debug(env);
break;
}
- } else if (env->stop || env->stopped) {
+ } else if (cpu->stop || env->stopped) {
break;
}
}
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 3ab2e25..04c7848 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -55,6 +55,7 @@ typedef struct CPUClass {
/**
* CPUState:
* @created: Indicates whether the CPU thread has been successfully created.
+ * @stop: Indicates a pending stop request.
*
* State of one CPU core or thread.
*/
@@ -69,6 +70,7 @@ struct CPUState {
#endif
bool thread_kicked;
bool created;
+ bool stop;
/* TODO Move common fields from CPUArchState here. */
};
--
1.7.10.4
^ permalink raw reply related [flat|nested] 18+ messages in thread