From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B7C8EB64D9 for ; Sat, 17 Jun 2023 21:57:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 849856B0071; Sat, 17 Jun 2023 17:57:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F9426B0072; Sat, 17 Jun 2023 17:57:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C0666B0075; Sat, 17 Jun 2023 17:57:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5E00D6B0071 for ; Sat, 17 Jun 2023 17:57:51 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2FECDA0240 for ; Sat, 17 Jun 2023 21:57:51 +0000 (UTC) X-FDA: 80913602742.16.6F8E4BE Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) by imf05.hostedemail.com (Postfix) with ESMTP id 61A72100008 for ; Sat, 17 Jun 2023 21:57:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=aCtKh1kd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of aravind.pub@gmail.com designates 209.85.160.41 as permitted sender) smtp.mailfrom=aravind.pub@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687039069; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=ylh9j/nku5c0Gyow2HEtnVsjvrLGhSHj92qzwa3W6W4=; b=gl5BYWtSZmCVSVMBgeNrnX6lX2zG9TBeRgaT0VoVCJrZGEbQq/1vxMQqbf1RBGggbNvJMl YyKXsC/jg3EA4N78Y7jP+ud/SVqJq0am512WGJEhi5cn7TvWSUtVEo2V4tMVpdXn4FJk5Q WRVl2a0ucSjdVDZ8zzzBrZLjbG0GSLc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=aCtKh1kd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of aravind.pub@gmail.com designates 209.85.160.41 as permitted sender) smtp.mailfrom=aravind.pub@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687039069; a=rsa-sha256; cv=none; b=L6Hqa/dNqAa/k/PpqF+QelCcp1vBlsv24Vn9Zv6D1CesMhj/sVQzOXjM+tGxz3NfeiehRo OxMp12tgSt65deG67/3Ojwd9824ypFiyFACGlflae/qYTQ26daGpZlbxfkhkmlUSOEheV8 VLAOgmMDtjsLzB9dmI+pIpc1rEHoTKU= Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-19f8af9aa34so2185050fac.1 for ; Sat, 17 Jun 2023 14:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687039068; x=1689631068; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ylh9j/nku5c0Gyow2HEtnVsjvrLGhSHj92qzwa3W6W4=; b=aCtKh1kd0NY4AD0mRIXLkJRlxlvsgSa61GN4vJjpyrsLbvPKtejBaJKcMaL6Cr2jk1 8xPMesy5IpvBLeIHe/Uyc1eNblai808X4FcpxmOAPBZ8hwoEIzkAUKqotjubuh9WBlPY idFcjOx1Xg1QHGcDoVj8GzRjOzKIMRv563WvQNgFTb2GZDDwFwoiubzl5wKplwmPiV0X 1zp1a8zc/bW2K416pjwCpjgY12uBH+rL184/hEYR4LD/wNiAfOaCkYMfqzxoNl5fSqxz mfCNQUmZAiKi0QAqGM7Eb0jGXMjGTrbnvKmxi8PbneauFt2jN0tpZMANmHgA9yrGW9Dl yHXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687039068; x=1689631068; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ylh9j/nku5c0Gyow2HEtnVsjvrLGhSHj92qzwa3W6W4=; b=eb6F6XbKoGj2s3vO6yW1F8hwGitX7umeW4eLtVh6YPRwawQ0lqvsvZeYjSEsfaR9ET kf1wYKU3QKdF0hieVJQdcINYWxw2DA8gQmmQwb9DnKk+6fecGM4nFJ3M6r/gZBqeMDxq vYKjr7X0pFh6zpYiDnLW19dTCkTRIusVy3C54F9tKmWE0J+oy2hhAiysWVQetwMJpLTQ UoP5tLafTvF5NiiDNP0Yih2Xi6FRJhOeFXiS4qujVnXG9Spka0wyKiTdO4Dv4ToOnuCW +8QNp0SKuYTiCPZ3fOPbc0vNNO4Y1SwMvmJNqQAEM8G3cySxLoER4ycvew5zs/pDH1rg 3LzQ== X-Gm-Message-State: AC+VfDzx3uHp5yGtzUj9Ge+8SPvK3reBlhuaYpdGSirXXAH1zASlngwU uV7SNUZpnwGIdu4PgGfaC0t8ysDVdj97tA== X-Google-Smtp-Source: ACHHUZ5JM7r3VyIafcVyy91JmUv8A9AwAbjl8CGg4bsnJkqqB5B3RczFH28j49+UZ7okPFQAAS8mtw== X-Received: by 2002:a05:6808:15a8:b0:398:5929:fab2 with SMTP id t40-20020a05680815a800b003985929fab2mr8068558oiw.14.1687039068261; Sat, 17 Jun 2023 14:57:48 -0700 (PDT) Received: from [192.168.43.16] ([199.7.157.10]) by smtp.gmail.com with ESMTPSA id p5-20020a170902bd0500b00186a2274382sm17897332pls.76.2023.06.17.14.57.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Jun 2023 14:57:47 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------qBusGfYiwtF0gHMgKbxtygdz" Message-ID: Date: Sat, 17 Jun 2023 17:57:45 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Content-Language: en-US To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org From: Aravind Ceyardass Subject: reference counting gcc plugin X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 61A72100008 X-Stat-Signature: oiqxqmtqmedgon1brjmmpn4yi8f7japs X-HE-Tag: 1687039069-403625 X-HE-Meta: U2FsdGVkX19WONM7I3oySC6IjNZIgrI1hpZIP+d2McGonW4vMZdTbfPjGKFjp59AhNtzqxVcZl+hUGXOQPK6mUlli/BgH+KHxmZR/VWbWiilzg0p3PImbyoNswYsmg6zjOroesguEgUJUlRrlgesbXEWvmN337qAD+BvE5x6F0oO6ZytMsT0TO5iYcQcXhySbbbjoyhSG0agRZe0GynBglUjIPTZOrBpbw2rXG61YaM92scw3LVq7xyDkO+TAO0/Wl2hvhD4A9A0rSMNkQRP1bvq2oTHFwzycznh11tsrWXTVf10xisRtYF9NThKYdj2jHv00yn1CH2SFqqDebzLT1RCoZVuHzv347l+qQjT+9SuCqDJtlXLKsQGFUCACqyTZrnTjR0k5PgQXnqTkz8BHwA00NOfYHPF1Mpnrtm1spYbzJp+4whMdPsp41/1s49ydMx1JLI7JRcwcDh60aCJ7DI2kc9jOjzvL7EDS+nm3HOU6KLVVKabXL2vpxHTegZa9y1exZdC2Zpzqnme7F4yBW6IFgfgNe8QoMiDWNuy+HeTb/sruNfDSCR/Y3dFudCcBJgpe7B+Oc6qg/+LRIhr4+K4EFsYuFJjpTNC1pY8l+erLkW1IWQxq9fQOQ6uldUPsyUwERyyc1aEvSmKm8F5IWktz17571A+MXG3eA8ZR9ys6LhF60/Fo5Ufdomalf65JsGdcslBq+je7apHu4wW4cseuJw3XbWdDril/6SE6TrC/4SzLwdaSjXpjk4tULU2ukeq8Z4fMLdMfEOCELBlrGYdlQP67pfLsniSviPfKSbiifw84O3EHYplO85scE6yT7kIXljuvjgaVWFco/CkBHPwX87PgHPYIdcSv1Hc2EHxNgmadW3OIHAvr4jL3tFHjVjoDb+iISRkxGnUOXrMutfKR196ADDNmIidKDLJklFt5deB4XKop5xlnUyl3+79KYK8fGikJ0pwdMtSwtT HTHDgA1b yf4c+DzAGRRuTq/bN7mtqY895a/yKhVb42axO4tc4EjiPw4fsxdvDveACcqoMuEqzpGRbhF6u0ZxgNem1BTewqbTpFg/UMFpStSfvI6aK0wUoEMQ2u93M8+NifUU609tzwj25GBUQMPJi2KkaM7W3gwlfEdttRL7om/oavI+ZFejs8rIRb17RPQ8uwk2Uszi6vQ4eDB0Fc5NbvFYDBsNVAs7RkVhI9HPQLmvTYDE5bM7oA69yxJi4ZcsKSsSTQfOo3gXJT6QP8n9QgPLkHF1KIlJxEk7Qnf9YOcNfDpm73FYhPstOD7nUWY+RoONtMXl7Iq9WM/orwKGb35VeEN+MHzVqN5HLjr0fDIa7O3WzIg7rtZGR5mL/S3wKF8Vltb70nqUjl+fxq7BQA/2P/t7YTahX0YmEDIHV/fQ8vE1MQPWveWKJKF68zTdDTIRjwuf/tCi4xCSkvejlv/OLN/1PxA61Rr0CvWOXmcOQqN9WyBDAXXTS2YkjO+m2lO6HArMe5lsaHcsVx5JGBDZVMKdB1jfhDg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a multi-part message in MIME format. --------------qBusGfYiwtF0gHMgKbxtygdz Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 --------------qBusGfYiwtF0gHMgKbxtygdz Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

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

--------------qBusGfYiwtF0gHMgKbxtygdz--