Importance of kobject
Hi All, I am kernel newbie, I want to know the importance of kobject, can anybody explain the importance of kobject with an example. Thanks in advance. Madhu
Madhu K <madhu.sk89@gmail.com> writes:
I am kernel newbie, I want to know the importance of kobject, can anybody explain the importance of kobject with an example.
I think the best generic example is that you can write Linux drivers, using kobjects all over, without ever having to actually worry about kobjects. You just use struct device, often without even realizing that there is a kobject embedded in it. At least that's all I know about them :-) If you want code exaples, then "git grep kobj drivers/" will provide enough for a lifetime. And more. Bjørn
Hi, On Wed, May 17, 2017 at 8:08 AM, Madhu K <madhu.sk89@gmail.com> wrote:
Hi All,
I am kernel newbie, I want to know the importance of kobject, can anybody explain the importance of kobject with an example.
To state a not-so-popular analogy, kobjects can also be viewed as root object in object oriented programming. So a bit like java.lang.Object. Of course it is not a root object and indeed C is not OO, but this view helps in thinking about it. This section from ldd3 lists some of the tasks handled by kobject: http://www.makelinux.net/ldd3/chp-14-sect-1. So whichever struct ultimately encapsulates (inherits from) kobject will have those tasks handled for it for free. This view is in addition to others expressed here. HTH Okash
On Wed, May 17, 2017 at 12:34:28PM +0100, Okash Khawaja wrote:
Hi,
On Wed, May 17, 2017 at 8:08 AM, Madhu K <madhu.sk89@gmail.com> wrote:
Hi All,
I am kernel newbie, I want to know the importance of kobject, can anybody explain the importance of kobject with an example.
To state a not-so-popular analogy, kobjects can also be viewed as root object in object oriented programming. So a bit like java.lang.Object. Of course it is not a root object and indeed C is not OO, but this view helps in thinking about it.
Well, it _is_ a "root object", and you can write OO code in C, which is what we did for kobjects (and struct device, and struct class, and kref, and other things like that.) So it is a "popular" analogy, as this is exactly what the authors of the code were intending for people to see. thanks, greg k-h
On Wed, May 17, 2017, at 04:50 AM, Greg KH wrote:
On Wed, May 17, 2017 at 12:34:28PM +0100, Okash Khawaja wrote:
Hi,
On Wed, May 17, 2017 at 8:08 AM, Madhu K <madhu.sk89@gmail.com> wrote:
Hi All,
I am kernel newbie, I want to know the importance of kobject, can anybody explain the importance of kobject with an example.
To state a not-so-popular analogy, kobjects can also be viewed as root object in object oriented programming. So a bit like java.lang.Object. Of course it is not a root object and indeed C is not OO, but this view helps in thinking about it.
Well, it _is_ a "root object", and you can write OO code in C, which is what we did for kobjects (and struct device, and struct class, and kref, and other things like that.)
So it is a "popular" analogy, as this is exactly what the authors of the code were intending for people to see.
thanks,
greg k-h
Hi, You also have GObject proving that you can do OOP in C. Use kobject like you would a base class. Luis
participants (5)
-
Bjørn Mork -
Greg KH -
Luis de Bethencourt -
Madhu K -
Okash Khawaja