Skip to content

php-in-php: getrusage() — delete phpc_getrusage.c (~78 lines), native VmProcess without host getrusage() #5388

Description

@PurHur

Category

php-in-php | stdlib | bootstrap

Problem

getrusage() is implemented in PHP (ext/standard/getrusage.php, VmProcess.php, JitGetrusage.php) but JIT/AOT still call __compiler_getrusage in lib/AOT/runtime/phpc_getrusage.c (~78 lines). VM VmProcess::getrusage() delegates to host \getrusage() — bootstrap/self-host must not depend on Zend for process stats.

Parity gaps tracked separately in #4600 (numeric-string who, TypeError messages).

php-src reference

Repro (failure today — host + C runtime)

<?php
$u = getrusage();
var_export(is_array($u));
echo "\n";
var_export(isset($u['ru_utime.tv_sec']));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
PHP_COMPILER_SELFHOST_AOT=1 php bin/compile.php -o /tmp/gr repro.php 2>/dev/null || true
# Native link still pulls phpc_getrusage.o from lib/AOT/runtime/
grep -l __compiler_getrusage lib/AOT/runtime/*.c
'
Check Today
lib/AOT/runtime/phpc_getrusage.c present yes
VmProcess::getrusage uses \getrusage() yes (host PHP)

Scope (this repo)

Layer Path Action
VM ext/standard/VmProcess.php libc getrusage via thin FFI/trampoline or compile PHP helper through pipeline
JIT ext/standard/JitGetrusage.php, lib/JIT/Builtin/StringGetrusage.php lower without __compiler_getrusage C
Linker lib/AOT/Linker.php drop phpc_getrusage.c from runtime objects
Delete lib/AOT/runtime/phpc_getrusage.c after PHP path green

PHP-in-PHP: port field mapping from php-src into ext/standard/; keep C only if unavoidable ABI (document in PR).

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter getrusage'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/ci-fast.sh --filter getrusage'

Links

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 4, 2026
  2. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#5388 getrusage: delete phpc_getrusage.c, LLVM from StringGetrusage.php).

  3. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    Merged via #6253.

    C removed: lib/AOT/runtime/phpc_getrusage.c (78 lines) — unlinked from lib/AOT/Linker.php.

    PHP path: lib/JIT/Builtin/StringGetrusage.php now emits LLVM for __compiler_getrusage (libc getrusage(2) + hashtable field mapping), wired via StringGetrusage::ensureLinked() in Type.php. Follows StringGettimeofday pattern; drops JIT-time C bitcode compilation.

    Verification:

    • vendor/bin/phpunit test/unit/JIT/StringGetrusageRuntimeStandaloneTest.php — OK
    • vendor/bin/phpunit --filter getrusage — VM compliance OK
    • php bin/vm.php test/repro/getrusage.php → ok
    • php bin/jit.php test/repro/getrusage.php → ok

    Follow-up: VmProcess still delegates to host \getrusage() on VM path; #4600 parity (numeric-string who, TypeError messages) remains open.

  4. PurHur commented on Jun 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #7858.

    VM phase: VmGetrusageNative routes VM getrusage() through libc FFI (getrusage(2)) instead of host \getrusage() delegation — same field layout as StringGetrusage JIT/AOT. LLVM lowering now normalizes who=1 → RUSAGE_CHILDREN per php-src microtime.c.

    Verification:

    • php bin/vm.php test/repro/getrusage.php → ok
    • vendor/bin/phpunit --filter VmGetrusageNativeTest → OK (5 tests)
    • vendor/bin/phpunit --filter "VMTest::testCases.*getrusage" → OK (5 PHPTs, VM + JIT)
    • vendor/bin/phpunit --filter GetrusageJITTest → OK

    No new C runtime; host fallback only when FFI disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions