Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2015, Michael Neuling, IBM Corp.
0004  * Original: Michael Neuling 19/7/2013
0005  * Edited: Rashmica Gupta 01/12/2015
0006  *
0007  * Do some transactions, see if the tar is corrupted.
0008  * If the transaction is aborted, the TAR should be rolled back to the
0009  * checkpointed value before the transaction began. The value written to
0010  * TAR in suspended mode should only remain in TAR if the transaction
0011  * completes.
0012  */
0013 
0014 #include <stdio.h>
0015 #include <stdlib.h>
0016 #include <unistd.h>
0017 #include <string.h>
0018 
0019 #include "tm.h"
0020 #include "utils.h"
0021 
0022 int num_loops   = 10000;
0023 
0024 int test_tar(void)
0025 {
0026     int i;
0027 
0028     SKIP_IF(!have_htm());
0029     SKIP_IF(htm_is_synthetic());
0030     SKIP_IF(!is_ppc64le());
0031 
0032     for (i = 0; i < num_loops; i++)
0033     {
0034         uint64_t result = 0;
0035         asm __volatile__(
0036             "li 7, 1;"
0037             "mtspr  %[tar], 7;" /* tar = 1 */
0038             "tbegin.;"
0039             "beq    3f;"
0040             "li 4, 0x7000;" /* Loop lots, to use time */
0041             "2:;"           /* Start loop */
0042             "li 7, 2;"
0043             "mtspr  %[tar], 7;" /* tar = 2 */
0044             "tsuspend.;"
0045             "li 7, 3;"
0046             "mtspr  %[tar], 7;" /* tar = 3 */
0047             "tresume.;"
0048             "subi   4, 4, 1;"
0049             "cmpdi  4, 0;"
0050             "bne    2b;"
0051             "tend.;"
0052 
0053             /* Transaction sucess! TAR should be 3 */
0054             "mfspr  7, %[tar];"
0055             "ori    %[res], 7, 4;"  // res = 3|4 = 7
0056             "b  4f;"
0057 
0058             /* Abort handler. TAR should be rolled back to 1 */
0059             "3:;"
0060             "mfspr  7, %[tar];"
0061             "ori    %[res], 7, 8;"  // res = 1|8 = 9
0062             "4:;"
0063 
0064             : [res]"=r"(result)
0065             : [tar]"i"(SPRN_TAR)
0066                : "memory", "r0", "r4", "r7");
0067 
0068         /* If result is anything else other than 7 or 9, the tar
0069          * value must have been corrupted. */
0070         if ((result != 7) && (result != 9))
0071             return 1;
0072     }
0073     return 0;
0074 }
0075 
0076 int main(int argc, char *argv[])
0077 {
0078     /* A low number of iterations (eg 100) can cause a false pass */
0079     if (argc > 1) {
0080         if (strcmp(argv[1], "-h") == 0) {
0081             printf("Syntax:\n\t%s [<num loops>]\n",
0082                    argv[0]);
0083             return 1;
0084         } else {
0085             num_loops = atoi(argv[1]);
0086         }
0087     }
0088 
0089     printf("Starting, %d loops\n", num_loops);
0090 
0091     return test_harness(test_tar, "tm_tar");
0092 }