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

Re: [XEN PATCH 3/4] xen/include: add pure and const attributes


  • To: Simone Ballarin <simone.ballarin@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 23 Oct 2023 17:33:37 +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=Eu8I1csfJJwZm1xoT0r+iPBept1d5pITUiALTTVQBgs=; b=DiRBo9C7XteX/A7S1s+y+t6AuyViAnzZClLkNXLKZM6VoKYTHiCvVWdsRmw7kNMbd3Jz8mbdgNkaCG0DTUv899f1Om865d3hCpJKgf34ps5wgLD3cv4t4kOihw8pY92Khn7tyMikQhKS7FWvmd45Qp9a4RK9R/auui1yNqAf9kV6BcqBD6UNv+orPEKgcGj3IzXy4vZ8CAu06pI7YrGxi+nN5BQikluyaYItlGGmn4rAQ2mTTHM+1hRA1j/hOUAcF0hCorJHGqpeeqJS9llw20QPPvF8MmVSNq0WHehSV3g3g7rQrIu0Xwt+J5mtoHBcKQy5ex5X4xVzbj8b+XIbHA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H5h3tR1O3G0NwyMPOurKNImK4gA+cxISZ0Gs0O8x6G1xguzGKR6Je2RXKjLtKlQiyltqS+oVkxK6TkZgPcy4vlGwQPol+BoyFJxJqkxswAmu27FGUjszizriKtu3xUJh3gQfcAHId5G2pjtjfudcUE5ATrBRBLejtftAThhyF3dozX6UOXiO7CziSK88chxzJ7mfBbdjy5D7kDpzEZeyByN/xX8zPe8kyhBRl9KzmZmjTIiEWYDeHxPkfEstOVFOCXF9LX7W/A26eZUqlePUR/PVRTS7Jt+/I/Sd+Ta6C3KPCNGtbbNKy3CtLMN/Wt3rrDfeZQhiErqT1uiLhTJ/Mg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: consulting@xxxxxxxxxxx, sstabellini@xxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 23 Oct 2023 15:33:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 23.10.2023 17:23, Simone Ballarin wrote:
> On 23/10/23 15:34, Jan Beulich wrote:
>> On 18.10.2023 16:18, Simone Ballarin wrote:
>>> --- a/xen/include/xen/pdx.h
>>> +++ b/xen/include/xen/pdx.h
>>> @@ -164,7 +164,7 @@ static inline unsigned long pfn_to_pdx(unsigned long 
>>> pfn)
>>>    * @param pdx Page index
>>>    * @return Obtained pfn after decompressing the pdx
>>>    */
>>> -static inline unsigned long pdx_to_pfn(unsigned long pdx)
>>> +static inline __attribute_pure__ unsigned long pdx_to_pfn(unsigned long 
>>> pdx)
>>>   {
>>>       return (pdx & pfn_pdx_bottom_mask) |
>>>              ((pdx << pfn_pdx_hole_shift) & pfn_top_mask);
>>
>> Taking this as an example for what I've said above: The compiler can't
>> know that the globals used by the functions won't change value. Even
>> within Xen it is only by convention that these variables are assigned
>> their values during boot, and then aren't changed anymore. Which makes
>> me wonder: Did you check carefully that around the time the variables
>> have their values established, no calls to the functions exist (which
>> might then be subject to folding)?
> 
> There is no need to check that, the GCC documentation explicitly says:
> 
> However, functions declared with the pure attribute *can safely read any 
> non-volatile objects*, and modify the value of objects in a way that 
> does not affect their return value or the observable state of the program.

I did quote this same text in response to what Andrew has said, but I also
did note there that this needs to be taken with a grain of salt: The
compiler generally assumes a single-threaded environment, i.e. no changes
to globals behind the back of the code it is processing.

Jan



 


Rackspace

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