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#include "qemu/osdep.h"
26
27#include "hw/i386/topology.h"
28
29static void test_topo_bits(void)
30{
31 X86CPUTopoInfo topo_info = {0};
32
33
34 topo_info = (X86CPUTopoInfo) {1, 1, 1};
35 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 0);
36 g_assert_cmpuint(apicid_core_width(&topo_info), ==, 0);
37 g_assert_cmpuint(apicid_die_width(&topo_info), ==, 0);
38
39 topo_info = (X86CPUTopoInfo) {1, 1, 1};
40 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0);
41 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1), ==, 1);
42 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2), ==, 2);
43 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 3), ==, 3);
44
45
46
47
48 topo_info = (X86CPUTopoInfo) {1, 1, 2};
49 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 1);
50 topo_info = (X86CPUTopoInfo) {1, 1, 3};
51 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2);
52 topo_info = (X86CPUTopoInfo) {1, 1, 4};
53 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2);
54
55 topo_info = (X86CPUTopoInfo) {1, 1, 14};
56 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4);
57 topo_info = (X86CPUTopoInfo) {1, 1, 15};
58 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4);
59 topo_info = (X86CPUTopoInfo) {1, 1, 16};
60 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4);
61 topo_info = (X86CPUTopoInfo) {1, 1, 17};
62 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 5);
63
64
65 topo_info = (X86CPUTopoInfo) {1, 30, 2};
66 g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5);
67 topo_info = (X86CPUTopoInfo) {1, 31, 2};
68 g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5);
69 topo_info = (X86CPUTopoInfo) {1, 32, 2};
70 g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5);
71 topo_info = (X86CPUTopoInfo) {1, 33, 2};
72 g_assert_cmpuint(apicid_core_width(&topo_info), ==, 6);
73
74 topo_info = (X86CPUTopoInfo) {1, 30, 2};
75 g_assert_cmpuint(apicid_die_width(&topo_info), ==, 0);
76 topo_info = (X86CPUTopoInfo) {2, 30, 2};
77 g_assert_cmpuint(apicid_die_width(&topo_info), ==, 1);
78 topo_info = (X86CPUTopoInfo) {3, 30, 2};
79 g_assert_cmpuint(apicid_die_width(&topo_info), ==, 2);
80 topo_info = (X86CPUTopoInfo) {4, 30, 2};
81 g_assert_cmpuint(apicid_die_width(&topo_info), ==, 2);
82
83
84
85
86
87
88 topo_info = (X86CPUTopoInfo) {1, 6, 3};
89 g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2);
90 g_assert_cmpuint(apicid_core_offset(&topo_info), ==, 2);
91 g_assert_cmpuint(apicid_die_offset(&topo_info), ==, 5);
92 g_assert_cmpuint(apicid_pkg_offset(&topo_info), ==, 5);
93
94 topo_info = (X86CPUTopoInfo) {1, 6, 3};
95 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0);
96 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1), ==, 1);
97 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2), ==, 2);
98
99 topo_info = (X86CPUTopoInfo) {1, 6, 3};
100 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 0), ==,
101 (1 << 2) | 0);
102 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 1), ==,
103 (1 << 2) | 1);
104 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 2), ==,
105 (1 << 2) | 2);
106
107 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2 * 3 + 0), ==,
108 (2 << 2) | 0);
109 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2 * 3 + 1), ==,
110 (2 << 2) | 1);
111 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2 * 3 + 2), ==,
112 (2 << 2) | 2);
113
114 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 5 * 3 + 0), ==,
115 (5 << 2) | 0);
116 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 5 * 3 + 1), ==,
117 (5 << 2) | 1);
118 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 5 * 3 + 2), ==,
119 (5 << 2) | 2);
120
121 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info,
122 1 * 6 * 3 + 0 * 3 + 0), ==, (1 << 5));
123 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info,
124 1 * 6 * 3 + 1 * 3 + 1), ==, (1 << 5) | (1 << 2) | 1);
125 g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info,
126 3 * 6 * 3 + 5 * 3 + 2), ==, (3 << 5) | (5 << 2) | 2);
127}
128
129int main(int argc, char **argv)
130{
131 g_test_init(&argc, &argv, NULL);
132
133 g_test_add_func("/cpuid/topology/basic", test_topo_bits);
134
135 g_test_run();
136
137 return 0;
138}
139