Skip to content

Commit

Permalink
Add more about instantiated/uninstantiated switch cycles.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed May 6, 2024
1 parent 4dd13b9 commit bda9d18
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,20 @@ pub const SPAWN_YIELD_CYCLES_BASE: u64 = 800;

The Cycles consumption of each Syscall is as follows. Among them, the constant 500 and BYTES_TRANSFERRED_CYCLES can be referred to [RFC-0014](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0014-vm-cycle-limits/0014-vm-cycle-limits.md).

| Syscall Name | Cycles Charge |
| -------------------- | -------------------------------------------------------------------------------- |
| Syscall Name | Cycles Charge |
| -------------------- | ---------------------------------------------------------------------------------- |
| spawn | 500 + SPAWN_YIELD_CYCLES_BASE + BYTES_TRANSFERRED_CYCLES + SPAWN_EXTRA_CYCLES_BASE |
| pipe | 500 + SPAWN_YIELD_CYCLES_BASE |
| inherited_fd | 500 + SPAWN_YIELD_CYCLES_BASE |
| pipe | 500 + SPAWN_YIELD_CYCLES_BASE |
| inherited_fd | 500 + SPAWN_YIELD_CYCLES_BASE |
| read | 500 + SPAWN_YIELD_CYCLES_BASE + BYTES_TRANSFERRED_CYCLES |
| write | 500 + SPAWN_YIELD_CYCLES_BASE + BYTES_TRANSFERRED_CYCLES |
| close | 500 + SPAWN_YIELD_CYCLES_BASE |
| wait | 500 + SPAWN_YIELD_CYCLES_BASE |
| process_id | 500 |
| close | 500 + SPAWN_YIELD_CYCLES_BASE |
| wait | 500 + SPAWN_YIELD_CYCLES_BASE |
| process_id | 500 |
| load block extension | 500 + BYTES_TRANSFERRED_CYCLES |

In addition, when a VM switches from instantiated to uninstantiated, or from uninstantiated to instantiated, each VM needs `SPAWN_EXTRA_CYCLES_BASE` cycles.

## Spawn Example

Consider the creation of a dependency library with a straightforward function that receives strings, concatenates them, and subsequently returns the resulting string to the caller(a.k.a echo).
Expand Down

0 comments on commit bda9d18

Please sign in to comment.