diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Kconfig.debug | 2 | ||||
| -rw-r--r-- | lib/Makefile | 2 | ||||
| -rw-r--r-- | lib/hweight.c | 2 | ||||
| -rw-r--r-- | lib/percpu_counter.c | 5 | ||||
| -rw-r--r-- | lib/prio_heap.c | 70 | ||||
| -rw-r--r-- | lib/spinlock_debug.c | 8 |
6 files changed, 81 insertions, 8 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 7d16e6433302..c567f219191d 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
| @@ -498,3 +498,5 @@ config FAULT_INJECTION_STACKTRACE_FILTER | |||
| 498 | select FRAME_POINTER | 498 | select FRAME_POINTER |
| 499 | help | 499 | help |
| 500 | Provide stacktrace filter for fault-injection capabilities | 500 | Provide stacktrace filter for fault-injection capabilities |
| 501 | |||
| 502 | source "samples/Kconfig" | ||
diff --git a/lib/Makefile b/lib/Makefile index c5f215d509d3..3a0983b77412 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -6,7 +6,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ | |||
| 6 | rbtree.o radix-tree.o dump_stack.o \ | 6 | rbtree.o radix-tree.o dump_stack.o \ |
| 7 | idr.o int_sqrt.o bitmap.o extable.o prio_tree.o \ | 7 | idr.o int_sqrt.o bitmap.o extable.o prio_tree.o \ |
| 8 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ | 8 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ |
| 9 | proportions.o | 9 | proportions.o prio_heap.o |
| 10 | 10 | ||
| 11 | lib-$(CONFIG_MMU) += ioremap.o | 11 | lib-$(CONFIG_MMU) += ioremap.o |
| 12 | lib-$(CONFIG_SMP) += cpumask.o | 12 | lib-$(CONFIG_SMP) += cpumask.o |
diff --git a/lib/hweight.c b/lib/hweight.c index 360556a7803d..389424ecb129 100644 --- a/lib/hweight.c +++ b/lib/hweight.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include <linux/module.h> | 1 | #include <linux/module.h> |
| 2 | #include <linux/bitops.h> | ||
| 2 | #include <asm/types.h> | 3 | #include <asm/types.h> |
| 3 | #include <asm/bitops.h> | ||
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * hweightN - returns the hamming weight of a N-bit word | 6 | * hweightN - returns the hamming weight of a N-bit word |
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 9659eabffc31..393a0e915c23 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c | |||
| @@ -124,12 +124,13 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, | |||
| 124 | mutex_lock(&percpu_counters_lock); | 124 | mutex_lock(&percpu_counters_lock); |
| 125 | list_for_each_entry(fbc, &percpu_counters, list) { | 125 | list_for_each_entry(fbc, &percpu_counters, list) { |
| 126 | s32 *pcount; | 126 | s32 *pcount; |
| 127 | unsigned long flags; | ||
| 127 | 128 | ||
| 128 | spin_lock(&fbc->lock); | 129 | spin_lock_irqsave(&fbc->lock, flags); |
| 129 | pcount = per_cpu_ptr(fbc->counters, cpu); | 130 | pcount = per_cpu_ptr(fbc->counters, cpu); |
| 130 | fbc->count += *pcount; | 131 | fbc->count += *pcount; |
| 131 | *pcount = 0; | 132 | *pcount = 0; |
| 132 | spin_unlock(&fbc->lock); | 133 | spin_unlock_irqrestore(&fbc->lock, flags); |
| 133 | } | 134 | } |
| 134 | mutex_unlock(&percpu_counters_lock); | 135 | mutex_unlock(&percpu_counters_lock); |
| 135 | return NOTIFY_OK; | 136 | return NOTIFY_OK; |
diff --git a/lib/prio_heap.c b/lib/prio_heap.c new file mode 100644 index 000000000000..471944a54e23 --- /dev/null +++ b/lib/prio_heap.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* | ||
| 2 | * Simple insertion-only static-sized priority heap containing | ||
| 3 | * pointers, based on CLR, chapter 7 | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <linux/slab.h> | ||
| 7 | #include <linux/prio_heap.h> | ||
| 8 | |||
| 9 | int heap_init(struct ptr_heap *heap, size_t size, gfp_t gfp_mask, | ||
| 10 | int (*gt)(void *, void *)) | ||
| 11 | { | ||
| 12 | heap->ptrs = kmalloc(size, gfp_mask); | ||
| 13 | if (!heap->ptrs) | ||
| 14 | return -ENOMEM; | ||
| 15 | heap->size = 0; | ||
| 16 | heap->max = size / sizeof(void *); | ||
| 17 | heap->gt = gt; | ||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | void heap_free(struct ptr_heap *heap) | ||
| 22 | { | ||
| 23 | kfree(heap->ptrs); | ||
| 24 | } | ||
| 25 | |||
| 26 | void *heap_insert(struct ptr_heap *heap, void *p) | ||
| 27 | { | ||
| 28 | void *res; | ||
| 29 | void **ptrs = heap->ptrs; | ||
| 30 | int pos; | ||
| 31 | |||
| 32 | if (heap->size < heap->max) { | ||
| 33 | /* Heap insertion */ | ||
| 34 | int pos = heap->size++; | ||
| 35 | while (pos > 0 && heap->gt(p, ptrs[(pos-1)/2])) { | ||
| 36 | ptrs[pos] = ptrs[(pos-1)/2]; | ||
| 37 | pos = (pos-1)/2; | ||
| 38 | } | ||
| 39 | ptrs[pos] = p; | ||
| 40 | return NULL; | ||
| 41 | } | ||
| 42 | |||
| 43 | /* The heap is full, so something will have to be dropped */ | ||
| 44 | |||
| 45 | /* If the new pointer is greater than the current max, drop it */ | ||
| 46 | if (heap->gt(p, ptrs[0])) | ||
| 47 | return p; | ||
| 48 | |||
| 49 | /* Replace the current max and heapify */ | ||
| 50 | res = ptrs[0]; | ||
| 51 | ptrs[0] = p; | ||
| 52 | pos = 0; | ||
| 53 | |||
| 54 | while (1) { | ||
| 55 | int left = 2 * pos + 1; | ||
| 56 | int right = 2 * pos + 2; | ||
| 57 | int largest = pos; | ||
| 58 | if (left < heap->size && heap->gt(ptrs[left], p)) | ||
| 59 | largest = left; | ||
| 60 | if (right < heap->size && heap->gt(ptrs[right], ptrs[largest])) | ||
| 61 | largest = right; | ||
| 62 | if (largest == pos) | ||
| 63 | break; | ||
| 64 | /* Push p down the heap one level and bump one up */ | ||
| 65 | ptrs[pos] = ptrs[largest]; | ||
| 66 | ptrs[largest] = p; | ||
| 67 | pos = largest; | ||
| 68 | } | ||
| 69 | return res; | ||
| 70 | } | ||
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c index 479fd462eaa9..9c4b0256490b 100644 --- a/lib/spinlock_debug.c +++ b/lib/spinlock_debug.c | |||
| @@ -60,12 +60,12 @@ static void spin_bug(spinlock_t *lock, const char *msg) | |||
| 60 | owner = lock->owner; | 60 | owner = lock->owner; |
| 61 | printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", | 61 | printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", |
| 62 | msg, raw_smp_processor_id(), | 62 | msg, raw_smp_processor_id(), |
| 63 | current->comm, current->pid); | 63 | current->comm, task_pid_nr(current)); |
| 64 | printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, " | 64 | printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, " |
| 65 | ".owner_cpu: %d\n", | 65 | ".owner_cpu: %d\n", |
| 66 | lock, lock->magic, | 66 | lock, lock->magic, |
| 67 | owner ? owner->comm : "<none>", | 67 | owner ? owner->comm : "<none>", |
| 68 | owner ? owner->pid : -1, | 68 | owner ? task_pid_nr(owner) : -1, |
| 69 | lock->owner_cpu); | 69 | lock->owner_cpu); |
| 70 | dump_stack(); | 70 | dump_stack(); |
| 71 | } | 71 | } |
| @@ -116,7 +116,7 @@ static void __spin_lock_debug(spinlock_t *lock) | |||
| 116 | printk(KERN_EMERG "BUG: spinlock lockup on CPU#%d, " | 116 | printk(KERN_EMERG "BUG: spinlock lockup on CPU#%d, " |
| 117 | "%s/%d, %p\n", | 117 | "%s/%d, %p\n", |
| 118 | raw_smp_processor_id(), current->comm, | 118 | raw_smp_processor_id(), current->comm, |
| 119 | current->pid, lock); | 119 | task_pid_nr(current), lock); |
| 120 | dump_stack(); | 120 | dump_stack(); |
| 121 | #ifdef CONFIG_SMP | 121 | #ifdef CONFIG_SMP |
| 122 | trigger_all_cpu_backtrace(); | 122 | trigger_all_cpu_backtrace(); |
| @@ -161,7 +161,7 @@ static void rwlock_bug(rwlock_t *lock, const char *msg) | |||
| 161 | 161 | ||
| 162 | printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n", | 162 | printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n", |
| 163 | msg, raw_smp_processor_id(), current->comm, | 163 | msg, raw_smp_processor_id(), current->comm, |
| 164 | current->pid, lock); | 164 | task_pid_nr(current), lock); |
| 165 | dump_stack(); | 165 | dump_stack(); |
| 166 | } | 166 | } |
| 167 | 167 | ||
