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#include <inttypes.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <assert.h>
30#include <asm/tm.h>
31
32#include "utils.h"
33#include "tm.h"
34#include "../pmu/lib.h"
35
36#define SPRN_DSCR 0x03
37
38int test_body(void)
39{
40 uint64_t rv, dscr1 = 1, dscr2, texasr;
41
42 SKIP_IF(!have_htm());
43 SKIP_IF(htm_is_synthetic());
44
45 printf("Check DSCR TM context switch: ");
46 fflush(stdout);
47 for (;;) {
48 asm __volatile__ (
49
50 "ld 3, %[dscr1];"
51 "mtspr %[sprn_dscr], 3;"
52
53 "li %[rv], 1;"
54
55 "tbegin.;"
56 "beq 1f;"
57 "tsuspend.;"
58
59
60 "2: ;"
61 "tcheck 0;"
62 "bc 4, 0, 2b;"
63
64
65 "mfspr 3, %[sprn_dscr];"
66 "std 3, %[dscr2];"
67 "mfspr 3, %[sprn_texasr];"
68 "std 3, %[texasr];"
69
70 "tresume.;"
71 "tend.;"
72 "li %[rv], 0;"
73 "1: ;"
74 : [rv]"=r"(rv), [dscr2]"=m"(dscr2), [texasr]"=m"(texasr)
75 : [dscr1]"m"(dscr1)
76 , [sprn_dscr]"i"(SPRN_DSCR), [sprn_texasr]"i"(SPRN_TEXASR)
77 : "memory", "r3"
78 );
79 assert(rv);
80 if ((texasr >> 56) != TM_CAUSE_RESCHED) {
81 continue;
82 }
83 if (dscr2 != dscr1) {
84 printf(" FAIL\n");
85 return 1;
86 } else {
87 printf(" OK\n");
88 return 0;
89 }
90 }
91}
92
93static int tm_resched_dscr(void)
94{
95 return eat_cpu(test_body);
96}
97
98int main(int argc, const char *argv[])
99{
100 return test_harness(tm_resched_dscr, "tm_resched_dscr");
101}
102