1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015, Michael Neuling, IBM Corp.
5 * Original: Michael Neuling 3/4/2014
6 * Modified: Rashmica Gupta 8/12/2015
8 * Check if any of the Transaction Memory SPRs get corrupted.
9 * - TFIAR - stores address of location of transaction failure
10 * - TFHAR - stores address of software failure handler (if transaction
12 * - TEXASR - lots of info about the transacion(s)
14 * (1) create more threads than cpus
16 * (a) set TFIAR and TFHAR a unique value
17 * (b) loop for awhile, continually checking to see if
18 * either register has been corrupted.
21 * (a) begin transaction
22 * (b) abort transaction
23 * (c) check TEXASR to see if FS has been corrupted
36 int num_loops = 10000;
39 void tfiar_tfhar(void *in)
42 unsigned long tfhar, tfhar_rd, tfiar, tfiar_rd;
46 cpu = (unsigned long)in >> 1;
47 CPU_SET(cpu, &cpuset);
48 sched_setaffinity(0, sizeof(cpuset), &cpuset);
50 /* TFIAR: Last bit has to be high so userspace can read register */
51 tfiar = ((unsigned long)in) + 1;
53 mtspr(SPRN_TFIAR, tfiar);
55 /* TFHAR: Last two bits are reserved */
56 tfhar = ((unsigned long)in);
59 mtspr(SPRN_TFHAR, tfhar);
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) ) {
77 for (i = 0; i < num_loops; i++) {
88 /* Check the TEXASR */
89 result = mfspr(SPRN_TEXASR);
90 if ((result & TEXASR_FS) == 0) {
104 SKIP_IF(!have_htm());
106 /* To cause some context switching */
107 thread_num = 10 * sysconf(_SC_NPROCESSORS_ONLN);
109 thread = malloc(thread_num * sizeof(pthread_t));
113 /* Test TFIAR and TFHAR */
114 for (i = 0; i < thread_num; i += 2) {
115 if (pthread_create(&thread[i], NULL, (void *)tfiar_tfhar,
120 for (i = 1; i < thread_num; i += 2) {
121 if (pthread_create(&thread[i], NULL, (void *)texasr, (void *)i))
125 for (i = 0; i < thread_num; i++) {
126 if (pthread_join(thread[i], NULL) != 0)
138 int main(int argc, char *argv[])
141 if (strcmp(argv[1], "-h") == 0) {
142 printf("Syntax:\t [<num loops>]\n");
145 num_loops = atoi(argv[1]);
148 return test_harness(test_tmspr, "tm_tmspr");