#define _XOPEN_SOURCE 500 #include #include /* this is an inclusive limit on the number of VCPUs */ #define MAX_CPUS 255 /* @limit is exclusive */ static unsigned width(unsigned limit) { assert(limit != 0); if (limit == 1) { return 0; } if (limit == 2) { return 1; } if (limit <= 4) { return 2; } if (limit <= 8) { return 3; } if (limit <= 16) { return 4; } if (limit <= 32) { return 5; } if (limit <= 64) { return 6; } if (limit <= 128) { return 7; } assert(limit <= 256); return 8; } int main(void) { unsigned pkgs, cores, threads; for ( pkgs = 1; pkgs <= MAX_CPUS; ++pkgs ) { for ( cores = 1; pkgs * cores <= MAX_CPUS; ++cores ) { for (threads = 1; pkgs * cores * threads <= MAX_CPUS; ++threads) { /* this is an actual APIC ID, not an exclusive limit */ unsigned max_apic_id; /* we limit the width of APIC IDs in 8 bits */ if (width(pkgs) + width(cores) + width(threads) > 8) { continue; } max_apic_id = pkgs - 1; max_apic_id = (max_apic_id << width(cores) ) | (cores - 1); max_apic_id = (max_apic_id << width(threads)) | (threads - 1); assert(max_apic_id < 256); if (max_apic_id == 255) { fprintf(stdout, "(%3u, %3u, %3u): " "cpus=%3u max_apic_id=%3u\n", pkgs, cores, threads, pkgs * cores * threads, max_apic_id); } } } } return 0; }