[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 04/10] xen: add reference counter support


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Fri, 17 Feb 2023 01:56:26 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.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=d2y/DrUVa0c11NRh59r0tbNS03ypDf2k1REZaYaAuKM=; b=d/xEBuepJ1fkSPVtz9wkfPINLO3HsG1tAMFoqRosyUQKBKAtFTfZi6YmDQ3NYa+QGEOhtVhpIvpeITmYZxCvo3s8iMqJdCzk2XJ6JgwsiYe1mtrU4H0UncvaYgPA5XFTvxiIdQiooaGxpmn4OfYLtFCHAtWnxtaH3Ulw73fQibh1D5k90+OZFRmhB/KjzM513xF3h7lWR1jw1F7Hesd2yEyJuiOCej9ynBc7D3JK4gG6xQB9QpYUS1avsDWjDoHYf8M4+Z0Rf7uJGGwyJbx5xBvLFXHzjyjaO8on60hDY/8V132mpPPGDw+zaHWJfVdebXSR69kkQbQvVUL5dZ4WaQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MSKbjKV7K1KFrbQ5RuailHgytiOr1QesUoS1oPk2RauXuyicmmdfIVDdWYzOgG//kHVPG5bKE0eLyHZkHigev5xmpIkkdN9eKuA9USFkksvhPQUrR6f7v192rT3CjYdWdT5rGF2lNKxL4L/6jrK1zqkaC4BWzc6JS/j4XJe9wTqA6fl1kgpdUqs0HnYlEe0vyYhvd2bj1EuVu1ZMKr8SUVNPQz5Azz5XuKTtcNtcceagxfE0h0YKgqzPazinFhocbKgB//TBsX7U4nQ2M64Ygl6ZNd5Dh3duY5IcgnqLmbXTPwo5IzT4FQtYfxD1xkMDme9vFd5iaieQ5FrtHEexGg==
  • 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: Fri, 17 Feb 2023 01:57:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYvUN+XE3jlJIvEkq5uMVpvnNlQq7Q5HaAgAKFNIA=
  • Thread-topic: [RFC PATCH 04/10] xen: add reference counter support

Hello Jan,

Jan Beulich <jbeulich@xxxxxxxx> writes:

> 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).

Sadly, TYPE_SAFE does not support pointers. e.g I can't get pointer to
an encapsulated value which is also passed as a pointer. I can expand
TYPE_SAFE with $FOO_x_ptr():

    static inline _type *_name##_x_ptr(_name##_t *n) { &return n->_name; }

or make custom encapsulation in refcnt.h. Which one you prefer?

>> +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);
> }
>

Thanks, did as you suggested. I was afraid that compiler would complain
about unused ret in non-debug builds.

> 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.

For now there are no such callers, so I don't want to implement unused
functionality. But, if you prefer this way, I'll do this.

[...]



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.