Linux Advanced Routing and Traffic Control list
 help / color / mirror / Atom feed
From: devik <devik@cdi.cz>
To: lartc@vger.kernel.org
Subject: [LARTC] PSCHED_TDIFF_SAFE bug in TC (QoS) subsystem
Date: Fri, 30 Nov 2001 15:21:48 +0000	[thread overview]
Message-ID: <marc-lartc-100713544215409@msgid-missing> (raw)

Hi all,

during developement of HTB I find bug in macro PSCHED_TDIFF_SAFE
in file include/net/pkt_sched.h. The bug causes minor errors in
TBF queuing discipline and possibly in CBQ. Solution is bellow.

Problem:

The psched_time_t is u64 (for PSCHED_CLOCK_SOURCE!=PSCHED_GETTIMEOFDAY).
The PSCHED_TDIFF_SAFE macro is meant as way to compute difference
between two such timestamps and provide upper bound for result.
Here is the declaration:
#define PSCHED_TDIFF_SAFE(tv1, tv2, bound, guard) ({ \
           long __delta = (tv1) - (tv2); \
           if ( __delta > (bound)) {  __delta = (bound); guard; } \
           __delta; \ })

tv1 is assumed to be greater than tv2. This works well is difference
between tv1 and tv1 <= 0xffffffff but ONLY IF "bound" argument is
unsigned. If you use signed bound whole function will start to behave
very wildly (I was ran into it infortunately).

Impact:

Moreover even if "bound" is unsigned then each 84 minutes (when
difference goes over 0xffffffff) the result is smaller than "bound"
for interval controled by "bound"'s value.

TBF uses it exactly in such way and if TBF class is idle for
84 minutes and then packet arrives it will be delayed more than
neccessary (thus introducing delay).

The error is dependent on "burst" parameter and for 1kbps rate
and 400k burst it is 10%.
The more sofisticated qdisc can rely even more on correct
PSCHED_TDIFF_SAFE behaviuor and here the error could be more
dramatic.

Solution:

Change "long" to "long long" or s32 (if does it exists). It will
introduce minor CPU penalty on 32bit systems but the result will
be correct.

Notes:

All macros PSCHED_XXX seems to assume that there can't be difference
larger than u32 range. Unfortunately author (ANK?) itself uses the
macros at places where the difference IS larger.

I hope in author's comments on this problem.

best regards,
Martin Devera aka devik


_______________________________________________
LARTC mailing list / LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://ds9a.nl/2.4Routing/

                 reply	other threads:[~2001-11-30 15:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=marc-lartc-100713544215409@msgid-missing \
    --to=devik@cdi.cz \
    --cc=lartc@vger.kernel.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