Enable all models if the require key is missing

Allows programs to update to a new libovni library without breaking the
instrumentation. Only until the first call to ovni_thread_require() the
models are enabled on demand.
This commit is contained in:
Rodrigo Arias 2023-11-10 15:27:55 +01:00
parent 59385fad03
commit 6f7ce4063f
4 changed files with 21 additions and 30 deletions

View File

@ -198,14 +198,13 @@ model_version_probe(struct model_spec *spec, struct emu *emu)
return -1; return -1;
} }
/* The ovni.require key is mandatory */
JSON_Object *require = json_object_dotget_object(t->meta, "ovni.require"); JSON_Object *require = json_object_dotget_object(t->meta, "ovni.require");
if (require == NULL) { if (require == NULL) {
err("missing 'ovni.require' key in metadata"); warn("missing 'ovni.require' key, enabling all models");
return -1; enable = 1;
break;
} }
/* But not all threads need to have this model */
const char *req_version = json_object_get_string(require, spec->name); const char *req_version = json_object_get_string(require, spec->name);
if (req_version == NULL) if (req_version == NULL)
continue; continue;

View File

@ -464,29 +464,6 @@ thread_metadata_store(void)
die("failed to write thread metadata"); die("failed to write thread metadata");
} }
static void
thread_require_unsafe(const char *model, const char *version)
{
int parsedver[3];
if (version_parse(version, parsedver) != 0)
die("failed to parse provided version \"%s\"", version);
/* Store into metadata */
JSON_Object *meta = json_value_get_object(rthread.meta);
if (meta == NULL)
die("json_value_get_object failed");
char dotpath[128];
if (snprintf(dotpath, 128, "ovni.require.%s", model) >= 128)
die("model name too long");
/* TODO: What if is already set? */
if (json_object_dotset_string(meta, dotpath, version) != 0)
die("json_object_dotset_string failed");
}
void void
ovni_thread_require(const char *model, const char *version) ovni_thread_require(const char *model, const char *version)
{ {
@ -507,7 +484,22 @@ ovni_thread_require(const char *model, const char *version)
if (version == NULL) if (version == NULL)
die("version string is NULL"); die("version string is NULL");
thread_require_unsafe(model, version); int parsedver[3];
if (version_parse(version, parsedver) != 0)
die("failed to parse provided version \"%s\"", version);
/* Store into metadata */
JSON_Object *meta = json_value_get_object(rthread.meta);
if (meta == NULL)
die("json_value_get_object failed");
char dotpath[128];
if (snprintf(dotpath, 128, "ovni.require.%s", model) >= 128)
die("model name too long");
if (json_object_dotset_string(meta, dotpath, version) != 0)
die("json_object_dotset_string failed");
} }
static void static void
@ -526,8 +518,6 @@ thread_metadata_populate(void)
if (json_object_dotset_string(meta, "ovni.lib.commit", OVNI_GIT_COMMIT) != 0) if (json_object_dotset_string(meta, "ovni.lib.commit", OVNI_GIT_COMMIT) != 0)
die("json_object_dotset_string failed"); die("json_object_dotset_string failed");
thread_require_unsafe("ovni", "1.0.0");
} }
static void static void

View File

@ -111,6 +111,7 @@ instr_start(int rank, int nranks)
dbg("thread %d has cpu %d (ncpus=%d)", dbg("thread %d has cpu %d (ncpus=%d)",
get_tid(), curcpu, nranks); get_tid(), curcpu, nranks);
instr_require("ovni");
instr_thread_execute(curcpu, -1, 0); instr_thread_execute(curcpu, -1, 0);
} }

View File

@ -46,6 +46,7 @@ main(void)
int lcpu = rank % N; int lcpu = rank % N;
ovni_thread_init(get_tid()); ovni_thread_init(get_tid());
instr_require("ovni");
instr_nosv_init(); instr_nosv_init();
instr_thread_execute(lcpu, -1, 0); instr_thread_execute(lcpu, -1, 0);