diff options
author | Huang Ying <ying.huang@intel.com> | 2011-09-08 02:00:42 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-10-04 05:30:53 -0400 |
commit | 1230db8e1543c0471dd165727d34647ab098cc1e (patch) | |
tree | 6667af62e0a0bb24b315f5b9e61ea7635293135b | |
parent | 22f92bacbeea24b20e447444c28e7cad9f1ac3f8 (diff) |
llist: Make some llist functions inline
Because llist code will be used in performance critical scheduler
code path, make llist_add() and llist_del_all() inline to avoid
function calling overhead and related 'glue' overhead.
Signed-off-by: Huang Ying <ying.huang@intel.com>
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1315461646-1379-2-git-send-email-ying.huang@intel.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | drivers/acpi/apei/Kconfig | 1 | ||||
-rw-r--r-- | include/linux/llist.h | 64 | ||||
-rw-r--r-- | lib/Kconfig | 3 | ||||
-rw-r--r-- | lib/Makefile | 4 | ||||
-rw-r--r-- | lib/llist.c | 40 |
5 files changed, 59 insertions, 53 deletions
diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig index e3f47872ec22..f0c1ce95a0ec 100644 --- a/drivers/acpi/apei/Kconfig +++ b/drivers/acpi/apei/Kconfig | |||
@@ -14,7 +14,6 @@ config ACPI_APEI_GHES | |||
14 | depends on ACPI_APEI && X86 | 14 | depends on ACPI_APEI && X86 |
15 | select ACPI_HED | 15 | select ACPI_HED |
16 | select IRQ_WORK | 16 | select IRQ_WORK |
17 | select LLIST | ||
18 | select GENERIC_ALLOCATOR | 17 | select GENERIC_ALLOCATOR |
19 | help | 18 | help |
20 | Generic Hardware Error Source provides a way to report | 19 | Generic Hardware Error Source provides a way to report |
diff --git a/include/linux/llist.h b/include/linux/llist.h index aa0c8b5b3cd0..3eccdfd66096 100644 --- a/include/linux/llist.h +++ b/include/linux/llist.h | |||
@@ -37,8 +37,28 @@ | |||
37 | * architectures that don't have NMI-safe cmpxchg implementation, the | 37 | * architectures that don't have NMI-safe cmpxchg implementation, the |
38 | * list can NOT be used in NMI handler. So code uses the list in NMI | 38 | * list can NOT be used in NMI handler. So code uses the list in NMI |
39 | * handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. | 39 | * handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. |
40 | * | ||
41 | * Copyright 2010,2011 Intel Corp. | ||
42 | * Author: Huang Ying <ying.huang@intel.com> | ||
43 | * | ||
44 | * This program is free software; you can redistribute it and/or | ||
45 | * modify it under the terms of the GNU General Public License version | ||
46 | * 2 as published by the Free Software Foundation; | ||
47 | * | ||
48 | * This program is distributed in the hope that it will be useful, | ||
49 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
50 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
51 | * GNU General Public License for more details. | ||
52 | * | ||
53 | * You should have received a copy of the GNU General Public License | ||
54 | * along with this program; if not, write to the Free Software | ||
55 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
40 | */ | 56 | */ |
41 | 57 | ||
58 | #include <linux/kernel.h> | ||
59 | #include <asm/system.h> | ||
60 | #include <asm/processor.h> | ||
61 | |||
42 | struct llist_head { | 62 | struct llist_head { |
43 | struct llist_node *first; | 63 | struct llist_node *first; |
44 | }; | 64 | }; |
@@ -113,14 +133,46 @@ static inline void init_llist_head(struct llist_head *list) | |||
113 | * test whether the list is empty without deleting something from the | 133 | * test whether the list is empty without deleting something from the |
114 | * list. | 134 | * list. |
115 | */ | 135 | */ |
116 | static inline int llist_empty(const struct llist_head *head) | 136 | static inline bool llist_empty(const struct llist_head *head) |
117 | { | 137 | { |
118 | return ACCESS_ONCE(head->first) == NULL; | 138 | return ACCESS_ONCE(head->first) == NULL; |
119 | } | 139 | } |
120 | 140 | ||
121 | void llist_add(struct llist_node *new, struct llist_head *head); | 141 | /** |
122 | void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last, | 142 | * llist_add - add a new entry |
123 | struct llist_head *head); | 143 | * @new: new entry to be added |
124 | struct llist_node *llist_del_first(struct llist_head *head); | 144 | * @head: the head for your lock-less list |
125 | struct llist_node *llist_del_all(struct llist_head *head); | 145 | */ |
146 | static inline void llist_add(struct llist_node *new, struct llist_head *head) | ||
147 | { | ||
148 | struct llist_node *entry, *old_entry; | ||
149 | |||
150 | #ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG | ||
151 | BUG_ON(in_nmi()); | ||
152 | #endif | ||
153 | |||
154 | entry = head->first; | ||
155 | do { | ||
156 | old_entry = entry; | ||
157 | new->next = entry; | ||
158 | cpu_relax(); | ||
159 | } while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry); | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * llist_del_all - delete all entries from lock-less list | ||
164 | * @head: the head of lock-less list to delete all entries | ||
165 | * | ||
166 | * If list is empty, return NULL, otherwise, delete all entries and | ||
167 | * return the pointer to the first entry. The order of entries | ||
168 | * deleted is from the newest to the oldest added one. | ||
169 | */ | ||
170 | static inline struct llist_node *llist_del_all(struct llist_head *head) | ||
171 | { | ||
172 | #ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG | ||
173 | BUG_ON(in_nmi()); | ||
174 | #endif | ||
175 | |||
176 | return xchg(&head->first, NULL); | ||
177 | } | ||
126 | #endif /* LLIST_H */ | 178 | #endif /* LLIST_H */ |
diff --git a/lib/Kconfig b/lib/Kconfig index 6c695ff9caba..32f3e5ae2be5 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -276,7 +276,4 @@ config CORDIC | |||
276 | so its calculations are in fixed point. Modules can select this | 276 | so its calculations are in fixed point. Modules can select this |
277 | when they require this function. Module will be called cordic. | 277 | when they require this function. Module will be called cordic. |
278 | 278 | ||
279 | config LLIST | ||
280 | bool | ||
281 | |||
282 | endmenu | 279 | endmenu |
diff --git a/lib/Makefile b/lib/Makefile index 3f5bc6d903e0..a4da283f5dc0 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -22,7 +22,7 @@ lib-y += kobject.o kref.o klist.o | |||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
25 | bsearch.o find_last_bit.o find_next_bit.o | 25 | bsearch.o find_last_bit.o find_next_bit.o llist.o |
26 | obj-y += kstrtox.o | 26 | obj-y += kstrtox.o |
27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
28 | 28 | ||
@@ -115,8 +115,6 @@ obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | |||
115 | 115 | ||
116 | obj-$(CONFIG_CORDIC) += cordic.o | 116 | obj-$(CONFIG_CORDIC) += cordic.o |
117 | 117 | ||
118 | obj-$(CONFIG_LLIST) += llist.o | ||
119 | |||
120 | hostprogs-y := gen_crc32table | 118 | hostprogs-y := gen_crc32table |
121 | clean-files := crc32table.h | 119 | clean-files := crc32table.h |
122 | 120 | ||
diff --git a/lib/llist.c b/lib/llist.c index da445724fa1f..3e3fa9139c41 100644 --- a/lib/llist.c +++ b/lib/llist.c | |||
@@ -30,28 +30,6 @@ | |||
30 | #include <asm/system.h> | 30 | #include <asm/system.h> |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * llist_add - add a new entry | ||
34 | * @new: new entry to be added | ||
35 | * @head: the head for your lock-less list | ||
36 | */ | ||
37 | void llist_add(struct llist_node *new, struct llist_head *head) | ||
38 | { | ||
39 | struct llist_node *entry, *old_entry; | ||
40 | |||
41 | #ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG | ||
42 | BUG_ON(in_nmi()); | ||
43 | #endif | ||
44 | |||
45 | entry = head->first; | ||
46 | do { | ||
47 | old_entry = entry; | ||
48 | new->next = entry; | ||
49 | cpu_relax(); | ||
50 | } while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry); | ||
51 | } | ||
52 | EXPORT_SYMBOL_GPL(llist_add); | ||
53 | |||
54 | /** | ||
55 | * llist_add_batch - add several linked entries in batch | 33 | * llist_add_batch - add several linked entries in batch |
56 | * @new_first: first entry in batch to be added | 34 | * @new_first: first entry in batch to be added |
57 | * @new_last: last entry in batch to be added | 35 | * @new_last: last entry in batch to be added |
@@ -109,21 +87,3 @@ struct llist_node *llist_del_first(struct llist_head *head) | |||
109 | return entry; | 87 | return entry; |
110 | } | 88 | } |
111 | EXPORT_SYMBOL_GPL(llist_del_first); | 89 | EXPORT_SYMBOL_GPL(llist_del_first); |
112 | |||
113 | /** | ||
114 | * llist_del_all - delete all entries from lock-less list | ||
115 | * @head: the head of lock-less list to delete all entries | ||
116 | * | ||
117 | * If list is empty, return NULL, otherwise, delete all entries and | ||
118 | * return the pointer to the first entry. The order of entries | ||
119 | * deleted is from the newest to the oldest added one. | ||
120 | */ | ||
121 | struct llist_node *llist_del_all(struct llist_head *head) | ||
122 | { | ||
123 | #ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG | ||
124 | BUG_ON(in_nmi()); | ||
125 | #endif | ||
126 | |||
127 | return xchg(&head->first, NULL); | ||
128 | } | ||
129 | EXPORT_SYMBOL_GPL(llist_del_all); | ||