* [Qemu-devel] Any better way to access CPUArchState in vl.c?
@ 2012-06-18 7:47 陳韋任 (Wei-Ren Chen)
2012-06-18 10:01 ` Andreas Färber
0 siblings, 1 reply; 10+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-06-18 7:47 UTC (permalink / raw)
To: qemu-devel
Hi all,
Say I want to print env->some_field in vl.c. I #include "dyngen-exec.h"
in vl.c, but got compilation error immediately.
/tmp/chenwj/qemu/dyngen-exec.h:64:10: error: attempt to use poisoned "CPUArchState"
/tmp/chenwj/qemu/dyngen-exec.h:64:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/tmp/chenwj/qemu/dyngen-exec.h:64:24: error: attempt to use poisoned "env"
After googling, I figure out QEMU poison some identifiers which cannot be used
in target indenpent code. Although we can get some_field by the following way,
int some_field = &env->some_field;
but it's not very convenient if we have many field of CPUState want to access. Is
there a better way to do so? Thanks!
Regards,
chenwj
[1]
http://stackoverflow.com/questions/9461625/gcc-error-message-attempt-to-use-poisoned-target-i386
--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-18 7:47 [Qemu-devel] Any better way to access CPUArchState in vl.c? 陳韋任 (Wei-Ren Chen)
@ 2012-06-18 10:01 ` Andreas Färber
2012-06-19 9:02 ` 陳韋任 (Wei-Ren Chen)
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Färber @ 2012-06-18 10:01 UTC (permalink / raw)
To: "陳韋任 (Wei-Ren Chen)"; +Cc: qemu-devel
Hi Wei-Ren,
Am 18.06.2012 09:47, schrieb 陳韋任 (Wei-Ren Chen):
> Say I want to print env->some_field in vl.c. I #include "dyngen-exec.h"
> in vl.c, but got compilation error immediately.
>
> /tmp/chenwj/qemu/dyngen-exec.h:64:10: error: attempt to use poisoned "CPUArchState"
> /tmp/chenwj/qemu/dyngen-exec.h:64:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
> /tmp/chenwj/qemu/dyngen-exec.h:64:24: error: attempt to use poisoned "env"
>
> After googling, I figure out QEMU poison some identifiers which cannot be used
> in target indenpent code. Although we can get some_field by the following way,
>
> int some_field = &env->some_field;
>
> but it's not very convenient if we have many field of CPUState want to access. Is
> there a better way to do so? Thanks!
Poisoned is the "env" variable. You cannot just #include "dyngen-exec.h"
and expect it to be usable since AREG0 targets don't guarantee it's set
properly (may be NULL even with traditional targets at times).
CPUArchState should currently be usable in vl.c, you just need explicit
access to it (e.g., a function argument).
Question is, what are you trying to do? In particular, of which CPU
(think SMP) are you trying to print ->some_field? :)
Regards,
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 [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-18 10:01 ` Andreas Färber
@ 2012-06-19 9:02 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 9:54 ` Andreas Färber
0 siblings, 1 reply; 10+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-06-19 9:02 UTC (permalink / raw)
To: Andreas Färber
Cc: qemu-devel, "陳韋任 (Wei-Ren Chen)"
Hi Andreas,
> Poisoned is the "env" variable. You cannot just #include "dyngen-exec.h"
> and expect it to be usable since AREG0 targets don't guarantee it's set
> properly (may be NULL even with traditional targets at times).
Oops, I miss that point.
> CPUArchState should currently be usable in vl.c, you just need explicit
> access to it (e.g., a function argument).
> Question is, what are you trying to do? In particular, of which CPU
> (think SMP) are you trying to print ->some_field? :)
Currently we only consider single CPU ARM guest, so there should be only one
env we need to take care of. We add some fields into CPUState and want to print
their value when the VM is terminated. For example,
---
static void main_loop(void)
{
do {
nonblocking = !kvm_enabled() && last_io > 0;
last_io = main_loop_wait(nonblocking);
} while (!main_loop_should_exit());
// print env->some_field1
// print env->some_field2
}
---
If we can access env in vl.c directly, it would make the task easier.
Regards,
chenwj
--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 9:02 ` 陳韋任 (Wei-Ren Chen)
@ 2012-06-19 9:54 ` Andreas Färber
2012-06-19 11:54 ` 陳韋任 (Wei-Ren Chen)
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Färber @ 2012-06-19 9:54 UTC (permalink / raw)
To: "陳韋任 (Wei-Ren Chen)"; +Cc: qemu-devel
Hi,
Am 19.06.2012 11:02, schrieb 陳韋任 (Wei-Ren Chen):
>> Question is, what are you trying to do? In particular, of which CPU
>> (think SMP) are you trying to print ->some_field? :)
>
> Currently we only consider single CPU ARM guest, so there should be only one
> env we need to take care of. We add some fields into CPUState and want to print
> their value when the VM is terminated. For example,
>
> ---
> static void main_loop(void)
> {
> do {
> nonblocking = !kvm_enabled() && last_io > 0;
> last_io = main_loop_wait(nonblocking);
> } while (!main_loop_should_exit());
>
> // print env->some_field1
> // print env->some_field2
> }
> ---
>
> If we can access env in vl.c directly, it would make the task easier.
If you only have one CPU then using first_cpu->some_field1 should be
almost as easy. :)
Regards,
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 [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 9:54 ` Andreas Färber
@ 2012-06-19 11:54 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 12:08 ` Peter Maydell
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-06-19 11:54 UTC (permalink / raw)
To: Andreas Färber
Cc: qemu-devel, "陳韋任 (Wei-Ren Chen)"
> If you only have one CPU then using first_cpu->some_field1 should be
> almost as easy. :)
I am afraid first_cpu (CPUArchState) is got poisoned, too. :/
Even I comment out CPUArchState from poison.h,
--- vl.c
extern CPUArchState *first_cpu;
static void main_loop(void)
{
... snip ...
printf("%d", first_cpu->created);
}
---
I still get compilation error below,
---
/tmp/chenwj/qemu/vl.c:1548:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/tmp/chenwj/qemu/vl.c: In function 'main_loop':
/tmp/chenwj/qemu/vl.c:1568:18: error: 'first_cpu' undeclared (first use in this function)
---
Any thought on what I am missing? Thanks.
Regards,
chenwj
--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 11:54 ` 陳韋任 (Wei-Ren Chen)
@ 2012-06-19 12:08 ` Peter Maydell
2012-06-20 8:03 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 12:09 ` Peter Crosthwaite
2012-06-19 12:12 ` Andreas Färber
2 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2012-06-19 12:08 UTC (permalink / raw)
To: 陳韋任 (Wei-Ren Chen); +Cc: Andreas Färber, qemu-devel
On 19 June 2012 12:54, 陳韋任 (Wei-Ren Chen) <chenwj@iis.sinica.edu.tw> wrote:
>> If you only have one CPU then using first_cpu->some_field1 should be
>> almost as easy. :)
>
> I am afraid first_cpu (CPUArchState) is got poisoned, too. :/
Yes. You'll need to write a function which lives in a source file which
has access to the poisoned symbols, and then call that from vl.c.
hw_error() might be a useful example to follow.
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 11:54 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 12:08 ` Peter Maydell
@ 2012-06-19 12:09 ` Peter Crosthwaite
2012-06-19 13:21 ` Andreas Färber
2012-06-19 12:12 ` Andreas Färber
2 siblings, 1 reply; 10+ messages in thread
From: Peter Crosthwaite @ 2012-06-19 12:09 UTC (permalink / raw)
To: 陳韋任 (Wei-Ren Chen); +Cc: qemu-devel, Andreas Färber
[-- Attachment #1: Type: text/plain, Size: 1204 bytes --]
Andreas, will an attribute((destructor)) work ? Cos if it does you can put
your printf pretty much anwhere rather than vl.c
On Jun 19, 2012 9:54 PM, "陳韋任 (Wei-Ren Chen)" <chenwj@iis.sinica.edu.tw>
wrote:
> > If you only have one CPU then using first_cpu->some_field1 should be
> > almost as easy. :)
>
> I am afraid first_cpu (CPUArchState) is got poisoned, too. :/
> Even I comment out CPUArchState from poison.h,
>
> --- vl.c
> extern CPUArchState *first_cpu;
>
> static void main_loop(void)
> {
> ... snip ...
>
> printf("%d", first_cpu->created);
> }
> ---
>
> I still get compilation error below,
>
> ---
> /tmp/chenwj/qemu/vl.c:1548:20: error: expected '=', ',', ';', 'asm' or
> '__attribute__' before '*' token
> /tmp/chenwj/qemu/vl.c: In function 'main_loop':
> /tmp/chenwj/qemu/vl.c:1568:18: error: 'first_cpu' undeclared (first use in
> this function)
> ---
>
> Any thought on what I am missing? Thanks.
>
> Regards,
> chenwj
>
> --
> Wei-Ren Chen (陳韋任)
> Computer Systems Lab, Institute of Information Science,
> Academia Sinica, Taiwan (R.O.C.)
> Tel:886-2-2788-3799 #1667
> Homepage: http://people.cs.nctu.edu.tw/~chenwj
>
>
[-- Attachment #2: Type: text/html, Size: 1678 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 11:54 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 12:08 ` Peter Maydell
2012-06-19 12:09 ` Peter Crosthwaite
@ 2012-06-19 12:12 ` Andreas Färber
2 siblings, 0 replies; 10+ messages in thread
From: Andreas Färber @ 2012-06-19 12:12 UTC (permalink / raw)
To: "陳韋任 (Wei-Ren Chen)"; +Cc: qemu-devel
Am 19.06.2012 13:54, schrieb 陳韋任 (Wei-Ren Chen):
>> If you only have one CPU then using first_cpu->some_field1 should be
>> almost as easy. :)
>
> I am afraid first_cpu (CPUArchState) is got poisoned, too. :/
> Even I comment out CPUArchState from poison.h,
>
> --- vl.c
> extern CPUArchState *first_cpu;
>
> static void main_loop(void)
> {
> ... snip ...
>
> printf("%d", first_cpu->created);
> }
> ---
>
> I still get compilation error below,
>
> ---
> /tmp/chenwj/qemu/vl.c:1548:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
> /tmp/chenwj/qemu/vl.c: In function 'main_loop':
> /tmp/chenwj/qemu/vl.c:1568:18: error: 'first_cpu' undeclared (first use in this function)
> ---
>
> Any thought on what I am missing? Thanks.
Sorry, my mistake: vl.c is not compiled per-target like I thought but
per target_phys_addr_t in libhwX, thus it cannot access cpu.h or
CPUArchState (only CPUState). That means evaluations of fields in
CPUARMState need to be done in target-arm/ and you might want to check
the Notifiers or in the worst case _atexit() to hook some callback
function up. With QOM CPUState there's finalizers in theory but I don't
think they get called yet for anything except linux-user thread exit.
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 [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 12:09 ` Peter Crosthwaite
@ 2012-06-19 13:21 ` Andreas Färber
0 siblings, 0 replies; 10+ messages in thread
From: Andreas Färber @ 2012-06-19 13:21 UTC (permalink / raw)
To: Peter Crosthwaite
Cc: qemu-devel, "陳韋任 (Wei-Ren Chen)"
Am 19.06.2012 14:09, schrieb Peter Crosthwaite:
> Andreas, will an attribute((destructor)) work ? Cos if it does you can
> put your printf pretty much anwhere rather than vl.c
Yes, it might. main() only seems to call cpus.c:pause_all_vcpus(), so
neither first_cpu nor the CPU(Arch)State would get cleaned up. But then
again all my comments are based on qemu.git master whereas Wei-Ren is
working on 0.14.x IIRC.
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 [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] Any better way to access CPUArchState in vl.c?
2012-06-19 12:08 ` Peter Maydell
@ 2012-06-20 8:03 ` 陳韋任 (Wei-Ren Chen)
0 siblings, 0 replies; 10+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-06-20 8:03 UTC (permalink / raw)
To: Peter Maydell
Cc: Andreas Färber, 陳韋任 (Wei-Ren Chen),
qemu-devel
On Tue, Jun 19, 2012 at 01:08:47PM +0100, Peter Maydell wrote:
> On 19 June 2012 12:54, 陳韋任 (Wei-Ren Chen) <chenwj@iis.sinica.edu.tw> wrote:
> >> If you only have one CPU then using first_cpu->some_field1 should be
> >> almost as easy. :)
> >
> > I am afraid first_cpu (CPUArchState) is got poisoned, too. :/
>
> Yes. You'll need to write a function which lives in a source file which
> has access to the poisoned symbols, and then call that from vl.c.
> hw_error() might be a useful example to follow.
I take your approach, thanks. :)
Regards,
chenwj
--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-06-20 8:03 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-18 7:47 [Qemu-devel] Any better way to access CPUArchState in vl.c? 陳韋任 (Wei-Ren Chen)
2012-06-18 10:01 ` Andreas Färber
2012-06-19 9:02 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 9:54 ` Andreas Färber
2012-06-19 11:54 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 12:08 ` Peter Maydell
2012-06-20 8:03 ` 陳韋任 (Wei-Ren Chen)
2012-06-19 12:09 ` Peter Crosthwaite
2012-06-19 13:21 ` Andreas Färber
2012-06-19 12:12 ` Andreas Färber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).