From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/3] btrfs: add const function attribute
Date: Fri, 4 Oct 2019 13:01:06 +0200 [thread overview]
Message-ID: <20191004110106.GX2751@twin.jikos.cz> (raw)
In-Reply-To: <625281f3-90fc-56d8-22e9-76557bb3d410@suse.com>
On Wed, Oct 02, 2019 at 02:07:50PM +0300, Nikolay Borisov wrote:
> > +struct list_head * __attribute_const__ btrfs_get_fs_uuids(void)
>
> I'm not entirely sure this function is cons. According to the manual:
>
> Calls to functions whose return value is not affected by changes to the
> observable state of the program and that have no observable effects on
> such state other than to return a value may lend themselves to
> optimizations such as common subexpression elimination.
>
> The const attribute prohibits a function from reading objects that
> affect its return value between successive invocations. However,
> functions declared with the attribute can safely read objects that do
> not change their return value, such as non-volatile constants.
>
>
> My doubt stems from the fact this function actually references outside
> memory, namely gets the ptr to fs_uuids. There is a specific remark not
> to use const when the function takes a ptr argument but it doesn't say
> anything when getting a ptr from a global var.
The fs_uuids are a non-volatile constant. It does not change accross the
lifetime of the module, so all code executed will always see the same
value.
next prev parent reply other threads:[~2019-10-04 11:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 17:57 [PATCH 0/3] Coldify, constify, purify (function attributes) David Sterba
2019-10-01 17:57 ` [PATCH 1/3] btrfs: add __cold attribute to more functions David Sterba
2019-10-02 10:52 ` Nikolay Borisov
2019-10-04 10:56 ` David Sterba
2019-10-01 17:57 ` [PATCH 2/3] btrfs: add const function attribute David Sterba
2019-10-02 11:07 ` Nikolay Borisov
2019-10-04 11:01 ` David Sterba [this message]
2019-10-01 17:57 ` [PATCH 3/3] btrfs: add __pure attribute to functions David Sterba
2019-10-02 11:09 ` Nikolay Borisov
2019-10-01 17:57 ` [PATCH 0/3] Coldify, constify, purify (function attributes) David Sterba
2019-10-02 12:20 ` Nikolay Borisov
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=20191004110106.GX2751@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
/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