From: Peter Maydell <peter.maydell@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-arm@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH v2 1/5] hw/arm/z2: convert DPRINTF to trace events and guest errors
Date: Mon, 22 Jan 2024 18:20:30 +0000 [thread overview]
Message-ID: <CAFEAcA9sqoDju6vpD_AN2=At_BbChGsMSckumfYL+u3+g9SJ2Q@mail.gmail.com> (raw)
In-Reply-To: <339219e962d90f47cf125f2be2d64afb0833e905.1705670342.git.manos.pitsidianakis@linaro.org>
On Fri, 19 Jan 2024 at 13:24, Manos Pitsidianakis
<manos.pitsidianakis@linaro.org> wrote:
>
> Tracing DPRINTFs to stderr might not be desired. A developer that relies
> on trace events should be able to opt-in to each trace event and rely on
> QEMU's log redirection, instead of stderr by default.
>
> This commit converts DPRINTFs in this file that are used for tracing
> into trace events. DPRINTFs that report guest errors are logged with
> LOG_GUEST_ERROR.
>
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
> hw/arm/strongarm.c | 55 ++++++++++++++++++++++-----------------------
> hw/arm/trace-events | 10 +++++++++
> hw/arm/z2.c | 27 +++++++---------------
Hi; thanks for sending these patches.
The strongarm.c and z2.c files aren't related (z2 uses
the pxa2xx CPU, not strongarm), so I think these are better
as two separate patches.
> 3 files changed, 45 insertions(+), 47 deletions(-)
>
> diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c
> index fef3638aca..9fca0b302c 100644
> --- a/hw/arm/strongarm.c
> +++ b/hw/arm/strongarm.c
> @@ -46,8 +46,7 @@
> #include "qemu/cutils.h"
> #include "qemu/log.h"
> #include "qom/object.h"
> -
> -//#define DEBUG
> +#include "trace.h"
>
> /*
> TODO
> @@ -66,12 +65,6 @@
> - Enhance UART with modem signals
> */
>
> -#ifdef DEBUG
> -# define DPRINTF(format, ...) printf(format , ## __VA_ARGS__)
> -#else
> -# define DPRINTF(format, ...) do { } while (0)
> -#endif
> -
> static struct {
> hwaddr io_base;
> int irq;
> @@ -151,8 +144,9 @@ static uint64_t strongarm_pic_mem_read(void *opaque, hwaddr offset,
> case ICPR:
> return s->pending;
> default:
> - printf("%s: Bad register offset 0x" HWADDR_FMT_plx "\n",
> - __func__, offset);
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "Bad pic mem register read offset 0x%zu",
> + offset);
Message strings for qemu_log_mask() need a trailing "\n"
(unlike trace-event strings).
'offset' is type 'hwaddr', so the correct format string is
HWADDR_FMT_plx as the printf already has, not %zu. (Watch out
that the HWADDR_FMT_* macros include the "%", unlike the
POSIX style PRIx64 etc macros.) Getting the format string
wrong can cause compilation failures on some hosts (eg
32-bit hosts where the size_t etc types are different sizes.)
It's nice with these error messages to be a bit more
precise about the device that's produced them than
just "pic mem". In this case you could say "strongarm_pic".
(The 'mem' isn't really part of the device name.) Or
we are often lazy and use __func__.
Similarly with the other qemu_log_mask() calls below.
> return 0;
> }
> }
> @@ -1029,8 +1024,11 @@ static void strongarm_uart_update_parameters(StrongARMUARTState *s)
> s->char_transmit_time = (NANOSECONDS_PER_SECOND / speed) * frame_size;
> qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
>
> - DPRINTF(stderr, "%s speed=%d parity=%c data=%d stop=%d\n", s->chr->label,
> - speed, parity, data_bits, stop_bits);
> + trace_strongarm_uart_update_parameters(s->chr.chr->label?:"NULL",
Something's gone wrong here. The old code had 's->chr->label'
and the new code has got an extra '.chr' in it from somewhere.
(Did this really compile ? Check your configure options were
such that the file is being recompiled and the trace events
are being emitted.)
The code needs to handle s->chr being NULL (this will happen
if you start a strongarm machine with the command line argument
"-serial none").
> + speed,
> + parity,
> + data_bits,
> + stop_bits);
> }
>
> @@ -1458,8 +1456,9 @@ static void strongarm_ssp_write(void *opaque, hwaddr addr,
> case SSCR0:
> s->sscr[0] = value & 0xffbf;
> if ((s->sscr[0] & SSCR0_SSE) && SSCR0_DSS(value) < 4) {
> - printf("%s: Wrong data size: %i bits\n", __func__,
> - (int)SSCR0_DSS(value));
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "Wrong data size: %i bits",
> + (int)SSCR0_DSS(value));
This message has no indication at all of what device is producing it.
> }
> if (!(value & SSCR0_SSE)) {
> s->sssr = 0;
> diff --git a/hw/arm/trace-events b/hw/arm/trace-events
> index cdc1ea06a8..b0a56fcdc6 100644
> --- a/hw/arm/trace-events
> +++ b/hw/arm/trace-events
> @@ -55,3 +55,13 @@ smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s
> smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s"
> smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64
>
> +# z2.c
> +z2_lcd_reg_update(uint8_t cur, uint8_t _0, uint8_t _1, uint8_t _2, uint32_t value) "cur_reg = 0x%xd, buf = [0x%xd, 0x%xd, 0x%xd], value = 0x%x"
Don't use argument names starting with underscores; those are
reserved for the compiler and the system. Here I would
suggest buf0, buf1, buf2.
"%xd" will print the number in hex followed by a literal 'd' character.
For hex numbers, just "0x%x" is sufficient. (Look at other
trace lines in this file for examples.)
> +z2_lcd_enable_disable_result(const char * result) "LCD %s"
No space after the '*' in the argument type.
> +z2_aer915_send_too_long(int8_t msg) "message too long (%i bytes)"
> +z2_aer915_send(uint8_t reg, uint8_t value) "reg %d value 0x%02x"
> +z2_aer915_event(int8_t event, int8_t len) "i2c event =0x%x len=%d bytes"
> +
> +# strongarm.c
> +strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d"
> +strongarm_ssp_read_underrun(void) "SSP rx underrun"
thanks
-- PMM
next prev parent reply other threads:[~2024-01-22 18:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 13:24 [PATCH v2 0/5] hw/{arm,xen} convert printfs to trace/reports Manos Pitsidianakis
2024-01-19 13:24 ` [PATCH v2 1/5] hw/arm/z2: convert DPRINTF to trace events and guest errors Manos Pitsidianakis
2024-01-22 18:20 ` Peter Maydell [this message]
2024-01-19 13:24 ` [PATCH v2 2/5] hw/arm/xen_arm.c: convert DPRINTF to trace events and error/warn reports Manos Pitsidianakis
2024-01-19 13:24 ` [PATCH v2 3/5] hw/xen/xen-mapcache.c: convert DPRINTF to tracepoints Manos Pitsidianakis
2024-01-19 13:24 ` [PATCH v2 4/5] hw/xen/xen-hvm-common.c: " Manos Pitsidianakis
2024-01-19 13:24 ` [PATCH v2 5/5] hw/xen: convert stderr prints to error/warn reports Manos Pitsidianakis
2024-01-19 17:04 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFEAcA9sqoDju6vpD_AN2=At_BbChGsMSckumfYL+u3+g9SJ2Q@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=manos.pitsidianakis@linaro.org \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).