From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Peter Maydell <peter.maydell@linaro.org>,
Corey Minyard <cminyard@mvista.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
"Linus Walleij" <linus.walleij@linaro.org>
Subject: [Qemu-devel] [PATCH] hw/i2c: Add trace events
Date: Wed, 6 Jun 2018 16:18:01 -0300 [thread overview]
Message-ID: <20180606191801.6331-1-f4bug@amsat.org> (raw)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
$ qemu-system ... -d trace:i2c_recv,trace:i2c_send
4486@1528311614.709959:i2c_recv recv(addr:0x50) data:0x00
4486@1528311614.709994:i2c_send send(addr:0x50) data:0x05
4486@1528311614.710060:i2c_recv recv(addr:0x50) data:0x02
4486@1528311614.710161:i2c_recv recv(addr:0x50) data:0x40
4486@1528311614.710185:i2c_send send(addr:0x50) data:0x02
4486@1528311614.710233:i2c_recv recv(addr:0x50) data:0x08
4486@1528311614.710380:i2c_recv recv(addr:0x50) data:0x0d
4486@1528311614.710396:i2c_send send(addr:0x50) data:0x1f
4486@1528311614.710437:i2c_recv recv(addr:0x50) data:0x40
or
$ qemu-system ... -d trace:i2c\*
4486@1528311614.698315:i2c_event start(addr:0x50)
4486@1528311614.698338:i2c_recv recv(addr:0x50) data:0x82
4486@1528311614.698349:i2c_event finish(addr:0x50)
4486@1528311614.698354:i2c_event start(addr:0x50)
4486@1528311614.698357:i2c_send send(addr:0x50) data:0x11
4486@1528311614.698377:i2c_event finish(addr:0x50)
4486@1528311614.698380:i2c_event start(addr:0x50)
4486@1528311614.698402:i2c_recv recv(addr:0x50) data:0x04
4486@1528311614.698485:i2c_event finish(addr:0x50)
Makefile.objs | 1 +
hw/i2c/core.c | 25 ++++++++++++++++++-------
hw/i2c/trace-events | 7 +++++++
3 files changed, 26 insertions(+), 7 deletions(-)
create mode 100644 hw/i2c/trace-events
diff --git a/Makefile.objs b/Makefile.objs
index 2c8cb72407..7a9828da28 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -213,6 +213,7 @@ trace-events-subdirs += hw/char
trace-events-subdirs += hw/display
trace-events-subdirs += hw/dma
trace-events-subdirs += hw/hppa
+trace-events-subdirs += hw/i2c
trace-events-subdirs += hw/i386
trace-events-subdirs += hw/i386/xen
trace-events-subdirs += hw/ide
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index ab72d5bf2b..b54725985a 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "hw/i2c/i2c.h"
+#include "trace.h"
#define I2C_BROADCAST 0x00
@@ -130,14 +131,16 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
}
QLIST_FOREACH(node, &bus->current_devs, next) {
+ I2CSlave *s = node->elt;
int rv;
- sc = I2C_SLAVE_GET_CLASS(node->elt);
+ sc = I2C_SLAVE_GET_CLASS(s);
/* If the bus is already busy, assume this is a repeated
start condition. */
if (sc->event) {
- rv = sc->event(node->elt, recv ? I2C_START_RECV : I2C_START_SEND);
+ trace_i2c_event("start", s->address);
+ rv = sc->event(s, recv ? I2C_START_RECV : I2C_START_SEND);
if (rv && !bus->broadcast) {
if (bus_scanned) {
/* First call, terminate the transfer. */
@@ -156,9 +159,11 @@ void i2c_end_transfer(I2CBus *bus)
I2CNode *node, *next;
QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) {
- sc = I2C_SLAVE_GET_CLASS(node->elt);
+ I2CSlave *s = node->elt;
+ sc = I2C_SLAVE_GET_CLASS(s);
if (sc->event) {
- sc->event(node->elt, I2C_FINISH);
+ trace_i2c_event("finish", s->address);
+ sc->event(s, I2C_FINISH);
}
QLIST_REMOVE(node, next);
g_free(node);
@@ -169,14 +174,17 @@ void i2c_end_transfer(I2CBus *bus)
int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
{
I2CSlaveClass *sc;
+ I2CSlave *s;
I2CNode *node;
int ret = 0;
if (send) {
QLIST_FOREACH(node, &bus->current_devs, next) {
- sc = I2C_SLAVE_GET_CLASS(node->elt);
+ s = node->elt;
+ sc = I2C_SLAVE_GET_CLASS(s);
if (sc->send) {
- ret = ret || sc->send(node->elt, *data);
+ trace_i2c_send(s->address, *data);
+ ret = ret || sc->send(s, *data);
} else {
ret = -1;
}
@@ -189,7 +197,9 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
if (sc->recv) {
- ret = sc->recv(QLIST_FIRST(&bus->current_devs)->elt);
+ s = QLIST_FIRST(&bus->current_devs)->elt;
+ ret = sc->recv(s);
+ trace_i2c_recv(s->address, ret);
if (ret < 0) {
return ret;
} else {
@@ -226,6 +236,7 @@ void i2c_nack(I2CBus *bus)
QLIST_FOREACH(node, &bus->current_devs, next) {
sc = I2C_SLAVE_GET_CLASS(node->elt);
if (sc->event) {
+ trace_i2c_event("nack", node->elt->address);
sc->event(node->elt, I2C_NACK);
}
}
diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events
new file mode 100644
index 0000000000..d339b61202
--- /dev/null
+++ b/hw/i2c/trace-events
@@ -0,0 +1,7 @@
+# See docs/devel/tracing.txt for syntax documentation.
+
+# hw/i2c/core.c
+
+i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)"
+i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x"
+i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x"
--
2.17.1
next reply other threads:[~2018-06-06 19:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-06 19:18 Philippe Mathieu-Daudé [this message]
2018-06-07 13:02 ` [Qemu-devel] [PATCH] hw/i2c: Add trace events Peter Maydell
2018-06-11 15:36 ` Corey Minyard
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=20180606191801.6331-1-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=cminyard@mvista.com \
--cc=linus.walleij@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.