From: Aravind Ceyardass <aravind.pub@gmail.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Subject: reference counting gcc plugin
Date: Sat, 17 Jun 2023 18:02:24 -0400 [thread overview]
Message-ID: <77f98dae-815f-2191-0a1d-63e2a0886d9e@gmail.com> (raw)
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
next reply other threads:[~2023-06-17 22:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-17 22:02 Aravind Ceyardass [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-06-17 21:57 Aravind Ceyardass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=77f98dae-815f-2191-0a1d-63e2a0886d9e@gmail.com \
--to=aravind.pub@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox