public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* mlx4_wq_overflow question
@ 2012-02-08 22:45 Eli Cohen
  2012-02-09 17:39 ` Roland Dreier
  0 siblings, 1 reply; 2+ messages in thread
From: Eli Cohen @ 2012-02-08 22:45 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A, RDMA list

Hi Roland,

referring to the function below, I can't find a strong reason to check
again after acquiring the cq spinlock. Any idea?

static int mlx4_wq_overflow(struct mlx4_ib_wq *wq, int nreq, struct
ib_cq *ib_cq)
{
        unsigned cur;
        struct mlx4_ib_cq *cq;

        cur = wq->head - wq->tail;
        if (likely(cur + nreq < wq->max_post))
                return 0;

        cq = to_mcq(ib_cq);
        spin_lock(&cq->lock);
        cur = wq->head - wq->tail;
        spin_unlock(&cq->lock);

        return cur + nreq >= wq->max_post;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mlx4_wq_overflow question
  2012-02-08 22:45 mlx4_wq_overflow question Eli Cohen
@ 2012-02-09 17:39 ` Roland Dreier
  0 siblings, 0 replies; 2+ messages in thread
From: Roland Dreier @ 2012-02-09 17:39 UTC (permalink / raw)
  To: Eli Cohen; +Cc: RDMA list

On Wed, Feb 8, 2012 at 2:45 PM, Eli Cohen <eli-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org> wrote:
> referring to the function below, I can't find a strong reason to check
> again after acquiring the cq spinlock. Any idea?
>
> static int mlx4_wq_overflow(struct mlx4_ib_wq *wq, int nreq, struct
> ib_cq *ib_cq)
> {
>        unsigned cur;
>        struct mlx4_ib_cq *cq;
>
>        cur = wq->head - wq->tail;
>        if (likely(cur + nreq < wq->max_post))
>                return 0;
>
>        cq = to_mcq(ib_cq);
>        spin_lock(&cq->lock);
>        cur = wq->head - wq->tail;
>        spin_unlock(&cq->lock);
>
>        return cur + nreq >= wq->max_post;
> }

This is the typical optimization of doing a cheaper imprecise check
first, and then only if we need to (ie the QP was close to full) take
the lock and synchronize with completions being polled to get an
exact answer.  Without the second check we might have spurious
"WQ full" indications.

If I recall correctly, MST first proposed this optimization for mthca
years ago.  If you search the archives you can probably find his
detailed explanation.

 - R.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-02-09 17:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08 22:45 mlx4_wq_overflow question Eli Cohen
2012-02-09 17:39 ` Roland Dreier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox