Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1508284

Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event

From Binoy Jayan <binoy.jayan@linaro.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event
Date 2016-10-25 15:10 +0200
Message-ID <sw9El-641-31@gated-at.bofh.it> (permalink)
References <sw8Ih-5rG-3@gated-at.bofh.it> <sw8Ih-5rG-9@gated-at.bofh.it> <sw91D-5BL-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 25 October 2016 at 17:58, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tuesday, October 25, 2016 5:31:57 PM CEST Binoy Jayan wrote:
>>  static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param,
>>                                     u64 out_param, unsigned long in_modifier,
>> @@ -198,11 +218,12 @@ static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param,
>>         struct hns_roce_cmdq *cmd = &hr_dev->cmd;
>>         struct device *dev = &hr_dev->pdev->dev;
>>         struct hns_roce_cmd_context *context;
>> -       int ret = 0;
>> +       int orig_free_head, ret = 0;
>> +
>> +       wait_event(cmd->wq, (orig_free_head = atomic_free_node(cmd, -1)) != -1);
>>
>>         spin_lock(&cmd->context_lock);
>> -       WARN_ON(cmd->free_head < 0);
>> -       context = &cmd->context[cmd->free_head];
>> +       context = &cmd->context[orig_free_head];
>>         context->token += cmd->token_mask + 1;
>>         cmd->free_head = context->next;
>>         spin_unlock(&cmd->context_lock);
>>
>
> You get the lock in atomic_free_node() and then again right after that.
> Why not combine the two and only take the lock inside of that
> function that returns a context?


Hi Arnd,

I couldn't figure out a way to wait for a node to be free followed by
acquiring a lock
in an atomic fashion. If the lock is acquired after the wait_event,
there could be race
between the wait_event and acquiring the lock. If the lock is acquired
before the
wait_event, the process may goto sleep with the lock held which is not desired.
Could you suggest me of some way to circumvent this?

-Binoy

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event Binoy Jayan <binoy.jayan@linaro.org> - 2016-10-25 14:10 +0200
  Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event Arnd Bergmann <arnd@arndb.de> - 2016-10-25 14:30 +0200
    Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event Binoy Jayan <binoy.jayan@linaro.org> - 2016-10-25 15:10 +0200
      Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event Arnd Bergmann <arnd@arndb.de> - 2016-10-25 15:30 +0200
        Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event Binoy Jayan <binoy.jayan@linaro.org> - 2016-10-25 15:40 +0200

csiph-web