DPDK patches and discussions
 help / color / mirror / Atom feed
From: bugzilla@dpdk.org
To: dev@dpdk.org
Subject: [dpdk-dev] [Bug 435] Proposed improvement to non-interactive loop timing
Date: Sat, 04 Apr 2020 01:47:54 +0000	[thread overview]
Message-ID: <bug-435-3@http.bugs.dpdk.org/> (raw)

https://bugs.dpdk.org/show_bug.cgi?id=435

            Bug ID: 435
           Summary: Proposed improvement to non-interactive loop timing
           Product: DPDK
           Version: 20.02
          Hardware: All
                OS: Linux
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: Normal
         Component: testpmd
          Assignee: dev@dpdk.org
          Reporter: cfb@hpe.com
  Target Milestone: ---

When running testpmd in non-interactive mode, and using a stats period value,
the current loop delay is less than ideal.

The current code:

                if (stats_period != 0) {
                        uint64_t prev_time = 0, cur_time, diff_time = 0;
                        uint64_t timer_period;

                        /* Convert to number of cycles */
                        timer_period = stats_period * rte_get_timer_hz();

                        while (f_quit == 0) {
                                cur_time = rte_get_timer_cycles();
                                diff_time += cur_time - prev_time;

                                if (diff_time >= timer_period) {
                                        print_stats();
                                        /* Reset the timer */
                                        diff_time = 0;
                                }
                                /* Sleep to avoid unnecessary checks */
                                prev_time = cur_time;
                                sleep(1);
                        }
                }

Compares the difference in time, and if the time has not expired, will sleep
for one second before checking again. The problem with this is when the
difference is close, but not at the timer period. This will result in an
additional second being added to the update period. (e.g. a one second period
becomes almost 2 seconds.)

Ideally, the sleep value would be based on the amount of time left (cur_time -
prev_time).

Using usleep(), it is possible to create delays that are closer to the desired
delay.

The following code appears to work for me, and takes into account the time
required for the print_stats() call, but there may be a better solution:

                if (stats_period != 0) {
                        uint64_t cur_time, ticks_per_usec;
                        uint64_t timer_period;

                        /* Convert to number of usecs */
                        timer_period = stats_period * 1000000;
                        /* How many CPU ticks per usec */
                        ticks_per_usec = rte_get_timer_hz() / 1000000;

                        while (f_quit == 0) {
                                /* Get the current CPU ticks */
                                cur_time = rte_get_timer_cycles();
                                print_stats();
                                /* Get the tick count again and sleep for the
difference */
                                usleep(timer_period - (rte_get_timer_cycles() -
cur_time) / ticks_per_usec);
                        }
                }

-- 
You are receiving this mail because:
You are the assignee for the bug.

             reply	other threads:[~2020-04-04  1:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-04  1:47 bugzilla [this message]
2021-01-25  5:55 ` bugzilla

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=bug-435-3@http.bugs.dpdk.org/ \
    --to=bugzilla@dpdk.org \
    --cc=dev@dpdk.org \
    /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).