DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Tyler Retzlaff <roretzla@linux.microsoft.com>
Cc: <dev@dpdk.org>, Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>
Subject: Re: [PATCH v2] eal/windows: resolve conversion and truncation warnings
Date: Thu, 7 Mar 2024 20:53:49 +0000	[thread overview]
Message-ID: <ZeopXXpsej2KPaiq@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <1709836482-22576-1-git-send-email-roretzla@linux.microsoft.com>

On Thu, Mar 07, 2024 at 10:34:42AM -0800, Tyler Retzlaff wrote:
> * Initialize const int NS_PER_SEC with an integer literal instead of
>   double thereby avoiding implicit conversion from double to int.
> 
> * Cast the result of the expression assigned to timespec.tv_nsec to long.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
> 
> v2:
>   * update commit message to correct misspelled timspec -> timespec,
>     remove remarks about casting to long they were unnecessary.
> 
>  lib/eal/windows/include/rte_os_shim.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
> index eda8113..19b12e9 100644
> --- a/lib/eal/windows/include/rte_os_shim.h
> +++ b/lib/eal/windows/include/rte_os_shim.h
> @@ -87,7 +87,7 @@
>  static inline int
>  rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
>  {
> -	const int NS_PER_SEC = 1E9;
> +	const int NS_PER_SEC = 1000000000;

Just for readability, and the immediate visibility of errors, could this be
rewritten as (1000 * 1000 * 1000). That avoids us having to count the zeros
to know that the number is correct.

BTW: is "int" still the best type to use for this value? Would it be better
as a #define?

/Bruce

>  	LARGE_INTEGER pf, pc;
>  	LONGLONG nsec;
>  
> @@ -102,7 +102,7 @@
>  
>  		nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
>  		tp->tv_sec = nsec / NS_PER_SEC;
> -		tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
> +		tp->tv_nsec = (long)(nsec - tp->tv_sec * NS_PER_SEC);
>  		return 0;
>  	default:
>  		return -1;
> -- 
> 1.8.3.1
> 

  reply	other threads:[~2024-03-07 20:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02 20:48 [PATCH] " Tyler Retzlaff
2023-08-02 22:29 ` Dmitry Kozlyuk
2023-08-02 22:41   ` Tyler Retzlaff
2023-08-02 23:44     ` Dmitry Kozlyuk
2023-08-03  0:30       ` Tyler Retzlaff
2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
2024-03-07 20:53   ` Bruce Richardson [this message]
2024-03-07 20:57     ` Tyler Retzlaff

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=ZeopXXpsej2KPaiq@bricha3-mobl1.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=pallavi.kadam@intel.com \
    --cc=roretzla@linux.microsoft.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;
as well as URLs for NNTP newsgroup(s).