This source file includes following definitions.
- tfiar_tfhar
 
- texasr
 
- test_tmspr
 
- main
 
   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 #define _GNU_SOURCE
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <unistd.h>
  30 #include <pthread.h>
  31 #include <string.h>
  32 
  33 #include "utils.h"
  34 #include "tm.h"
  35 
  36 int     num_loops       = 10000;
  37 int     passed = 1;
  38 
  39 void tfiar_tfhar(void *in)
  40 {
  41         int i, cpu;
  42         unsigned long tfhar, tfhar_rd, tfiar, tfiar_rd;
  43         cpu_set_t cpuset;
  44 
  45         CPU_ZERO(&cpuset);
  46         cpu = (unsigned long)in >> 1;
  47         CPU_SET(cpu, &cpuset);
  48         sched_setaffinity(0, sizeof(cpuset), &cpuset);
  49 
  50         
  51         tfiar = ((unsigned long)in) + 1;
  52         tfiar += 2;
  53         mtspr(SPRN_TFIAR, tfiar);
  54 
  55         
  56         tfhar = ((unsigned long)in);
  57         tfhar &= ~0x3UL;
  58         tfhar += 4;
  59         mtspr(SPRN_TFHAR, tfhar);
  60 
  61         for (i = 0; i < num_loops; i++) {
  62                 tfhar_rd = mfspr(SPRN_TFHAR);
  63                 tfiar_rd = mfspr(SPRN_TFIAR);
  64                 if ( (tfhar != tfhar_rd) || (tfiar != tfiar_rd) ) {
  65                         passed = 0;
  66                         return;
  67                 }
  68         }
  69         return;
  70 }
  71 
  72 void texasr(void *in)
  73 {
  74         unsigned long i;
  75         uint64_t result = 0;
  76 
  77         for (i = 0; i < num_loops; i++) {
  78                 asm __volatile__(
  79                         "tbegin.;"
  80                         "beq    3f ;"
  81                         "tabort. 0 ;"
  82                         "tend.;"
  83 
  84                         
  85                         "3: ;"
  86                         ::: "memory");
  87 
  88                 
  89                 result = mfspr(SPRN_TEXASR);
  90                 if ((result & TEXASR_FS) == 0) {
  91                         passed = 0;
  92                         return;
  93                 }
  94         }
  95         return;
  96 }
  97 
  98 int test_tmspr()
  99 {
 100         pthread_t       *thread;
 101         int             thread_num;
 102         unsigned long   i;
 103 
 104         SKIP_IF(!have_htm());
 105 
 106         
 107         thread_num = 10 * sysconf(_SC_NPROCESSORS_ONLN);
 108 
 109         thread = malloc(thread_num * sizeof(pthread_t));
 110         if (thread == NULL)
 111                 return EXIT_FAILURE;
 112 
 113         
 114         for (i = 0; i < thread_num; i += 2) {
 115                 if (pthread_create(&thread[i], NULL, (void *)tfiar_tfhar,
 116                                    (void *)i))
 117                         return EXIT_FAILURE;
 118         }
 119         
 120         for (i = 1; i < thread_num; i += 2) {
 121                 if (pthread_create(&thread[i], NULL, (void *)texasr, (void *)i))
 122                         return EXIT_FAILURE;
 123         }
 124 
 125         for (i = 0; i < thread_num; i++) {
 126                 if (pthread_join(thread[i], NULL) != 0)
 127                         return EXIT_FAILURE;
 128         }
 129 
 130         free(thread);
 131 
 132         if (passed)
 133                 return 0;
 134         else
 135                 return 1;
 136 }
 137 
 138 int main(int argc, char *argv[])
 139 {
 140         if (argc > 1) {
 141                 if (strcmp(argv[1], "-h") == 0) {
 142                         printf("Syntax:\t [<num loops>]\n");
 143                         return 0;
 144                 } else {
 145                         num_loops = atoi(argv[1]);
 146                 }
 147         }
 148         return test_harness(test_tmspr, "tm_tmspr");
 149 }