Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933490AbcJYM3M (ORCPT ); Tue, 25 Oct 2016 08:29:12 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:60617 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750785AbcJYM3J (ORCPT ); Tue, 25 Oct 2016 08:29:09 -0400 From: Arnd Bergmann To: Binoy Jayan Cc: Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 6/8] IB/hns: Replace counting semaphore event_sem with wait_event Date: Tue, 25 Oct 2016 14:28:57 +0200 Message-ID: <5375848.bxLv0aDzDv@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-34-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <1477396919-27669-7-git-send-email-binoy.jayan@linaro.org> References: <1477396919-27669-1-git-send-email-binoy.jayan@linaro.org> <1477396919-27669-7-git-send-email-binoy.jayan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:9oHN/731kc3mAvlDnGG8MT5HwfQSM6UAkfOlBw6OU/0FajE49I3 kRji8h5DKrZ2ORxCE6O9t3C88hMIW4izYJCFaH6/zlgV8UxnLpESAMX86AvXGCyAET4Ywxa ZBJ698DnHImecHlaDqNDQxBY0ZFxI/0ZCSX8IGEhSL1aAgiXiKf36yTrCH604OiqP7opsTK /FM+YYvfXzlpZeLuk1A6g== X-UI-Out-Filterresults: notjunk:1;V01:K0:hXv4UX0NSxc=:wQFSMzj7SGWTK9sfTdbfGL 6cr0RtrRFYf5/obOYaYkta2AzVBO5IA1Xk0ZnC4YDI8W7551CpnJ/RvsqXtP4St6EaHbst4Dt 4rQq3ddCMDZleAokA9My+TDc/5XeTZc7/+5mq+FpaaOboQEfxrR1OimqjvDIg7e7W3ncHWDOv s91XWZK5GLV0fa59EFabV5YovkTOtNCrwkk49utmzZW3NZdiFDNXN3T8IOBBlgaSITmm859gr W2mpvItG6sjmjh3EklqHwp6OYuoiVvnJo/qrEBDFglZ0HqxeuXuv48pII08VbTMu0SlIg/0H4 U37Ddi60Zc9T3zaEoIzUrp7BekBGPvSSm98tftKWZlTQ0n+3HnAQzbBhstWKuxIK84GSrAIJ9 y6y5YAwMaHKxBGKjNRvpqXaR0M0rdPR0bMXuNnNWusTtW5c4VgNDuPxaLZvXcMjVN5OiYclyb /aqdqKfg9Wu1GY6doqunzoKCGHM0YNtvhF+nF9a+BUwx3SbxK17aDz7IopIhMsn62wPvj3GHn xn37kcmTzq0B85Am2ZCaveYnh8GuC0lEzKhNAZmJNQdj1ZZcwLj3EMWXNUtf3IFnD5myvhqH1 PWuimdTJQjcSbjBHKTt/rC/nWZ1JxfRyFNOqLEWCgsFIzmU1hSHO2/KGl0S0Q5go52UUqxp6Z vjMhbF39ORwQAeCcTsPQ7MfOP0WW4SDRheP5FHraOfjmiMQyxBd+uJnfUhA2YxfEKLelqKY/A dY4kel3Rvc8PoEjQ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1127 Lines: 26 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? Arnd