linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* reference counting gcc plugin
@ 2023-06-17 22:02 Aravind Ceyardass
  0 siblings, 0 replies; 2+ messages in thread
From: Aravind Ceyardass @ 2023-06-17 22:02 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-kernel

2nd attempt. I hope this is the right mailing list. :-)

Hello Kernel People,

I have developed a gcc plugin for implementing reference counting. I see that the kernel has implemented many different techniques over the years, but I couldn't find any with compiler support.

I would like your ideas, inputs before I release the plugin for everyone hoping that it would benefit the Linux kernel.

Here is a sample code to give you an idea of usage and the code transformation done by the plugin.


#include "hrcmm.h"
/*
  REFTRACK_STRUCT macro defines the following declarations

  struct foo;
  void foo_addref(const struct foo *const);
  void foo_removeref(const struct foo *const);
  void foo_destroy(struct foo *const);
*/

REFTRACK_STRUCT(foo){
    int bar;
};

/*
  REFTRACK_EPILOG_WITH_DTOR macro calls foo_destroy when reference count is zero.
  This is optional, if there is no special cleanup to be done, use REFTRACK_EPILOG. 
*/
REFTRACK_EPILOG_WITH_DTOR(foo);

// This function is called when the reference count for object pointed to by p is zero
void foo_destroy(struct foo *p){
    if (p)
        printf("foo destroyed:%p\n", p);
}

typedef struct foo foo;

// statements commented out are injected by the plugin
     
void baz(foo *p){
    printf("%d\n", p->bar);
    // foo_removeref(p);
}

int main(int argc, char *argv[]){
    foo *p = rc_malloc(sizeof(foo)); // rc_malloc is a default wrapper provided
    // foo_addref(p); 
    p->bar = 123;
    
    // foo_addref(p); 
    foo *q = p;

    // foo_addref(q); 
    baz(q);

    // foo_removeref(p); 
    // foo_removeref(q); 
}


Aravind



^ permalink raw reply	[flat|nested] 2+ messages in thread

* reference counting gcc plugin
@ 2023-06-17 21:57 Aravind Ceyardass
  0 siblings, 0 replies; 2+ messages in thread
From: Aravind Ceyardass @ 2023-06-17 21:57 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]

I hope this is the correct mailing list.


Hello Kernel People,

I have developed a gcc plugin for implementing reference counting. I see that the kernel has implemented many different techniques over the years, but I couldn't find any with compiler support.

I would like your ideas, inputs before I release the plugin for everyone hoping that it would benefit the Linux kernel.

Here is a sample code to give you an idea of usage and the code transformation done by the plugin.


#include "hrcmm.h"
/*
  REFTRACK_STRUCT macro defines the following declarations

  struct foo;
  void foo_addref(const struct foo *const);
  void foo_removeref(const struct foo *const);
  void foo_destroy(struct foo *const);
*/

REFTRACK_STRUCT(foo){
    int bar;
};

/*
  REFTRACK_EPILOG_WITH_DTOR macro calls foo_destroy when reference count is zero.
  This is optional, if there is no special cleanup to be done, use REFTRACK_EPILOG. 
*/
REFTRACK_EPILOG_WITH_DTOR(foo);

// This function is called when the reference count for object pointed to by p is zero
void foo_destroy(struct foo *p){
    if (p)
        printf("foo destroyed:%p\n", p);
}

typedef struct foo foo;

// statements commented out are injected by the plugin
     
void baz(foo *p){
    printf("%d\n", p->bar);
    // foo_removeref(p);
}

int main(int argc, char *argv[]){
    foo *p = rc_malloc(sizeof(foo)); // rc_malloc is a default wrapper provided
    // foo_addref(p); 
    p->bar = 123;
    
    // foo_addref(p); 
    foo *q = p;

    // foo_addref(q); 
    baz(q);

    // foo_removeref(p); 
    // foo_removeref(q); 
}


Aravind

[-- Attachment #2: Type: text/html, Size: 1932 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-17 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 22:02 reference counting gcc plugin Aravind Ceyardass
  -- strict thread matches above, loose matches on Subject: below --
2023-06-17 21:57 Aravind Ceyardass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox