linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Liuyixian (Eason)" <liuyixian@huawei.com>
Cc: dledford@redhat.com, leon@kernel.org, linux-rdma@vger.kernel.org,
	linuxarm@huawei.com
Subject: Re: [PATCH v7 for-next 2/2] RDMA/hns: Delayed flush cqe process with workqueue
Date: Wed, 5 Feb 2020 16:30:40 -0400	[thread overview]
Message-ID: <20200205203040.GA25297@ziepe.ca> (raw)
In-Reply-To: <f4794cf0-e9db-540b-9752-761734edef5a@huawei.com>

On Tue, Feb 04, 2020 at 04:47:38PM +0800, Liuyixian (Eason) wrote:
> 
> 
> On 2020/1/29 4:05, Jason Gunthorpe wrote:
> > On Wed, Jan 15, 2020 at 05:49:13PM +0800, Yixian Liu wrote:
> >> diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
> >> index fa38582..ad7ed07 100644
> >> +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
> >> @@ -56,10 +56,16 @@ static void flush_work_handle(struct work_struct *work)
> >>  	attr_mask = IB_QP_STATE;
> >>  	attr.qp_state = IB_QPS_ERR;
> >>  
> >> -	ret = hns_roce_modify_qp(&hr_qp->ibqp, &attr, attr_mask, NULL);
> >> -	if (ret)
> >> -		dev_err(dev, "Modify QP to error state failed(%d) during CQE flush\n",
> >> -			ret);
> >> +	while (atomic_read(&hr_qp->flush_cnt)) {
> >> +		ret = hns_roce_modify_qp(&hr_qp->ibqp, &attr, attr_mask, NULL);
> >> +		if (ret)
> >> +			dev_err(dev, "Modify QP to error state failed(%d) during CQE flush\n",
> >> +				ret);
> >> +
> >> +		/* If flush_cnt larger than 1, only need one more time flush */
> >> +		if (atomic_dec_and_test(&hr_qp->flush_cnt))
> >> +			atomic_set(&hr_qp->flush_cnt, 1);
> >> +	}
> > 
> > And this while loop is just 
> 
> There is a bug here, the code should be:
> if (!atomic_dec_and_test(&hr_qp->flush_cnt))
> 	atomic_set(&hr_qp->flush_cnt, 1);
> 
> It merges all further flush operation requirements into only one more time flush,
> that is, do the loop once again if flush_cnt larger than 1.
> 
> > 
> > if (atomic_xchg(&hr_qp->flush_cnt, 0)) {
> >   [..]
> > }
> 
> I think we can't use if instead of while loop.

Well, you can't do two operations and still have an atomic, so you
have to fix it somehow. Possibly this needs a spinlock approach
instead.

> With your solution, when user posts a new wr during the
> implementation of [...] in if condition, it will re-queue a new
> init_flush_work, which will lead to a multiple call problem as we
> discussed in v2.

queue_work can be called while a work is still running, it just makes
sure it will run again.

> > I'm not even sure this needs to be a counter, all you need is set_bit()
> > and test_and_clear()
> 
> We need the value of flush_cnt large than 1 to record further flush
> requirements, that's why flush_cnt can be defined as a flag or bit
> value.

This explanation doesn't make sense, the counter isn't being used to
count anything, it is just a flag.

Jason

  reply	other threads:[~2020-02-05 20:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15  9:49 [PATCH v7 for-next 0/2] RDMA/hns: Add the workqueue framework for flush cqe handler Yixian Liu
2020-01-15  9:49 ` [PATCH v7 for-next 1/2] " Yixian Liu
2020-01-15  9:49 ` [PATCH v7 for-next 2/2] RDMA/hns: Delayed flush cqe process with workqueue Yixian Liu
2020-01-28 19:56   ` Jason Gunthorpe
2020-02-04  7:41     ` Liuyixian (Eason)
2020-01-28 20:05   ` Jason Gunthorpe
2020-02-04  8:47     ` Liuyixian (Eason)
2020-02-05 20:30       ` Jason Gunthorpe [this message]
2020-02-06  9:14         ` Liuyixian (Eason)

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=20200205203040.GA25297@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=dledford@redhat.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=liuyixian@huawei.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;
as well as URLs for NNTP newsgroup(s).