From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: idr_get_new_exact ? Date: Mon, 20 Sep 2010 12:31:40 -0700 Message-ID: <20100920123140.f524de79.akpm@linux-foundation.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-rdma-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Ohad Ben-Cohen Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Jean Delvare (PC drivers, core)" , "Ben Dooks (embedded platforms)" , Roland Dreier , Sean Hefty , Hal Rosenstock , Steve Wise , Neil Brown , Paul Mackerras , linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-ppp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: dm-devel.ids On Mon, 20 Sep 2010 16:11:31 +0200 Ohad Ben-Cohen wrote: > Occasionally, drivers care about the value that idr associates with > their pointers. > > Today we have idr_get_new_above() which allocates a new idr entry > above or equal to a given starting id, but sometimes drivers need to > force an exact value. > > To overcome this small API gap, drivers are wrapping idr_get_new_above > and then either BUG_ON() or just call idr_remove() and returns -EBUSY > when idr allocates them an id which is different than their requested > value. > > There are only a handful of users who need this (see below. especially > note the i2c comment :), but it might be nice to have such an API (a > bit less of code, and a bit less error prone). > > Would something like the below be desirable/acceptable ? It seems OK to me - it's an improvement over what we have now. > (untested. and i just picked the simplest and straight-forward way to > implement this; obviously it's not optimal since there's no reason to > even allocate an id if we know it's not the id we're looking for. but > it's enough to get the idea, it's not a hot path, and it's what > drivers are doing today) Sure, we can speed it up later if that appears to be necessary. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Date: Mon, 20 Sep 2010 19:31:40 +0000 Subject: Re: idr_get_new_exact ? Message-Id: <20100920123140.f524de79.akpm@linux-foundation.org> List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Ohad Ben-Cohen Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Jean Delvare (PC drivers, core)" , "Ben Dooks (embedded platforms)" , Roland Dreier , Sean Hefty , Hal Rosenstock , Steve Wise , Neil Brown , Paul Mackerras , linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-ppp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org On Mon, 20 Sep 2010 16:11:31 +0200 Ohad Ben-Cohen wrote: > Occasionally, drivers care about the value that idr associates with > their pointers. > > Today we have idr_get_new_above() which allocates a new idr entry > above or equal to a given starting id, but sometimes drivers need to > force an exact value. > > To overcome this small API gap, drivers are wrapping idr_get_new_above > and then either BUG_ON() or just call idr_remove() and returns -EBUSY > when idr allocates them an id which is different than their requested > value. > > There are only a handful of users who need this (see below. especially > note the i2c comment :), but it might be nice to have such an API (a > bit less of code, and a bit less error prone). > > Would something like the below be desirable/acceptable ? It seems OK to me - it's an improvement over what we have now. > (untested. and i just picked the simplest and straight-forward way to > implement this; obviously it's not optimal since there's no reason to > even allocate an id if we know it's not the id we're looking for. but > it's enough to get the idea, it's not a hot path, and it's what > drivers are doing today) Sure, we can speed it up later if that appears to be necessary. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932133Ab0ITTfe (ORCPT ); Mon, 20 Sep 2010 15:35:34 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:53693 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932067Ab0ITTfc (ORCPT ); Mon, 20 Sep 2010 15:35:32 -0400 Date: Mon, 20 Sep 2010 12:31:40 -0700 From: Andrew Morton To: Ohad Ben-Cohen Cc: linux-kernel@vger.kernel.org, "Jean Delvare (PC drivers, core)" , "Ben Dooks (embedded platforms)" , Roland Dreier , Sean Hefty , Hal Rosenstock , Steve Wise , Neil Brown , Paul Mackerras , linux-i2c@vger.kernel.org, linux-rdma@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-ppp@vger.kernel.org, netdev@vger.kernel.org Subject: Re: idr_get_new_exact ? Message-Id: <20100920123140.f524de79.akpm@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 2.4.8 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 20 Sep 2010 16:11:31 +0200 Ohad Ben-Cohen wrote: > Occasionally, drivers care about the value that idr associates with > their pointers. > > Today we have idr_get_new_above() which allocates a new idr entry > above or equal to a given starting id, but sometimes drivers need to > force an exact value. > > To overcome this small API gap, drivers are wrapping idr_get_new_above > and then either BUG_ON() or just call idr_remove() and returns -EBUSY > when idr allocates them an id which is different than their requested > value. > > There are only a handful of users who need this (see below. especially > note the i2c comment :), but it might be nice to have such an API (a > bit less of code, and a bit less error prone). > > Would something like the below be desirable/acceptable ? It seems OK to me - it's an improvement over what we have now. > (untested. and i just picked the simplest and straight-forward way to > implement this; obviously it's not optimal since there's no reason to > even allocate an id if we know it's not the id we're looking for. but > it's enough to get the idea, it's not a hot path, and it's what > drivers are doing today) Sure, we can speed it up later if that appears to be necessary.