Skip to content

Commit

Permalink
wip: v3 migration scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 15, 2023
1 parent 174f910 commit 1a9d58a
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@
u3_noun day; // doss, only in u3H (moveme)
} pro;

struct { // transient/persistent memoization
u3p(u3h_root) har_p; // (map (pair term noun) noun)
u3p(u3h_root) per_p; // (map (pair term noun) noun)
struct { // memoization caches
u3p(u3h_root) har_p; // transient
u3p(u3h_root) per_p; // persistent
u3p(u3h_root) fod_p; // ford
u3p(u3h_root) sam_p; // ames
} cax;
} u3a_road;
typedef u3a_road u3_road;
Expand Down
7 changes: 5 additions & 2 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// @file

#include "manage.h"
#include "pkg/noun/manage.h"
#include "pkg/noun/v2/manage.h"
#include "pkg/noun/v3/manage.h"

#include <ctype.h>
#include <errno.h>
Expand Down Expand Up @@ -597,7 +599,8 @@ _find_home(void)

switch ( ver_w ) {
case 1: u3m_v2_migrate();
case 2: break;
case 2: u3m_v3_migrate();
case 3: break;
default: {
fprintf(stderr, "loom: checkpoint version mismatch: "
"have %u, need %u\r\n",
Expand Down
29 changes: 29 additions & 0 deletions pkg/noun/v3/allocate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef U3_ALLOCATE_V3_H
#define U3_ALLOCATE_V3_H

#include "pkg/noun/allocate.h"

#include "pkg/noun/v3/manage.h"
#include "options.h"

/** Aliases.
**/
# define u3R_v3 u3a_Road
# define u3a_v3_balign u3a_balign
# define u3a_v3_road u3a_road
# define u3a_v3_walign u3a_walign

/** Data structures.
**/

/** Globals.
**/

/** Functions.
**/
/** Allocation.
**/
/* Reference and arena control.
*/

#endif /* ifndef U3_ALLOCATE_V3_H */
8 changes: 8 additions & 0 deletions pkg/noun/v3/hashtable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef U3_HASHTABLE_V3_H
#define U3_HASHTABLE_V3_H

#define u3h_v3_new_cache u3h_new_cache

#include "pkg/noun/hashtable.h"

#endif /* U3_HASHTABLE_V3_H */
99 changes: 99 additions & 0 deletions pkg/noun/v3/manage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/// @file

#include "pkg/noun/v3/manage.h"

#include "pkg/noun/v3/allocate.h"
#include "pkg/noun/v3/hashtable.h"
#include "pkg/noun/version.h"
#include "pkg/noun/v2/vortex.h"
#include "pkg/noun/v3/vortex.h"

/* u3m_v3_migrate: perform loom migration if necessary.
*/
void
u3m_v3_migrate()
{
fprintf(stderr, "loom: memoization migration running...\r\n");


c3_w ver_w = *(u3_Loom + u3C.wor_i - 1); // XX
c3_w *mem_w = u3_Loom + u3a_v3_walign;
c3_w len_w = u3C.wor_i - u3a_v3_walign;
c3_w suz_w = c3_wiseof(u3v_v2_home);
// XX check this later
c3_w *mut_w = c3_align(mem_w + len_w - suz_w, u3a_v3_balign, C3_ALGLO);

// old road
u3v_v2_home* hum_u = (u3v_v2_home*)mut_w;
u3a_v2_road* rud_u = &hum_u->rod_u;
size_t ruz_t = sizeof(u3a_v2_road);

// new home, new road
u3v_v3_home hom_u = {0};
u3a_v3_road rod_u = {0};

// copy members, one-by-one, from old road to new road
rod_u.par_p = rud_u->par_p;
rod_u.kid_p = rud_u->kid_p;
rod_u.nex_p = rud_u->nex_p;

rod_u.cap_p = rud_u->cap_p;
rod_u.hat_p = rud_u->hat_p;
rod_u.mat_p = rud_u->mat_p;
rod_u.rut_p = rud_u->rut_p;
rod_u.ear_p = rud_u->ear_p;

// no need to zero-out fut_w

// no need to do anything with esc

rod_u.how.fag_w = rud_u->how.fag_w;

// XX destination buffer is size 196; is that because of padding?
memcpy(rod_u.all.fre_p, rud_u->all.fre_p, sizeof(rud_u->all.fre_p));
rod_u.all.cel_p = rud_u->all.cel_p;
rod_u.all.fre_w = rud_u->all.fre_w;
rod_u.all.max_w = rud_u->all.max_w;

rod_u.jed.hot_p = rud_u->jed.hot_p;
rod_u.jed.war_p = rud_u->jed.war_p;
rod_u.jed.cod_p = rud_u->jed.cod_p;
rod_u.jed.han_p = rud_u->jed.han_p;
rod_u.jed.bas_p = rud_u->jed.bas_p;

rod_u.byc.har_p = rud_u->byc.har_p;

rod_u.ski.gul = rud_u->ski.gul;

rod_u.bug.tax = rud_u->bug.tax;
rod_u.bug.mer = rud_u->bug.mer;

rod_u.pro.nox_d = rud_u->pro.nox_d;
rod_u.pro.cel_d = rud_u->pro.cel_d;
rod_u.pro.don = rud_u->pro.don;
rod_u.pro.trace = rud_u->pro.trace;
rod_u.pro.day = rud_u->pro.day;

rod_u.cax.har_p = rud_u->cax.har_p;

// prepare the new home
hom_u.arv_u = hum_u->arv_u;
hom_u.rod_u = rod_u;
hom_u.ver_w = U3V_VER3;

// place the new home over the old one
c3_w siz_w = c3_wiseof(u3v_home);
c3_w *mat_w = c3_align(mem_w + len_w - siz_w, u3a_v3_balign, C3_ALGLO);
memcpy(mat_w, &hom_u, sizeof(u3v_home));

// set globals
u3H_v3 = (void*)mat_w;
u3R_v3 = &u3H_v3->rod_u;

// initialize persistent cache
u3R_v3->cax.per_p = u3h_v3_new_cache(u3C.per_w);

u3H_v3->ver_w = U3V_VER3;

fprintf(stderr, "loom: memoization migration done\r\n");
}
14 changes: 14 additions & 0 deletions pkg/noun/v3/manage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// @file

#ifndef U3_MANAGE_V3_H
#define U3_MANAGE_V3_H

/** System management.
**/
/* u3m_v3_migrate: perform pointer compression loom migration if necessary.
ver_w - target version
*/
void
u3m_v3_migrate();

#endif /* ifndef U3_MANAGE_V3_H */
5 changes: 5 additions & 0 deletions pkg/noun/v3/vortex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @file

#include "pkg/noun/v3/vortex.h"

u3v_v3_home* u3v_v3_Home;
40 changes: 40 additions & 0 deletions pkg/noun/v3/vortex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// @file

#ifndef U3_VORTEX_V3_H
#define U3_VORTEX_V3_H

#include "pkg/noun/vortex.h"

#include "pkg/noun/v3/allocate.h"
#include "pkg/noun/version.h"

/** Aliases.
**/
# define u3v_v3_arvo u3v_arvo

/** Data structures.
**/
/* u3v_v3_home: all internal (within image) state.
** NB: version must be last for discriminability in north road
*/
typedef struct _u3v_v3_home {
u3a_v3_road rod_u; // storage state
u3v_v3_arvo arv_u; // arvo state
u3v_version ver_w; // version number
} u3v_v3_home;

/** Globals.
**/
/// Arvo internal state.
extern u3v_v3_home* u3v_v3_Home;
# define u3H_v3 u3v_v3_Home
# define u3A_v3 (&(u3v_v3_Home->arv_u))

/** Functions.
**/
/* u3v_v3_rewrite_compact(): rewrite arvo kernel for compaction.
*/
void
u3v_v3_rewrite_compact();

#endif /* ifndef U3_VORTEX_V3_H */
3 changes: 2 additions & 1 deletion pkg/noun/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ typedef c3_w u3v_version;

#define U3V_VER1 1
#define U3V_VER2 2
#define U3V_VERLAT U3V_VER2
#define U3V_VER3 3
#define U3V_VERLAT U3V_VER3

/* EVENTS
*/
Expand Down

0 comments on commit 1a9d58a

Please sign in to comment.