Skip to content
1 change: 0 additions & 1 deletion pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ STATIC_ASSERT( u3a_vits <= u3a_min_log,
u3p(u3a_dell) fre_p; // free list entry
u3p(u3a_dell) erf_p; // free list exit
u3p(u3a_dell) cac_p; // cached pgfree struct
u3_post bot_p; // XX s/b rut_p
c3_ws dir_ws; // 1 || -1 (multiplicand for local offsets)
c3_ws off_ws; // 0 || -1 (word-offset for hat && rut)
c3_w siz_w; // directory size
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static u3_ce_patch*
_ce_patch_compose(c3_w max_w)
{
c3_w pgs_w = 0;
c3_w off_w = u3R->hep.bot_p >> u3a_page;
c3_w off_w = u3R->rut_p >> u3a_page;

/* Count dirty pages.
*/
Expand Down Expand Up @@ -1114,7 +1114,7 @@ _ce_page_fine(u3e_image* img_u, c3_w pag_w, c3_z off_z)
static c3_o
_ce_loom_fine(void)
{
c3_w off_w = u3R->hep.bot_p >> u3a_page;
c3_w off_w = u3R->rut_p >> u3a_page;
c3_w blk_w, bit_w, pag_w, i_w;
c3_o fin_o = c3y;

Expand Down
35 changes: 27 additions & 8 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,22 @@ _pave_parts(void)
u3R->byc.har_p = u3h_new();
}

static c3_d
_pave_params(void)
{
// pam_d bits:
// { word-size[1], virtual-bits[2], page-size[3], bytecode[5], ... }
//
// word-size: 0==32, 1==64
// page-size: relative binary-log in bytes
//
//
return 0
^ (u3a_vits << 1)
^ ((u3a_page + 2 - 12) << 3)
^ (U3N_VERLAT << 6);
}

/* _pave_home(): initialize pristine home road.
*/
static void
Expand All @@ -546,14 +562,7 @@ _pave_home(void)
u3H = u3to(u3v_home, 0);
memset(u3H, 0, sizeof(u3v_home));
u3H->ver_d = U3V_VERLAT;

// pam_d bits: { word-size[1], virtual-bits[2], page-size[3], ... }
// word-size: 0==32, 1==64
// page-size: relative binary-log in bytes
//
u3H->pam_d = 0
^ (u3a_vits << 1)
^ ((u3a_page + 2 - 12) << 3);
u3H->pam_d = _pave_params();

u3R = &u3H->rod_u;

Expand All @@ -569,6 +578,8 @@ STATIC_ASSERT( (c3_wiseof(u3v_home) <= (1U << u3a_page)),
STATIC_ASSERT( ((c3_wiseof(u3v_home) * 4) == sizeof(u3v_home)),
"home road alignment" );

STATIC_ASSERT( U3N_VERLAT < (1U << 5), "5-bit bytecode version" );

/* _find_home(): in restored image, point to home road.
*/
static void
Expand Down Expand Up @@ -600,6 +611,14 @@ _find_home(void)
abort();
}

if ( ((pam_d >> 6) & 31) != U3N_VERLAT ) {
fprintf(stderr, "loom: discarding stale bytecode programs\r\n");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also update Nock version in the home road here? to prevent freeing bytecode cache on every boot

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good call.

u3n_ream();
u3n_reclaim();
u3j_reclaim();
u3H->pam_d = _pave_params();
}

// NB: the home road is always north
//
{
Expand Down
21 changes: 11 additions & 10 deletions pkg/noun/palloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
# define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void) (addr), (void) (size))
#endif

#define page_to_post(pag_w) (HEAP.bot_p + (HEAP.dir_ws * (c3_ws)((c3_w)(pag_w - HEAP.off_ws) << u3a_page)))
#define post_to_page(som_p) (_abs_dif(som_p, (c3_ws)HEAP.bot_p + HEAP.off_ws) >> u3a_page)
#ifndef BASE
#define BASE u3R->rut_p
#endif

#define page_to_post(pag_w) (BASE + (HEAP.dir_ws * (c3_ws)((c3_w)(pag_w - HEAP.off_ws) << u3a_page)))
#define post_to_page(som_p) (_abs_dif(som_p, (c3_ws)BASE + HEAP.off_ws) >> u3a_page)

#ifndef HEAP
#define HEAP u3R->hep
Expand Down Expand Up @@ -91,13 +95,9 @@ _init_heap(void)
HEAP.off_ws = -1;
}

// XX and rut
//
assert ( !(u3R->hat_p & ((1U << u3a_page) - 1)) );

HEAP.bot_p = u3R->hat_p;

assert( !(u3R->hat_p & ((1U << u3a_page) - 1)) );
assert( u3R->hat_p > u3a_rest_pg );
assert( u3R->hat_p == u3R->rut_p );

// XX check for overflow

Expand Down Expand Up @@ -1084,7 +1084,7 @@ _idle_words(void)
pag_w++;
}

if ( siz_w ) {
if ( (u3C.wag_w & u3o_verbose) && siz_w ) {
fprintf(stderr, "idle words: class=%u (%u words) blocks=%u (in %u pages) ",
i_w, (1U << (i_w + u3a_min_log)), siz_w, pag_w);
u3a_print_memory(stderr, "total", siz_w << (i_w + u3a_min_log));
Expand Down Expand Up @@ -1839,7 +1839,8 @@ _pack_seek_hunks(void)
nex_p = pag_u->nex_p;
pag_u->nex_p = 0;

u3_assert( pre_u.pag_w < pag_u->pag_w );
u3_assert( (pre_u.pag_w < pag_u->pag_w)
|| (!pre_u.pag_w && !pag_u->pag_w) );

rag_u = u3a_pack_alloc(len_w);
hap_w = &(rag_u->mar_w[hun_u->map_s]);
Expand Down
92 changes: 1 addition & 91 deletions pkg/noun/palloc_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct heap {
struct heap hep_u;

#define HEAP (hep_u)
#define BASE (hep_u.bot_p)

#include "./palloc.c"

Expand Down Expand Up @@ -77,93 +78,6 @@ _test_print_pages(c3_w max_w)
}
}

void
u3m_fall(void);
void
u3m_leap(c3_w pad_w);

static void
_test_palloc(void)
{
c3_w *wor_w;
u3_post pos_p, sop_p;
struct heap tmp_u;

memset(&(HEAP), 0x0, sizeof(HEAP));
_init_heap();

pos_p = _imalloc(4);

fprintf(stderr, "north: pos_p %x\n", pos_p);

wor_w = u3a_into(pos_p);

wor_w[0] = 0;
wor_w[1] = 1;
wor_w[2] = 2;
wor_w[3] = 3;

sop_p = _imalloc(4);

fprintf(stderr, "north: sop_p %x\n", sop_p);

_ifree(pos_p);
_ifree(sop_p);

fprintf(stderr, "palloc_tests: pre-leap: hat=0x%x cap=0x%x\n", u3R->hat_p, u3R->cap_p);

memcpy(&tmp_u, &hep_u, sizeof(tmp_u));
u3m_leap(1U << u3a_page);

fprintf(stderr, "palloc_tests: post-leap: hat=0x%x cap=0x%x\n", u3R->hat_p, u3R->cap_p);

memset(&(HEAP), 0x0, sizeof(HEAP));
_init_heap();

pos_p = _imalloc(4);

fprintf(stderr, "south: pos_p %x\n", pos_p);

wor_w = u3a_into(pos_p);

wor_w[0] = 0;
wor_w[1] = 1;
wor_w[2] = 2;
wor_w[3] = 3;

sop_p = _imalloc(4);

fprintf(stderr, "south: sop_p %x\n", sop_p);

_ifree(pos_p);
_ifree(sop_p);

fprintf(stderr, "palloc_tests: pre-fall: hat=0x%x cap=0x%x\n", u3R->hat_p, u3R->cap_p);

u3m_fall();
memcpy(&hep_u, &tmp_u, sizeof(tmp_u));

fprintf(stderr, "palloc_tests: post-fall: hat=0x%x cap=0x%x\n", u3R->hat_p, u3R->cap_p);

pos_p = _imalloc(4);

fprintf(stderr, "north: pos_p %x\n", pos_p);

wor_w = u3a_into(pos_p);

wor_w[0] = 0;
wor_w[1] = 1;
wor_w[2] = 2;
wor_w[3] = 3;

sop_p = _imalloc(4);

fprintf(stderr, "north: sop_p %x\n", sop_p);

_ifree(pos_p);
_ifree(sop_p);
}

/* main(): run all test cases.
*/
int
Expand All @@ -173,9 +87,5 @@ main(int argc, char* argv[])

_test_print_chunks();
_test_print_pages(10);

_test_palloc();

fprintf(stderr, "palloc okeedokee\n");
return 0;
}
7 changes: 7 additions & 0 deletions pkg/noun/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ typedef c3_d u3v_version;
#define U3V_VER5 (u3v_version)5 // ?? palloc
#define U3V_VERLAT U3V_VER5

/* bytecode semantics (within u3v_version)
*/
typedef c3_w u3n_version;

#define U3N_VER1 (u3n_version)0 // zero-indexedfor backcompat
#define U3N_VERLAT U3N_VER1

/* snapshot patch format
*/
typedef c3_w u3e_version;
Expand Down
43 changes: 27 additions & 16 deletions pkg/vere/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,9 +1819,17 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e)
}

_disk_migrate_loom(log_u->dir_u->pax_c, log_u->dun_d);
u3m_stop();
u3m_boot(log_u->dir_u->pax_c, (size_t)1 << u3_Host.ops_u.lom_y); // XX confirm

if ( c3n == _disk_epoc_roll(log_u, log_u->dun_d) ) {
fprintf(stderr, "disk: failed to initialize epoch during loom migration\r\n");
exit(1);
}

_disk_unlink_stale_loom(log_u->dir_u->pax_c);
// XX u3m_stop()
} // fallthru
return _epoc_good;
} break;

case U3E_VER2: {
if ( u3_dlod_epoc == lod_e ) {
Expand Down Expand Up @@ -1858,27 +1866,30 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e)
exit(1);
}

if ( !(u3C.wag_w & u3o_yolo) // XX better argument to disable autoroll
&& ( (!log_u->epo_d && log_u->dun_d)
|| (c3y == _disk_vere_diff(log_u)) ))
if ( (u3C.wag_w & u3o_yolo) // XX better argument to disable autoroll
|| (!log_u->epo_d && log_u->dun_d && !u3A->eve_d)
|| (c3n == _disk_vere_diff(log_u)) )
{
if ( log_u->dun_d != u3A->eve_d ) {
// XX stale snapshot, new binary, error out
// XX bad, add to enum
fprintf(stderr, "stale snapshot, downgrade runtime to replay\r\n");
exit(1);
}
else if ( c3n == _disk_epoc_roll(log_u, log_u->dun_d) ) {
fprintf(stderr, "disk: failed to initialize epoch\r\n");
exit(1);
}
return _epoc_good;
}
else if ( log_u->dun_d != u3A->eve_d ) {
// XX stale snapshot, new binary, error out
// XX bad, add to enum
fprintf(stderr, "stale snapshot, downgrade runtime to replay\r\n");
exit(1);
}
else if ( c3n == _disk_epoc_roll(log_u, log_u->dun_d) ) {
fprintf(stderr, "disk: failed to initialize epoch\r\n");
exit(1);
}

return _epoc_good;
} break;

default: u3_assert(0);
}

return _epoc_good;
u3_assert(!"unreachable");
}

/* u3_disk_make(): make pier directories.
Expand Down
17 changes: 12 additions & 5 deletions pkg/vere/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,13 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d)
u3l_log("---------------- playback complete ----------------");
u3m_save();

if ( (mar_u->dun_d == log_u->dun_d)
&& !log_u->epo_d
&& !(u3C.wag_w & u3o_yolo) )
{
u3_disk_roll(mar_u->log_u, mar_u->dun_d);
}

return pay_d;
}

Expand Down Expand Up @@ -1932,28 +1939,28 @@ u3_mars_boot(u3_mars* mar_u, c3_d len_d, c3_y* hun_y)

if ( c3n == _mars_boot_make(&inp_u, com, &ova, &cax, &met_u) ) {
fprintf(stderr, "boot: preparation failed\r\n");
return c3n; // XX cleanup
exit(1); // XX cleanup
}

if ( c3n == u3_disk_save_meta_meta(log_u->com_u->pax_c, &met_u) ) {
fprintf(stderr, "boot: failed to save top-level metadata\r\n");
return c3n; // XX cleanup
exit(1); // XX cleanup
}

if ( c3n == u3_disk_save_meta(log_u->mdb_u, &met_u) ) {
return c3n; // XX cleanup
exit(1); // XX cleanup
}

u3_disk_plan_list(log_u, ova);

if ( c3n == u3_disk_sync(log_u) ) {
return c3n; // XX cleanup
exit(1); // XX cleanup
}

_mars_step_trace(mar_u->dir_c);

if ( c3n == _mars_do_boot(log_u, log_u->dun_d, cax) ) {
return c3n; // XX cleanup
exit(1); // XX cleanup
}

u3m_save();
Expand Down