diff mbox

[v4,3/3] net/xen-netback: Don't mix hexa and decimal with 0x in the printf format

Message ID 1434481848-26387-4-git-send-email-julien.grall@citrix.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Julien Grall June 16, 2015, 7:10 p.m. UTC
Append 0x to all %x in order to avoid while reading when there is other
decimal value in the log.

Also replace some of the hexadecimal print to decimal to uniformize the
format with netfront.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: netdev@vger.kernel.org

---
    Changes in v4:
        - Patch added
---
 drivers/net/xen-netback/netback.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Sergei Shtylyov June 16, 2015, 8:07 p.m. UTC | #1
Hello.

On 06/16/2015 10:10 PM, Julien Grall wrote:

> Append 0x to all %x in order to avoid while reading when there is other
> decimal value in the log.

> Also replace some of the hexadecimal print to decimal to uniformize the
> format with netfront.

> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: netdev@vger.kernel.org

> ---
>      Changes in v4:
>          - Patch added
> ---
>   drivers/net/xen-netback/netback.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)

> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index ba3ae30..11bd9d8 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
[...]
> @@ -874,7 +874,7 @@ static inline void xenvif_grant_handle_set(struct xenvif_queue *queue,
>   	if (unlikely(queue->grant_tx_handle[pending_idx] !=
>   		     NETBACK_INVALID_HANDLE)) {
>   		netdev_err(queue->vif->dev,
> -			   "Trying to overwrite active handle! pending_idx: %x\n",
> +			   "Trying to overwrite active handle! pending_idx: 0x%x\n",

    Using "%#x" is shorter ind does the same.

>   			   pending_idx);
>   		BUG();
>   	}
> @@ -887,7 +887,7 @@ static inline void xenvif_grant_handle_reset(struct xenvif_queue *queue,
>   	if (unlikely(queue->grant_tx_handle[pending_idx] ==
>   		     NETBACK_INVALID_HANDLE)) {
>   		netdev_err(queue->vif->dev,
> -			   "Trying to unmap invalid handle! pending_idx: %x\n",
> +			   "Trying to unmap invalid handle! pending_idx: 0x%x\n",

    Same here.

[...]
> @@ -1731,7 +1731,7 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx)
>   				&queue->mmap_pages[pending_idx], 1);
>   	if (ret) {
>   		netdev_err(queue->vif->dev,
> -			   "Unmap fail: ret: %d pending_idx: %d host_addr: %llx handle: %x status: %d\n",
> +			   "Unmap fail: ret: %d pending_idx: %d host_addr: %llx handle: 0x%x status: %d\n",

    And here.

[...]

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches June 16, 2015, 10:09 p.m. UTC | #2
On Tue, 2015-06-16 at 23:07 +0300, Sergei Shtylyov wrote:
> On 06/16/2015 10:10 PM, Julien Grall wrote:
> > Append 0x to all %x in order to avoid while reading when there is other
> > decimal value in the log.
[]
> > @@ -874,7 +874,7 @@ static inline void xenvif_grant_handle_set(struct xenvif_queue *queue,
> >   	if (unlikely(queue->grant_tx_handle[pending_idx] !=
> >   		     NETBACK_INVALID_HANDLE)) {
> >   		netdev_err(queue->vif->dev,
> > -			   "Trying to overwrite active handle! pending_idx: %x\n",
> > +			   "Trying to overwrite active handle! pending_idx: 0x%x\n",
> 
>     Using "%#x" is shorter ind does the same.

That's true, but it's also far less common.

$ git grep -E "%#[\*\d\.]*x" | wc -l
1419
$ git grep "0x%" | wc -l
29844


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sergei Shtylyov June 16, 2015, 10:29 p.m. UTC | #3
Hello.

On 06/17/2015 01:09 AM, Joe Perches wrote:

>>> Append 0x to all %x in order to avoid while reading when there is other
>>> decimal value in the log.

> []

>>> @@ -874,7 +874,7 @@ static inline void xenvif_grant_handle_set(struct xenvif_queue *queue,
>>>    	if (unlikely(queue->grant_tx_handle[pending_idx] !=
>>>    		     NETBACK_INVALID_HANDLE)) {
>>>    		netdev_err(queue->vif->dev,
>>> -			   "Trying to overwrite active handle! pending_idx: %x\n",
>>> +			   "Trying to overwrite active handle! pending_idx: 0x%x\n",

>>      Using "%#x" is shorter ind does the same.

> That's true, but it's also far less common.

    Which is a pity... People just don't know the format specifiers well 
enough. :-(

> $ git grep -E "%#[\*\d\.]*x" | wc -l
> 1419
> $ git grep "0x%" | wc -l
> 29844

    Which means 29 KB could theoretically be saved on allyesconfig build. :-)
(Actually less since the width specifiers will likely need to be fixed where 
present.)

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches June 16, 2015, 11:55 p.m. UTC | #4
On Wed, 2015-06-17 at 01:29 +0300, Sergei Shtylyov wrote:
> Hello.
> 
> On 06/17/2015 01:09 AM, Joe Perches wrote:
> 
> >>> Append 0x to all %x in order to avoid while reading when there is other
> >>> decimal value in the log.
> 
> > []
> 
> >>> @@ -874,7 +874,7 @@ static inline void xenvif_grant_handle_set(struct xenvif_queue *queue,
> >>>    	if (unlikely(queue->grant_tx_handle[pending_idx] !=
> >>>    		     NETBACK_INVALID_HANDLE)) {
> >>>    		netdev_err(queue->vif->dev,
> >>> -			   "Trying to overwrite active handle! pending_idx: %x\n",
> >>> +			   "Trying to overwrite active handle! pending_idx: 0x%x\n",
> 
> >>      Using "%#x" is shorter ind does the same.
> 
> > That's true, but it's also far less common.
> 
>     Which is a pity... People just don't know the format specifiers well 
> enough. :-(
> 
> > $ git grep -E "%#[\*\d\.]*x" | wc -l
> > 1419
> > $ git grep "0x%" | wc -l
> > 29844
> 
>     Which means 29 KB could theoretically be saved on allyesconfig build. :-)
> (Actually less since the width specifiers will likely need to be fixed where 
> present.)

And less than that because a lot of these are in
arch specific code.

0x%x is easier and simpler to visualize than %#x.

But you are welcome to try to make the kernel smaller.
One byte at a time.

There are ~14.5k uses of 0x%x in ~10.5k lines and
~2600 files that would be changed.

That's a lot of lines and a lot of patches.

$ git grep --name-only "0x%x" | xargs sed -i -e 's/0x%x/%#x/g'
$ git diff | wc
  96250  415388 3949872

Only a 4M patch.

The pretty common (~5k) "0x%08x" would be "%#010x"
so that doesn't save any space.

but this one's a ~3.5M patch.

$ git grep --name-only -P "0x%\d+\w*x" | xargs perl -p -i -e 's/0x%0(\d+)(\w*)x/"\%#0" . eval($1 + 2) . "$2x"/eg'
$ git diff | wc
  80857  344565 3306990

enjoy...

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ian Campbell June 17, 2015, 8:54 a.m. UTC | #5
On Tue, 2015-06-16 at 16:55 -0700, Joe Perches wrote:
> 0x%x is easier and simpler to visualize than %#x.

They also don't produce the same output if the value is 0 (0x%x=>0x0, %
#x=>0), which can matter if you are trying to line up a column or
whatever.

Ian.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jan Beulich June 17, 2015, 9:13 a.m. UTC | #6
>>> On 16.06.15 at 21:10, <julien.grall@citrix.com> wrote:
> Append 0x to all %x in order to avoid while reading when there is other
> decimal value in the log.

To save on the space taken by the format strings you should prefer
%#x over 0x%x (like we do in the hypervisor).

Jan

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ian Campbell June 17, 2015, 9:25 a.m. UTC | #7
On Tue, 2015-06-16 at 20:10 +0100, Julien Grall wrote:
> Append 0x to all %x in order to avoid while reading when there is other
> decimal value in the log.
> 
> Also replace some of the hexadecimal print to decimal to uniformize the
> format with netfront.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: netdev@vger.kernel.org

You meant s/Append/Prepend/, nonetheless:

Acked-by: Ian Campbell <ian.campbell@citrix.com>


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Julien Grall June 17, 2015, 9:30 a.m. UTC | #8
Hi Ian,

On 17/06/2015 10:25, Ian Campbell wrote:
> On Tue, 2015-06-16 at 20:10 +0100, Julien Grall wrote:
>> Append 0x to all %x in order to avoid while reading when there is other
>> decimal value in the log.
>>
>> Also replace some of the hexadecimal print to decimal to uniformize the
>> format with netfront.
>>
>> Signed-off-by: Julien Grall <julien.grall@citrix.com>
>> Cc: Wei Liu <wei.liu2@citrix.com>
>> Cc: Ian Campbell <ian.campbell@citrix.com>
>> Cc: netdev@vger.kernel.org
>
> You meant s/Append/Prepend/, nonetheless:

I noticed a missing word after "avoid" in the commit message too. I will 
update to:

"Prepend 0x to all %x in order to avoid confusion while reading when 
there is other decimal value in the log.

[...]".

>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

I see different opinion on whether using 0x% or %#. As I plan to resend 
a version with the commit message update, shall I use %#?

Regards,
Ian Campbell June 17, 2015, 9:37 a.m. UTC | #9
On Wed, 2015-06-17 at 10:30 +0100, Julien Grall wrote:
> I see different opinion on whether using 0x% or %#. As I plan to resend 
> a version with the commit message update, shall I use %#?

I think it's mostly pointless bike-shedding over a saving measured in
single digit bytes, use whichever you like.

Ian.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller June 21, 2015, 4:41 p.m. UTC | #10
From: Julien Grall <julien.grall@citrix.com>
Date: Tue, 16 Jun 2015 20:10:48 +0100

> Append 0x to all %x in order to avoid while reading when there is other
> decimal value in the log.
> 
> Also replace some of the hexadecimal print to decimal to uniformize the
> format with netfront.
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
diff mbox

Patch

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index ba3ae30..11bd9d8 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -748,7 +748,7 @@  static int xenvif_count_requests(struct xenvif_queue *queue,
 		slots++;
 
 		if (unlikely((txp->offset + txp->size) > PAGE_SIZE)) {
-			netdev_err(queue->vif->dev, "Cross page boundary, txp->offset: %x, size: %u\n",
+			netdev_err(queue->vif->dev, "Cross page boundary, txp->offset: %u, size: %u\n",
 				 txp->offset, txp->size);
 			xenvif_fatal_tx_err(queue->vif);
 			return -EINVAL;
@@ -874,7 +874,7 @@  static inline void xenvif_grant_handle_set(struct xenvif_queue *queue,
 	if (unlikely(queue->grant_tx_handle[pending_idx] !=
 		     NETBACK_INVALID_HANDLE)) {
 		netdev_err(queue->vif->dev,
-			   "Trying to overwrite active handle! pending_idx: %x\n",
+			   "Trying to overwrite active handle! pending_idx: 0x%x\n",
 			   pending_idx);
 		BUG();
 	}
@@ -887,7 +887,7 @@  static inline void xenvif_grant_handle_reset(struct xenvif_queue *queue,
 	if (unlikely(queue->grant_tx_handle[pending_idx] ==
 		     NETBACK_INVALID_HANDLE)) {
 		netdev_err(queue->vif->dev,
-			   "Trying to unmap invalid handle! pending_idx: %x\n",
+			   "Trying to unmap invalid handle! pending_idx: 0x%x\n",
 			   pending_idx);
 		BUG();
 	}
@@ -1243,7 +1243,7 @@  static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 		/* No crossing a page as the payload mustn't fragment. */
 		if (unlikely((txreq.offset + txreq.size) > PAGE_SIZE)) {
 			netdev_err(queue->vif->dev,
-				   "txreq.offset: %x, size: %u, end: %lu\n",
+				   "txreq.offset: %u, size: %u, end: %lu\n",
 				   txreq.offset, txreq.size,
 				   (unsigned long)(txreq.offset&~PAGE_MASK) + txreq.size);
 			xenvif_fatal_tx_err(queue->vif);
@@ -1593,12 +1593,12 @@  static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)
 					queue->pages_to_unmap,
 					gop - queue->tx_unmap_ops);
 		if (ret) {
-			netdev_err(queue->vif->dev, "Unmap fail: nr_ops %tx ret %d\n",
+			netdev_err(queue->vif->dev, "Unmap fail: nr_ops %tu ret %d\n",
 				   gop - queue->tx_unmap_ops, ret);
 			for (i = 0; i < gop - queue->tx_unmap_ops; ++i) {
 				if (gop[i].status != GNTST_okay)
 					netdev_err(queue->vif->dev,
-						   " host_addr: %llx handle: %x status: %d\n",
+						   " host_addr: 0x%llx handle: 0x%x status: %d\n",
 						   gop[i].host_addr,
 						   gop[i].handle,
 						   gop[i].status);
@@ -1731,7 +1731,7 @@  void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx)
 				&queue->mmap_pages[pending_idx], 1);
 	if (ret) {
 		netdev_err(queue->vif->dev,
-			   "Unmap fail: ret: %d pending_idx: %d host_addr: %llx handle: %x status: %d\n",
+			   "Unmap fail: ret: %d pending_idx: %d host_addr: %llx handle: 0x%x status: %d\n",
 			   ret,
 			   pending_idx,
 			   tx_unmap_op.host_addr,