DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Thomas Monjalon" <thomas@monjalon.net>,
	"Min Hu (Connor)" <humin29@huawei.com>
Cc: <dev@dpdk.org>, <ferruh.yigit@intel.com>, <skori@marvell.com>,
	<jerinj@marvell.com>
Subject: Re: [dpdk-dev] [PATCH v2] eal: fix use wrong time API
Date: Wed, 5 May 2021 09:08:04 +0200	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35C61749@smartserver.smartshare.dk> (raw)
In-Reply-To: <15286141.XL2fGeQaG1@thomas>

> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Wednesday, May 5, 2021 8:51 AM
> 
> 05/05/2021 08:26, Morten Brørup:
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas
> Monjalon
> > > Sent: Wednesday, May 5, 2021 8:14 AM
> > >
> > > 04/05/2021 21:12, Morten Brørup:
> > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas
> > > Monjalon
> > > > > Sent: Tuesday, May 4, 2021 6:50 PM
> > > > >
> > > > > 29/04/2021 04:10, Min Hu (Connor):
> > > > > > Currently, the mp uses gettimeofday() API to get the time,
> and
> > > used
> > > > > as
> > > > > > timeout parameter.
> > > > > >
> > > > > > But the time which gets from gettimeofday() API isn't
> > > monotonically
> > > > > > increasing. The process may fail if the system time is
> changed.
> > > > > >
> > > > > > This fixes it by using clock_gettime() API with monotonic
> > > > > attribution.
> > > > > >
> > > > > > Fixes: 783b6e54971d ("eal: add synchronous multi-process
> > > > > communication")
> > > > > > Fixes: f05e26051c15 ("eal: add IPC asynchronous request")
> > > > > > Cc: stable@dpdk.org
> > > > > >
> > > > > > Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> > > > > > Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> > > > > > ---
> > > > > [...]
> > > > > > --- a/lib/eal/common/eal_common_proc.c	
> > > > > > +++ b/lib/eal/common/eal_common_proc.c
> > > > > > -	if (gettimeofday(&now, NULL) < 0) {
> > > > > > -		RTE_LOG(ERR, EAL, "Cannot get current time\n");
> > > > > > -		goto no_trigger;
> > > > > > -	}
> > > > > > -	ts_now.tv_nsec = now.tv_usec * 1000;
> > > > > > -	ts_now.tv_sec = now.tv_sec;
> > > > > > +	clock_gettime(CLOCK_MONOTONIC, &ts_now);
> > > > >
> > > > > Why not testing the return value?
> > > >
> > > > Because it is guaranteed not to fail. Ref:
> > > > https://linux.die.net/man/3/clock_gettime
> > > > https://www.freebsd.org/cgi/man.cgi?query=clock_gettime
> > >
> > > I see "return 0 for success, or -1 for failure".
> > > Where is it said it cannot fail?
> >
> > I'm sorry about being unclear. Referring to the "Errors" chapter in
> the function's man page, this function call is guaranteed not to fail
> with these parameters. So there is no need to check the return value.
> 
> I don't agree.
> Especially for this error:
> "The clk_id specified is not supported on this system."
> How can you be sure it is always supported for any system
> we try to run this code now and in future experiments?
> 

I referred to both Linux and BSD man pages because they say that it is defined there. This should cover current supported systems, excl. Windows, which doesn't have gettimeofday() or clock_gettime() anyway.

However, for future operating systems that might be supported by DPDK, you are correct that CLOCK_MONOTONIC is optional.
Ref: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html

This can be fixed by adding:
#if !defined(CLOCK_MONOTONIC)
#error CLOCK_MONOTONIC is not defined.
#endif

If we only check the return value at runtime, the function would fail every time on a system without CLOCK_MONOTONIC, and eal_common_proc.c would need to be fixed anyway. It's better to catch at compile time.


  reply	other threads:[~2021-05-05  7:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  8:12 [dpdk-dev] [PATCH] " Min Hu (Connor)
2021-04-28  9:24 ` Morten Brørup
2021-04-28 10:36   ` fengchengwen
2021-04-28 10:59     ` Morten Brørup
2021-04-29  2:12       ` Min Hu (Connor)
2021-04-29  2:10 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
2021-04-29  7:12   ` Morten Brørup
2021-05-04 16:49   ` Thomas Monjalon
2021-05-04 19:12     ` Morten Brørup
2021-05-05  6:14       ` Thomas Monjalon
2021-05-05  6:26         ` Morten Brørup
2021-05-05  6:51           ` Thomas Monjalon
2021-05-05  7:08             ` Morten Brørup [this message]
2021-05-05  3:43   ` [dpdk-dev] [PATCH v3] " Chengwen Feng
2021-05-11  7:36     ` Thomas Monjalon
2021-05-11 10:49       ` fengchengwen
2021-05-11 10:41 ` [dpdk-dev] [PATCH v4] " Chengwen Feng
2021-05-12 14:52   ` Thomas Monjalon

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=98CBD80474FA8B44BF855DF32C47DC35C61749@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=humin29@huawei.com \
    --cc=jerinj@marvell.com \
    --cc=skori@marvell.com \
    --cc=thomas@monjalon.net \
    /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).