/* * netsniff-ng - the packet sniffing beast * Copyright 2011 Daniel Borkmann. * Subject to the GPL, version 2. */ #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_assigned = NULL; static unsigned int cpu_len = 0; static struct rwlock map_lock; void init_cpusched(unsigned int cpus) { rwlock_init(&map_lock); rwlock_wr_lock(&map_lock); cpu_len = cpus; cpu_assigned = xzmalloc(cpus * sizeof(*cpu_assigned)); memset(&mapper, 0, sizeof(mapper)); init_hash(&mapper); rwlock_unlock(&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_assigned[i] < work) { work = cpu_assigned[i]; cpu = i; } } return cpu; } unsigned int socket_to_cpu(int fd) { int cpu = 0; struct map_entry *entry; errno = 0; 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; else errno = ENOENT; 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_assigned[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; errno = 0; 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; else errno = ENOENT; 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 == 0 && errno == ENOENT) return; rwlock_wr_lock(&map_lock); cpu_assigned[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_batch(void *ptr) { struct map_entry *next; struct map_entry *e = ptr; if (!e) return 0; while ((next = e->next)) { e->next = NULL; xfree(e); e = next; } xfree(e); return 0; } void destroy_cpusched(void) { rwlock_wr_lock(&map_lock); xfree(cpu_assigned); cpu_len = 0; for_each_hash(&mapper, cleanup_batch); free_hash(&mapper); rwlock_unlock(&map_lock); rwlock_destroy(&map_lock); } 0b1f124f807'>sound/usb/bcd2000/Makefile
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-25 14:30:04 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-25 14:30:04 -0800
commit3ddc76dfc786cc6f87852693227fb0b1f124f807 (patch)
tree8192b4721e05cf6823087f9696db8c0c8f144b02 /sound/usb/bcd2000/Makefile
parentb272f732f888d4cf43c943a40c9aaa836f9b7431 (diff)
parent1f3a8e49d8f28f498b8694464623ac20aebfe62a (diff)
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer type cleanups from Thomas Gleixner: "This series does a tree wide cleanup of types related to timers/timekeeping. - Get rid of cycles_t and use a plain u64. The type is not really helpful and caused more confusion than clarity - Get rid of the ktime union. The union has become useless as we use the scalar nanoseconds storage unconditionally now. The 32bit timespec alike storage got removed due to the Y2038 limitations some time ago. That leaves the odd union access around for no reason. Clean it up. Both changes have been done with coccinelle and a small amount of manual mopping up" * 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: ktime: Get rid of ktime_equal() ktime: Cleanup ktime_set() usage ktime: Get rid of the union clocksource: Use a plain u64 instead of cycle_t
Diffstat (limited to 'sound/usb/bcd2000/Makefile')