public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Roland Dreier <rdreier@cisco.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: kfifo:  possible weird violation of what should be invariant
Date: Wed, 17 Mar 2010 07:22:28 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.2.00.1003170720060.5960@localhost> (raw)
In-Reply-To: <adamxy79a5u.fsf@roland-alpha.cisco.com>

On Tue, 16 Mar 2010, Roland Dreier wrote:

>  >   sure, the code seems to work, but allowing the internal values of a
>  > kfifo to contain invalid values on a regular basis would seem to make
>  > a mess of, say, tracing or debugging.  making sure that offset values
>  > actually lie within their valid range would seem to be one of those
>  > ASSERT() things that should always be true, should it not?  is there a
>  > reason the design is like this?
>
> Actually I believe having the values be free-running without
> clamping them makes the code much simpler -- the reason being that
> you preserve the invariant of "in" always being ahead of "out".  If
> you reduce the pointers modulo the size, then you end up having a
> lot of code that has two cases: one to handle "in > out", and one to
> handle "in < out because in has wrapped and out hasn't yet".

  yes, i see your point.  so, as i read it, the internal kfifo "in"
and "out" pointers are *never* actually normalized modulo the buffer
size, which means that, at any time, you can easily check how much
*total* data has gone through the kfifo.  potentially useful.  perhaps
there should be a comment or note to that effect stuffed in there
somewhere as some kernel programmers might find that handy, who knows?

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
========================================================================

      reply	other threads:[~2010-03-17 11:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-15 21:22 kfifo: possible weird violation of what should be invariant Robert P. J. Day
2010-03-16 22:25 ` Roland Dreier
2010-03-17 11:22   ` Robert P. J. Day [this message]

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=alpine.LFD.2.00.1003170720060.5960@localhost \
    --to=rpjday@crashcourse.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.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