summaryrefslogtreecommitdiffstats
path: root/tools/memory-model
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2018-12-11 11:38:53 -0500
committerPaul E. McKenney <paulmck@linux.ibm.com>2019-03-18 13:27:52 -0400
commit648e717586f2a832687fe44e2e0afb7a6fdea232 (patch)
tree584681e0101cfe03755e20a99faaafc1f885ad04 /tools/memory-model
parentad9fd20b6dadb0cb14551477fcebe0fdf2e697dd (diff)
tools/memory-model: Update Documentation/explanation.txt to include SRCU support
The recent commit adding support for SRCU to the Linux Kernel Memory Model ended up changing the names and meanings of several relations. This patch updates the explanation.txt documentation file to reflect those changes. It also revises the statement of the RCU Guarantee to a more accurate form, and it adds a short paragraph mentioning the new support for SRCU. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Cc: Akira Yokosawa <akiyks@gmail.com> Cc: Andrea Parri <andrea.parri@amarulasolutions.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Daniel Lustig <dlustig@nvidia.com> Cc: David Howells <dhowells@redhat.com> Cc: Jade Alglave <j.alglave@ucl.ac.uk> Cc: Luc Maranget <luc.maranget@inria.fr> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: "Paul E. McKenney" <paulmck@linux.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com> Acked-by: Andrea Parri <andrea.parri@amarulasolutions.com>
Diffstat (limited to 'tools/memory-model')
-rw-r--r--tools/memory-model/Documentation/explanation.txt289
1 files changed, 152 insertions, 137 deletions
diff --git a/tools/memory-model/Documentation/explanation.txt b/tools/memory-model/Documentation/explanation.txt
index 35bff92cc773..68caa9a976d0 100644
--- a/tools/memory-model/Documentation/explanation.txt
+++ b/tools/memory-model/Documentation/explanation.txt
@@ -27,7 +27,7 @@ Explanation of the Linux-Kernel Memory Consistency Model
27 19. AND THEN THERE WAS ALPHA 27 19. AND THEN THERE WAS ALPHA
28 20. THE HAPPENS-BEFORE RELATION: hb 28 20. THE HAPPENS-BEFORE RELATION: hb
29 21. THE PROPAGATES-BEFORE RELATION: pb 29 21. THE PROPAGATES-BEFORE RELATION: pb
30 22. RCU RELATIONS: rcu-link, gp, rscs, rcu-fence, and rb 30 22. RCU RELATIONS: rcu-link, rcu-gp, rcu-rscsi, rcu-fence, and rb
31 23. LOCKING 31 23. LOCKING
32 24. ODDS AND ENDS 32 24. ODDS AND ENDS
33 33
@@ -1430,8 +1430,8 @@ they execute means that it cannot have cycles. This requirement is
1430the content of the LKMM's "propagation" axiom. 1430the content of the LKMM's "propagation" axiom.
1431 1431
1432 1432
1433RCU RELATIONS: rcu-link, gp, rscs, rcu-fence, and rb 1433RCU RELATIONS: rcu-link, rcu-gp, rcu-rscsi, rcu-fence, and rb
1434---------------------------------------------------- 1434-------------------------------------------------------------
1435 1435
1436RCU (Read-Copy-Update) is a powerful synchronization mechanism. It 1436RCU (Read-Copy-Update) is a powerful synchronization mechanism. It
1437rests on two concepts: grace periods and read-side critical sections. 1437rests on two concepts: grace periods and read-side critical sections.
@@ -1446,17 +1446,19 @@ As far as memory models are concerned, RCU's main feature is its
1446Grace-Period Guarantee, which states that a critical section can never 1446Grace-Period Guarantee, which states that a critical section can never
1447span a full grace period. In more detail, the Guarantee says: 1447span a full grace period. In more detail, the Guarantee says:
1448 1448
1449 If a critical section starts before a grace period then it 1449 For any critical section C and any grace period G, at least
1450 must end before the grace period does. In addition, every 1450 one of the following statements must hold:
1451 store that propagates to the critical section's CPU before the
1452 end of the critical section must propagate to every CPU before
1453 the end of the grace period.
1454 1451
1455 If a critical section ends after a grace period ends then it 1452(1) C ends before G does, and in addition, every store that
1456 must start after the grace period does. In addition, every 1453 propagates to C's CPU before the end of C must propagate to
1457 store that propagates to the grace period's CPU before the 1454 every CPU before G ends.
1458 start of the grace period must propagate to every CPU before 1455
1459 the start of the critical section. 1456(2) G starts before C does, and in addition, every store that
1457 propagates to G's CPU before the start of G must propagate
1458 to every CPU before C starts.
1459
1460In particular, it is not possible for a critical section to both start
1461before and end after a grace period.
1460 1462
1461Here is a simple example of RCU in action: 1463Here is a simple example of RCU in action:
1462 1464
@@ -1483,10 +1485,11 @@ The Grace Period Guarantee tells us that when this code runs, it will
1483never end with r1 = 1 and r2 = 0. The reasoning is as follows. r1 = 1 1485never end with r1 = 1 and r2 = 0. The reasoning is as follows. r1 = 1
1484means that P0's store to x propagated to P1 before P1 called 1486means that P0's store to x propagated to P1 before P1 called
1485synchronize_rcu(), so P0's critical section must have started before 1487synchronize_rcu(), so P0's critical section must have started before
1486P1's grace period. On the other hand, r2 = 0 means that P0's store to 1488P1's grace period, contrary to part (2) of the Guarantee. On the
1487y, which occurs before the end of the critical section, did not 1489other hand, r2 = 0 means that P0's store to y, which occurs before the
1488propagate to P1 before the end of the grace period, violating the 1490end of the critical section, did not propagate to P1 before the end of
1489Guarantee. 1491the grace period, contrary to part (1). Together the results violate
1492the Guarantee.
1490 1493
1491In the kernel's implementations of RCU, the requirements for stores 1494In the kernel's implementations of RCU, the requirements for stores
1492to propagate to every CPU are fulfilled by placing strong fences at 1495to propagate to every CPU are fulfilled by placing strong fences at
@@ -1504,11 +1507,11 @@ before" or "ends after" a grace period? Some aspects of the meaning
1504are pretty obvious, as in the example above, but the details aren't 1507are pretty obvious, as in the example above, but the details aren't
1505entirely clear. The LKMM formalizes this notion by means of the 1508entirely clear. The LKMM formalizes this notion by means of the
1506rcu-link relation. rcu-link encompasses a very general notion of 1509rcu-link relation. rcu-link encompasses a very general notion of
1507"before": Among other things, X ->rcu-link Z includes cases where X 1510"before": If E and F are RCU fence events (i.e., rcu_read_lock(),
1508happens-before or is equal to some event Y which is equal to or comes 1511rcu_read_unlock(), or synchronize_rcu()) then among other things,
1509before Z in the coherence order. When Y = Z this says that X ->rfe Z 1512E ->rcu-link F includes cases where E is po-before some memory-access
1510implies X ->rcu-link Z. In addition, when Y = X it says that X ->fr Z 1513event X, F is po-after some memory-access event Y, and we have any of
1511and X ->co Z each imply X ->rcu-link Z. 1514X ->rfe Y, X ->co Y, or X ->fr Y.
1512 1515
1513The formal definition of the rcu-link relation is more than a little 1516The formal definition of the rcu-link relation is more than a little
1514obscure, and we won't give it here. It is closely related to the pb 1517obscure, and we won't give it here. It is closely related to the pb
@@ -1516,171 +1519,173 @@ relation, and the details don't matter unless you want to comb through
1516a somewhat lengthy formal proof. Pretty much all you need to know 1519a somewhat lengthy formal proof. Pretty much all you need to know
1517about rcu-link is the information in the preceding paragraph. 1520about rcu-link is the information in the preceding paragraph.
1518 1521
1519The LKMM also defines the gp and rscs relations. They bring grace 1522The LKMM also defines the rcu-gp and rcu-rscsi relations. They bring
1520periods and read-side critical sections into the picture, in the 1523grace periods and read-side critical sections into the picture, in the
1521following way: 1524following way:
1522 1525
1523 E ->gp F means there is a synchronize_rcu() fence event S such 1526 E ->rcu-gp F means that E and F are in fact the same event,
1524 that E ->po S and either S ->po F or S = F. In simple terms, 1527 and that event is a synchronize_rcu() fence (i.e., a grace
1525 there is a grace period po-between E and F. 1528 period).
1526 1529
1527 E ->rscs F means there is a critical section delimited by an 1530 E ->rcu-rscsi F means that E and F are the rcu_read_unlock()
1528 rcu_read_lock() fence L and an rcu_read_unlock() fence U, such 1531 and rcu_read_lock() fence events delimiting some read-side
1529 that E ->po U and either L ->po F or L = F. You can think of 1532 critical section. (The 'i' at the end of the name emphasizes
1530 this as saying that E and F are in the same critical section 1533 that this relation is "inverted": It links the end of the
1531 (in fact, it also allows E to be po-before the start of the 1534 critical section to the start.)
1532 critical section and F to be po-after the end).
1533 1535
1534If we think of the rcu-link relation as standing for an extended 1536If we think of the rcu-link relation as standing for an extended
1535"before", then X ->gp Y ->rcu-link Z says that X executes before a 1537"before", then X ->rcu-gp Y ->rcu-link Z roughly says that X is a
1536grace period which ends before Z executes. (In fact it covers more 1538grace period which ends before Z begins. (In fact it covers more than
1537than this, because it also includes cases where X executes before a 1539this, because it also includes cases where some store propagates to
1538grace period and some store propagates to Z's CPU before Z executes 1540Z's CPU before Z begins but doesn't propagate to some other CPU until
1539but doesn't propagate to some other CPU until after the grace period 1541after X ends.) Similarly, X ->rcu-rscsi Y ->rcu-link Z says that X is
1540ends.) Similarly, X ->rscs Y ->rcu-link Z says that X is part of (or 1542the end of a critical section which starts before Z begins.
1541before the start of) a critical section which starts before Z 1543
1542executes. 1544The LKMM goes on to define the rcu-fence relation as a sequence of
1543 1545rcu-gp and rcu-rscsi links separated by rcu-link links, in which the
1544The LKMM goes on to define the rcu-fence relation as a sequence of gp 1546number of rcu-gp links is >= the number of rcu-rscsi links. For
1545and rscs links separated by rcu-link links, in which the number of gp 1547example:
1546links is >= the number of rscs links. For example:
1547 1548
1548 X ->gp Y ->rcu-link Z ->rscs T ->rcu-link U ->gp V 1549 X ->rcu-gp Y ->rcu-link Z ->rcu-rscsi T ->rcu-link U ->rcu-gp V
1549 1550
1550would imply that X ->rcu-fence V, because this sequence contains two 1551would imply that X ->rcu-fence V, because this sequence contains two
1551gp links and only one rscs link. (It also implies that X ->rcu-fence T 1552rcu-gp links and one rcu-rscsi link. (It also implies that
1552and Z ->rcu-fence V.) On the other hand: 1553X ->rcu-fence T and Z ->rcu-fence V.) On the other hand:
1553 1554
1554 X ->rscs Y ->rcu-link Z ->rscs T ->rcu-link U ->gp V 1555 X ->rcu-rscsi Y ->rcu-link Z ->rcu-rscsi T ->rcu-link U ->rcu-gp V
1555 1556
1556does not imply X ->rcu-fence V, because the sequence contains only 1557does not imply X ->rcu-fence V, because the sequence contains only
1557one gp link but two rscs links. 1558one rcu-gp link but two rcu-rscsi links.
1558 1559
1559The rcu-fence relation is important because the Grace Period Guarantee 1560The rcu-fence relation is important because the Grace Period Guarantee
1560means that rcu-fence acts kind of like a strong fence. In particular, 1561means that rcu-fence acts kind of like a strong fence. In particular,
1561if W is a write and we have W ->rcu-fence Z, the Guarantee says that W 1562E ->rcu-fence F implies not only that E begins before F ends, but also
1562will propagate to every CPU before Z executes. 1563that any write po-before E will propagate to every CPU before any
1564instruction po-after F can execute. (However, it does not imply that
1565E must execute before F; in fact, each synchronize_rcu() fence event
1566is linked to itself by rcu-fence as a degenerate case.)
1563 1567
1564To prove this in full generality requires some intellectual effort. 1568To prove this in full generality requires some intellectual effort.
1565We'll consider just a very simple case: 1569We'll consider just a very simple case:
1566 1570
1567 W ->gp X ->rcu-link Y ->rscs Z. 1571 G ->rcu-gp W ->rcu-link Z ->rcu-rscsi F.
1568 1572
1569This formula means that there is a grace period G and a critical 1573This formula means that G and W are the same event (a grace period),
1570section C such that: 1574and there are events X, Y and a read-side critical section C such that:
1571 1575
1572 1. W is po-before G; 1576 1. G = W is po-before or equal to X;
1573 1577
1574 2. X is equal to or po-after G; 1578 2. X comes "before" Y in some sense (including rfe, co and fr);
1575 1579
1576 3. X comes "before" Y in some sense; 1580 2. Y is po-before Z;
1577 1581
1578 4. Y is po-before the end of C; 1582 4. Z is the rcu_read_unlock() event marking the end of C;
1579 1583
1580 5. Z is equal to or po-after the start of C. 1584 5. F is the rcu_read_lock() event marking the start of C.
1581 1585
1582From 2 - 4 we deduce that the grace period G ends before the critical 1586From 1 - 4 we deduce that the grace period G ends before the critical
1583section C. Then the second part of the Grace Period Guarantee says 1587section C. Then part (2) of the Grace Period Guarantee says not only
1584not only that G starts before C does, but also that W (which executes 1588that G starts before C does, but also that any write which executes on
1585on G's CPU before G starts) must propagate to every CPU before C 1589G's CPU before G starts must propagate to every CPU before C starts.
1586starts. In particular, W propagates to every CPU before Z executes 1590In particular, the write propagates to every CPU before F finishes
1587(or finishes executing, in the case where Z is equal to the 1591executing and hence before any instruction po-after F can execute.
1588rcu_read_lock() fence event which starts C.) This sort of reasoning 1592This sort of reasoning can be extended to handle all the situations
1589can be expanded to handle all the situations covered by rcu-fence. 1593covered by rcu-fence.
1590 1594
1591Finally, the LKMM defines the RCU-before (rb) relation in terms of 1595Finally, the LKMM defines the RCU-before (rb) relation in terms of
1592rcu-fence. This is done in essentially the same way as the pb 1596rcu-fence. This is done in essentially the same way as the pb
1593relation was defined in terms of strong-fence. We will omit the 1597relation was defined in terms of strong-fence. We will omit the
1594details; the end result is that E ->rb F implies E must execute before 1598details; the end result is that E ->rb F implies E must execute
1595F, just as E ->pb F does (and for much the same reasons). 1599before F, just as E ->pb F does (and for much the same reasons).
1596 1600
1597Putting this all together, the LKMM expresses the Grace Period 1601Putting this all together, the LKMM expresses the Grace Period
1598Guarantee by requiring that the rb relation does not contain a cycle. 1602Guarantee by requiring that the rb relation does not contain a cycle.
1599Equivalently, this "rcu" axiom requires that there are no events E and 1603Equivalently, this "rcu" axiom requires that there are no events E
1600F with E ->rcu-link F ->rcu-fence E. Or to put it a third way, the 1604and F with E ->rcu-link F ->rcu-fence E. Or to put it a third way,
1601axiom requires that there are no cycles consisting of gp and rscs 1605the axiom requires that there are no cycles consisting of rcu-gp and
1602alternating with rcu-link, where the number of gp links is >= the 1606rcu-rscsi alternating with rcu-link, where the number of rcu-gp links
1603number of rscs links. 1607is >= the number of rcu-rscsi links.
1604 1608
1605Justifying the axiom isn't easy, but it is in fact a valid 1609Justifying the axiom isn't easy, but it is in fact a valid
1606formalization of the Grace Period Guarantee. We won't attempt to go 1610formalization of the Grace Period Guarantee. We won't attempt to go
1607through the detailed argument, but the following analysis gives a 1611through the detailed argument, but the following analysis gives a
1608taste of what is involved. Suppose we have a violation of the first 1612taste of what is involved. Suppose both parts of the Guarantee are
1609part of the Guarantee: A critical section starts before a grace 1613violated: A critical section starts before a grace period, and some
1610period, and some store propagates to the critical section's CPU before 1614store propagates to the critical section's CPU before the end of the
1611the end of the critical section but doesn't propagate to some other 1615critical section but doesn't propagate to some other CPU until after
1612CPU until after the end of the grace period. 1616the end of the grace period.
1613 1617
1614Putting symbols to these ideas, let L and U be the rcu_read_lock() and 1618Putting symbols to these ideas, let L and U be the rcu_read_lock() and
1615rcu_read_unlock() fence events delimiting the critical section in 1619rcu_read_unlock() fence events delimiting the critical section in
1616question, and let S be the synchronize_rcu() fence event for the grace 1620question, and let S be the synchronize_rcu() fence event for the grace
1617period. Saying that the critical section starts before S means there 1621period. Saying that the critical section starts before S means there
1618are events E and F where E is po-after L (which marks the start of the 1622are events Q and R where Q is po-after L (which marks the start of the
1619critical section), E is "before" F in the sense of the rcu-link 1623critical section), Q is "before" R in the sense used by the rcu-link
1620relation, and F is po-before the grace period S: 1624relation, and R is po-before the grace period S. Thus we have:
1621 1625
1622 L ->po E ->rcu-link F ->po S. 1626 L ->rcu-link S.
1623 1627
1624Let W be the store mentioned above, let Z come before the end of the 1628Let W be the store mentioned above, let Y come before the end of the
1625critical section and witness that W propagates to the critical 1629critical section and witness that W propagates to the critical
1626section's CPU by reading from W, and let Y on some arbitrary CPU be a 1630section's CPU by reading from W, and let Z on some arbitrary CPU be a
1627witness that W has not propagated to that CPU, where Y happens after 1631witness that W has not propagated to that CPU, where Z happens after
1628some event X which is po-after S. Symbolically, this amounts to: 1632some event X which is po-after S. Symbolically, this amounts to:
1629 1633
1630 S ->po X ->hb* Y ->fr W ->rf Z ->po U. 1634 S ->po X ->hb* Z ->fr W ->rf Y ->po U.
1631 1635
1632The fr link from Y to W indicates that W has not propagated to Y's CPU 1636The fr link from Z to W indicates that W has not propagated to Z's CPU
1633at the time that Y executes. From this, it can be shown (see the 1637at the time that Z executes. From this, it can be shown (see the
1634discussion of the rcu-link relation earlier) that X and Z are related 1638discussion of the rcu-link relation earlier) that S and U are related
1635by rcu-link, yielding: 1639by rcu-link:
1636 1640
1637 S ->po X ->rcu-link Z ->po U. 1641 S ->rcu-link U.
1638 1642
1639The formulas say that S is po-between F and X, hence F ->gp X. They 1643Since S is a grace period we have S ->rcu-gp S, and since L and U are
1640also say that Z comes before the end of the critical section and E 1644the start and end of the critical section C we have U ->rcu-rscsi L.
1641comes after its start, hence Z ->rscs E. From all this we obtain: 1645From this we obtain:
1642 1646
1643 F ->gp X ->rcu-link Z ->rscs E ->rcu-link F, 1647 S ->rcu-gp S ->rcu-link U ->rcu-rscsi L ->rcu-link S,
1644 1648
1645a forbidden cycle. Thus the "rcu" axiom rules out this violation of 1649a forbidden cycle. Thus the "rcu" axiom rules out this violation of
1646the Grace Period Guarantee. 1650the Grace Period Guarantee.
1647 1651
1648For something a little more down-to-earth, let's see how the axiom 1652For something a little more down-to-earth, let's see how the axiom
1649works out in practice. Consider the RCU code example from above, this 1653works out in practice. Consider the RCU code example from above, this
1650time with statement labels added to the memory access instructions: 1654time with statement labels added:
1651 1655
1652 int x, y; 1656 int x, y;
1653 1657
1654 P0() 1658 P0()
1655 { 1659 {
1656 rcu_read_lock(); 1660 L: rcu_read_lock();
1657 W: WRITE_ONCE(x, 1); 1661 X: WRITE_ONCE(x, 1);
1658 X: WRITE_ONCE(y, 1); 1662 Y: WRITE_ONCE(y, 1);
1659 rcu_read_unlock(); 1663 U: rcu_read_unlock();
1660 } 1664 }
1661 1665
1662 P1() 1666 P1()
1663 { 1667 {
1664 int r1, r2; 1668 int r1, r2;
1665 1669
1666 Y: r1 = READ_ONCE(x); 1670 Z: r1 = READ_ONCE(x);
1667 synchronize_rcu(); 1671 S: synchronize_rcu();
1668 Z: r2 = READ_ONCE(y); 1672 W: r2 = READ_ONCE(y);
1669 } 1673 }
1670 1674
1671 1675
1672If r2 = 0 at the end then P0's store at X overwrites the value that 1676If r2 = 0 at the end then P0's store at Y overwrites the value that
1673P1's load at Z reads from, so we have Z ->fre X and thus Z ->rcu-link X. 1677P1's load at W reads from, so we have W ->fre Y. Since S ->po W and
1674In addition, there is a synchronize_rcu() between Y and Z, so therefore 1678also Y ->po U, we get S ->rcu-link U. In addition, S ->rcu-gp S
1675we have Y ->gp Z. 1679because S is a grace period.
1676 1680
1677If r1 = 1 at the end then P1's load at Y reads from P0's store at W, 1681If r1 = 1 at the end then P1's load at Z reads from P0's store at X,
1678so we have W ->rcu-link Y. In addition, W and X are in the same critical 1682so we have X ->rfe Z. Together with L ->po X and Z ->po S, this
1679section, so therefore we have X ->rscs W. 1683yields L ->rcu-link S. And since L and U are the start and end of a
1684critical section, we have U ->rcu-rscsi L.
1680 1685
1681Then X ->rscs W ->rcu-link Y ->gp Z ->rcu-link X is a forbidden cycle, 1686Then U ->rcu-rscsi L ->rcu-link S ->rcu-gp S ->rcu-link U is a
1682violating the "rcu" axiom. Hence the outcome is not allowed by the 1687forbidden cycle, violating the "rcu" axiom. Hence the outcome is not
1683LKMM, as we would expect. 1688allowed by the LKMM, as we would expect.
1684 1689
1685For contrast, let's see what can happen in a more complicated example: 1690For contrast, let's see what can happen in a more complicated example:
1686 1691
@@ -1690,51 +1695,52 @@ For contrast, let's see what can happen in a more complicated example:
1690 { 1695 {
1691 int r0; 1696 int r0;
1692 1697
1693 rcu_read_lock(); 1698 L0: rcu_read_lock();
1694 W: r0 = READ_ONCE(x); 1699 r0 = READ_ONCE(x);
1695 X: WRITE_ONCE(y, 1); 1700 WRITE_ONCE(y, 1);
1696 rcu_read_unlock(); 1701 U0: rcu_read_unlock();
1697 } 1702 }
1698 1703
1699 P1() 1704 P1()
1700 { 1705 {
1701 int r1; 1706 int r1;
1702 1707
1703 Y: r1 = READ_ONCE(y); 1708 r1 = READ_ONCE(y);
1704 synchronize_rcu(); 1709 S1: synchronize_rcu();
1705 Z: WRITE_ONCE(z, 1); 1710 WRITE_ONCE(z, 1);
1706 } 1711 }
1707 1712
1708 P2() 1713 P2()
1709 { 1714 {
1710 int r2; 1715 int r2;
1711 1716
1712 rcu_read_lock(); 1717 L2: rcu_read_lock();
1713 U: r2 = READ_ONCE(z); 1718 r2 = READ_ONCE(z);
1714 V: WRITE_ONCE(x, 1); 1719 WRITE_ONCE(x, 1);
1715 rcu_read_unlock(); 1720 U2: rcu_read_unlock();
1716 } 1721 }
1717 1722
1718If r0 = r1 = r2 = 1 at the end, then similar reasoning to before shows 1723If r0 = r1 = r2 = 1 at the end, then similar reasoning to before shows
1719that W ->rscs X ->rcu-link Y ->gp Z ->rcu-link U ->rscs V ->rcu-link W. 1724that U0 ->rcu-rscsi L0 ->rcu-link S1 ->rcu-gp S1 ->rcu-link U2 ->rcu-rscsi
1720However this cycle is not forbidden, because the sequence of relations 1725L2 ->rcu-link U0. However this cycle is not forbidden, because the
1721contains fewer instances of gp (one) than of rscs (two). Consequently 1726sequence of relations contains fewer instances of rcu-gp (one) than of
1722the outcome is allowed by the LKMM. The following instruction timing 1727rcu-rscsi (two). Consequently the outcome is allowed by the LKMM.
1723diagram shows how it might actually occur: 1728The following instruction timing diagram shows how it might actually
1729occur:
1724 1730
1725P0 P1 P2 1731P0 P1 P2
1726-------------------- -------------------- -------------------- 1732-------------------- -------------------- --------------------
1727rcu_read_lock() 1733rcu_read_lock()
1728X: WRITE_ONCE(y, 1) 1734WRITE_ONCE(y, 1)
1729 Y: r1 = READ_ONCE(y) 1735 r1 = READ_ONCE(y)
1730 synchronize_rcu() starts 1736 synchronize_rcu() starts
1731 . rcu_read_lock() 1737 . rcu_read_lock()
1732 . V: WRITE_ONCE(x, 1) 1738 . WRITE_ONCE(x, 1)
1733W: r0 = READ_ONCE(x) . 1739r0 = READ_ONCE(x) .
1734rcu_read_unlock() . 1740rcu_read_unlock() .
1735 synchronize_rcu() ends 1741 synchronize_rcu() ends
1736 Z: WRITE_ONCE(z, 1) 1742 WRITE_ONCE(z, 1)
1737 U: r2 = READ_ONCE(z) 1743 r2 = READ_ONCE(z)
1738 rcu_read_unlock() 1744 rcu_read_unlock()
1739 1745
1740This requires P0 and P2 to execute their loads and stores out of 1746This requires P0 and P2 to execute their loads and stores out of
@@ -1744,6 +1750,15 @@ section in P0 both starts before P1's grace period does and ends
1744before it does, and the critical section in P2 both starts after P1's 1750before it does, and the critical section in P2 both starts after P1's
1745grace period does and ends after it does. 1751grace period does and ends after it does.
1746 1752
1753Addendum: The LKMM now supports SRCU (Sleepable Read-Copy-Update) in
1754addition to normal RCU. The ideas involved are much the same as
1755above, with new relations srcu-gp and srcu-rscsi added to represent
1756SRCU grace periods and read-side critical sections. There is a
1757restriction on the srcu-gp and srcu-rscsi links that can appear in an
1758rcu-fence sequence (the srcu-rscsi links must be paired with srcu-gp
1759links having the same SRCU domain with proper nesting); the details
1760are relatively unimportant.
1761
1747 1762
1748LOCKING 1763LOCKING
1749------- 1764-------