1 From 7f536bd95b67f43531a225ed4e4f538f08eb2493 Mon Sep 17 00:00:00 2001
2 From: Thomas Gleixner <tglx@linutronix.de>
3 Date: Tue, 14 Jul 2015 14:26:34 +0200
4 Subject: [PATCH 174/366] idr: Use local lock instead of preempt enable/disable
6 We need to protect the per cpu variable and prevent migration.
8 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
10 include/linux/idr.h | 4 ++++
11 lib/idr.c | 43 +++++++++++++++++++++++++++++++++++++------
12 2 files changed, 41 insertions(+), 6 deletions(-)
14 diff --git a/include/linux/idr.h b/include/linux/idr.h
15 index 013fd9b..f62be0a 100644
16 --- a/include/linux/idr.h
17 +++ b/include/linux/idr.h
18 @@ -95,10 +95,14 @@ bool idr_is_empty(struct idr *idp);
19 * Each idr_preload() should be matched with an invocation of this
20 * function. See idr_preload() for details.
22 +#ifdef CONFIG_PREEMPT_RT_FULL
23 +void idr_preload_end(void);
25 static inline void idr_preload_end(void)
32 * idr_find - return pointer for given id
33 diff --git a/lib/idr.c b/lib/idr.c
34 index 6098336..9decbe9 100644
38 #include <linux/idr.h>
39 #include <linux/spinlock.h>
40 #include <linux/percpu.h>
41 +#include <linux/locallock.h>
43 #define MAX_IDR_SHIFT (sizeof(int) * 8 - 1)
44 #define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)
45 @@ -45,6 +46,37 @@ static DEFINE_PER_CPU(struct idr_layer *, idr_preload_head);
46 static DEFINE_PER_CPU(int, idr_preload_cnt);
47 static DEFINE_SPINLOCK(simple_ida_lock);
49 +#ifdef CONFIG_PREEMPT_RT_FULL
50 +static DEFINE_LOCAL_IRQ_LOCK(idr_lock);
52 +static inline void idr_preload_lock(void)
54 + local_lock(idr_lock);
57 +static inline void idr_preload_unlock(void)
59 + local_unlock(idr_lock);
62 +void idr_preload_end(void)
64 + idr_preload_unlock();
66 +EXPORT_SYMBOL(idr_preload_end);
68 +static inline void idr_preload_lock(void)
73 +static inline void idr_preload_unlock(void)
80 /* the maximum ID which can be allocated given idr->layers */
81 static int idr_max(int layers)
83 @@ -115,14 +147,14 @@ static struct idr_layer *idr_layer_alloc(gfp_t gfp_mask, struct idr *layer_idr)
84 * context. See idr_preload() for details.
86 if (!in_interrupt()) {
89 new = __this_cpu_read(idr_preload_head);
91 __this_cpu_write(idr_preload_head, new->ary[0]);
92 __this_cpu_dec(idr_preload_cnt);
96 + idr_preload_unlock();
100 @@ -366,7 +398,6 @@ static void idr_fill_slot(struct idr *idr, void *ptr, int id,
101 idr_mark_full(pa, id);
106 * idr_preload - preload for idr_alloc()
107 * @gfp_mask: allocation mask to use for preloading
108 @@ -401,7 +432,7 @@ void idr_preload(gfp_t gfp_mask)
109 WARN_ON_ONCE(in_interrupt());
110 might_sleep_if(gfpflags_allow_blocking(gfp_mask));
113 + idr_preload_lock();
116 * idr_alloc() is likely to succeed w/o full idr_layer buffer and
117 @@ -413,9 +444,9 @@ void idr_preload(gfp_t gfp_mask)
118 while (__this_cpu_read(idr_preload_cnt) < MAX_IDR_FREE) {
119 struct idr_layer *new;
122 + idr_preload_unlock();
123 new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
125 + idr_preload_lock();