#define _GNU_SOURCE #include #include #include #include #include "locking.h" #include "cpusched.h" #include "xmalloc.h" #include "hash.h" struct map_entry { int fd; unsigned int cpu; struct map_entry *next; }; static struct hash_table mapper; static unsigned int *cpu_work_map = NULL; static unsigned int cpu_len = 0; static struct rwlock map_lock; static int get_appropriate_cpu(void) { int i, cpu = 0; int work = INT_MAX; for (i = 0; i < cpu_len; ++i) { if (cpu_work_map[i] < work) { work = cpu_work_map[i]; cpu = i; } } return cpu; } unsigned int socket_to_cpu(int fd) { int cpu = 0; struct map_entry *entry; rwlock_rd_lock(&map_lock); entry = lookup_hash(fd, &mapper); while (entry && fd != entry->fd) entry = entry->next; if (entry && fd == entry->fd) cpu = entry->cpu; rwlock_unlock(&map_lock); return cpu; } unsigned int register_socket(int fd) { void **pos; struct map_entry *entry; rwlock_wr_lock(&map_lock); entry = xzmalloc(sizeof(*entry)); entry->fd = fd; entry->cpu = get_appropriate_cpu(); cpu_work_map[entry->cpu]++; pos = insert_hash(entry->fd, entry, &mapper); if (pos) { entry->next = (*pos); (*pos) = entry; } rwlock_unlock(&map_lock); return entry->cpu; } static struct map_entry *socket_to_map_entry(int fd) { struct map_entry *entry, *ret = NULL; rwlock_rd_lock(&map_lock); entry = lookup_hash(fd, &mapper); while (entry && fd != entry->fd) entry = entry->next; if (entry && fd == entry->fd) ret = entry; rwlock_unlock(&map_lock); return ret; } void unregister_socket(int fd) { struct map_entry *pos; struct map_entry *entry = socket_to_map_entry(fd); if (entry == NULL) return; rwlock_wr_lock(&map_lock); cpu_work_map[entry->cpu]--; pos = remove_hash(entry->fd, entry, entry->next, &mapper); while (pos && pos->next && pos->next != entry) pos = pos->next; if (pos && pos->next && pos->next == entry) pos->next = entry->next; entry->next = NULL; xfree(entry); rwlock_unlock(&map_lock); } static int cleanup_cpusched_batch(void *ptr) { struct map_entry *next; struct map_entry *entry = ptr; if (!entry) return 0; while ((next = entry->next)) { entry->next = NULL; xfree(entry); entry = next; } xfree(entry); return 0; } void init_cpusched(unsigned int cpus) { rwlock_init(&map_lock); cpu_work_map = xzmalloc((cpu_len = cpus) * sizeof(*cpu_work_map)); init_hash(&mapper); } void destroy_cpusched(void) { xfree(cpu_work_map); for_each_hash(&mapper, cleanup_cpusched_batch); free_hash(&mapper); rwlock_destroy(&map_lock); } >
diff options
context:
space:
mode:
authorIdo Schimmel <idosch@mellanox.com>2017-02-09 10:28:38 +0100
committerDavid S. Miller <davem@davemloft.net>2017-02-10 11:32:12 -0500
commit58e3bdd59742feef680861acec19126e40e4fa8d (patch)
tree0824a2a0665d1be34d066957755d243edec9a52b
parenta507c346b7fdc97296fa74626df49fdb7296a04e (diff)
ipv4: fib: Only flush FIB aliases belonging to currently flushed table
In case the MAIN table is flushed and its trie is shared with the LOCAL table, then we might be flushing FIB aliases belonging to the latter. This can lead to FIB_ENTRY_DEL notifications sent with the wrong table ID. The above doesn't affect current listeners, as the table ID is ignored during entry deletion, but this will change later in the patchset. When flushing a particular table, skip any aliases belonging to a different one. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> CC: Alexander Duyck <alexander.h.duyck@intel.com> CC: Patrick McHardy <kaber@trash.net> Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/fib_trie.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c