mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Thorsten Blum' <thorsten.blum@toblux.com>,
	"Russell King (Oracle)" <linux@armlinux.org.uk>
Cc: "marcin.s.wojtas@gmail.com" <marcin.s.wojtas@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH net-next] net: mvpp2: Improve data types and use min()
Date: Wed, 17 Jul 2024 12:30:35 +0000	[thread overview]
Message-ID: <3f8d78d6b539465c8040888409eb35a7@AcuMS.aculab.com> (raw)
In-Reply-To: <D2AAC5AF-59D0-4985-A3DD-EC9E72324CD7@toblux.com>

From: Thorsten Blum
> Sent: 16 July 2024 18:49
> 
> On 15. Jul 2024, at 17:44, Russell King (Oracle) <linux@armlinux.org.uk> wrote:
> > On Thu, Jul 11, 2024 at 05:47:43PM +0200, Thorsten Blum wrote:
> >> Change the data type of the variable freq in mvpp2_rx_time_coal_set()
> >> and mvpp2_tx_time_coal_set() to u32 because port->priv->tclk also has
> >> the data type u32.
> >>
> >> Change the data type of the function parameter clk_hz in
> >> mvpp2_usec_to_cycles() and mvpp2_cycles_to_usec() to u32 accordingly
> >> and remove the following Coccinelle/coccicheck warning reported by
> >> do_div.cocci:
> >>
> >>  WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead
> >>
> >> Use min() to simplify the code and improve its readability.
> >>
> >> Compile-tested only.
> >>
> >> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> >
> > I'm still on holiday, but it's a wet day today. Don't expect replies
> > from me to be regular.
> >
> > I don't think this is a good idea.
> >
> > priv->tclk comes from clk_get_rate() which returns an unsigned long.
> > tclk should _also_ be an unsigned long, not a u32, so that the range
> > of values clk_get_rate() returns can be represented without being
> > truncted.
> >
> > Thus the use of unsigned long elsewhere where tclk is passed into is
> > actually correct.
> 
> I don't think tclk should be an unsigned long.
> 
> In [1] Eric Dumazet wrote:
> 
>   "This is silly, clk_hz fits in a u32, why pretends it is 64bit ?"
> 
> and all functions in mvpp2_main.c (mvpp2_write(), do_div(),
> device_property_read_u32(), and mvpp22_gop_fca_set_timer()), which have
> tclk as a direct or indirect argument, assume tclk is a u32.
> 
> Although mvpp2_cycles_to_usec() suggests it can be called with an
> unsigned long clk_hz, do_div() then immediately casts it to a u32
> anyway.
> 
> Yes, the function clk_get_rate() returns an unsigned long according to
> its signature, but tclk is always used as a u32 afterwards.
> 
> I'm not familiar with the hardware, but I guess the clock rate always
> fits into 32 bits (just like Eric wrote)?

'long' can't be correct - it is 32bit on 32bit systems.
They are just as likely to have a clock that is faster than 4GHz than a 64bit system.

The type should either be u64 or u32 (or just unsigned int - Linux isn't going to
get far if int is 16 bits).
This is true of a lot of the uses of 'long'.

There are cases where 'long' will generate better code than 'int' on 64bit systems.
In particular it can save sign/zero extension (and maybe masking) of function
parameters and results.
But that is only likely to matter on very hot paths - and particularly for array indexes.
(OTOH the masking for char/short is likely to be really horrid on anything except x86.)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


      reply	other threads:[~2024-07-17 12:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11 15:47 Thorsten Blum
2024-07-12 18:25 ` Simon Horman
2024-07-13 22:50 ` patchwork-bot+netdevbpf
2024-07-15 15:44 ` Russell King (Oracle)
2024-07-15 16:07   ` Jakub Kicinski
2024-07-15 18:39   ` Simon Horman
2024-07-16 17:48   ` Thorsten Blum
2024-07-17 12:30     ` David Laight [this message]

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=3f8d78d6b539465c8040888409eb35a7@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=marcin.s.wojtas@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=thorsten.blum@toblux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®