From: Andrew Morton <akpm@linux-foundation.org>
To: "Kuan Luo" <kluo@nvidia.com>
Cc: <linux-kernel@vger.kernel.org>, <jeff@garzik.org>,
"Peer Chen" <pchen@nvidia.com>
Subject: Re: [PATCH] ata: Add the SW NCQ support to sata_nv for MCP51/MCP55/MCP61
Date: Wed, 27 Jun 2007 02:21:14 -0700 [thread overview]
Message-ID: <20070627022114.455bc0d6.akpm@linux-foundation.org> (raw)
In-Reply-To: <15F501D1A78BD343BE8F4D8DB854566B059FE157@hkemmail01.nvidia.com>
On Wed, 27 Jun 2007 17:09:29 +0800 "Kuan Luo" <kluo@nvidia.com> wrote:
> > +static void nv_swncq_qc_to_dq(struct ata_port *ap, struct
> ata_queued_cmd *qc)
> > +{
> > + struct nv_swncq_port_priv *pp = ap->private_data;
> > + defer_queue_t *dq = &pp->defer_queue;
> > +
> > + /* queue is full */
> > + WARN_ON((dq->rear + 1) % (ATA_MAX_QUEUE + 1) == dq->front);
>
> >This is peculiar. The array is sized ATA_MAX_QUEUE+1 (ie: 33) and the
> code
> >uses ATA_MAX_QUEUE+1 everywhere.
>
> >It looks to me like the ata code was designed to queue up to 32
> elements
> >and all this code has taken that to 33. What exactly is going on here?
>
>
> The code is designed to contain 32 elements. But the position of rear
> doesn't point to
> a valid element to check whether the queue is full or null. If front ==
> rear , queue is null.
> if (rear + 1) % (ATA_MAX_QUEUE + 1) == front, queue is full.
> So the value of the array is 32 + 1.
that's the wrong way of doing a circular buffer..
It's better to allow the head and tail indices to wrap all the way through
0xffffffff and only mask them when they are actually used for subscripting.
That way:
add:
array[head++ & (ATA_MAX_QUEUE-1)] = item;
remove:
item = array[tail++ & (ATA_MAX_QUEUE-1)];
full:
head - tail == ATA_MAX_QUEUE
empty:
head == tail
number of items:
head - tail
This requires that the array size be a power of two.
next prev parent reply other threads:[~2007-06-27 9:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-27 3:04 [PATCH] ata: Add the SW NCQ support to sata_nv for MCP51/MCP55/MCP61 kuan luo
2007-06-27 5:26 ` Andrew Morton
2007-06-27 9:09 ` Kuan Luo
2007-06-27 9:21 ` Andrew Morton [this message]
2007-06-27 10:17 ` Kuan Luo
[not found] <fa.5TBvnXzjCgAIfcuKOLBWeXi+y5I@ifi.uio.no>
2007-06-27 5:06 ` Robert Hancock
2007-06-27 8:15 ` Peer Chen
2007-06-27 8:34 ` Jeff Garzik
2007-06-27 16:09 ` Prakash Punnoor
-- strict thread matches above, loose matches on Subject: below --
2007-06-27 10:51 Zoltan Boszormenyi
2007-07-03 22:31 ` Zoltan Boszormenyi
2007-07-05 18:53 ` Bill Davidsen
2007-07-06 8:31 kuan luo
2007-07-07 7:33 ` Zoltan Boszormenyi
2007-07-09 2:48 ` Peer Chen
2007-07-09 16:28 ` Prakash Punnoor
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=20070627022114.455bc0d6.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jeff@garzik.org \
--cc=kluo@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pchen@nvidia.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