From patchwork Wed Oct 26 14:27:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 9397379 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E37160236 for ; Wed, 26 Oct 2016 14:27:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63FF429B61 for ; Wed, 26 Oct 2016 14:27:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 577FB29BBC; Wed, 26 Oct 2016 14:27:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C166729B61 for ; Wed, 26 Oct 2016 14:27:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C5DA26E881; Wed, 26 Oct 2016 14:27:49 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 46CF66E881 for ; Wed, 26 Oct 2016 14:27:48 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id y138so3590678wme.1 for ; Wed, 26 Oct 2016 07:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id; bh=4Z/f6HvxC6dJ/yqsTwa3tMk/NZ13f6zdrwYhwQhYL4w=; b=egmonpdcv2Trqc5SmXNw96TTffqlArgWWHwS20J93WHzMIHIOkZDPkHhLWl0oZzTb7 qgvLiKxnRheNaHNtVvJHLP0y8Y3NW9rja8+4e8h7klyKkWoDM2mqunj0VEBGGsHWFq0d I5nsK84hi60LPqU//84htSHFDjIHQtslVapA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4Z/f6HvxC6dJ/yqsTwa3tMk/NZ13f6zdrwYhwQhYL4w=; b=EexgHc5yFlKoTM+a/zGyFypnmCkjo8z3kM5dzRBZbuMmviz/duWj8jv8zso7Y7qtPc mS8FFJJeT292lDrdJX76xEtztqY9RJG1jKp0DoJzKQzW71Xs1y/H4yTO7mV+8nhRcJaK qPRc8Qvo9Vr9U0YBytYWwlQ7cgl9jofjBaDX3sjamjQMm5lGmjuh2bjOrFM7ld9iZKt6 DoyAka3Gv6liLxpP1xZcWylWojFhBPjTJE+EQWHfM67dJ+UjXjrICUHf3zYDWPLirDFf 6tHDyBXifU6jNUgtFhCun64cGNGAsLAgZWlpRdu/QVLhSJ03SVKTfktDOWbSRUwYFlSi Ek1w== X-Gm-Message-State: ABUngvfeHPR/ROichatybN72e/62IqRhFYk+KHBn+2Jnxda9F4wC6MXDY35kWHQ6BQMqJg== X-Received: by 10.194.235.7 with SMTP id ui7mr2506153wjc.66.1477492066875; Wed, 26 Oct 2016 07:27:46 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:56b5:0:ac27:b86c:7764:9429]) by smtp.gmail.com with ESMTPSA id ya1sm2948439wjb.23.2016.10.26.07.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Oct 2016 07:27:46 -0700 (PDT) From: Daniel Vetter To: LKML Date: Wed, 26 Oct 2016 16:27:39 +0200 Message-Id: <20161026142739.20266-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.10.1 Cc: Michal Hocko , Daniel Vetter , Intel Graphics Development , Tejun Heo , Daniel Vetter , Andrew Morton , Mel Gorman , Vlastimil Babka Subject: [Intel-gfx] [PATCH] lib/ida: Document locking requirements a bit better X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP I wanted to wrap a bunch of ida_simple_get calls into their own locking, until I dug around and read the original commit message. Stuff like this should imo be added to the kernel doc, let's do that. Cc: Mel Gorman Cc: Michal Hocko Cc: Vlastimil Babka Cc: Tejun Heo Cc: Andrew Morton Signed-off-by: Daniel Vetter --- lib/idr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/idr.c b/lib/idr.c index 6098336df267..5508d7f6d7be 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -927,6 +927,9 @@ EXPORT_SYMBOL(ida_pre_get); * and go back to the ida_pre_get() call. If the ida is full, it will * return %-ENOSPC. * + * Note that callers must ensure that concurrent access to @ida is not possible. + * When simplicity trumps concurrency needs look at ida_simple_get() instead. + * * @p_id returns a value in the range @starting_id ... %0x7fffffff. */ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) @@ -1073,6 +1076,10 @@ EXPORT_SYMBOL(ida_destroy); * Allocates an id in the range start <= id < end, or returns -ENOSPC. * On memory allocation failure, returns -ENOMEM. * + * Compared to ida_get_new_above() this function does its own locking and hence + * is recommended everywhere where simplicity is preferred over the last bit of + * speed. + * * Use ida_simple_remove() to get rid of an id. */ int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, @@ -1119,6 +1126,13 @@ EXPORT_SYMBOL(ida_simple_get); * ida_simple_remove - remove an allocated id. * @ida: the (initialized) ida. * @id: the id returned by ida_simple_get. + * + * Use to release an id allocated with ida_simple_get(). + * + * Compared to ida_get_new_above() this function does its own locking and hence + * is recommended everywhere where simplicity is preferred over the last bit of + * speed. + * */ void ida_simple_remove(struct ida *ida, unsigned int id) {