summaryrefslogtreecommitdiff
path: root/tests/aslts/src/runtime/collections/mt/mutex/common.asl
blob: db79bf5144d33265c929acc910dcba5670e89a08 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
    /*
     * Some or all of this work - Copyright (c) 2006 - 2020, Intel Corp.
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * Redistributions of source code must retain the above copyright notice,
     * this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright notice,
     * this list of conditions and the following disclaimer in the documentation
     * and/or other materials provided with the distribution.
     * Neither the name of Intel Corporation nor the names of its contributors
     * may be used to endorse or promote products derived from this software
     * without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    /*
     * SEE:
     * ??????????? Multi-threading common definitions
     * see: see structure and the name of this file also later !!!!!!!!!!!!!!
     * ??????????????????????????????????????????????????????????????????????
     *
     *
     * NOTIONS and NOTATIONS:
     *
     * ID and Index of thread:
     *
     *   each thread is identified by its ID (delivered from the underlying system)
     *   and its calculated unique index between all the threads participating in
     *   the test.
     *
     * Control Thread - the thread with index equal to 0
     * Slave Threads  - all other threads with the non-zero index
     *
     * Number of threads (total) -
     *    the value passed to AcpiExec Threads command
     *    as a number of threads parameter.
     *
     * Number of threads actually in work -
     *    number of threads actually participating the relevant test.
     *    Note: this value includes the Control Thread too.
     */
    Name (Z147, 0x93)
    /*
     * Common data of threads
     *
     * Usage:
     *
     *   command line: Threads 6 1 MAIN
     *     6 - number of threads, it can be greater or less than 6
     *
     *   redm      - set it to zero to reduce the run time
     *   vb00-vb06 - use them to suppress the output
     *
     *   FLG1      - the _TCI-based Initialization of multithreading interconnection
     *               (run command TCI_CMD_GET_ID_OF_THREADS to determine indexes of threads)
     */
    /*
     * Flags
     */
    Name (CTL0, 0x00) /* the Control thread is ready */
    Name (REDM, 0x01) /* run tests in reduced mode */
    Name (GLDI, 0x00) /* global data initialized */
    /*
     * Simple switch of the verbal mode
     *
     * 0 - silent
     * otherwise - allow
     *
     * s-flags (defaults are given in comment (0/1))
     */
    Name (VB00, 0x00) /* (0) common messages */
    Name (VB02, 0x01) /* (1) trace Control thread */
    Name (VB03, 0x00) /* (0) trace Slave threads */
    Name (VB04, 0x01) /* (1) report statistics */
    Name (VB05, 0x00) /* (0) report warnings by slave-threads */
    Name (VB06, 0x01) /* (1) report errors by slave-threads */
    /*
     * Multi-conditional switches of the verbal mode
     *
     * 0 - silent
     * 1 - allow only for Control Thread to report
     * 2 - allow only for Slave Threads to report
     * 3 - allow for all threads to report
     *
     * mc-flags
     */
    Name (VB01, 0x01) /* header of test */
    /* Sleep mode */

    Name (SL00, 0x32) /* Default milliseconds to sleep for Control thread */
    Name (SL01, 0x32) /* Default milliseconds to sleep for Slave threads */
    /*
     * Default milliseconds to sleep for Control thread
     * before to check hang status of slave threads on
     * operations.
     */
    Name (SL02, 0x01F4)
    /* How many times maximum to repeat sl02 sleeping */

    Name (SL03, 0x01)
    Name (SLM0, 0x00)   /* Sleeping mode for slave threads */
    /* Milliseconds to sleep for non-zero slm0 */

    Name (I100, 0x32)
    Name (I101, 0x64)
    Name (I102, 0xC8)
    Name (I103, 0x0190)
    Name (I104, 0x01F4)
    Name (I105, 0x4B)
    Name (I106, 0x96)
    Name (I107, 0xFA)
    Name (I108, 0x012C)
    /* Commands for slaves */

    Name (C100, 0xF0) /* Idle thread */
    Name (C101, 0xF1) /* Exit the infinite loop */
    Name (C102, 0xF2) /* Sleep for the specified number of Milliseconds */
    Name (C103, 0xF3) /* Acquire/Sleep/Release */
    Name (C104, 0xF4) /* <Acquire/Sleep>(0-15 levels)/Release(15-0 levels) */
    Name (C105, 0xF5) /* Example 0 */
    Name (C106, 0xF6) /* Acquire specified set of mutexes */
    Name (C107, 0xF7) /* Release specified set of mutexes */
    Name (C108, 0xF8) /* Terminate thread */
    Name (C109, 0xF9) /* Invoke Serialized method */
    Name (C10A, 0xFA) /* Invoke non-Serialized method, use Mutex for exclusive access to critical section */
    Name (C10B, 0xFB) /* Non-serialized method is grabbed simultaneously */
    /* Responds of slave threads (not intersect with 'Commands for slaves') */

    Name (RS00, 0x97) /* "I see zero do00" */
    /* Common use strategies provided by the Control thread */

    Name (CM01, 0x01) /* all slaves to exit the infinite loop */
    Name (CM02, 0x02) /* all slaves to sleep for the specified period */
    /*
     * This buffer is to be filled by the control thread.
     * It is filed with the commands to be fulfilled by the
     * slave threads.
     *
     * The thread of i-th index takes the command from the
     * i-th element of Buffer.
     *
     * It is read-only for slave threads.
     */
    Name (BS00, Buffer (0x01)
    {
         0x00                                             // .
    })
    /*
     * This buffer is zeroed by the control thread and then to be
     * filled by the slave threads with the commands they have been
     * fulfilled.
     */
    Name (BS01, Buffer (0x01)
    {
         0x00                                             // .
    })
    /*
     * This buffer is zeroed by the control thread and then to be
     * filled by the slave threads when they see that do00 is zero.
     *
     * The control thread uses it to check that all the slave threads
     * saw zero do00 (are idle) before to start the next command.
     */
    Name (BS02, Buffer (0x01)
    {
         0x00                                             // .
    })
    /*
     * This buffer is zeroed by the control thread and then to
     * be filled by the idle slave threads.
     */
    Name (BS03, Buffer (0x01)
    {
         0x00                                             // .
    })
    /*
     * This buffer is zeroed by the control thread and then to be
     * set up by the slave threads when they complete.
     */
    Name (BS04, Buffer (0x01)
    {
         0x00                                             // .
    })
    /*
     * p10X - statistics
     */
    /*
     * These package are zeroed by the control thread,
     * the slave threads accumulate there:
     * - errors
     * - number of errors
     * - warnings
     * - number of warnings
     */
    Name (P100, Package (0x01)
    {
        0x00
    }) /* scale of errors */
    Name (P101, Package (0x01)
    {
        0x00
    }) /* number of errors */
    Name (P102, Package (0x01)
    {
        0x00
    }) /* scale of warnings */
    Name (P103, Package (0x01)
    {
        0x00
    }) /* number of warnings */
    /* Command statistics */

    Name (P104, Package (0x01)
    {
        0x00
    }) /* number of Sleep */
    Name (P105, Package (0x01)
    {
        0x00
    }) /* number of Acquire */
    Name (P106, Package (0x01)
    {
        0x00
    }) /* number of Release */
    /*
     * To be filled by the control thread,
     * non-zero enables to fulfill the commands specified by bs00.
     */
    Name (DO00, 0x00)
    /* Opcodes of errors reported by slave threads */

    Name (ER00, 0x01) /* Acquire failed */
    Name (ER01, 0x02) /* Flag of mutex is already non-zero (set up by some thread(s)) */
    Name (ER02, 0x04) /* Invalid flag of mutex (changed by other thread while this one owned that mutex) */
    Name (ER03, 0x08) /* Unexpected exception */
    Name (ER04, 0x10) /* Improper exception (no exception, or unexpected opcode, or more than one exception) */
    Name (ER05, 0x20) /* Invalid command */
    Name (ER06, 0x40) /* Invalid Index of current thread */
    Name (ER07, 0x80) /* Too big Index of current thread */
    Name (ER08, 0x0100) /* Invalid counter of mutex owning */
    Name (ER09, 0x0200) /* Acquire returned zero but FAIL expected */
    Name (ER10, 0x0400) /* Serialized method doesnt provide exclusive call */
    Name (ER11, 0x0800) /* Serialized method doesnt provide exclusive call */
    Name (ER12, 0x1000) /* Non-serialized method thr-1 didn't get into method */
    Name (ER13, 0x2000) /* Non-serialized method thr-N didn't get into method */
    /* Opcodes of warnings reported by slave threads */

    Name (WN00, 0x01) /* Acquire repeatedly the same mutex by thread which already owns it */
    /*
     * These packages are to be filled by the control thread.
     * They are filed with the arguments of commands specified
     * for the slave threads.
     *
     * The thread of i-th index takes the arguments from the
     * i-th elements of Packages.
     *
     * These are read-only for slave threads.
     *
     * For Acquire/Release:
     *
     * p200 - starting level of mutex
     * p201 - number of Levels of mutexes
     * p202 - starting index of mutex (on the specified level)
     * p203 - number of mutexes of the same level
     * p204 - exceptional conditions
     * p205 - opcode of TimeOutValue (see comment to ma00)
     */
    Name (P200, Package (0x01)
    {
        0x00
    })
    Name (P201, Package (0x01)
    {
        0x00
    })
    Name (P202, Package (0x01)
    {
        0x00
    })
    Name (P203, Package (0x01)
    {
        0x00
    })
    Name (P204, Package (0x01)
    {
        0x00
    })
    Name (P205, Package (0x01)
    {
        0x00
    })
    /* Exceptions total number */

    Name (EX10, 0x00)
    /*
     * p30X - Current state
     */
    Name (P300, Package (0x01)
    {
        0x00
    }) /* scale of errors */
    Name (P301, Package (0x01)
    {
        0x00
    }) /* scale of warnings */
    /*
     * Non-zero means to check absence of exception
     * before and after each operation additionally
     * to the checking (if any) specified per-operation.
     */
    Name (FLG0, 0x00)
    /*
     * Handle exceptions
     *
     * Exceptional condition flag:
     *
     * EX0D      - FAIL expected
     * EX0E      - check for "no exception"
     * otherwise - opcode of exception expected
     */
    /*
     * The _TCI-based Initialization of multithreading interconnection
     * (run command TCI_CMD_GET_ID_OF_THREADS to determine indexes of threads).
     *
     * Note: now when arguments (arg0, arg1, arg2) are determined
     *       by Threads command of AcpiExec and passed to test, it
     *       is unnecessary to do "The _TCI-based Initialization of
     *       multithreading interconnection" below. Used temporary.
     */
    Name (FLG1, 0x00)
    /*
     * Variables used by particular tests
     *
     * FLG2,
     * FLG3
     *   1) To show that Serialized method is grabbed exclusively
     *   2) To show that non-Serialized method is grabbed by two threads simultaneously
     */
    Name (FLG2, 0x00)
    Name (FLG3, 0x00)
    /*
     * The Control Thread manages and controls the specified testing strategy
     * to be fulfilled by the Slave Threads.
     *
     * arg0 - number of threads
     * arg1 - ID of current thread (0, can be used for control only)
     * arg2 - Index of current thread
     * arg3 - cammand - index of the test strategy to be
     *        managed and controlled by the Control Thread
     *        and fulfilled by the Slave Threads (Slaves).
     *
     * Arguments of the command arg3:
     *
     * arg4
     * arg5
     * arg6
     */
    Method (M100, 7, Serialized)
    {
        /* Prohibits activity of all the slave threads */

        Switch (Arg3)
        {
            Case (0x01)
            {
                /* CM01: All slaves to exit the infinite loop */

                M10C (Arg0)
            }
            Case (0x02)
            {
                /* CM02: All slaves to sleep for the specified period */

                M10D (Arg0)
            }

        }
    }

    /*
     * Open testing - init interaction data
     *
     * arg0 - number of threads
     */
    Method (M102, 1, Serialized)
    {
        Name (B000, Buffer (Arg0){})
        Name (P000, Package (Arg0){})
        Name (LPN0, 0x00)
        Name (LPC0, 0x00)
        DO00 = 0x00
        CopyObject (B000, BS00) /* \BS00 */
        CopyObject (B000, BS01) /* \BS01 */
        CopyObject (B000, BS02) /* \BS02 */
        CopyObject (B000, BS03) /* \BS03 */
        CopyObject (P000, P200) /* \P200 */
        CopyObject (P000, P201) /* \P201 */
        CopyObject (P000, P202) /* \P202 */
        CopyObject (P000, P203) /* \P203 */
        CopyObject (P000, P204) /* \P204 */
        CopyObject (P000, P205) /* \P205 */
        CopyObject (P000, P300) /* \P300 */
        CopyObject (P000, P301) /* \P301 */
        LPN0 = Arg0
        LPC0 = 0x00
        While (LPN0)
        {
            P300 [LPC0] = 0x00
            P301 [LPC0] = 0x00
            LPN0--
            LPC0++
        }

        /*
         * Initialization to be done once
         */
        If (!GLDI)
        {
            /* Statistics */

            CopyObject (P000, P100) /* \P100 */
            CopyObject (P000, P101) /* \P101 */
            CopyObject (P000, P102) /* \P102 */
            CopyObject (P000, P103) /* \P103 */
            CopyObject (P000, P104) /* \P104 */
            CopyObject (P000, P105) /* \P105 */
            CopyObject (P000, P106) /* \P106 */
            CopyObject (B000, BS04) /* \BS04 */
            LPN0 = Arg0
            LPC0 = 0x00
            While (LPN0)
            {
                P100 [LPC0] = 0x00
                P101 [LPC0] = 0x00
                P102 [LPC0] = 0x00
                P103 [LPC0] = 0x00
                P104 [LPC0] = 0x00
                P105 [LPC0] = 0x00
                P106 [LPC0] = 0x00
                LPN0--
                LPC0++
            }
        }

        /* Init fl01 */

        M339 ()
        /*
         * Reset all counters (cnt0) and flags (fl00)
         * corresponding to all Mutexes.
         */
        M330 ()
        /* Report that the Control thread is ready */

        CTL0 = 0x01
        GLDI = 0x01
    }

    /*
     * Control thread waits for all the slave threads to
     * fulfill the specified for them buffer of commands.
     *
     * arg0 - number of threads
     */
    Method (M103, 1, Serialized)
    {
        /* Wait for all Slave threads and check their statuses */

        Name (B000, Buffer (Arg0){})
        Name (B001, Buffer (Arg0){})
        Name (B002, Buffer (Arg0){})
        CopyObject (BS00, B000) /* \M103.B000 */
        M110 (Arg0, B000, B001, B002)
    }

    /*
     * The _TCI-based initialization of multithreading interconnection
     *
     * In result each thread knows its ID and calculated its index
     * between all threads participating in the test.
     *
     * arg0 - number of threads
     *
     * Return:
     *   success   - II-Package
     *   otherwise - 0
     */
    Method (M104, 1, NotSerialized)
    {
        /*
         * Local0 - array of thread IDs
         * Local1 - auxiliary
         * Local2 - auxiliary
         * Local7 - II-Package
         */
        If (VB00)
        {
            Debug = "Checking for the Test Command Interface with the ACPICA (_TCI) support"
        }

        If (!M3A5 ())
        {
            Debug = "The Test Command Interface with the ACPICA (_TCI) is not supported"
            Return (0x00)
        }

        If (VB00)
        {
            Debug = "Getting array of thread IDs"
        }

        Local0 = M163 (Arg0)
        Local1 = ObjectType (Local0)
        If ((Local1 != C00C))
        {
            Debug = "Failed to get array of thread indexes"
            Return (0x00)
        }

        If (VB00)
        {
            Debug = "Calculating index of thread"
        }

        Local7 = M105 (Local0, Arg0)
        Local2 = ObjectType (Local7)
        If ((Local2 != C00C))
        {
            Debug = "Invalid contents of Package of threads"
            Return (0x00)
        }

        Return (Local7)
    }

    /*
     * Calculate and return II-Package with Index of current thread between
     * all threads participating in the test and ID of that thread.
     *
     * arg0 - the Package of thread IDs returned by m163 which
     *        executes the command TCI_CMD_GET_ID_OF_THREADS.
     * arg1 - number of threads
     *
     * Return:
     * II-Package in success:
     *	0-th element - ID of that current thread
     *	1-th element - Index of current thread between all threads participating in test
     * Integer otherwise:
     *    0
     */
    Method (M105, 2, NotSerialized)
    {
        /*
         * Local0 - auxiliary
         * Local1 - auxiliary
         * Local2 - lpN0
         * Local3 - lpC0
         * Local4 - TCI_PACKAGE_THR_NUM
         * Local5 - TCI_PACKAGE_THR_NUM_REAL
         * Local6 - TCI_PACKAGE_THR_ID (ID of thread)
         * Local7 - Index of thread
         */
        Local7 = FF32 /* \FF32 */
        /* Store(arg0, Debug) */

        Local4 = DerefOf (Arg0 [C22C]) /* TCI_PACKAGE_THR_NUM */
        If (!Local4)
        {
            Debug = "TCI_PACKAGE_THR_NUM is zero"
            Return (0x00)
        }

        Local5 = DerefOf (Arg0 [C22D]) /* TCI_PACKAGE_THR_NUM_REAL */
        If (!Local5)
        {
            Debug = "TCI_PACKAGE_THR_NUM_REAL is zero"
            Return (0x00)
        }

        Local6 = DerefOf (Arg0 [C22E]) /* TCI_PACKAGE_THR_ID */
        If (!Local6)
        {
            Debug = "TCI_PACKAGE_THR_ID is zero"
            Return (0x00)
        }

        If ((Local4 != Local5))
        {
            Debug = "TCI_PACKAGE_THR_NUM != TCI_PACKAGE_THR_NUM_REAL"
            Debug = Local4
            Debug = Local5
            Return (0x00)
        }

        If ((Local4 != Arg1))
        {
            Debug = "TCI_PACKAGE_THR_NUM != Number of threads"
            Debug = Local4
            Debug = Arg1
            Return (0x00)
        }

        /* Calculate index of thread */

        Local2 = Arg1
        Local3 = 0x00
        Local0 = C22F /* \C22F */
        While (Local2)
        {
            Local1 = DerefOf (Arg0 [Local0])
            If (!Local1)
            {
                Debug = "thread ID is zero"
                Return (0x00)
            }
            ElseIf ((Local1 == Local6))
            {
                If ((Local7 != FF32))
                {
                    Debug = "thread ID encountered twice"
                    Return (0x00)
                }

                Local7 = Local3
            }

            Local0++
            Local2--
            Local3++
        }

        /* Return Package: Index of current thread, ID of current thread */

        Local0 = Package (0x02){}
        Local0 [0x00] = Local6
        Local0 [0x01] = Local7
        Return (Local0)
    }

    /*
     * Report errors detected by the slave threads
     *
     * arg0 - name of test
     * arg1 - number of threads
     */
    Method (M106, 2, Serialized)
    {
        Name (LPN0, 0x00)
        Name (LPC0, 0x00)
        LPN0 = Arg1
        LPC0 = 0x00
        While (LPN0)
        {
            Local0 = DerefOf (P300 [LPC0])
            If (Local0)
            {
                /*
                 * Reports:
                 * lpC0   - Index of thread
                 * Local0 - the scale of its errors
                 */
                ERR (Arg0, Z147, __LINE__, 0x00, 0x00, LPC0, Local0)
            }

            LPN0--
            LPC0++
        }
    }

    /*
     * Initialization of multithreading interconnection
     *
     * Note: now when arguments (arg0, arg1, arg2) are determined
     *       by Threads command of AcpiExec and passed to test, it
     *       is unnecessary to do "The _TCI-based Initialization of
     *       multithreading interconnection" below. Used temporary.
     *
     * arg0 - number of threads
     * arg1 - ID of current thread
     * arg2 - Index of current thread
     * arg3 - minimal number of threads needed for test
     */
    Method (M107, 4, NotSerialized)
    {
        /* Set the multi-threading mode flag */

        SET3 (0x01)
        /*
         * Local0 - auxiliary
         * Local1 - auxiliary
         * Local6 - ID of thread
         * Local7 - Index of thread
         */
        /* The _TCI-based Initialization of multithreading interconnection */
        If (FLG1)
        {
            Local0 = M104 (Arg0)
            Local1 = ObjectType (Local0)
            If ((Local1 != C00C))
            {
                ERR ("m107", Z147, __LINE__, 0x00, 0x00, Local1, C00C)
                Return (0x00)
            }

            /* Get ID and Index of current thread */

            Local6 = DerefOf (Local0 [0x00])
            Local7 = DerefOf (Local0 [0x01])
            If ((Local6 != Arg1))
            {
                ERR ("m107", Z147, __LINE__, 0x00, 0x00, Local6, Arg1)
                Return (0x00)
            }

            If ((Local7 != Arg2))
            {
                ERR ("m107", Z147, __LINE__, 0x00, 0x00, Local7, Arg2)
                Return (0x00)
            }
        }

        If (((Arg0 < 0x02) || (Arg0 < Arg3)))
        {
            Debug = "Insufficient number of threads for Test!"
            Return (0x00)
        }

        Return (0x01)
    }

    /*
     * Close testing
     *
     * arg0 - name of test
     * arg1 - number of threads
     * arg2 - ID of current thread
     * arg3 - Index of current thread
     */
    Method (M108, 4, NotSerialized)
    {
        /* all slaves to exit the infinite loop */

        M100 (Arg1, Arg2, Arg3, CM01, 0x00, 0x00, 0x00)
        /* Report errors detected by the slave threads */

        M106 (Arg0, Arg1)
    }

    /*
     * CM01: all slaves to exit the infinite loop
     *
     * arg0 - number of threads
     */
    Method (M10C, 1, Serialized)
    {
        /* All slaves to exit the infinite loop */

        M200 (BS00, Arg0, C101) /* cmd: Exit the infinite loop */
        M114 (Arg0)
        /* Wait for all Slave threads */

        Name (B000, Buffer (Arg0){})
        Name (B001, Buffer (Arg0){})
        Name (B002, Buffer (Arg0){})
        CopyObject (BS00, B000) /* \M10C.B000 */
        M110 (Arg0, B000, B001, B002)
    }

    /*
     * CM02: all slaves to sleep for the specified period
     *
     * arg0 - number of threads
     */
    Method (M10D, 1, NotSerialized)
    {
        /* All slaves to sleep for the specified period */

        M200 (BS00, Arg0, C102) /* cmd: Sleep for the specified number of Milliseconds */
        M114 (Arg0)
        /* Wait for all Slave threads */

        M103 (Arg0)
    }

    /*
     * Control thread checks that the specified set of slave threads
     * hang on the specified operations or completed the operations.
     *
     * arg0 - number of threads
     * arg1 - buffer of arg0 length
     *        1 - check completion of operation
     *        2 - check hang
     *
     * Return:
     *   These mean unexpected behaviour:
     *     0x01 - some threads has not completed operation
     *     0x02 - some threads are not hang on operation
     *   These report the contents of buffer:
     *     0x10 - has checkings of completed operation
     *     0x20 - has checkings of hang on operation
     */
    Method (M10E, 2, Serialized)
    {
        Name (LPN0, 0x00)
        Name (LPC0, 0x00)
        Name (RVAL, 0x00)
        LPN0 = Arg0
        LPC0 = 0x00
        While (LPN0)
        {
            /* For not a Control thread only */

            If ((LPC0 != 0x00))
            {
                Local0 = DerefOf (Arg1 [LPC0])
                Local1 = DerefOf (BS01 [LPC0])
                If ((Local0 == 0x01))
                {
                    /* check completion of operation */

                    RVAL |= 0x10
                    If (!Local1)
                    {
                        RVAL |= 0x01
                    }
                }
                ElseIf ((Local0 == 0x02))
                {
                    /* check hang */

                    RVAL |= 0x20
                    If (Local1)
                    {
                        RVAL |= 0x02
                    }
                }
            }

            LPN0--
            LPC0++
        }

        Return (RVAL) /* \M10E.RVAL */
    }

    /*
     * Run and analyze result of m10e()
     *
     * arg0,
     * arg1 - see m10e
     */
    Method (M10F, 2, Serialized)
    {
        Name (LPN0, 0x00)
        Name (LPC0, 0x00)
        Name (RVAL, 0x00)
        LPN0 = SL03 /* \SL03 */
        LPC0 = 0x00
        While (LPN0)
        {
            Sleep (SL02)
            RVAL = M10E (Arg0, Arg1)
            If (!(RVAL & 0x20))
            {
                /* doesn't have checkings of hang */

                If (!(RVAL & 0x01))
                {
                    /* all examined have completed */

                    Break
                }
            }

            LPN0--
            LPC0++
        }

        Return (RVAL) /* \M10F.RVAL */
    }

    /*
     * Control thread waits for all the slave threads to
     * fulfill the specified for them buffer of commands.
     *
     * arg0 - number of threads (total)
     * arg1 - the per-thread expectations of completion status mapping buffer
     * arg2 - the per-thread expectations of hang       status mapping buffer
     * arg3 - the per-thread expectations of idle       status mapping buffer
     */
    Method (M110, 4, Serialized)
    {
        Name (LPN0, 0x00)
        Name (LPC0, 0x00)
        Name (FIND, 0x00)
        Name (SL80, 0x00)
        Name (SL81, 0x00)
        Name (CMD0, 0x00)
        Name (HNG0, 0x00)
        Name (IDL0, 0x00)
        Name (QUIT, 0x00)
        /*
         * Check that all the slave threads saw my
         * non-zero do00 and fulfilled the proper command.
         */
        While (0x01)
        {
            FIND = 0x00
            LPN0 = Arg0
            LPC0 = 0x00
            While (LPN0)
            {
                /* For not a Control thread only */

                If ((LPC0 != 0x00))
                {
                    CMD0 = DerefOf (Arg1 [LPC0])
                    HNG0 = DerefOf (Arg2 [LPC0])
                    IDL0 = DerefOf (Arg3 [LPC0])
                    Local0 = DerefOf (BS00 [LPC0])
                    Local1 = DerefOf (BS01 [LPC0])
                    Local2 = DerefOf (BS03 [LPC0])
                    Local3 = DerefOf (BS04 [LPC0]) /* terminated threads */
                    If (Local3){                    /* Thread already completed by c108 */
                    }
                    ElseIf (CMD0)
                    {
                        If ((Local0 != CMD0))
                        {
                            ERR ("m110", Z147, __LINE__, 0x00, 0x00, Local0, CMD0)
                            Debug = LPC0 /* \M110.LPC0 */
                        }

                        If (!Local1)
                        {
                            /* Not completed yet */

                            FIND = 0x01
                            Break
                        }
                        ElseIf ((Local1 != Local0))
                        {
                            /* Has executed unexpected command */

                            ERR ("m110", Z147, __LINE__, 0x00, 0x00, Local1, Local0)
                            Debug = LPC0 /* \M110.LPC0 */
                        }
                    }
                    ElseIf (HNG0)
                    {
                        SL81 = 0x01
                        If ((SL80 < SL03))
                        {
                            /*
                             * Delay here is some pure attempt to be objective -
                             * it can look like hang now but go just after this
                             * checking.
                             */
                            SL80++
                            Sleep (SL02)
                        }

                        Local4 = DerefOf (BS01 [LPC0])
                        If (Local4)
                        {
                            /* Doesn't hang */

                            If ((Local4 != Local0))
                            {
                                /* Has executed unexpected command */

                                ERR ("m110", Z147, __LINE__, 0x00, 0x00, Local1, Local0)
                                Debug = LPC0 /* \M110.LPC0 */
                            }

                            ERR ("m110", Z147, __LINE__, 0x00, 0x00, Local0, Local4)
                            Debug = LPC0 /* \M110.LPC0 */
                        }
                    }
                    ElseIf (IDL0)
                    {
                        If ((Local0 != C100))
                        {
                            ERR ("m110", Z147, __LINE__, 0x00, 0x00, Local0, CMD0)
                            Debug = LPC0 /* \M110.LPC0 */
                        }

                        If (!Local2)
                        {
                            /* Not completed yet */

                            FIND = 0x01
                            Break
                        }
                        ElseIf ((Local2 != C100))
                        {
                            /* Has executed unexpected command */

                            ERR ("m110", Z147, __LINE__, 0x00, 0x00, Local0, CMD0)
                            Debug = LPC0 /* \M110.LPC0 */
                        }
                    }
                    Else
                    {
                        ERR ("m110", Z147, __LINE__, 0x00, 0x00, LPC0, Local0)
                        Debug = LPC0 /* \M110.LPC0 */
                    }
                }

                LPN0--
                LPC0++
            }

            QUIT = 0x00
            If (!FIND)
            {
                QUIT = 0x01
                /*
                 * All threads except those being checked for hang status
                 * have completed their commands.
                 */
                If (SL81)
                {
                    /* Has threads to check hang status */

                    If ((SL80 < SL03))
                    {
                        /* Not completed yet the specified delay */

                        QUIT = 0x00
                    }
                }
            }

            If (QUIT)
            {
                Break
            }

            /*
             * Don't report about Control thread sleeping -
             * don't use m206(0, sl00).
             */
            Sleep (SL00)
        }

        /*
         * Set do00 to zero and check that all the slave threads
         * saw my zero do00 (if only it is not the EXIT command).
         */
        M200 (BS02, Arg0, 0x00)
        DO00 = 0x00
        While (0x01)
        {
            FIND = 0x00
            LPN0 = Arg0
            LPC0 = 0x00
            While (LPN0)
            {
                /* For not a Control thread only */

                If ((LPC0 != 0x00))
                {
                    /*
                     * Reset the specified command for each thread
                     * which in fact doesn't hang.
                     */
                    Local0 = DerefOf (BS02 [LPC0])
                    If (Local0)
                    {
                        /* Alive, doesn't hang, so reset its command */

                        BS00 [LPC0] = C100 /* \C100 */
                        BS01 [LPC0] = 0x00
                    }

                    /*
                     * For all threads except those being checked for
                     * hang status and completed already.
                     */
                    HNG0 = DerefOf (Arg2 [LPC0])
                    Local0 = DerefOf (BS04 [LPC0])
                    If ((!HNG0 && !Local0))
                    {
                        Local0 = DerefOf (BS02 [LPC0])
                        If (!Local0)
                        {
                            FIND = 0x01
                            Break
                        }
                    }
                }

                LPN0--
                LPC0++
            }

            /*
             * All threads except those being checked for hang status
             * have zeroed do00.
             */
            If (!FIND)
            {
                Break
            }

            /*
             * Don't report about Control thread sleeping -
             * don't use m206(0, sl00).
             */
            Sleep (SL00)
        }
        /* All the slave threads are ready for any next command */
    }

    /*
     * Check absence of exception
     *
     * arg0 - ID of current thread
     * arg1 - Index of current thread
     * arg2 - exceptional condition flag
     * arg3 - the name of operation
     *
     * Return opcode of exception to be generated or zero
     */
    Method (M111, 4, Serialized)
    {
        If ((FLG0 || Arg2))
        {
            Local0 = CH08 ("m111", Arg0, Z147, 0x0C, 0x00, 0x00)
            If (Local0)
            {
                SE00 (Arg1, ER03, "Error er03")
            }
        }

        /* Analyze opcode of exception to be generated */

        Switch (Arg2)
        {
            Case (0x00)
            {
                Local0 = 0x00
            }
            Case (0xFE)
            {
                /* EX0E - check "no exception" */

                Local0 = 0x00
            }
            Case (0xFD)
            {
                /* EX0D - FAIL expected */

                Local0 = Arg2
                Concatenate (Arg3, ", generating FAIL condition ", Local1)
                M201 (Arg1, VB03, Local1)
            }
            Default
            {
                Local0 = Arg2
                Concatenate (Arg3, ", generating exceptional condition ", Local1)
                Concatenate (Local1, Local0, Local1)
                M201 (Arg1, VB03, Local1)
            }

        }

        Return (Local0)
    }

    /*
     * Check exception
     *
     * arg0 - ID of current thread
     * arg1 - Index of current thread
     * arg2 - exceptional condition flag
     * arg3 - return code of operation
     */
    Method (M112, 4, NotSerialized)
    {
        Local2 = 0x00
        If ((Arg2 == EX0E))
        {
            /* check "no exception" */

            Local0 = CH08 ("m112", Arg0, Z147, 0x0D, 0x00, 0x00)
            If (Local0)
            {
                SE00 (Arg1, ER03, "Error er03")
            }
        }
        ElseIf ((Arg2 == EX0D))
        {
            /* FAIL of operation expected */

            If (!Arg3)
            {
                ERR ("m112", Z147, __LINE__, 0x00, 0x00, Arg3, 0x01)
            }
        }
        ElseIf (Arg2)
        {
            /* check presence of particular exception */

            Local0 = CH09 (0x00, Arg0, Arg2, Z147, 0x0F, RefOf (Local2))
            If (Local0)
            {
                SE00 (Arg1, ER04, "Error er04")
            }
        }

        If (FLG0)
        {
            Local0 = CH08 ("m112", Arg0, Z147, 0x10, 0x00, 0x00)
            If (Local0)
            {
                SE00 (Arg1, ER03, "Error er03")
            }
        }
    }

    /*
     * Control thread initiates execution of commands by the slave threads
     *
     * arg0 - number of threads (total)
     */
    Method (M114, 1, NotSerialized)
    {
        M200 (BS01, Arg0, 0x00)
        M200 (BS03, Arg0, 0x00)
        DO00 = 0x01
    }

    /*
     * Return index of the greatest alive non-terminated yet thread
     *
     * arg0 - number of threads
     */
    Method (M115, 1, Serialized)
    {
        Name (LPN0, 0x00)
        Name (LPC0, 0x00)
        /* Means 'not found' */

        Local7 = Arg0
        /* Inverse order, excluding a Control thread */

        LPN0 = (Arg0 - 0x01)
        LPC0 = (Arg0 - 0x01)
        While (LPN0)
        {
            Local0 = DerefOf (BS04 [LPC0])
            If (!Local0)
            {
                Local7 = LPC0 /* \M115.LPC0 */
                Break
            }

            LPN0--
            LPC0--
        }

        Return (Local7)
    }

    /*
     * Add error-bit relative to arg0-th thread
     *
     * arg0 - Index of thread
     * arg1 - error-bit
     * arg2 - message
     */
    Method (SE00, 3, NotSerialized)
    {
        Local0 = DerefOf (P300 [Arg0])
        Local1 = (Arg1 | Local0)
        P300 [Arg0] = Local1
        If (VB04)
        {
            /* Add scale of Errors */

            Local0 = DerefOf (P100 [Arg0])
            Local1 = (Arg1 | Local0)
            P100 [Arg0] = Local1
            /* Increment statistics of Errors (number) */

            M212 (RefOf (P101), Arg0)
        }

        If (VB06)
        {
            Concatenate ("ERROR: ", Arg2, Local0)
            M201 (Arg0, 0x01, Local0)
        }
    }

    /*
     * Add warning-bit relative to arg0-th thread
     *
     * arg0 - Index of thread
     * arg1 - warning-bit
     * arg2 - message
     */
    Method (WRN0, 3, NotSerialized)
    {
        Local0 = DerefOf (P301 [Arg0])
        Local1 = (Arg1 | Local0)
        P301 [Arg0] = Local1
        If (VB04)
        {
            /* Add scale of Warnings */

            Local0 = DerefOf (P102 [Arg0])
            Local1 = (Arg1 | Local0)
            P102 [Arg0] = Local1
            /* Increment statistics of Warnings (number) */

            M212 (RefOf (P103), Arg0)
        }

        If (VB05)
        {
            Concatenate ("WARNING: ", Arg2, Local0)
            M201 (Arg0, 0x01, Local0)
        }
    }