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

Re: [PATCH v4 1/5] xen/ppc: Implement atomic.h


  • To: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 11 Sep 2023 13:33:35 +0200
  • 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=eV9VmPO7J7RbGIB1ovl8ONYr13bwZ0HfyL8oaBvtUrQ=; b=mWXg5vlqdliAa/2sIqnW/eOqrsv48m1xP26JqeamVeouLZQ2ivey2b0Jgxr/CsEMaV9pHePAQt1hrRT7H7jzDrelDUPzndbaH3WTKdtBp0PClnbQromGq+8K0byGtUaHBM1aE8W34Z1TAxh8Wq5+6yhMuswB5h0meAzb1H1rrN+HNGfHKHwqF2ccDh0TL7U8ePeqmG5zjCjMb3ih6inuC1CX9WWPCi7l/zDgzE3C4vzyyN6oFf0YWGZNbbYlOEMgzJe3kuLLrZbTXyXeHSkfvEpJ9Iy7yFB5oZ9KpMEgLLtsfF1NBARAX6jsxTuRDHCSybsGI0xCH0ewYAvTJY3tXg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lw2UP0VXOy58jIVrd3bN77Q4LHAKG7sKNAstwS9ZI8bNiBdpKBjvcwfYrLmfaSp1Zbi1KeQ2j47NNaMFsGKL1jR0oODBSx0i0QEZdiWXvUNFEN9r/vZNEpuSsfTpKPWhcc2aH8B+4AsrrhL8TW5MV1+RsiFSmPLiDGbdJ/AmvCE0uwuBHh9oL1E1i8W5cd+NSboh3gqZM1EC8r9fpXqRiPLiFwRujLVK1obuAOMynjarc+iVL5xSbdhB1NdwqeSbWI+MeXV57Z/lJ2KWlIK6R8cGrqvr9UJofaJTKTxGPoAr79Cikqsh+UG7xl2+qnsbhUwIshxhfsfim6duImSb5Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 11 Sep 2023 11:33:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 09.09.2023 00:50, Shawn Anastasio wrote:
> Implement atomic.h for PPC, based off of the original Xen 3.2
> implementation. This implementation depends on some functions that are
> not yet defined (notably __cmpxchg), so it can't yet be used.
> 
> Signed-off-by: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>

Acked-by: Jan Beulich <jbeulich@xxxxxxxx>

Just one remaining question:

> +static always_inline void read_atomic_size(const volatile void *p, void *res,
> +                                           unsigned int size)
> +{
> +    ASSERT(IS_ALIGNED((vaddr_t)p, size));
> +    switch ( size )
> +    {
> +    case 1:
> +        *(uint8_t *)res = read_u8_atomic(p);
> +        break;
> +    case 2:
> +        *(uint16_t *)res = read_u16_atomic(p);
> +        break;
> +    case 4:
> +        *(uint32_t *)res = read_u32_atomic(p);
> +        break;
> +    case 8:
> +        *(uint64_t *)res = read_u64_atomic(p);
> +        break;
> +    default:
> +        __bad_atomic_read(p, res);
> +        break;
> +    }
> +}
> +
> +static always_inline void write_atomic_size(volatile void *p, const void 
> *val,
> +                                            unsigned int size)
> +{
> +    ASSERT(IS_ALIGNED((vaddr_t)p, size));
> +    switch ( size )
> +    {
> +    case 1:
> +        write_u8_atomic(p, *(const uint8_t *)val);
> +        break;
> +    case 2:
> +        write_u16_atomic(p, *(const uint16_t *)val);
> +        break;
> +    case 4:
> +        write_u32_atomic(p, *(const uint32_t *)val);
> +        break;
> +    case 8:
> +        write_u64_atomic(p, *(const uint64_t *)val);
> +        break;
> +    default:
> +        __bad_atomic_size();
> +        break;
> +    }
> +}

These two functions being as similar as is possible, ...

> +#define read_atomic(p)                                                       
>   \
> +    ({                                                                       
>   \
> +        union {                                                              
>   \
> +            typeof(*(p)) val;                                                
>   \
> +            char c[sizeof(*(p))];                                            
>   \
> +        } x_;                                                                
>   \
> +        read_atomic_size(p, x_.c, sizeof(*(p)));                             
>   \
> +        x_.val;                                                              
>   \
> +    })

... is there a reason you keep using a union here ...

> +#define write_atomic(p, x)                                                   
>   \
> +    do                                                                       
>   \
> +    {                                                                        
>   \
> +        typeof(*(p)) x_ = (x);                                               
>   \
> +        write_atomic_size(p, &x_, sizeof(*(p)));                             
>   \
> +    } while ( 0 )

... while you did away with its use here?

Jan



 


Rackspace

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