From 1766cbdd153a67c7f30923d5dc69ff5ffba68c67 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 18 Apr 2025 09:42:46 +0800 Subject: [PATCH] bin/runcpu: don't wrap programs under systemd, parse the result instead --- src/bin/runcpu.ts | 74 +++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/src/bin/runcpu.ts b/src/bin/runcpu.ts index c046414..bbd5005 100644 --- a/src/bin/runcpu.ts +++ b/src/bin/runcpu.ts @@ -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}`)); \ No newline at end of file +const baseRatios = await getBaseRatios(specProc); +console.log(baseRatios); \ No newline at end of file