| 288 | |
| 289 | #endif |
| 290 | struct cpu_info* probe_system_cpu(void) |
| 291 | { |
| 292 | static struct cpu_info cpu_dev; |
| 293 | |
| 294 | struct cpu_item* cpu_item; |
| 295 | int cpu_number; |
| 296 | int cluster_number = 1; |
| 297 | |
| 298 | cpu_number = get_cpu_items(&cpu_item); |
| 299 | |
| 300 | /* assuming cluster cpus are continuous */ |
| 301 | for(int i = 1; i < cpu_number; i++) |
| 302 | { |
| 303 | if(cpu_item[i - 1].cluster_leader != cpu_item[i].cluster_leader) |
| 304 | cluster_number++; |
| 305 | } |
| 306 | |
| 307 | struct cpu_cluster* cpu_cluster = ( struct cpu_cluster* )malloc(sizeof(struct cpu_cluster) * cluster_number); |
| 308 | |
| 309 | memset(cpu_cluster->hw_cpu_id, -1, sizeof(int) * MAX_CLUSTER_CPU_NUMBER); |
| 310 | |
| 311 | /* setup cpu 0 */ |
| 312 | cpu_cluster[0].cpu_number = 1; |
| 313 | cpu_cluster[0].max_freq = cpu_item[0].max_freq; |
| 314 | cpu_cluster[0].hw_cpu_id[0] = cpu_item[0].cpu_id; |
| 315 | |
| 316 | int top_max_freq = 0; |
| 317 | struct cpu_cluster* cluster = cpu_cluster; |
| 318 | |
| 319 | for(int i = 1; i < cpu_number; i++) |
| 320 | { |
| 321 | /* assuming cluster's cpu is continuous*/ |
| 322 | |
| 323 | if(cpu_item[i - 1].cluster_leader != cpu_item[i].cluster_leader) |
| 324 | { |
| 325 | cluster++; |
| 326 | memset(cluster->hw_cpu_id, -1, sizeof(int) * MAX_CLUSTER_CPU_NUMBER); |
| 327 | cluster->cpu_number = 0; |
| 328 | cluster->max_freq = cpu_item[i].max_freq; |
| 329 | |
| 330 | if(cluster->max_freq > top_max_freq) |
| 331 | top_max_freq = cluster->max_freq; |
| 332 | } |
| 333 | |
| 334 | cluster->hw_cpu_id[cluster->cpu_number] = cpu_item[i].cpu_id; |
| 335 | cluster->cpu_number++; |
| 336 | } |
| 337 | |
| 338 | free(cpu_item); |
| 339 | |
| 340 | for(int i = 0; i < cluster_number; i++) |
| 341 | { |
| 342 | struct cpu_cluster* cluster = cpu_cluster + i; |
| 343 | |
| 344 | get_cpu_model_arch(cluster->hw_cpu_id[0], cluster); |
| 345 | } |
| 346 | |
| 347 | cpu_dev.cluster_number = cluster_number; |
no test coverage detected