#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 unsigned int get_appropriate_cpu(void) { unsigned int i, cpu = 0; unsigned int work = UINT_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); } name='q' value=''/>
AgeCommit message (Expand)AuthorFilesLines
2017-02-08net: introduce device min_header_lenWillem de Bruijn1-0/+4
2017-02-08lwtunnel: valid encap attr check should return 0 when lwtunnel is disabledDavid Ahern1-1/+4
2017-02-07Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netLinus Torvalds3-7/+10
2017-02-07udp: properly cope with csum errorsEric Dumazet1-1/+3
2017-02-04netlabel: out of bound access in cipso_v4_validate()Eric Dumazet1-0/+4
2017-02-04Merge branch 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/ker...Linus Torvalds1-0/+17
2017-02-04Merge tag 'char-misc-4.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/g...Linus Torvalds1-2/+30
2017-02-03base/memory, hotplug: fix a kernel oops in show_valid_zones()Toshi Kani1-1/+2
2017-02-03Merge tag 'drm-fixes-for-v4.10-rc7' of git://people.freedesktop.org/~airlied/...Linus Torvalds2-1/+16
2017-02-03Merge branch 'modversions' (modversions fixes for powerpc from Ard)Linus Torvalds3-17/+25
2017-02-03log2: make order_base_2() behave correctly on const input value zeroArd Biesheuvel1-1/+12
2017-02-03module: unify absolute krctab definitions for 32-bit and 64-bitArd Biesheuvel1-7/+0
2017-02-03modversions: treat symbol CRCs as 32 bit quantitiesArd Biesheuvel3-12/+27
2017-02-03ipv6: sr: remove cleanup flag and fix HMAC computationDavid Lebrun1-6/+3
2017-02-02Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/ke...Linus Torvalds1-3/+0
2017-02-01Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netLinus Torvalds4-19/+26
2017-02-01Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/vir...Linus Torvalds1-0/+1
2017-02-01net: fix ndo_features_check/ndo_fix_features comment orderingDimitris Michailidis1-14/+15
2017-02-01perf/x86/intel/uncore: Make package handling more robustThomas Gleixner1-2/+0