From 19966a5cb3a8d9cf8edbae225953da042dadfa96 Mon Sep 17 00:00:00 2001
From: Vito Caputo <vcaputo@pengaru.com>
Date: Tue, 10 Jan 2023 15:09:29 -0800
Subject: *: introduce paths for module contexts

There needs to be a way to address module context instances
by name externally, in a manner complementary to settings and
taps.

This commit adds a string-based path to til_module_context_t, and
modifies til_module_create_context() to accept a parent path
which is then concatenated with the name of the module to produce
the module instance's new path.

The name separator used in the paths is '/' just like filesystem
paths, but these paths have no relationship to filesystems or
files.

The root module context creation in rototiller's main simply
passes "" as the parent path, resulting in a "/" root as one
would expect.

There are some obvious complications introduced here however:

 - checkers in particular creates a context per cpu, simply using
   the same seed and setup to try make the contexts identical at
   the same ticks value.  With this commit I'm simply passing the
   incoming path as the parent for creating those contexts, but
   it's unclear to me if that will work OK.  With an eye towards
   taps deriving their parent path from the context path, I guess
   these taps would all get the same parent and hash to the same
   value despite being duplicated.  Maybe it Just Works, but one
   thing is clear - there won't be any way to address the per-cpu
   taps as-is.  Maybe that's desirable though, there's probably
   not much use in trying to control the taps at the CPU
   granularity.

 - when the recursive settings stuff lands, it should bring along
   the ability to explicitly name settings blocks.  Those names
   should override the module name in constructing the path.
   I've noted as such in the code.

 - these paths probably need to be hashed @ initialization time
   so there needs to be a hash function added to til, and a hash
   value accompanying the name in the module context.  It'd be
   dumb to keep recomputing the hash when these paths get used
   for hash table lookups multiple times per frame...

there's probably more I'm forgetting right now, but this seems
like a good first step.

fixup root path
---
 src/modules/moire/moire.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/modules/moire')

diff --git a/src/modules/moire/moire.c b/src/modules/moire/moire.c
index d528f8c..9bf782c 100644
--- a/src/modules/moire/moire.c
+++ b/src/modules/moire/moire.c
@@ -47,14 +47,14 @@ static moire_setup_t moire_default_setup = {
 };
 
 
-static til_module_context_t * moire_create_context(unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup)
+static til_module_context_t * moire_create_context(unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup)
 {
 	moire_context_t	*ctxt;
 
 	if (!setup)
 		setup = &moire_default_setup.til_setup;
 
-	ctxt = til_module_context_new(sizeof(moire_context_t) + ((moire_setup_t *)setup)->n_centers * sizeof(moire_center_t), seed, ticks, n_cpus);
+	ctxt = til_module_context_new(sizeof(moire_context_t) + ((moire_setup_t *)setup)->n_centers * sizeof(moire_center_t), seed, ticks, n_cpus, path);
 	if (!ctxt)
 		return NULL;
 
-- 
cgit v1.2.3