1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35
36
37 package ti.sdo.ipc.gates;
38
39 import xdc.runtime.Error;
40 import xdc.runtime.Assert;
41 import xdc.runtime.IGateProvider;
42 import xdc.runtime.Diags;
43 import xdc.runtime.Log;
44 import xdc.rov.ViewInfo;
45
46 import ti.sdo.utils.MultiProc;
47 import ti.sdo.ipc.Ipc;
48
49 import ti.sdo.ipc.interfaces.IGateMPSupport;
50
51 /*!
52 * ======== GatePetersonN (for N processors) ========
53 * IGateMPSupport gate based on the Peterson's algorithm
54 *
55 * This module implements the {@link ti.sdo.ipc.interfaces.IGateMPSupport}
56 * interface using the Peterson Algorithm in shared memory. This
57 * implementation works for N processors.
58 *
59 * Each GatePetersonN instance requires a small piece of
60 * shared memory. The base address of this shared memory is specified as
61 * the 'sharedAddr' argument to the create. The amount of shared memory
62 * consumed by a single instance can be obtained using the
63 * {@link #sharedMemReq} call.
64 *
65 * Shared memory has to conform to the following specification. Padding is
66 * added between certain elements in shared memory if cache alignment is
67 * required for the region in which the instance is placed.
68 *
69 * @p(code)
70 *
71 * shmBaseAddr -> ------------------------------ bytes
72 * | enteredStage[0] | 4
73 * | (PADDING if aligned) |
74 * |----------------------------|
75 * | enteredStage[1] | 4
76 * | (PADDING if aligned) |
77 * |----------------------------|
78 * . . .
79 * |----------------------------|
80 * | enteredStage[N-1] | 4
81 * | (PADDING if aligned) |
82 * |----------------------------|
83 * | lastProcEnteringStage[1] | 4
84 * | (PADDING if aligned) |
85 * |----------------------------|
86 * . . .
87 * |----------------------------|
88 * | lastProcEnteringStage[N-1]| 4
89 * | (PADDING if aligned) |
90 * |----------------------------|
91 * @p
92 */
93 @InstanceInitError
94 @InstanceFinalize
95
96 module GatePetersonN inherits IGateMPSupport
97 {
98 /*! @_nodoc */
99 metaonly struct BasicView {
100 String objType;
101 Ptr localGate;
102 UInt nested;
103 String gateOwner;
104 }
105
106 /*! @_nodoc */
107 @Facet
108 metaonly config ViewInfo.Instance rovViewInfo =
109 ViewInfo.create({
110 viewMap: [
111 ['Basic',
112 {
113 type: ViewInfo.INSTANCE,
114 viewInitFxn: 'viewInitBasic',
115 structName: 'BasicView'
116 }
117 ],
118 ]
119 });
120
121 /*!
122 * ======== numInstances ========
123 * Maximum number of instances supported by the GatePetersonN module
124 */
125 config UInt numInstances = 512;
126 config UInt MAX_NUM_PROCS = 8;
127
128 instance:
129
130 /*!
131 * @_nodoc
132 * ======== enter ========
133 * Enter this gate
134 */
135 @DirectCall
136 override IArg enter();
137
138 /*!
139 * @_nodoc
140 * ======== leave ========
141 * Leave this gate
142 */
143 @DirectCall
144 override Void leave(IArg key);
145
146 internal:
147
148 const Int32 NOT_INTERESTED = -1;
149
150
151 Void postInit(Object *obj);
152
153 struct Instance_State {
154 volatile Int32 *enteredStage[MAX_NUM_PROCS];
155 volatile Int32 *lastProcEnteringStage[MAX_NUM_PROCS-1];
156 UInt16 selfId;
157 UInt16 numProcessors;
158 UInt nested;
159 IGateProvider.Handle localGate;
160 Ipc.ObjType objType;
161 SizeT cacheLineSize;
162 Bool cacheEnabled;
163 };
164 }