Skip to content

Commit 033b577

Browse files
authored
Merge pull request #301 from nathanchance/various-pgo-fixes
2 parents 611cc49 + 852a11c commit 033b577

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

tc_build/kernel.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@ def __init__(self, arch):
2626
self.bolt_sampling_output = None
2727
self.config_targets = []
2828
self.cross_compile = None
29+
self.lsm = None
2930
self.make_variables = {
3031
'ARCH': arch,
3132
# We do not want warnings to cause build failures when profiling.
3233
'KCFLAGS': '-Wno-error',
3334
}
3435
self.show_commands = True
3536
self.toolchain_prefix = None
36-
self.toolchain_version = None
37+
self.toolchain_version = ()
3738

3839
def build(self):
39-
if not self.toolchain_version:
40-
self.toolchain_version = self.get_toolchain_version()
41-
4240
if self.bolt_instrumentation:
4341
self.make_variables['CC'] = Path(self.toolchain_prefix, 'bin/clang.inst')
4442
# The user may have configured clang without the host target, in which
@@ -118,6 +116,9 @@ def can_use_ias(self):
118116
return True
119117

120118
def get_toolchain_version(self):
119+
if self.toolchain_version:
120+
return self.toolchain_version
121+
121122
if not self.toolchain_prefix:
122123
raise RuntimeError('get_toolchain_version(): No toolchain prefix set?')
123124
if not (clang := Path(self.toolchain_prefix, 'bin/clang')).exists():
@@ -131,7 +132,8 @@ def get_toolchain_version(self):
131132
input=clang_input,
132133
text=True).stdout.strip()
133134

134-
return tuple(int(elem) for elem in clang_output.split(' '))
135+
self.toolchain_version = tuple(int(elem) for elem in clang_output.split(' '))
136+
return self.toolchain_version
135137

136138
def can_use_clang_as_hostcc(self):
137139
clang = Path(self.toolchain_prefix, 'bin/clang')
@@ -155,7 +157,7 @@ def __init__(self):
155157
self.cross_compile = 'arm-linux-gnueabi-'
156158

157159
def can_use_ias(self):
158-
return self.toolchain_version >= (13, 0, 0)
160+
return self.get_toolchain_version() >= (13, 0, 0)
159161

160162

161163
class ArmV5KernelBuilder(ArmKernelBuilder):
@@ -173,6 +175,19 @@ def __init__(self):
173175

174176
self.config_targets = ['aspeed_g5_defconfig']
175177

178+
def build(self):
179+
if not self.lsm:
180+
raise RuntimeError('build() called without LinuxSourceManager?')
181+
182+
if self.get_toolchain_version() < (14, 0, 0) and self.lsm.get_version() >= (6, 14, 0):
183+
# https://github.com/ClangBuiltLinux/continuous-integration2/pull/807
184+
tc_build.utils.print_warning(
185+
'aspeed_g5_defconfig does not build with LLVM < 14.0.0 and Linux >= 6.14.0, skipping build...'
186+
)
187+
return
188+
189+
super().build()
190+
176191

177192
class ArmV7KernelBuilder(ArmKernelBuilder):
178193

@@ -200,9 +215,8 @@ def __init__(self):
200215
super().__init__('loongarch')
201216

202217
def build(self):
203-
self.toolchain_version = self.get_toolchain_version()
204218
# https://git.kernel.org/linus/4d35d6e56447a5d09ccd1c1b3a6d3783b2947670
205-
if self.toolchain_version < (min_version := (18, 0, 0)):
219+
if self.get_toolchain_version() < (min_version := (18, 0, 0)):
206220
tc_build.utils.print_warning(
207221
f"LoongArch does not build with LLVM < {'.'.join(map(str, min_version))}, skipping build..."
208222
)
@@ -247,7 +261,7 @@ def __init__(self):
247261

248262
# https://github.com/llvm/llvm-project/commit/33504b3bbe10d5d4caae13efcb99bd159c126070
249263
def can_use_ias(self):
250-
return self.toolchain_version >= (14, 0, 2)
264+
return self.get_toolchain_version() >= (14, 0, 2)
251265

252266
# https://github.com/ClangBuiltLinux/linux/issues/1601
253267
def needs_binutils(self):
@@ -263,9 +277,8 @@ def __init__(self):
263277
self.cross_compile = 'powerpc64le-linux-gnu-'
264278

265279
def build(self):
266-
self.toolchain_version = self.get_toolchain_version()
267280
# https://github.com/ClangBuiltLinux/linux/issues/1260
268-
if self.toolchain_version < (12, 0, 0):
281+
if self.get_toolchain_version() < (12, 0, 0):
269282
self.make_variables['LD'] = self.cross_compile + 'ld'
270283

271284
super().build()
@@ -280,7 +293,7 @@ def __init__(self):
280293

281294
# https://github.com/llvm/llvm-project/commit/bbea64250f65480d787e1c5ff45c4de3ec2dcda8
282295
def can_use_ias(self):
283-
return self.toolchain_version >= (13, 0, 0)
296+
return self.get_toolchain_version() >= (13, 0, 0)
284297

285298

286299
class S390KernelBuilder(KernelBuilder):
@@ -291,8 +304,7 @@ def __init__(self):
291304
self.cross_compile = 's390x-linux-gnu-'
292305

293306
def build(self):
294-
self.toolchain_version = self.get_toolchain_version()
295-
if self.toolchain_version <= (15, 0, 0):
307+
if self.get_toolchain_version() <= (15, 0, 0):
296308
# https://git.kernel.org/linus/30d17fac6aaedb40d111bb159f4b35525637ea78
297309
tc_build.utils.print_warning(
298310
's390 does not build with LLVM < 15.0.0, skipping build...')
@@ -339,6 +351,18 @@ class X8664KernelBuilder(KernelBuilder):
339351
def __init__(self):
340352
super().__init__('x86_64')
341353

354+
def build(self):
355+
if not self.lsm:
356+
raise RuntimeError('build() called without LinuxSourceManager?')
357+
358+
if self.get_toolchain_version() < (15, 0, 0) and self.lsm.get_version() >= (6, 15, 0):
359+
# https://git.kernel.org/linus/7861640aac52bbbb3dc2cd40fb93dfb3b3d0f43c
360+
tc_build.utils.print_warning(
361+
'x86_64 does not build with LLVM < 15.0.0 and Linux >= 6.15.0, skipping build...')
362+
return
363+
364+
super().build()
365+
342366

343367
class LLVMKernelBuilder(Builder):
344368

@@ -410,6 +434,7 @@ def build(self):
410434
builder.bolt_sampling_output = self.bolt_sampling_output
411435
builder.folders.build = self.folders.build
412436
builder.folders.source = self.folders.source
437+
builder.lsm = lsm
413438
builder.toolchain_prefix = self.toolchain_prefix
414439
builder.build()
415440

@@ -420,6 +445,7 @@ def __init__(self, location=None):
420445
super().__init__(location)
421446

422447
self.patches = []
448+
self._version = ()
423449

424450
def get_kernelversion(self):
425451
return subprocess.run(['make', '-s', 'kernelversion'],
@@ -433,7 +459,10 @@ def get_kernelversion(self):
433459
# particular version.
434460
def get_version(self):
435461
# elem.split('-')[0] in case we are dealing with an -rc release.
436-
return tuple(int(elem.split('-')[0]) for elem in self.get_kernelversion().split('.', 3))
462+
if not self._version:
463+
self._version = tuple(
464+
int(elem.split('-')[0]) for elem in self.get_kernelversion().split('.', 3))
465+
return self._version
437466

438467
def prepare(self):
439468
self.tarball.download()

0 commit comments

Comments
 (0)