2011-06-13 21:30:11

by Németh Márton

[permalink] [raw]
Subject: [PATCH 2/3] usbip: dump the port status difference

From: Márton Németh <[email protected]>

At the beginning of vhci_hub_control() function the port
status is saved to show what are the differences between the
previous and the new status. Change the dump function to
really show the differences in the status bit changes: put
a '+' sign before the symbolic name of a bit where a bit
was set, a '-' sign where the bit was cleared and a SPACE
where the bit was not changed. This is similar to the way
"diff -u" shows the changes and easy to understand.

Signed-off-by: Márton Németh <[email protected]>
---
drivers/staging/usbip/vhci_hcd.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index 512a97f..d3ce569 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -92,14 +92,22 @@ static const char * const bit_desc[] = {
"R31", /*31*/
};

-static void dump_port_status(u32 status)
+static void dump_port_status_diff(u32 prev_status, u32 new_status)
{
int i = 0;

- pr_debug("status %08x:", status);
+ pr_debug("status %08x -> %08x:", prev_status, new_status);
for (i = 0; i < 32; i++) {
- if (status & (1 << i))
- pr_debug(" %s", bit_desc[i]);
+ if (!(prev_status & (1 << i)) &&
+ new_status & (1 << i)) {
+ pr_debug(" +%s", bit_desc[i]);
+ } else if (prev_status & (1 << i) &&
+ !(new_status & (1 << i))) {
+ pr_debug(" -%s", bit_desc[i]);
+ } else if (prev_status & (1 << i) &&
+ new_status & (1 << i)) {
+ pr_debug(" %s", bit_desc[i]);
+ }
}
pr_debug("\n");
}
@@ -466,8 +474,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
pr_debug("port %d\n", rhport);
/* Only dump valid port status */
if (0 <= rhport) {
- dump_port_status(prev_port_status[rhport]);
- dump_port_status(dum->port_status[rhport]);
+ dump_port_status_diff(prev_port_status[rhport],
+ dum->port_status[rhport]);
}
}
usbip_dbg_vhci_rh(" bye\n");
--
1.7.2.5


2011-06-13 21:47:54

by Németh Márton

[permalink] [raw]
Subject: Re: [PATCH 2/3] usbip: dump the port status difference

From: Márton Németh <[email protected]>

At the beginning of vhci_hub_control() function the port
status is saved to show what are the differences between the
previous and the new status. Change the dump function to
really show the differences in the status bit changes: put
a '+' sign before the symbolic name of a bit where a bit
was set, a '-' sign where the bit was cleared and a SPACE
where the bit was not changed. This is similar to the way
"diff -u" shows the changes and easy to understand.

Signed-off-by: Márton Németh <[email protected]>
---
drivers/staging/usbip/vhci_hcd.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index 512a97f..d3ce569 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -92,14 +92,22 @@ static const char * const bit_desc[] = {
"R31", /*31*/
};

-static void dump_port_status(u32 status)
+static void dump_port_status_diff(u32 prev_status, u32 new_status)
{
int i = 0;

- pr_debug("status %08x:", status);
+ pr_debug("status %08x -> %08x:", prev_status, new_status);
for (i = 0; i < 32; i++) {
- if (status & (1 << i))
- pr_debug(" %s", bit_desc[i]);
+ if (!(prev_status & (1 << i)) &&
+ new_status & (1 << i)) {
+ pr_debug(" +%s", bit_desc[i]);
+ } else if (prev_status & (1 << i) &&
+ !(new_status & (1 << i))) {
+ pr_debug(" -%s", bit_desc[i]);
+ } else if (prev_status & (1 << i) &&
+ new_status & (1 << i)) {
+ pr_debug(" %s", bit_desc[i]);
+ }
}
pr_debug("\n");
}
@@ -466,8 +474,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
pr_debug("port %d\n", rhport);
/* Only dump valid port status */
if (rhport >= 0) {
- dump_port_status(prev_port_status[rhport]);
- dump_port_status(dum->port_status[rhport]);
+ dump_port_status_diff(prev_port_status[rhport],
+ dum->port_status[rhport]);
}
}
usbip_dbg_vhci_rh(" bye\n");
--
1.7.2.5

2011-06-13 22:12:30

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 2/3] usbip: dump the port status difference

On Mon, 2011-06-13 at 23:30 +0200, Németh Márton wrote:
> From: Márton Németh <[email protected]>
>
> Change the dump function to
> really show the differences in the status bit changes
> +static void dump_port_status_diff(u32 prev_status, u32 new_status)
> {
> int i = 0;

> - pr_debug("status %08x:", status);
> + pr_debug("status %08x -> %08x:", prev_status, new_status);
> for (i = 0; i < 32; i++) {
> - if (status & (1 << i))
> - pr_debug(" %s", bit_desc[i]);
> + if (!(prev_status & (1 << i)) &&
> + new_status & (1 << i)) {
> + pr_debug(" +%s", bit_desc[i]);
> + } else if (prev_status & (1 << i) &&
> + !(new_status & (1 << i))) {
> + pr_debug(" -%s", bit_desc[i]);
> + } else if (prev_status & (1 << i) &&
> + new_status & (1 << i)) {
> + pr_debug(" %s", bit_desc[i]);
> + }
> }
> pr_debug("\n");

trivia:

I think the output isn't quite what you might expect.
It could be interleaved by pr_cont from a different
thread.

I think this might be a bit more readable as below and
this doesn't use implicit newlines by successive pr_<level>.

static void dump_port_status_diff(u32 old_status, u32 new_status)
{
int i = 0;
u32 bit = 1;

char change;
pr_debug("status old->new %08x -> %08x\n", old_status, new_status);
while (bit) {
u32 old = old_status & bit;
u32 new = new_status & bit;
char change;

if (!old && new)
change = '+';
else if (old && !new)
change = '-';
else
change = ' ';
if (old || new)
pr_debug(" %c%s\n", change, bit_desc[i]);
bit <<= 1;
i++;
}
}

I don't know if this is in any sort of fast-path or if
gcc will completely optimize this completely away if
pr_debug isn't declared, but maybe surround the function
implementation with

static void dump_port_status_diff(u32 prev_status, u32 new_status)
{
#ifdef DEBUG
...
#endif
}

2011-06-14 06:28:40

by Németh Márton

[permalink] [raw]
Subject: Re: [PATCH 2/3] usbip: dump the port status difference

From: Márton Németh <[email protected]>

At the beginning of vhci_hub_control() function the port
status is saved to show what are the differences between the
previous and the new status. Change the dump function to
really show the differences in the status bit changes: put
a '+' sign before the symbolic name of a bit where a bit
was set, a '-' sign where the bit was cleared and a SPACE
where the bit was not changed. This is similar to the way
"diff -u" shows the changes and easy to understand.

Signed-off-by: Márton Németh <[email protected]>
Cc: Joe Perches <[email protected]>
---
---
drivers/staging/usbip/vhci_hcd.c | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index 658c674..d3f11a3 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -92,14 +92,28 @@ static const char * const bit_desc[] = {
"R31", /*31*/
};

-static void dump_port_status(u32 status)
+static void dump_port_status_diff(u32 prev_status, u32 new_status)
{
int i = 0;
-
- pr_debug("status %08x:", status);
- for (i = 0; i < 32; i++) {
- if (status & (1 << i))
- pr_debug(" %s", bit_desc[i]);
+ u32 bit = 1;
+
+ pr_debug("status prev -> new: %08x -> %08x\n", prev_status, new_status);
+ while (bit) {
+ u32 prev = prev_status & bit;
+ u32 new = new_status & bit;
+ char change;
+
+ if (!prev && new)
+ change = '+';
+ else if (prev && !new)
+ change = '-';
+ else
+ change = ' ';
+
+ if (prev || new)
+ pr_debug(" %c%s\n", change, bit_desc[i]);
+ bit <<= 1;
+ i++;
}
pr_debug("\n");
}
@@ -466,8 +480,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
pr_debug("port %d\n", rhport);
/* Only dump valid port status */
if (rhport >= 0) {
- dump_port_status(prev_port_status[rhport]);
- dump_port_status(dum->port_status[rhport]);
+ dump_port_status_diff(prev_port_status[rhport],
+ dum->port_status[rhport]);
}
}
usbip_dbg_vhci_rh(" bye\n");
--
1.7.2.5