3

I was going through chipidea usb otg driver code and I see such similar definitions numerous times.

static DEFINE_IDA(ci_ida);

I don't get what it meant in the programming world and its purpose. Can someone please explain the same?

Adit Ya
  • 731
  • 1
  • 8
  • 19
  • 1
    it's just a macro and means [`struct ida name = IDA_INIT(name)`](https://github.com/torvalds/linux/blob/3e1e21c7bfcfa9bf06c07f48a13faca2f62b3339/include/linux/idr.h#L174) in this case. – PeterT Feb 11 '16 at 11:33
  • what does ida define/mean exactly. As I see in docs that "IDA - IDR based id allocator, use when translation from id to pointer isn't necessary.". I didnt get the gist of it. If possible, please explain/ – Adit Ya Feb 11 '16 at 11:36

1 Answers1

4

As already noted, DEFINE_IDE(name) is #defined as struct ida name = IDA_INIT(name). You should check out LXR which is very convenient for browsing kernel source.

IDR is a subsystem in the kernel that provides an efficient way to map ids to pointers. Normally you would use the id as an offset into an array of pointers, but this limits how big your ids are. IDR solves this by using radix trees instead for lookup.

Sometimes you just want unique ids without associating them with pointers and that's what IDA is for.

 /* IDA - IDR based ID allocator  
  * 
  * This is id allocator without id -> pointer translation.  Memory
  * usage is much lower than full blown idr because each id only
  * occupies a bit.
a3f
  • 8,517
  • 1
  • 41
  • 46
  • Thanks a3f. That helps. https://lwn.net/Articles/103209/ helped me understand the internals. They are simply a replacement for pointers and these are how the minor numbers are addressed by the kernel. These IDs are mapped to the pointers which hold the start location of the memory-the structure that holds all related info. Plz correct me if I am wrong; meanwhile, your answer did answer my question and also helped me with the "IDR" part and I was able to browse and find some indepth information. So, marking it as an answer. Thanks. – Adit Ya Feb 15 '16 at 06:55
  • The API changed a bit since the article was released in 2004. There is a more up to date [lwn article on it](https://lwn.net/Articles/536293/). IDA is for IDs _without_ pointer mapping, this is needed for instance ids of the same device in your case. – a3f Feb 15 '16 at 07:57
  • While the gist was clearly understood; in the latest changes, we don't need to worry about looping to get a valid memory allocated and thereby getitng valid id. "It is, instead, stored in a single per-CPU array" - This line has generated few more queries. Are different processors allotted different memory spaces in RAM for performing their computation. Please throw some light on this/suggest some links to get a bit deeper understanding of this whole concept. Thanks. – Adit Ya Feb 15 '16 at 10:03