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

Re: [PATCH v2 05/13] tools/xenstore: make some write limit functions static



On 03.05.23 16:51, Andrew Cooper wrote:
On 30/03/2023 9:50 am, Juergen Gross wrote:
+static void wrl_xfer_credit(wrl_creditt *debit,  wrl_creditt debit_floor,
+                           wrl_creditt *credit, wrl_creditt credit_ceil)
+       /*
+        * Transfers zero or more credit from "debit" to "credit".
+        * Transfers as much as possible while maintaining
+        * debit >= debit_floor and credit <= credit_ceil.
+        * (If that's violated already, does nothing.)
+        *
+        * Sufficient conditions to avoid overflow, either of:
+        *  |every argument| <= 0x3fffffff
+        *  |every argument| <= 1E9
+        *  |every argument| <= WRL_CREDIT_MAX
+        * (And this condition is preserved.)
+        */
+{
+       wrl_creditt xfer = MIN( *debit      - debit_floor,
+                               credit_ceil - *credit      );

MIN() evaluates its parameters multiple times.  I believe the only legal
way for the compiler to emit this code is to interleave double reads.

As with pretty much any C code, you want to read the pointers into
locals first, then operate on them, then write them out at the end.

xenstored is single-threaded. So no need to worry here.


Juergen

Attachment: OpenPGP_0xB0DE9DD628BF132F.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


 


Rackspace

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