snapkitty
compilers
c
asm
File size: 5,624 Bytes
96dc096
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**

 * intent_router.h

 * Ω…ΩˆΨ¬Ω‡ Ψ§Ω„Ω†ΩˆΨ§ΩŠΨ§ - Ω†ΨΈΨ§Ω… Ψ§Ω„ΨͺΩˆΨ¬ΩŠΩ‡ Ψ§Ω„Ψ―ΩŠΩ†Ψ§Ω…ΩŠΩƒΩŠ

 * Intent Router - Dynamic Routing System

 *

 * Routes incoming intents from ring buffer to appropriate KAR agents

 * based on intent type, priority, and system state.

 *

 * Author: Ahmad Ali Parr

 * License: Sovereign Source

 */

#ifndef ASOS_INTENT_ROUTER_H
#define ASOS_INTENT_ROUTER_H

#include "intent_schema.h"

/* Forward declarations */
struct IntentRing;
struct KARWorkerPool;

/* ═══════════════════════════════════════════════════════════════

 * Router Configuration | ΨͺΩƒΩˆΩŠΩ† Ψ§Ω„Ω…ΩˆΨ¬Ω‡

 * ═══════════════════════════════════════════════════════════════ */

/**

 * RouterConfig - Configuration for intent routing

 */
struct RouterConfig {
    unsigned int num_workers;        /* Number of worker threads */
    unsigned int max_queue_depth;    /* Max pending intents */
    unsigned int routing_timeout_ms; /* Timeout for routing decision */
    bool enable_load_balancing;      /* Distribute across workers */
    bool enable_priority_preempt;    /* Allow high-priority preemption */
};

/* Default router configuration */
#define DEFAULT_ROUTER_CONFIG {     \
    .num_workers = 4,               \
    .max_queue_depth = 256,         \
    .routing_timeout_ms = 1000,     \
    .enable_load_balancing = true,  \
    .enable_priority_preempt = true \
}

/* ═══════════════════════════════════════════════════════════════

 * Routing Decision | Ω‚Ψ±Ψ§Ψ± Ψ§Ω„ΨͺΩˆΨ¬ΩŠΩ‡

 * ═══════════════════════════════════════════════════════════════ */

/**

 * RoutingDecision - Where and how to process an intent

 */
struct RoutingDecision {
    unsigned int worker_id;          /* Which worker thread */
    unsigned int agent_id;           /* Which KAR agent */
    bool use_accelerator;            /* Route to NPU/FPGA */
    unsigned int estimated_cost_ns;  /* Estimated processing time */
};

/* ═══════════════════════════════════════════════════════════════

 * Router Lifecycle | دورة حياة Ψ§Ω„Ω…ΩˆΨ¬Ω‡

 * ═══════════════════════════════════════════════════════════════ */

/**

 * router_init - Initialize the intent router

 * @ring: Ring buffer to monitor

 * @config: Router configuration

 *

 * Returns: 0 on success, negative error code on failure

 */
int router_init(struct IntentRing *ring, const struct RouterConfig *config);

/**

 * router_shutdown - Shutdown the router and worker pool

 */
void router_shutdown(void);

/* ═══════════════════════════════════════════════════════════════

 * Routing Operations | ΨΉΩ…Ω„ΩŠΨ§Ψͺ Ψ§Ω„ΨͺΩˆΨ¬ΩŠΩ‡

 * ═══════════════════════════════════════════════════════════════ */

/**

 * router_route_intent - Route a single intent to KAR

 * @intent: Intent to route

 * @decision_out: Output for routing decision

 *

 * Returns: 0 on success, negative error code on failure

 *

 * This is called by the ring buffer consumer to determine where

 * to send the intent for processing.

 */
int router_route_intent(const struct SystemIntent *intent,

                        struct RoutingDecision *decision_out);

/**

 * router_enqueue_intent - Enqueue intent to worker thread

 * @intent: Intent to enqueue

 * @decision: Routing decision from router_route_intent()

 *

 * Returns: 0 on success, negative error code on failure

 */
int router_enqueue_intent(const struct SystemIntent *intent,

                          const struct RoutingDecision *decision);

/* ═══════════════════════════════════════════════════════════════

 * Router Statistics | Ψ₯حءائياΨͺ Ψ§Ω„Ω…ΩˆΨ¬Ω‡

 * ═══════════════════════════════════════════════════════════════ */

/**

 * RouterStats - Runtime statistics for monitoring

 */
struct RouterStats {
    uint64_t total_routed;           /* Total intents routed */
    uint64_t routing_errors;         /* Failed routing attempts */
    uint64_t queue_full_rejects;     /* Rejected due to queue full */
    uint64_t avg_routing_time_ns;    /* Average routing decision time */
    unsigned int current_queue_depth;/* Current pending intents */
};

/**

 * router_get_stats - Get current router statistics

 * @stats_out: Output buffer for statistics

 *

 * Returns: 0 on success

 */
int router_get_stats(struct RouterStats *stats_out);

#endif /* ASOS_INTENT_ROUTER_H */