Page ofGA22-7000-4 Revised September 1, 1975
By TNL: GN22-0498 SRR UPDATE Routine
Initial conditions:
General register (GR) 2 contains the address of the word
to be updated. L 3,0(2) FETCH THE WORD TRY AGN LR 4,3 MOVE IT TO GR4
[ANY INSTRUCTION] MODIFY GR4 (e.g., add a constant,
set a bit, etc.) CS BNE
3,4,0(2) STORE THE NEW VALUE IF THE WORD HAS NOT CHANGED
TRYAGN
The branch to TRY AGN is different from "bit-spinning" in that the branch will be taken only if some other program modifies the update location. If a number of CPUs simul­
taneously attempt to modify one location, one CPU will
fall through the loop, another will loop once, and so on until
all CPUs have succeeded.
Bypassing POST The following routine allows the SVC "POST" as used in OS/VS to be bypassed whenever the corresponding WAIT
has not yet been issued, provided that the supervisor WAIT
and POST routines use COMPARE AND SWAP to manipu­
late event control blocks (ECBs). BYPASS POST Routine
Initial conditions:
GRl contains the address of the ECB. GRO contains the POST code. HSPOST L 3,0(1) GR3 = CONTENTS OF ECB
LTR 3,3 ECB MARKED 'WAITING'
BM PSVC YES, ISSUE AN SVC CS 3,0,0(1) NO, STORE POST CODE BE EXIT CONTINUE PSVC SVC POST ECB ADDRESS IS IN GRl, POST CODE IN GRO EXIT [ANY INSTRUCTION] A corresponding bypass WAIT function, using TM, is in
use at present.
The following routine may be used in place of the previous HSPOST routine if the ECB is assumed to contain zeros
when it is not "WAITING." HSPOST SR 0,0 CS 0,2,0(1) BE EXIT SVC POST EXIT [ANY INSTRUCTION] Lock/Unlock When SRRs larger than a doubleword are to be updated, it
is usually necessary to provide special interlocks to ensure
312 System/370 Principles of Operation
that a single program at a time updates the SRR. In general,
updating a list, or even scanning a list, cannot be safely
accomplished without first "freezing" the list. However,
the COMPARE AND SWAP instructions can be used in
certain restricted situations to perform queuing and list
manipulation. Of prime importance is the capability to per­
form the lock/unlock functions and to provide sufficient
queuing to resolve contentions, either in a LIFO or FIFO manner. The lock/unlock functions can then be used as the
interlock mechanism for updating an SRR of any complexity.
The lock/unlock functions are based on the use of a header
associated with the SRR. The header is the common starting
point for determining the states of the SRR, either free or
in use, and is also used for queuing requests when con­
tentions occur. Contentions are resolved using WAIT and POST. Although the examples do not show it, it is expected
that the BYPASS WAIT and BYPASS POST would be used.
The general programming technique requires that the pro­
gram that encounters a locked SRR must "leave a mark on
the wall" indicating the address of an ECB on which it will
WAIT. The program "unlocking" sees the mark and posts
the ECB, thus permitting the waiting program to continue.
In the two examples given, all programs using a particular SRR must use either the LIFO queuing scheme or the FIFO scheme; the two cannot be mixed. When more complex
queuing is required, it is suggested that the queue for the SRR be locked using one of the two methods shown. Lock/Unlock with LIFO Queuing for Contentions
The header consists of a word, which can contain zero, a
positive value, or a negative value. A zero value indicates that the SRR is free. A negative value indicates that the SRR is in use but no
additional programs are waiting for the SRR. A positive value indicates that the SRR is in use and that
one or more additional programs are waiting for the SRR.
Each waiting program is identified by an element in a
chained list. The positive value in the header is the address
of the element most recently added to the list. . Each element consists of two words. The first word is used
as an ECB; the second word is used as a pointer to the next
element in the list. A negative value in a pointer indicates
that the element is the last element in the list. The element
is required only if the program finds the SRR locked and
desires to be placed in the list.
The following char
f . scribes the action taken for LIFO LOCK and LIFO UNLOCK routines.
Action
Function
Header
Header Header
Contains
Contains Contains
Zero
Positive Negative
Value Value LIFO LOCK (The incoming element is at location AI SRR is free. SRR is in use. Store the contents Set the header to of the header into location A +4.
a negative value. Store the address A into the header.
Use the SRR. WAIT; the ECB is at location A.
LI FO UNLOCK Error Someone is The list is empty.
waiting for the Store zeros into SRR. Move the the header. The
pointer from the SRR is free. "last in" element into the header. POST; the ECB
is in the "Iast in" element. The following routines allow enabled code to perform the
actions described in the previous chart.
LIFO LOCK Routine:
Initial conditions:
GRI contains the address of the incoming element.
GR2 contains the address of the header. LLOCK SR 3,3 GR3 ::;: 0 ST 3,0(1) INITIALIZE THE ECB
LNR 0,1 GRO = A NEGATIVE VALUE TRYAGN CS 3,0,0(2) SET tHE HEADER TO A NEGATIVE V ALUE IF THE HEADER CON­ TAINS ZEROS BE USE DID THE HEADER CONTAIN ZEROS? ST 3,4(1) NO, STORE THE VALUE OF THE
HEADER INTO THE POINTER IN
THE INCOMING ELEMENT CS 3,1,0(2) STORE THE ADDRESS OF THE
INCOMING ELEMENT INTO THE
HEADER
LA 3,0(0) GR3 = 0 BNE TRYAGNDID THE HEADER GET UPDATED?
WAIT (1) YES, WAIT FOR THE RESOURCE; THE ECB IS IN THE INCOMING
ELEMENT USE [ANY INSTRUCTION] LIFO UNLOCK Routine:
Initial conditions:
GR2 contains the address of the header. LUNLK L 1,0(2) GRI ::;: THE CONTENTS OF THE
A
B
EXIT
LTR 1,1
BM B
L 0,4(1) CS 1,0,0(2) HEADER DOES THE HEADER CONTAIN A
NEGATIVE VALUE? NO, LOAD THE POINTER FROM THE "LAST IN" ELEMENT AND STORE IT
IN THE HEADER
BNE A DID THE HEADER GET UPDATED? POST (1) YES, POST THE "LAST IN" ELEMENT
B EXIT CONTINUE SR 0,0 THE HEADER CONTAINS A NEGATIVE CS 1,0,0(2) VALUE; FREE THE HEADER AND
BNE A CONTINUE [ANY INSTRUCTION] Page of GA22-7000-4 Revised September 1, 1975
By TNL: GN22-0498
Note that the L 1,0(2) instruction at location LUNLK
would have to be CS 1,1,0(2) if it were not for the rule
that a full word fetch starting on a word boundary must
fetch the word such that if another CPU changes the word
being fetched, either the entire new or the entire old value
of the word, and not a combination of the two, is obtained.
LOCK/UNLOCK with FIFO Queuing for Contentions
Both a header and a free element are associated with the SRR. Each program using the SRR must provide an element
regardless of whether contention occurs. The element pro­
vided by the program becomes the new free element, and
the old free element becomes the program's new current
element. The free element is initialized to contain a posted
ECB. In the example, the element need be only a single
word. In some cases, the element could be made larger to
include a reverse pointer to the previous element.
The following chart describes the action taken for FIFO LOCK and FIFO UNLOCK routines.
Function FIFO LOCK (The incoming element is at location A) FIFO UNLOCK Action
Store the address A into the header. WAIT; the ECB is at the location addressed by the old contents of the
header. POST; the ECB is at the location that
you specified as an element when you locked. The following routines allow enabled code to perform the
actions described in the previous chart.
FIFO LOCK Routine:
Initial conditions: PNTRS is a doubleword containing two pointers. The first
word is a pointer to the current element owned by this
program. The second word is a pointer to the previous
element owned by this program.
GR3 contains the address of the header. FLOCK L 2,PNTRS GR2 = ADDRESS OF THE SR ST L
1,1 1,0(2) 1,0(3) CURRENT ELEMENT
GRI = ZERO INITIALIZE THE ECB
GRI = CONTENTS OF THE OLD ELEMENT TRY AGN CS 1,2,0(3) STORE THE ADDRESS OF THE USE BNE TRY AGN CURRENT ELEMENT INTO THE
HEADER, CURRENT ELEMENT BECOMES NEW FREE ELEMENT
STM 1,2PNTRS SAVE THE ADDRESSES IN GRI
WAIT (1) , AND GR2 FOR FUTURE USE, CURRENT ELEMENT BECOMES PREVIOUS ELEMENT, OLD FREE ELEMENT BECOMES CURRENT ELEMENT
GRI CONTAINS THE ADDRESS OF THE ECB [ANY INSTRUCTION] I:(' < , k Appendix I. Number Representation and Instruction-Use Examples 313
Previous Page Next Page