[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: Tue, 12 Sep 2023 08:48:07 +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=ziIlcc1oiZPK6j/k834YE6oO6Sk9Q7wyTUsUy5JeGb4=; b=YuGfSGqfCSqm8iN1fOBTI+osqsgvo0RbfbZqXDTd1Q0d3jGt8ZCek4BXZTJM6aEKey0lpkL/cdhdDZ+0HXDePxMN/0GRLpVSASGKhSJTC7/riUH1HJ1PXeLNoquZFrenWrA9BqOqRoZuATYGo5ScKIqiYnZVL92sbsCs8jk+MAk99W92HteSTv/QYdBBzChPk4ZHazdtgiAI3iWISFqpjR6xw97aNW9FERpTK0Ev6rvFomN9hawh+mN1ML8EHTbuycfGwUIegNSik1UZVwkB0l4UPHKTZrv/dyXDXfBjxl3Zhe2OfiEZXXCdxl+x+7atq1vjtyTRcK4kcJqKrsgB0A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A5RPWnCrLAR17Ch50I+QZPPyURQG7EBegU/TkNDgliO+s98t5nAngs85GiWGIRKvvS7jZhRb4pMST5PNC2Cz41D4CMT2Tp74f3SFZoRI5cFAtHX30JksI7kNiH6o7dTrYPeRbfw5f0wagbiH7FnQkGmQb6wBScshujhCh+Yezq7NgiJT4iIHFqGWSX2Wlmd+FPe478ECIAiKaYijzhH0emnQ4s/lyNDRghE429i92ue81wZmBtA5/8XnmeczRC+qjuFH2+XQ1HvceRkyfRzhm2XjNAGFJg/9VFUGLidIlF+1MqP/IBymQ6Yn1YKx0ITc2tmuiPxZVbCMJRnHDaNWyg==
  • 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: Tue, 12 Sep 2023 06:48:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12.09.2023 01:56, Shawn Anastasio wrote:
> On 9/11/23 6:33 AM, Jan Beulich wrote:
>> On 09.09.2023 00:50, Shawn Anastasio wrote:
>>> +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?
>>
> 
> Yes. In the case of read_atomic the caller is allowed (expected, even)
> to pass in const pointers for `p`, which wouldn't work if a simple
> typeof(*(p)) declaration was used since it would inherit the constness
> and thus wouldn't be passable to read_atomic_size.

But the helper function's first parameter is const volatile void *, and
while you can't assign to a const variable, such a variable can of course
have an initializer (like you have it in the write case).

Jan



 


Rackspace

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