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