[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 04/10] xen: add reference counter support
- To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Wed, 15 Feb 2023 12:20:23 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PLQBwUo8pTsjmjnQXXWMkKlj6IoehQgr5Q98hhErjCQ=; b=PT1LZgkKf2XS1F6gFwvooCOIv72/n813ZnCbG6xqmQjJ+AMHJnn6OHFRe2tyvY+Ik8MbyMMi+JtXrlF2aT6FDWpbprC2vCX57F8LBFzZ/51WCMT46Kh9Qb+vJB3+uRXC+0T+fx4um2xbM+8OqVS34P7pZOMcvtyfJYSHW9lH5lxuMhrt+2DrUHv9MmNnpGxY14OVZVs1WygB1UA1deQVZkxFSHo4KR3xqTkiIEVZh9WNZ2fNvuQY/y27UcsNtLdG8+xG/LHNtWO3nkaYTq4jN8P4sGGLCFMkMZnqHVt8Kw6xlKuPWJG79sNj5wP9FWQ4BtaKvR3uAVHvbsf1jYH2Fw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fAnNdXpkwzhiBfFwlNTkOmY+kA2gMdIav+jSd5wYyveYgNF2P2M03pnGhARNBQ5c0oLFXOUXtckI61iVrabo7iUjVfrPn33+xgAPSrz6/HsaeOgfRG+ec23Y2+bRjfazWHGeeOeC8EsorGH2CeUnSF+OEbuwgxztBGvtQTC+gMcugw4/mjSx3bdvZrL28Gqc7T9Bk9xx9qoNsf0I7vLRpBrol2AwjpcmMy5FrL7ll/pRzoL9KRvFzXLxSoYli9ZUAonM37EmREWew6ZW3syGALMx/N+wQr8vUtnYaA70t4DoxDCdfF3ephsYzkr0+geW04XnDNMEEvinKeqIrxhDJw==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Wed, 15 Feb 2023 11:20:55 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 31.08.2022 16:10, Volodymyr Babchuk wrote:
> --- /dev/null
> +++ b/xen/include/xen/refcnt.h
> @@ -0,0 +1,28 @@
> +#ifndef __XEN_REFCNT_H__
> +#define __XEN_REFCNT_H__
> +
> +#include <asm/atomic.h>
> +
> +typedef atomic_t refcnt_t;
Like Linux has it, I think this would better be a separate struct. At
least in debug builds, i.e. it could certainly use typesafe.h if that
ended up to be a good fit (which I'm not sure it would, so this is
merely a thought).
> +static inline void refcnt_init(refcnt_t *refcnt)
> +{
> + atomic_set(refcnt, 1);
> +}
> +
> +static inline void refcnt_get(refcnt_t *refcnt)
> +{
> +#ifndef NDEBUG
> + ASSERT(atomic_add_unless(refcnt, 1, 0) > 0);
> +#else
> + atomic_add_unless(refcnt, 1, 0);
> +#endif
> +}
I think this wants doing without any #ifdef-ary, e.g.
static inline void refcnt_get(refcnt_t *refcnt)
{
int ret = atomic_add_unless(refcnt, 1, 0);
ASSERT(ret > 0);
}
I wonder though whether certain callers may not want to instead know
whether a refcount was successfully obtained, i.e. whether instead of
asserting here you don't want to return a boolean success indicator,
which callers then would deal with (either by asserting or by suitably
handling the case). See get_page() and page_get_owner_and_reference()
for similar behavior we have (and use) already.
> +static inline void refcnt_put(refcnt_t *refcnt, void (*destructor)(refcnt_t
> *refcnt))
> +{
> + if ( atomic_dec_and_test(refcnt) )
> + destructor(refcnt);
> +}
No assertion here as to the count being positive?
Also the entire file wants to use Xen's space indentation, not hard
tabs.
Jan
|