bin/runcpu: don't wrap programs under systemd, parse the result instead

This commit is contained in:
2025-04-18 09:42:46 +08:00
parent 76c230f554
commit 1766cbdd15

View File

@@ -1,10 +1,8 @@
import yargs from 'yargs';
import { spawn } from 'child_process';
import { promisifySpawn } from '../cli.js';
import { RunCPUOptions, runcpuOptions } from '../commands/spec.js';
import { systemdRunOptions } from '../commands/systemd.js';
import path from 'path';
import { ConfigOptions, mkSPEC, renderConfig } from '../spec/index.js';
import { ConfigOptions, mkSPEC, renderConfig, getBaseRatios } from '../spec/index.js';
import { sw64TargetOptions } from '../commands/compiler.js';
import crypto from 'crypto';
import { hideBin } from 'yargs/helpers';
@@ -85,31 +83,16 @@ console.log(`using sysroot: ${chalk.red(sysroot)}`);
const specPath = path.resolve(argv.spec);
interface systemdRunSPECOptions {
specConfig: string;
id: string;
runcpuOverride?: (old: RunCPUOptions) => RunCPUOptions;
}
function systemdRunSPEC({
specConfig,
id,
runcpuOverride,
}: systemdRunSPECOptions) {
function runspec(specConfig: string, id: string) {
const config = `${id}.cfg`;
const spec = mkSPEC(specPath);
spec.newConfig(config, specConfig);
return spawn('systemd-run', [
...systemdRunOptions({
scope: false,
unit: id,
user: true,
}),
'runcpu',
...runcpuOptions((runcpuOverride || (x => x))({
return spawn('runcpu', [
...runcpuOptions({
outputRoot: path.resolve(path.resolve(argv.output), id),
config,
setprocgroup: true,
@@ -117,8 +100,8 @@ function systemdRunSPEC({
buildType: argv.buildType as RunCPUOptions["buildType"],
benchmarks: argv.benchmarks as RunCPUOptions["benchmarks"],
action: argv.action as RunCPUOptions["action"],
})),
], { env: spec.getEnvironment(), stdio: "inherit" });
}),
], { env: spec.getEnvironment() });
}
// Function to convert hash to prefix
@@ -128,8 +111,6 @@ const uuid = crypto.randomUUID();
const prefix = path.resolve(argv.compilerPrefix);
console.log(prefix);
const o3LTOFlags = [
"-O3",
"-flto",
@@ -143,29 +124,26 @@ const unalignedFlags = [
];
// SPEC configuration
const specConfig = renderConfig({
prefix,
optimize: [
"-O2",
...sw64TargetOptions({ simd: argv.simd }),
...argv.compilerSuite == "llvm" ? [sunway.mcpu(sunwayGeneration)] : [], // Only add -mcpu for llvm
],
ldflags: [
'-static',
`-L${path.resolve(prefix, 'lib')}`,
],
sysroot,
compiler: argv.compilerSuite as ConfigOptions["compiler"],
});
console.log(`Running SPEC compiled from ${prefix} as ${uuid}`);
console.log(`View: ${path.resolve(argv.output, uuid)}`)
await promisifySpawn(systemdRunSPEC({
specConfig,
id: uuid,
}));
const specProc = runspec(
renderConfig({
prefix,
optimize: [
"-O2",
...sw64TargetOptions({ simd: argv.simd }),
...argv.compilerSuite == "llvm" ? [sunway.mcpu(sunwayGeneration)] : [], // Only add -mcpu for llvm
],
ldflags: [
'-static',
`-L${path.resolve(prefix, 'lib')}`,
],
sysroot,
compiler: argv.compilerSuite as ConfigOptions["compiler"],
}),
uuid
);
console.log(`Command suggest:`);
console.log(chalk.green(`systemctl --user status ${uuid}`));
console.log(chalk.green(`journalctl --user -xeu ${uuid}`));
const baseRatios = await getBaseRatios(specProc);
console.log(baseRatios);