@@ -31,26 +31,26 @@ void cpuinfo_x86_freebsd_init(void) {
31
31
struct cpuinfo_freebsd_topology freebsd_topology = cpuinfo_freebsd_detect_topology ();
32
32
processors = calloc (freebsd_topology .threads , sizeof (struct cpuinfo_processor ));
33
33
if (processors == NULL ) {
34
- cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " logical processors" ,
34
+ cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " logical processors" ,
35
35
freebsd_topology .threads * sizeof (struct cpuinfo_processor ), freebsd_topology .threads );
36
36
goto cleanup ;
37
37
}
38
38
cores = calloc (freebsd_topology .cores , sizeof (struct cpuinfo_core ));
39
39
if (cores == NULL ) {
40
- cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " cores" ,
40
+ cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " cores" ,
41
41
freebsd_topology .cores * sizeof (struct cpuinfo_core ), freebsd_topology .cores );
42
42
goto cleanup ;
43
43
}
44
44
/* On x86 cluster of cores is a physical package */
45
45
clusters = calloc (freebsd_topology .packages , sizeof (struct cpuinfo_cluster ));
46
46
if (clusters == NULL ) {
47
- cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " core clusters" ,
47
+ cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " core clusters" ,
48
48
freebsd_topology .packages * sizeof (struct cpuinfo_cluster ), freebsd_topology .packages );
49
49
goto cleanup ;
50
50
}
51
51
packages = calloc (freebsd_topology .packages , sizeof (struct cpuinfo_package ));
52
52
if (packages == NULL ) {
53
- cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " physical packages" ,
53
+ cpuinfo_log_error ("failed to allocate %zu bytes for descriptions of %" PRIu32 " physical packages" ,
54
54
freebsd_topology .packages * sizeof (struct cpuinfo_package ), freebsd_topology .packages );
55
55
goto cleanup ;
56
56
}
@@ -61,7 +61,7 @@ void cpuinfo_x86_freebsd_init(void) {
61
61
char brand_string [48 ];
62
62
cpuinfo_x86_normalize_brand_string (x86_processor .brand_string , brand_string );
63
63
64
- const uint32_t threads_per_core = freebsd_topology .threads / freebsd_topology . cores ;
64
+ const uint32_t threads_per_core = freebsd_topology .threads_per_core ;
65
65
const uint32_t threads_per_package = freebsd_topology .threads / freebsd_topology .packages ;
66
66
const uint32_t cores_per_package = freebsd_topology .cores / freebsd_topology .packages ;
67
67
for (uint32_t i = 0 ; i < freebsd_topology .packages ; i ++ ) {
@@ -122,60 +122,52 @@ void cpuinfo_x86_freebsd_init(void) {
122
122
123
123
uint32_t threads_per_l1 = 0 , l1_count = 0 ;
124
124
if (x86_processor .cache .l1i .size != 0 || x86_processor .cache .l1d .size != 0 ) {
125
- if (threads_per_l1 == 0 ) {
126
- /* Assume that threads on the same core share L1 */
127
- threads_per_l1 = freebsd_topology .threads / freebsd_topology .cores ;
128
- cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L1 cache; assume %" PRIu32 ,
129
- threads_per_l1 );
130
- }
125
+ /* Assume that threads on the same core share L1 */
126
+ threads_per_l1 = freebsd_topology .threads / freebsd_topology .cores ;
127
+ cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L1 cache; assume %" PRIu32 ,
128
+ threads_per_l1 );
131
129
l1_count = freebsd_topology .threads / threads_per_l1 ;
132
130
cpuinfo_log_debug ("detected %" PRIu32 " L1 caches" , l1_count );
133
131
}
134
132
135
133
uint32_t threads_per_l2 = 0 , l2_count = 0 ;
136
134
if (x86_processor .cache .l2 .size != 0 ) {
137
- if (threads_per_l2 == 0 ) {
138
- if (x86_processor .cache .l3 .size != 0 ) {
139
- /* This is not a last-level cache; assume that threads on the same core share L2 */
140
- threads_per_l2 = freebsd_topology .threads / freebsd_topology .cores ;
141
- } else {
142
- /* This is a last-level cache; assume that threads on the same package share L2 */
143
- threads_per_l2 = freebsd_topology .threads / freebsd_topology .packages ;
144
- }
145
- cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L2 cache; assume %" PRIu32 ,
146
- threads_per_l2 );
147
- }
135
+ if (x86_processor .cache .l3 .size != 0 ) {
136
+ /* This is not a last-level cache; assume that threads on the same core share L2 */
137
+ threads_per_l2 = freebsd_topology .threads / freebsd_topology .cores ;
138
+ } else {
139
+ /* This is a last-level cache; assume that threads on the same package share L2 */
140
+ threads_per_l2 = freebsd_topology .threads / freebsd_topology .packages ;
141
+ }
142
+ cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L2 cache; assume %" PRIu32 ,
143
+ threads_per_l2 );
148
144
l2_count = freebsd_topology .threads / threads_per_l2 ;
149
145
cpuinfo_log_debug ("detected %" PRIu32 " L2 caches" , l2_count );
150
146
}
151
147
152
148
uint32_t threads_per_l3 = 0 , l3_count = 0 ;
153
149
if (x86_processor .cache .l3 .size != 0 ) {
154
- if (threads_per_l3 == 0 ) {
155
- /*
156
- * Assume that threads on the same package share L3.
157
- * However, is it not necessarily the last-level cache (there may be L4 cache as well)
158
- */
159
- threads_per_l3 = freebsd_topology .threads / freebsd_topology .packages ;
160
- cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L3 cache; assume %" PRIu32 ,
161
- threads_per_l3 );
162
- }
150
+ /*
151
+ * Assume that threads on the same package share L3.
152
+ * However, is it not necessarily the last-level cache (there may be L4 cache as well)
153
+ */
154
+ threads_per_l3 = freebsd_topology .threads / freebsd_topology .packages ;
155
+ cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L3 cache; assume %" PRIu32 ,
156
+ threads_per_l3 );
163
157
l3_count = freebsd_topology .threads / threads_per_l3 ;
164
158
cpuinfo_log_debug ("detected %" PRIu32 " L3 caches" , l3_count );
165
159
}
166
160
167
161
uint32_t threads_per_l4 = 0 , l4_count = 0 ;
168
162
if (x86_processor .cache .l4 .size != 0 ) {
169
- if (threads_per_l4 == 0 ) {
170
- /*
171
- * Assume that all threads share this L4.
172
- * As of now, L4 cache exists only on notebook x86 CPUs, which are single-package,
173
- * but multi-socket systems could have shared L4 (like on IBM POWER8).
174
- */
175
- threads_per_l4 = freebsd_topology .threads ;
176
- cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L4 cache; assume %" PRIu32 ,
177
- threads_per_l4 );
178
- }
163
+ /*
164
+ * Assume that all threads share this L4.
165
+ * As of now, L4 cache exists only on notebook x86 CPUs, which are single-package,
166
+ * but multi-socket systems could have shared L4 (like on IBM POWER8).
167
+ */
168
+ threads_per_l4 = freebsd_topology .threads ;
169
+ cpuinfo_log_warning ("freebsd kernel did not report number of threads sharing L4 cache; assume %" PRIu32 ,
170
+ threads_per_l4 );
179
171
l4_count = freebsd_topology .threads / threads_per_l4 ;
180
172
cpuinfo_log_debug ("detected %" PRIu32 " L4 caches" , l4_count );
181
173
}
0 commit comments