36#define MAX_NUM_ROUTES 1023
63 .route = entry1->
route,
72static inline void _entry(
const entry_t* entry,
int index) {
98 log_debug(
"find merge %d %d", left, index);
122 log_debug(
"merge left %d right %d", left, right);
123 while (left < right) {
126 for (
int index = left + 1; index <= right; index++) {
149 uint32_t r_tmp =
routes[i];
169 log_debug(
"index %d routes %d", index, route);
181 log_error(
"Too many different routes to compress found %d "
182 "compared to max legal of %d",
190static inline uint32_t find_route_index(uint32_t route) {
196 log_error(
"Route 0x%08x not found!", route);
217 route_offset[i] = offset;
219 route_end[i] = offset - 1;
224 uint32_t pos_index = 0;
227 while (pos < n_entries) {
232 uint32_t route_index = find_route_index(entry.
route);
235 uint32_t read_index = pos_index;
239 if (route_index == read_index) {
241 if (pos < route_offset[route_index]) {
250 uint32_t new_pos = route_offset[route_index];
251 if (new_pos >= n_entries) {
252 log_error(
"New table position %u out of range!", new_pos);
256 if (new_pos > route_end[route_index]) {
257 log_error(
"New table position %u of region %u is out of range!",
258 new_pos, route_index);
261 route_offset[route_index] += 1;
268 if (new_pos <= pos) {
272 read_index = route_index;
275 route_index = find_route_index(entry.
route);
280 if (pos == next_index_offset) {
294 volatile bool *stop_compressing) {
295 use(failed_by_malloc);
300 log_error(
"MAX_NUM_ROUTES %d != rtr_alloc_max() %d",
308 for (
int index = 0; index < table_size; index++) {
320 if (*stop_compressing) {
321 log_info(
"Stopping as asked to stop");
330 log_debug(
"do sort_table by route %u", table_size);
334 uint32_t duration = 0xFFFFFFFF - tc[
T2_COUNT];
336 log_info(
"Sorting table took %u clock cycles", duration);
337 if (*stop_compressing) {
338 log_info(
"Stopping before compression as asked to stop");
343 int max_index = table_size - 1;
346 while (left <= max_index) {
349 log_debug(
"A %u %u %u %u", left, max_index, right, left_route);
350 while ((right < table_size - 1) &&
356 log_debug(
"compress %u %u", left, right);
360 duration = 0xFFFFFFFF - tc[
T2_COUNT];
362 log_info(
"Compressing %u routes took %u", right - left + 1, duration);
365 log_error(
"Compression not possible as already found %d "
366 "entries where max allowed is %d",
371 if (*stop_compressing) {
372 log_info(
"Stopping during compression as asked to stop");
#define check(condition, message,...)
#define use(x)
This can be used to silence gcc's "-Wall -Wextra" warnings about failure to use function arguments.
SpiNNaker debug header file.
void log_error(const char *message,...)
This function logs errors. Errors usually indicate a serious fault in the program,...
void log_debug(const char *message,...)
This function logs debugging messages. This level of message is normally not printed except when the ...
void log_info(const char *message,...)
This function logs informational messages. This is the lowest level of message normally printed.
API for routing table minimisation.
bool standalone(void)
Whether this is a standalone compressor.
static bool find_merge(int left, int index)
Finds if two routes can be merged.
static void sort_routes(void)
Implementation of insertion sort for routes based on frequency.
static entry_t merge(const entry_t *entry1, const entry_t *entry2)
Merges a single pair of route entries.
static uint32_t routes[MAX_NUM_ROUTES]
Table of routes being produced.
static uint32_t write_index
The index of the next place in the compressed table to write a route.
static int remaining_index
The index of the first route after the ones being compressed in this step.
#define MAX_NUM_ROUTES
Absolute maximum number of routes that we may produce.
bool minimise_run(int target_length, bool *failed_by_malloc, volatile bool *stop_compressing)
Implementation of minimise()
static bool update_frequency(int index)
Computes route histogram.
static void compress_by_route(int left, int right)
Does the actual routing compression.
static void cancel_dmas(void)
Cancel any outstanding DMA transfers.
static entry_t route_cache[2][MAX_NUM_ROUTES]
Space for caching routes while going through them.
static uint32_t routes_count
Count of unique routes (as opposed to routes with just different key_masks).
static uint32_t routes_frequency[MAX_NUM_ROUTES]
Route frequency histogram.
void sort_table(void)
Implementation of insertion sort for routes based on route information.
Utilities for a single routing table.
key_mask_t key_mask
Key and mask.
static key_mask_t key_mask_merge(key_mask_t a, key_mask_t b)
Generate a new key-mask which is a combination of two other key_masks.
static void routing_table_copy_entry(int new_index, int old_index)
Copy an entry from one index to another.
uint32_t route
Routing direction.
int routing_table_get_n_entries(void)
Get the number of entries in the routing table.
static bool key_mask_intersect(key_mask_t a, key_mask_t b)
Determine if two key_masks would match any of the same keys.
entry_t * routing_table_get_entry(uint32_t entry_id_to_find)
Gets a pointer to where this entry is stored.
static void routing_table_put_entry(const entry_t *entry, int index)
Write an entry to a specific index.
void routing_table_remove_from_size(int size_to_remove)
updates table stores accordingly.
uint32_t source
Source of packets arriving at this entry.
Holds data for a routing table entry.
void rt_error(uint code,...)