0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <inttypes.h>
0013 #include <htmintrin.h>
0014 #include <string.h>
0015 #include <stdlib.h>
0016 #include <stdio.h>
0017 #include <pthread.h>
0018 #include <sys/mman.h>
0019 #include <unistd.h>
0020
0021 #include "tm.h"
0022 #include "utils.h"
0023
0024 int passed;
0025
0026 void *worker(void *unused)
0027 {
0028 __int128 vmx0;
0029 uint64_t texasr;
0030
0031 asm goto (
0032 "li 3, 1;"
0033 "std 3, 0(%[vmx0_ptr]);"
0034 "lvx 0, 0, %[vmx0_ptr];"
0035
0036
0037 "lis 3, 0x3fff;"
0038 "1: ;"
0039 "addi 3, 3, -1;"
0040 "cmpdi 3, 0;"
0041 "bne 1b;"
0042
0043
0044
0045 "tbegin. ;"
0046 "beq failure;"
0047
0048
0049 "vaddcuw 0,0,0;"
0050
0051 "tend. ;"
0052 "b %l[success];"
0053
0054
0055 "failure: ;"
0056 "lvx 1, 0, %[vmx0_ptr];"
0057 "vcmpequb. 2, 0, 1;"
0058 "bc 4, 24, %l[value_mismatch];"
0059 "b %l[value_match];"
0060 :
0061 : [vmx0_ptr] "r"(&vmx0)
0062 : "r3"
0063 : success, value_match, value_mismatch
0064 );
0065
0066
0067 value_mismatch:
0068 texasr = __builtin_get_texasr();
0069
0070 printf("\n\n==============\n\n");
0071 printf("Failure with error: %lx\n", _TEXASR_FAILURE_CODE(texasr));
0072 printf("Summary error : %lx\n", _TEXASR_FAILURE_SUMMARY(texasr));
0073 printf("TFIAR exact : %lx\n\n", _TEXASR_TFIAR_EXACT(texasr));
0074
0075 passed = 0;
0076 return NULL;
0077
0078
0079 value_match:
0080
0081 return NULL;
0082
0083 success:
0084
0085 return NULL;
0086 }
0087
0088 int tm_vmx_unavail_test()
0089 {
0090 int threads;
0091 pthread_t *thread;
0092
0093 SKIP_IF(!have_htm());
0094 SKIP_IF(htm_is_synthetic());
0095
0096 passed = 1;
0097
0098 threads = sysconf(_SC_NPROCESSORS_ONLN) * 4;
0099 thread = malloc(sizeof(pthread_t)*threads);
0100 if (!thread)
0101 return EXIT_FAILURE;
0102
0103 for (uint64_t i = 0; i < threads; i++)
0104 pthread_create(&thread[i], NULL, &worker, NULL);
0105
0106 for (uint64_t i = 0; i < threads; i++)
0107 pthread_join(thread[i], NULL);
0108
0109 free(thread);
0110
0111 return passed ? EXIT_SUCCESS : EXIT_FAILURE;
0112 }
0113
0114
0115 int main(int argc, char **argv)
0116 {
0117 return test_harness(tm_vmx_unavail_test, "tm_vmx_unavail_test");
0118 }