Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758174AbcJRFQ4 (ORCPT ); Tue, 18 Oct 2016 01:16:56 -0400 Received: from mail-vk0-f44.google.com ([209.85.213.44]:33683 "EHLO mail-vk0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755736AbcJRFQq (ORCPT ); Tue, 18 Oct 2016 01:16:46 -0400 MIME-Version: 1.0 In-Reply-To: <5900385.6T4BAIyXjD@wuerfel> References: <1476721862-7070-1-git-send-email-binoy.jayan@linaro.org> <1476721862-7070-7-git-send-email-binoy.jayan@linaro.org> <5900385.6T4BAIyXjD@wuerfel> From: Binoy Jayan Date: Tue, 18 Oct 2016 10:46:45 +0530 Message-ID: Subject: Re: [PATCH 6/8] IB/hns: Replace counting semaphore event_sem with wait condition To: Arnd Bergmann Cc: Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, Linux kernel mailing list Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1585 Lines: 43 On 18 October 2016 at 01:59, Arnd Bergmann wrote: > On Monday, October 17, 2016 10:01:00 PM CEST Binoy Jayan wrote: >> --- a/drivers/infiniband/hw/hns/hns_roce_cmd.c >> +++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c >> @@ -248,10 +248,14 @@ static int hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param, >> { >> int ret = 0; >> >> - down(&hr_dev->cmd.event_sem); >> + wait_event(hr_dev->cmd.event_sem.wq, >> + atomic_add_unless(&hr_dev->cmd.event_sem.count, -1, 0)); >> + >> ret = __hns_roce_cmd_mbox_wait(hr_dev, in_param, out_param, >> in_modifier, op_modifier, op, timeout); >> - up(&hr_dev->cmd.event_sem); >> + >> + if (atomic_inc_return(&hr_dev->cmd.event_sem.count) == 1) >> + wake_up(&hr_dev->cmd.event_sem.wq); >> >> return ret; >> } > > This is the only interesting use of the event_sem that cares about > the counting and it protects the __hns_roce_cmd_mbox_wait() from being > entered too often. The count here is the number of size of the > hr_dev->cmd.context[] array. > > However, that function already use a spinlock to protect that array > and pick the correct context. I think changing the inner function > to handle the case of 'no context available' by using a waitqueue > without counting anything would be a reasonable transformation > away from the semaphore. > > Arnd Hi Arnd, Thank you for replying for the questions. I''ll look for alternatives for patches 6,7 and 8 and resend the series. -Binoy