From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 38A34A0562; Sat, 4 Apr 2020 03:47:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9C6D82B89; Sat, 4 Apr 2020 03:47:56 +0200 (CEST) Received: from inbox.dpdk.org (xvm-172-178.dc0.ghst.net [95.142.172.178]) by dpdk.org (Postfix) with ESMTP id 016F13B5 for ; Sat, 4 Apr 2020 03:47:54 +0200 (CEST) Received: by inbox.dpdk.org (Postfix, from userid 33) id C2B6AA057B; Sat, 4 Apr 2020 03:47:54 +0200 (CEST) From: bugzilla@dpdk.org To: dev@dpdk.org Date: Sat, 04 Apr 2020 01:47:54 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: DPDK X-Bugzilla-Component: testpmd X-Bugzilla-Version: 20.02 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: cfb@hpe.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: Normal X-Bugzilla-Assigned-To: dev@dpdk.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://bugs.dpdk.org/ Auto-Submitted: auto-generated X-Auto-Response-Suppress: All MIME-Version: 1.0 Subject: [dpdk-dev] [Bug 435] Proposed improvement to non-interactive loop timing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" https://bugs.dpdk.org/show_bug.cgi?id=3D435 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 valu= e, the current loop delay is less than ideal. The current code: if (stats_period !=3D 0) { uint64_t prev_time =3D 0, cur_time, diff_time =3D 0; uint64_t timer_period; /* Convert to number of cycles */ timer_period =3D stats_period * rte_get_timer_hz(); while (f_quit =3D=3D 0) { cur_time =3D rte_get_timer_cycles(); diff_time +=3D cur_time - prev_time; if (diff_time >=3D timer_period) { print_stats(); /* Reset the timer */ diff_time =3D 0; } /* Sleep to avoid unnecessary checks */ prev_time =3D 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 peri= od becomes almost 2 seconds.) Ideally, the sleep value would be based on the amount of time left (cur_tim= e - prev_time). Using usleep(), it is possible to create delays that are closer to the desi= red 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 !=3D 0) { uint64_t cur_time, ticks_per_usec; uint64_t timer_period; /* Convert to number of usecs */ timer_period =3D stats_period * 1000000; /* How many CPU ticks per usec */ ticks_per_usec =3D rte_get_timer_hz() / 1000000; while (f_quit =3D=3D 0) { /* Get the current CPU ticks */ cur_time =3D rte_get_timer_cycles(); print_stats(); /* Get the tick count again and sleep for t= he difference */ usleep(timer_period - (rte_get_timer_cycles= () - cur_time) / ticks_per_usec); } } --=20 You are receiving this mail because: You are the assignee for the bug.=