@@ -47,6 +47,7 @@ def __init__(self):
4747 self .gdb_bin = ''
4848 self .interactive = False
4949 self .kernel = None
50+ self .kernel_config = None
5051 self .kernel_dir = None
5152 self .supports_efi = False
5253 # It may be tempting to use self.use_kvm during initialization of
@@ -90,33 +91,40 @@ def _find_dtb(self):
9091 return dtb
9192
9293 def _get_default_smp_value (self ):
93- if not self .kernel_dir :
94- raise RuntimeError ('No kernel build folder specified?' )
95-
96- # If kernel_dir is the kernel source, the configuration will be at
97- # <kernel_dir>/.config
98- #
99- # If kernel_dir is the direct parent to the full kernel image, the
100- # configuration could either be:
101- # * <kernel_dir>/.config (if the image is vmlinux)
102- # * <kernel_dir>/../../../.config (if the image is in arch/*/boot/)
103- # * <kernel_dir>/config (if the image is in a TuxMake folder)
104- possible_locations = ['.config' , '../../../.config' , 'config' ]
105- configuration = utils .find_first_file (self .kernel_dir ,
106- possible_locations ,
107- required = False )
108-
109- config_nr_cpus = 8 # sensible default based on treewide defaults,
110- if configuration :
111- conf_txt = configuration .read_text (encoding = 'utf-8' )
112- if (match := re .search (r'CONFIG_NR_CPUS=(\d+)' , conf_txt )):
113- config_nr_cpus = int (match .groups ()[0 ])
114-
11594 # Use the minimum of the number of usable processers for the script or
11695 # CONFIG_NR_CPUS.
96+ config_nr_cpus_default = 8 # sensible default based on treewide defaults,
97+ config_nr_cpus = int (
98+ self ._get_kernel_config_val ('CONFIG_NR_CPUS' ,
99+ config_nr_cpus_default ))
117100 usable_cpus = os .cpu_count ()
118101 return min (usable_cpus , config_nr_cpus )
119102
103+ def _get_kernel_config_val (self , config , default = 'n' ):
104+ if not self .kernel_config :
105+ if not self .kernel_dir :
106+ raise RuntimeError ('No kernel build folder specified?' )
107+
108+ # If kernel_dir is the kernel source, the configuration will be at
109+ # <kernel_dir>/.config
110+ #
111+ # If kernel_dir is the direct parent to the full kernel image, the
112+ # configuration could either be:
113+ # * <kernel_dir>/.config (if the image is vmlinux)
114+ # * <kernel_dir>/../../../.config (if the image is in arch/*/boot/)
115+ # * <kernel_dir>/config (if the image is in a TuxMake folder)
116+ possible_locations = ['.config' , '../../../.config' , 'config' ]
117+ self .kernel_config = utils .find_first_file (self .kernel_dir ,
118+ possible_locations ,
119+ required = False )
120+
121+ if self .kernel_config :
122+ conf_txt = self .kernel_config .read_text (encoding = 'utf-8' )
123+ if (match := re .search (fr'^{ config } =(.*)$' , conf_txt , flags = re .M )):
124+ return match .groups ()[0 ]
125+
126+ return default
127+
120128 def _get_kernel_ver_tuple (self , decomp_prog ):
121129 if not self .kernel :
122130 raise RuntimeError ('No kernel set?' )
0 commit comments