Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use xsnap worker CPU meter and start reporting consumption #2384

Merged
merged 5 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,13 @@ jobs:
run: cd packages/SwingSet && yarn test
env:
ESM_DISABLE_CACHE: true
- name: yarn test (xsnap)
run: cd packages/xsnap && yarn test
env:
ESM_DISABLE_CACHE: true
# explicitly test the XS worker, for visibility
- name: yarn test (SwingSet XS Worker)
working-directory: ./packages/SwingSet
run: yarn test:xs-worker
run: cd packages/SwingSet && yarn test:xs-worker
env:
ESM_DISABLE_CACHE: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { assert, details } from '@agoric/assert';
import { makeTranscriptManager } from './transcript';
import { createSyscall } from './syscall';

import '../../types';
import './types';

// eslint-disable-next-line no-unused-vars
function parentLog(first, ...args) {
// console.error(`--parent: ${first}`, ...args);
Expand All @@ -26,7 +29,6 @@ const decoder = new TextDecoder();
* @typedef { ReturnType<typeof import('@agoric/xsnap').xsnap> } XSnap
* @typedef { ReturnType<typeof import('../state/kernelKeeper').default> } KernelKeeper
* @typedef { ReturnType<typeof import('./manager-nodeworker').makeNodeWorkerVatManagerFactory> } VatManagerFactory
* @typedef { [unknown, ...unknown[]] } Tagged
*/
export function makeXsSubprocessFactory({
allVatPowers: { transformTildot },
Expand Down Expand Up @@ -135,18 +137,18 @@ export function makeXsSubprocessFactory({
await worker.evaluate(`(${superCode.source}\n)()`.trim());
}

/** @type { (item: Tagged) => Promise<Tagged> } */
/** @type { (item: Tagged) => Promise<CrankResults> } */
async function issueTagged(item) {
parentLog(item[0], '...', item.length - 1);
const txt = await worker.issueStringCommand(JSON.stringify(item));
const reply = JSON.parse(txt);
const result = await worker.issueStringCommand(JSON.stringify(item));
const reply = JSON.parse(result.reply);
assert(Array.isArray(reply));
const [tag, ...rest] = reply;
return [tag, ...rest];
return { ...result, reply: [tag, ...rest] };
}

parentLog(vatID, `instructing worker to load bundle..`);
const bundleReply = await issueTagged([
const { reply: bundleReply } = await issueTagged([
'setBundle',
vatID,
bundle,
Expand All @@ -159,12 +161,12 @@ export function makeXsSubprocessFactory({
throw new Error(`failed to setBundle: ${bundleReply}`);
}

/** @type { (item: Tagged) => Promise<Tagged> } */
/** @type { (item: Tagged) => Promise<CrankResults> } */
async function deliver(delivery) {
parentLog(vatID, `sending delivery`, delivery);
transcriptManager.startDispatch(delivery);
const result = await issueTagged(['deliver', ...delivery]);
parentLog(vatID, `deliverDone`, result[0], result.length);
parentLog(vatID, `deliverDone`, result.reply[0], result.reply.length);
transcriptManager.finishDispatch();
return result;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/SwingSet/src/kernel/vatManager/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @typedef { [unknown, ...unknown[]] } Tagged
* @typedef { { meterType: string, allocate: number|null, compute: number|null } }
* CrankStats
* @typedef { { reply: Tagged, crankStats: CrankStats } } CrankResults
*/
2 changes: 2 additions & 0 deletions packages/xsnap/makefiles/lin/xsnap.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ C_OPTIONS = \
-fno-common \
-DINCLUDE_XSPLATFORM \
-DXSPLATFORM=\"xsnap.h\" \
-DXSNAP_VERSION=\"$(XSNAP_VERSION)\" \
-DmxParse=1 \
-DmxRun=1 \
-DmxSloppy=1 \
-DmxSnapshot=1 \
-DmxMetering=1 \
-DmxRegExpUnicodePropertyEscapes=1 \
-I$(INC_DIR) \
-I$(PLT_DIR) \
Expand Down
2 changes: 2 additions & 0 deletions packages/xsnap/makefiles/mac/xsnap.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ C_OPTIONS = \
$(MACOS_VERSION_MIN) \
-DINCLUDE_XSPLATFORM \
-DXSPLATFORM=\"xsnap.h\" \
-DXSNAP_VERSION=\"$(XSNAP_VERSION)\" \
-DmxParse=1 \
-DmxRun=1 \
-DmxSloppy=1 \
-DmxSnapshot=1 \
-DmxMetering=1 \
-DmxRegExpUnicodePropertyEscapes=1 \
-I$(INC_DIR) \
-I$(PLT_DIR) \
Expand Down
2 changes: 2 additions & 0 deletions packages/xsnap/makefiles/win/xsnap.mak
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ C_OPTIONS = \
/D _CRT_SECURE_NO_DEPRECATE \
/D INCLUDE_XSPLATFORM \
/D XSPLATFORM=\"xsnap.h\" \
/D XSNAP_VERSION=\"$(XSNAP_VERSION)\" \
/D mxParse=1 \
/D mxRun=1 \
/D mxSloppy=1 \
/D mxSnapshot=1 \
/D mxMetering=1 \
/D mxRegExpUnicodePropertyEscapes=1 \
/I$(INC_DIR) \
/I$(PLT_DIR) \
Expand Down
18 changes: 11 additions & 7 deletions packages/xsnap/src/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as childProcess from 'child_process';
import { existsSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import os from 'os';

function exec(command, cwd, args = []) {
Expand Down Expand Up @@ -47,16 +47,20 @@ function exec(command, cwd, args = []) {
await exec('git', '.', ['submodule', 'update', '--init']);
}

const pjson = readFileSync(`${__dirname}/../package.json`, 'utf-8');
const pkg = JSON.parse(pjson);
const XSNAP_VERSION = `XSNAP_VERSION=${pkg.version}`;

// Run command depending on the OS
if (os.type() === 'Linux') {
await exec('make', 'makefiles/lin');
await exec('make', 'makefiles/lin', ['GOAL=debug']);
await exec('make', 'makefiles/lin', [XSNAP_VERSION]);
await exec('make', 'makefiles/lin', ['GOAL=debug', XSNAP_VERSION]);
} else if (os.type() === 'Darwin') {
await exec('make', 'makefiles/mac');
await exec('make', 'makefiles/mac', ['GOAL=debug']);
await exec('make', 'makefiles/mac', [XSNAP_VERSION]);
await exec('make', 'makefiles/mac', ['GOAL=debug', XSNAP_VERSION]);
} else if (os.type() === 'Windows_NT') {
await exec('nmake', 'makefiles/win');
await exec('make', 'makefiles/win', ['GOAL=debug']);
await exec('nmake', 'makefiles/win', [XSNAP_VERSION]);
await exec('make', 'makefiles/win', ['GOAL=debug', XSNAP_VERSION]);
} else {
throw new Error(`Unsupported OS found: ${os.type()}`);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/xsnap/src/netstring.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const encoder = new TextEncoder();
* @param {AsyncIterable<Uint8Array>} input
* @param {string=} name
* @param {number=} capacity
* @returns {AsyncGenerator<Uint8Array>} input
* @returns {AsyncGenerator<Uint8Array, Uint8Array, unknown>} input
*/
export async function* reader(input, name = '<unknown>', capacity = 1024) {
let length = 0;
Expand Down Expand Up @@ -72,6 +72,7 @@ export async function* reader(input, name = '<unknown>', capacity = 1024) {
`Unexpected dangling message at offset ${offset} of ${name}`,
);
}
return new Uint8Array(0);
}

/**
Expand Down
Loading