@@ -1149,7 +1149,7 @@ struct timeval tv_even, tv_odd, tv_delta;
11491149int * irq_column_2_cpu ; /* /proc/interrupts column numbers */
11501150int * irqs_per_cpu ; /* indexed by cpu_num */
11511151
1152- void setup_all_buffers (void );
1152+ void setup_all_buffers (bool startup );
11531153
11541154char * sys_lpi_file ;
11551155char * sys_lpi_file_sysfs = "/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us" ;
@@ -3691,7 +3691,7 @@ int for_all_proc_cpus(int (func) (int))
36913691void re_initialize (void )
36923692{
36933693 free_all_buffers ();
3694- setup_all_buffers ();
3694+ setup_all_buffers (false );
36953695 fprintf (outf , "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n" , topo .num_cpus , topo .allowed_cpus );
36963696}
36973697
@@ -5692,7 +5692,7 @@ int dir_filter(const struct dirent *dirp)
56925692 return 0 ;
56935693}
56945694
5695- void topology_probe ()
5695+ void topology_probe (bool startup )
56965696{
56975697 int i ;
56985698 int max_core_id = 0 ;
@@ -5734,7 +5734,12 @@ void topology_probe()
57345734 CPU_ZERO_S (cpu_allowed_setsize , cpu_allowed_set );
57355735
57365736 /*
5737- * Validate that all cpus in cpu_subset are also in cpu_present_set
5737+ * Validate cpu_subset and update cpu_allowed_set.
5738+ *
5739+ * Make sure all cpus in cpu_subset are also in cpu_present_set during startup,
5740+ * and give a warning when cpus in cpu_subset become unavailable at runtime.
5741+ *
5742+ * cpu_allowed_set is the intersection of cpu_present_set and cpu_subset.
57385743 */
57395744 for (i = 0 ; i < CPU_SUBSET_MAXCPUS ; ++ i ) {
57405745 if (!cpu_subset ) {
@@ -5743,9 +5748,15 @@ void topology_probe()
57435748 continue ;
57445749 }
57455750 if (CPU_ISSET_S (i , cpu_subset_size , cpu_subset )) {
5746- if (!CPU_ISSET_S (i , cpu_present_setsize , cpu_present_set ))
5747- err (1 , "cpu%d not present" , i );
5748- CPU_SET_S (i , cpu_allowed_setsize , cpu_allowed_set );
5751+ if (!CPU_ISSET_S (i , cpu_present_setsize , cpu_present_set )) {
5752+ /* all cpus in cpu_subset must be in cpu_present_set during startup */
5753+ if (startup )
5754+ err (1 , "cpu%d not present" , i );
5755+ else
5756+ fprintf (stderr , "cpu%d not present\n" , i );
5757+ } else {
5758+ CPU_SET_S (i , cpu_allowed_setsize , cpu_allowed_set );
5759+ }
57495760 }
57505761 }
57515762
@@ -5973,9 +5984,9 @@ void topology_update(void)
59735984 topo .allowed_packages = 0 ;
59745985 for_all_cpus (update_topo , ODD_COUNTERS );
59755986}
5976- void setup_all_buffers (void )
5987+ void setup_all_buffers (bool startup )
59775988{
5978- topology_probe ();
5989+ topology_probe (startup );
59795990 allocate_irq_buffers ();
59805991 allocate_fd_percpu ();
59815992 allocate_counters (& thread_even , & core_even , & package_even );
@@ -6002,7 +6013,7 @@ void set_base_cpu(void)
60026013
60036014void turbostat_init ()
60046015{
6005- setup_all_buffers ();
6016+ setup_all_buffers (true );
60066017 set_base_cpu ();
60076018 check_dev_msr ();
60086019 check_permissions ();
0 commit comments