Re: [RFC PATCH 04/16] rv/include: Add deterministic automata monitor definition via C macros
From: Peter Zijlstra
Date: Wed May 19 2021 - 14:28:18 EST
On Wed, May 19, 2021 at 01:36:25PM +0200, Daniel Bristot de Oliveira wrote:
> +struct da_monitor {
> + char curr_state;
> + bool monitoring;
> + void *model;
> +};
> +
> +#define MAX_PID 1024000
> +/*
> + * Functions to define, init and get a per-task monitor.
> + *
> + * XXX: Make it dynamic? make it part of the task structure?
Yes !
I'd start with maybe adding a list_head to da_monitor and embedding a
single copy into task_struct and link from there. Yes lists suck, but
how many monitors do you realistically expect to run concurrently?
> + */
> +#define DECLARE_DA_MON_INIT_PER_TASK(name, type) \
> + \
> +struct da_monitor da_mon_##name[MAX_PID]; \
That's ~16M of memory, which seems somewhat silly.
> + \
> +static inline struct da_monitor *da_get_monitor_##name(pid_t pid) \
> +{ \
> + return &da_mon_##name[pid]; \
> +} \
> + \
> +void da_monitor_reset_all_##name(void) \
> +{ \
> + struct da_monitor *mon = da_mon_##name; \
> + int i; \
> + for (i = 0; i < MAX_PID; i++) \
> + da_monitor_reset_##name(&mon[i]); \
> +} \
> + \
> +static void da_monitor_init_##name(void) \
> +{ \
> + struct da_monitor *mon = da_mon_##name; \
> + int i; \
> + \
> + for (i = 0; i < MAX_PID; i++) { \
> + mon[i].curr_state = model_get_init_state_##name(); \
> + mon[i].monitoring = 0; \
> + mon[i].model = model_get_model_##name(); \
> + } \
> +} \