[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 1/6] xen: add reference counter support
- To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Thu, 16 Mar 2023 15:03:42 +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=Z2uhJWPbKKDrpppv7FdA/IBSH0epMWBxkyGNEEiYxUA=; b=oIZGyw6WFORPGyPvG6m5sdDKwgFjTRNIzvOVg+D1Kv9S31LSdVuhOHGA2cXjiJebsOYbG27MVrWoLdtnOhOLSFdAFqYjiNsekiXlLn1Q02e7kJAeWMUAuw+ShzUJJRwR6UveW3cLk7HJaST/FFFidT16/3sBRtOpYX0Drt6nFA2APa6X340k13tnQKbEYsA60lvQ5Jq79u5DQ4SysKsPq4IYcAoT1N/LN+ITbeUZl11w9+fcooxbAqSjTRYtIIzgpSULpfGEGApEIRtEM3rBk/BseQQSDgPJ9AU15KI5IUG+teTrLr1mW6HBrmu+MbgQD/xZRRcc2rEJGCtz8hy00A==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AOsQLgyALbRtjWMw/D5OcB1QGDxv+K9jNBrEwkoqUvTyW9VCdXZTW/DxqGCvGFlByIw54b9LG6Wey+xDHcltdvaaZ/qowx5G5ZkhFIpglgpLUCHrntDZXhRWqkp7kibQ4tZM4HS/Ad2an6f2V+53iM9kq9cC3lj8jHXT5BiN8vcccCsCKtStv1H0y/y1qH3XHWiw620XvRvpC+L9hmpA3c9HOuzI/ySKMrMeLuO/zFTVrN4X1qUwoz9en9DAw4Tvx6tqrJwt/jArvKnG1gujZM9bE7JdczLA+AHBfqdGsc9GTB+pplLvTVFxd+aF7Pt81MHI4WyejGUAiN8eE9UPdg==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
- Delivery-date: Thu, 16 Mar 2023 14:03:56 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 16.03.2023 14:54, Roger Pau Monné wrote:
> On Tue, Mar 14, 2023 at 08:56:29PM +0000, Volodymyr Babchuk wrote:
>> --- /dev/null
>> +++ b/xen/include/xen/refcnt.h
>> @@ -0,0 +1,59 @@
>
> This seems to be missing some kind of license, can we have an SPDX tag
> at least?
Not "at least", but strictly that way for any new code. Patches to convert
various existing code to SPDX are already pending iirc.
>> +#ifndef __XEN_REFCNT_H__
>> +#define __XEN_REFCNT_H__
>> +
>> +#include <asm/atomic.h>
>> +#include <asm/bug.h>
>> +
>> +#define REFCNT_SATURATED (INT_MIN / 2)
>> +
>> +typedef struct {
>> + atomic_t refcnt;
>> +} refcnt_t;
>> +
>> +static inline void refcnt_init(refcnt_t *refcnt)
>> +{
>> + atomic_set(&refcnt->refcnt, 1);
>> +}
>> +
>> +static inline int refcnt_read(refcnt_t *refcnt)
>
> const.
>
>> +{
>> + return atomic_read(&refcnt->refcnt);
>> +}
>> +
>> +static inline void refcnt_get(refcnt_t *refcnt)
>> +{
>> + int old = atomic_add_unless(&refcnt->refcnt, 1, 0);
>> +
>> + if ( unlikely(old < 0) || unlikely (old + 1 < 0) )
> ^ extra space
>
> You want a single unlikely for both conditions.
Are you sure? My experience was generally the other way around: likely()
and unlikely() become ineffectual as soon as the compiler needs more
than one branch for the inner construct (ie generally for and && or ||).
Jan
|