aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-12-12 14:44:25 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-12-12 14:44:25 -0500
commit2bf3b685a35c80fe368dad9da0e77ba48b460939 (patch)
tree3516a82ec33f96d5e9d3f36abef751aa0b788748 /tools
parentbf006e149a5717a4614d44a62090ae98775af7a0 (diff)
parentd06e622d3d9206e6a2cc45a0f9a3256da8773ff4 (diff)
Merge schedutil governor updates for v4.10.
Diffstat (limited to 'tools')
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h2
-rw-r--r--tools/objtool/arch/x86/decode.c9
-rw-r--r--tools/objtool/builtin-check.c68
-rw-r--r--tools/perf/jvmti/Makefile2
-rw-r--r--tools/perf/ui/browsers/hists.c3
-rw-r--r--tools/perf/util/header.c2
-rw-r--r--tools/perf/util/parse-events.l4
-rw-r--r--tools/power/cpupower/utils/cpufreq-set.c7
-rw-r--r--tools/virtio/ringtest/Makefile4
-rw-r--r--tools/virtio/ringtest/main.c20
-rw-r--r--tools/virtio/ringtest/main.h4
-rw-r--r--tools/virtio/ringtest/noring.c6
-rw-r--r--tools/virtio/ringtest/ptr_ring.c22
-rw-r--r--tools/virtio/ringtest/ring.c18
-rw-r--r--tools/virtio/ringtest/virtio_ring_0_9.c64
15 files changed, 103 insertions, 132 deletions
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 1188bc849ee3..a39629206864 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -194,6 +194,8 @@
194#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */ 194#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */
195 195
196#define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */ 196#define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */
197#define X86_FEATURE_AVX512_4VNNIW (7*32+16) /* AVX-512 Neural Network Instructions */
198#define X86_FEATURE_AVX512_4FMAPS (7*32+17) /* AVX-512 Multiply Accumulation Single precision */
197 199
198/* Virtualization flags: Linux defined, word 8 */ 200/* Virtualization flags: Linux defined, word 8 */
199#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ 201#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index c0c0b265e88e..b63a31be1218 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -98,6 +98,15 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
98 *type = INSN_FP_SETUP; 98 *type = INSN_FP_SETUP;
99 break; 99 break;
100 100
101 case 0x8d:
102 if (insn.rex_prefix.bytes &&
103 insn.rex_prefix.bytes[0] == 0x48 &&
104 insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
105 insn.sib.nbytes && insn.sib.bytes[0] == 0x24)
106 /* lea %(rsp), %rbp */
107 *type = INSN_FP_SETUP;
108 break;
109
101 case 0x90: 110 case 0x90:
102 *type = INSN_NOP; 111 *type = INSN_NOP;
103 break; 112 break;
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 143b6cdd7f06..e8a1f699058a 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -97,6 +97,19 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
97 return next; 97 return next;
98} 98}
99 99
100static bool gcov_enabled(struct objtool_file *file)
101{
102 struct section *sec;
103 struct symbol *sym;
104
105 list_for_each_entry(sec, &file->elf->sections, list)
106 list_for_each_entry(sym, &sec->symbol_list, list)
107 if (!strncmp(sym->name, "__gcov_.", 8))
108 return true;
109
110 return false;
111}
112
100#define for_each_insn(file, insn) \ 113#define for_each_insn(file, insn) \
101 list_for_each_entry(insn, &file->insn_list, list) 114 list_for_each_entry(insn, &file->insn_list, list)
102 115
@@ -713,6 +726,7 @@ static struct rela *find_switch_table(struct objtool_file *file,
713 struct instruction *insn) 726 struct instruction *insn)
714{ 727{
715 struct rela *text_rela, *rodata_rela; 728 struct rela *text_rela, *rodata_rela;
729 struct instruction *orig_insn = insn;
716 730
717 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len); 731 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
718 if (text_rela && text_rela->sym == file->rodata->sym) { 732 if (text_rela && text_rela->sym == file->rodata->sym) {
@@ -733,10 +747,16 @@ static struct rela *find_switch_table(struct objtool_file *file,
733 747
734 /* case 3 */ 748 /* case 3 */
735 func_for_each_insn_continue_reverse(file, func, insn) { 749 func_for_each_insn_continue_reverse(file, func, insn) {
736 if (insn->type == INSN_JUMP_UNCONDITIONAL || 750 if (insn->type == INSN_JUMP_DYNAMIC)
737 insn->type == INSN_JUMP_DYNAMIC)
738 break; 751 break;
739 752
753 /* allow small jumps within the range */
754 if (insn->type == INSN_JUMP_UNCONDITIONAL &&
755 insn->jump_dest &&
756 (insn->jump_dest->offset <= insn->offset ||
757 insn->jump_dest->offset > orig_insn->offset))
758 break;
759
740 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, 760 text_rela = find_rela_by_dest_range(insn->sec, insn->offset,
741 insn->len); 761 insn->len);
742 if (text_rela && text_rela->sym == file->rodata->sym) 762 if (text_rela && text_rela->sym == file->rodata->sym)
@@ -1034,34 +1054,6 @@ static int validate_branch(struct objtool_file *file,
1034 return 0; 1054 return 0;
1035} 1055}
1036 1056
1037static bool is_gcov_insn(struct instruction *insn)
1038{
1039 struct rela *rela;
1040 struct section *sec;
1041 struct symbol *sym;
1042 unsigned long offset;
1043
1044 rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
1045 if (!rela)
1046 return false;
1047
1048 if (rela->sym->type != STT_SECTION)
1049 return false;
1050
1051 sec = rela->sym->sec;
1052 offset = rela->addend + insn->offset + insn->len - rela->offset;
1053
1054 list_for_each_entry(sym, &sec->symbol_list, list) {
1055 if (sym->type != STT_OBJECT)
1056 continue;
1057
1058 if (offset >= sym->offset && offset < sym->offset + sym->len)
1059 return (!memcmp(sym->name, "__gcov0.", 8));
1060 }
1061
1062 return false;
1063}
1064
1065static bool is_kasan_insn(struct instruction *insn) 1057static bool is_kasan_insn(struct instruction *insn)
1066{ 1058{
1067 return (insn->type == INSN_CALL && 1059 return (insn->type == INSN_CALL &&
@@ -1083,9 +1075,6 @@ static bool ignore_unreachable_insn(struct symbol *func,
1083 if (insn->type == INSN_NOP) 1075 if (insn->type == INSN_NOP)
1084 return true; 1076 return true;
1085 1077
1086 if (is_gcov_insn(insn))
1087 return true;
1088
1089 /* 1078 /*
1090 * Check if this (or a subsequent) instruction is related to 1079 * Check if this (or a subsequent) instruction is related to
1091 * CONFIG_UBSAN or CONFIG_KASAN. 1080 * CONFIG_UBSAN or CONFIG_KASAN.
@@ -1146,6 +1135,19 @@ static int validate_functions(struct objtool_file *file)
1146 ignore_unreachable_insn(func, insn)) 1135 ignore_unreachable_insn(func, insn))
1147 continue; 1136 continue;
1148 1137
1138 /*
1139 * gcov produces a lot of unreachable
1140 * instructions. If we get an unreachable
1141 * warning and the file has gcov enabled, just
1142 * ignore it, and all other such warnings for
1143 * the file.
1144 */
1145 if (!file->ignore_unreachables &&
1146 gcov_enabled(file)) {
1147 file->ignore_unreachables = true;
1148 continue;
1149 }
1150
1149 WARN_FUNC("function has unreachable instruction", insn->sec, insn->offset); 1151 WARN_FUNC("function has unreachable instruction", insn->sec, insn->offset);
1150 warnings++; 1152 warnings++;
1151 } 1153 }
diff --git a/tools/perf/jvmti/Makefile b/tools/perf/jvmti/Makefile
index 5ce61a1bda9c..df14e6b67b63 100644
--- a/tools/perf/jvmti/Makefile
+++ b/tools/perf/jvmti/Makefile
@@ -36,7 +36,7 @@ SOLIBEXT=so
36# The following works at least on fedora 23, you may need the next 36# The following works at least on fedora 23, you may need the next
37# line for other distros. 37# line for other distros.
38ifneq (,$(wildcard /usr/sbin/update-java-alternatives)) 38ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
39JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | cut -d ' ' -f 3) 39JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
40else 40else
41 ifneq (,$(wildcard /usr/sbin/alternatives)) 41 ifneq (,$(wildcard /usr/sbin/alternatives))
42 JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g') 42 JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g')
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fb8e42c7507a..4ffff7be9299 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -601,7 +601,8 @@ int hist_browser__run(struct hist_browser *browser, const char *help)
601 u64 nr_entries; 601 u64 nr_entries;
602 hbt->timer(hbt->arg); 602 hbt->timer(hbt->arg);
603 603
604 if (hist_browser__has_filter(browser)) 604 if (hist_browser__has_filter(browser) ||
605 symbol_conf.report_hierarchy)
605 hist_browser__update_nr_entries(browser); 606 hist_browser__update_nr_entries(browser);
606 607
607 nr_entries = hist_browser__nr_entries(browser); 608 nr_entries = hist_browser__nr_entries(browser);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 85dd0db0a127..2f3eded54b0c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1895,7 +1895,6 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
1895 if (ph->needs_swap) 1895 if (ph->needs_swap)
1896 nr = bswap_32(nr); 1896 nr = bswap_32(nr);
1897 1897
1898 ph->env.nr_numa_nodes = nr;
1899 nodes = zalloc(sizeof(*nodes) * nr); 1898 nodes = zalloc(sizeof(*nodes) * nr);
1900 if (!nodes) 1899 if (!nodes)
1901 return -ENOMEM; 1900 return -ENOMEM;
@@ -1932,6 +1931,7 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
1932 1931
1933 free(str); 1932 free(str);
1934 } 1933 }
1934 ph->env.nr_numa_nodes = nr;
1935 ph->env.numa_nodes = nodes; 1935 ph->env.numa_nodes = nodes;
1936 return 0; 1936 return 0;
1937 1937
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 9f43fda2570f..660fca05bc93 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -136,8 +136,8 @@ do { \
136group [^,{}/]*[{][^}]*[}][^,{}/]* 136group [^,{}/]*[{][^}]*[}][^,{}/]*
137event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* 137event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
138event [^,{}/]+ 138event [^,{}/]+
139bpf_object .*\.(o|bpf) 139bpf_object [^,{}]+\.(o|bpf)
140bpf_source .*\.c 140bpf_source [^,{}]+\.c
141 141
142num_dec [0-9]+ 142num_dec [0-9]+
143num_hex 0x[a-fA-F0-9]+ 143num_hex 0x[a-fA-F0-9]+
diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c
index b4bf76971dc9..1eef0aed6423 100644
--- a/tools/power/cpupower/utils/cpufreq-set.c
+++ b/tools/power/cpupower/utils/cpufreq-set.c
@@ -296,7 +296,7 @@ int cmd_freq_set(int argc, char **argv)
296 struct cpufreq_affected_cpus *cpus; 296 struct cpufreq_affected_cpus *cpus;
297 297
298 if (!bitmask_isbitset(cpus_chosen, cpu) || 298 if (!bitmask_isbitset(cpus_chosen, cpu) ||
299 cpupower_is_cpu_online(cpu)) 299 cpupower_is_cpu_online(cpu) != 1)
300 continue; 300 continue;
301 301
302 cpus = cpufreq_get_related_cpus(cpu); 302 cpus = cpufreq_get_related_cpus(cpu);
@@ -316,10 +316,7 @@ int cmd_freq_set(int argc, char **argv)
316 cpu <= bitmask_last(cpus_chosen); cpu++) { 316 cpu <= bitmask_last(cpus_chosen); cpu++) {
317 317
318 if (!bitmask_isbitset(cpus_chosen, cpu) || 318 if (!bitmask_isbitset(cpus_chosen, cpu) ||
319 cpupower_is_cpu_online(cpu)) 319 cpupower_is_cpu_online(cpu) != 1)
320 continue;
321
322 if (cpupower_is_cpu_online(cpu) != 1)
323 continue; 320 continue;
324 321
325 printf(_("Setting cpu: %d\n"), cpu); 322 printf(_("Setting cpu: %d\n"), cpu);
diff --git a/tools/virtio/ringtest/Makefile b/tools/virtio/ringtest/Makefile
index 877a8a4721b6..c012edbdb13b 100644
--- a/tools/virtio/ringtest/Makefile
+++ b/tools/virtio/ringtest/Makefile
@@ -3,8 +3,8 @@ all:
3all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder ptr_ring noring 3all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder ptr_ring noring
4 4
5CFLAGS += -Wall 5CFLAGS += -Wall
6CFLAGS += -pthread -O2 -ggdb 6CFLAGS += -pthread -O2 -ggdb -flto -fwhole-program
7LDFLAGS += -pthread -O2 -ggdb 7LDFLAGS += -pthread -O2 -ggdb -flto -fwhole-program
8 8
9main.o: main.c main.h 9main.o: main.c main.h
10ring.o: ring.c main.h 10ring.o: ring.c main.h
diff --git a/tools/virtio/ringtest/main.c b/tools/virtio/ringtest/main.c
index 147abb452a6c..f31353fac541 100644
--- a/tools/virtio/ringtest/main.c
+++ b/tools/virtio/ringtest/main.c
@@ -96,7 +96,13 @@ void set_affinity(const char *arg)
96 assert(!ret); 96 assert(!ret);
97} 97}
98 98
99static void run_guest(void) 99void poll_used(void)
100{
101 while (used_empty())
102 busy_wait();
103}
104
105static void __attribute__((__flatten__)) run_guest(void)
100{ 106{
101 int completed_before; 107 int completed_before;
102 int completed = 0; 108 int completed = 0;
@@ -141,7 +147,7 @@ static void run_guest(void)
141 assert(completed <= bufs); 147 assert(completed <= bufs);
142 assert(started <= bufs); 148 assert(started <= bufs);
143 if (do_sleep) { 149 if (do_sleep) {
144 if (enable_call()) 150 if (used_empty() && enable_call())
145 wait_for_call(); 151 wait_for_call();
146 } else { 152 } else {
147 poll_used(); 153 poll_used();
@@ -149,7 +155,13 @@ static void run_guest(void)
149 } 155 }
150} 156}
151 157
152static void run_host(void) 158void poll_avail(void)
159{
160 while (avail_empty())
161 busy_wait();
162}
163
164static void __attribute__((__flatten__)) run_host(void)
153{ 165{
154 int completed_before; 166 int completed_before;
155 int completed = 0; 167 int completed = 0;
@@ -160,7 +172,7 @@ static void run_host(void)
160 172
161 for (;;) { 173 for (;;) {
162 if (do_sleep) { 174 if (do_sleep) {
163 if (enable_kick()) 175 if (avail_empty() && enable_kick())
164 wait_for_kick(); 176 wait_for_kick();
165 } else { 177 } else {
166 poll_avail(); 178 poll_avail();
diff --git a/tools/virtio/ringtest/main.h b/tools/virtio/ringtest/main.h
index 16917acb0ade..34e63cc4c572 100644
--- a/tools/virtio/ringtest/main.h
+++ b/tools/virtio/ringtest/main.h
@@ -56,15 +56,15 @@ void alloc_ring(void);
56int add_inbuf(unsigned, void *, void *); 56int add_inbuf(unsigned, void *, void *);
57void *get_buf(unsigned *, void **); 57void *get_buf(unsigned *, void **);
58void disable_call(); 58void disable_call();
59bool used_empty();
59bool enable_call(); 60bool enable_call();
60void kick_available(); 61void kick_available();
61void poll_used();
62/* host side */ 62/* host side */
63void disable_kick(); 63void disable_kick();
64bool avail_empty();
64bool enable_kick(); 65bool enable_kick();
65bool use_buf(unsigned *, void **); 66bool use_buf(unsigned *, void **);
66void call_used(); 67void call_used();
67void poll_avail();
68 68
69/* implemented by main */ 69/* implemented by main */
70extern bool do_sleep; 70extern bool do_sleep;
diff --git a/tools/virtio/ringtest/noring.c b/tools/virtio/ringtest/noring.c
index eda2f4824130..b8d1c1daac7c 100644
--- a/tools/virtio/ringtest/noring.c
+++ b/tools/virtio/ringtest/noring.c
@@ -24,8 +24,9 @@ void *get_buf(unsigned *lenp, void **bufp)
24 return "Buffer"; 24 return "Buffer";
25} 25}
26 26
27void poll_used(void) 27bool used_empty()
28{ 28{
29 return false;
29} 30}
30 31
31void disable_call() 32void disable_call()
@@ -54,8 +55,9 @@ bool enable_kick()
54 assert(0); 55 assert(0);
55} 56}
56 57
57void poll_avail(void) 58bool avail_empty()
58{ 59{
60 return false;
59} 61}
60 62
61bool use_buf(unsigned *lenp, void **bufp) 63bool use_buf(unsigned *lenp, void **bufp)
diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c
index bd2ad1d3b7a9..635b07b4fdd3 100644
--- a/tools/virtio/ringtest/ptr_ring.c
+++ b/tools/virtio/ringtest/ptr_ring.c
@@ -133,18 +133,9 @@ void *get_buf(unsigned *lenp, void **bufp)
133 return datap; 133 return datap;
134} 134}
135 135
136void poll_used(void) 136bool used_empty()
137{ 137{
138 void *b; 138 return (tailcnt == headcnt || __ptr_ring_full(&array));
139
140 do {
141 if (tailcnt == headcnt || __ptr_ring_full(&array)) {
142 b = NULL;
143 barrier();
144 } else {
145 b = "Buffer\n";
146 }
147 } while (!b);
148} 139}
149 140
150void disable_call() 141void disable_call()
@@ -173,14 +164,9 @@ bool enable_kick()
173 assert(0); 164 assert(0);
174} 165}
175 166
176void poll_avail(void) 167bool avail_empty()
177{ 168{
178 void *b; 169 return !__ptr_ring_peek(&array);
179
180 do {
181 barrier();
182 b = __ptr_ring_peek(&array);
183 } while (!b);
184} 170}
185 171
186bool use_buf(unsigned *lenp, void **bufp) 172bool use_buf(unsigned *lenp, void **bufp)
diff --git a/tools/virtio/ringtest/ring.c b/tools/virtio/ringtest/ring.c
index c25c8d248b6b..747c5dd47be8 100644
--- a/tools/virtio/ringtest/ring.c
+++ b/tools/virtio/ringtest/ring.c
@@ -163,12 +163,11 @@ void *get_buf(unsigned *lenp, void **bufp)
163 return datap; 163 return datap;
164} 164}
165 165
166void poll_used(void) 166bool used_empty()
167{ 167{
168 unsigned head = (ring_size - 1) & guest.last_used_idx; 168 unsigned head = (ring_size - 1) & guest.last_used_idx;
169 169
170 while (ring[head].flags & DESC_HW) 170 return (ring[head].flags & DESC_HW);
171 busy_wait();
172} 171}
173 172
174void disable_call() 173void disable_call()
@@ -180,13 +179,11 @@ void disable_call()
180 179
181bool enable_call() 180bool enable_call()
182{ 181{
183 unsigned head = (ring_size - 1) & guest.last_used_idx;
184
185 event->call_index = guest.last_used_idx; 182 event->call_index = guest.last_used_idx;
186 /* Flush call index write */ 183 /* Flush call index write */
187 /* Barrier D (for pairing) */ 184 /* Barrier D (for pairing) */
188 smp_mb(); 185 smp_mb();
189 return ring[head].flags & DESC_HW; 186 return used_empty();
190} 187}
191 188
192void kick_available(void) 189void kick_available(void)
@@ -213,20 +210,17 @@ void disable_kick()
213 210
214bool enable_kick() 211bool enable_kick()
215{ 212{
216 unsigned head = (ring_size - 1) & host.used_idx;
217
218 event->kick_index = host.used_idx; 213 event->kick_index = host.used_idx;
219 /* Barrier C (for pairing) */ 214 /* Barrier C (for pairing) */
220 smp_mb(); 215 smp_mb();
221 return !(ring[head].flags & DESC_HW); 216 return avail_empty();
222} 217}
223 218
224void poll_avail(void) 219bool avail_empty()
225{ 220{
226 unsigned head = (ring_size - 1) & host.used_idx; 221 unsigned head = (ring_size - 1) & host.used_idx;
227 222
228 while (!(ring[head].flags & DESC_HW)) 223 return !(ring[head].flags & DESC_HW);
229 busy_wait();
230} 224}
231 225
232bool use_buf(unsigned *lenp, void **bufp) 226bool use_buf(unsigned *lenp, void **bufp)
diff --git a/tools/virtio/ringtest/virtio_ring_0_9.c b/tools/virtio/ringtest/virtio_ring_0_9.c
index 761866212aac..bbc3043b2fb1 100644
--- a/tools/virtio/ringtest/virtio_ring_0_9.c
+++ b/tools/virtio/ringtest/virtio_ring_0_9.c
@@ -194,24 +194,16 @@ void *get_buf(unsigned *lenp, void **bufp)
194 return datap; 194 return datap;
195} 195}
196 196
197void poll_used(void) 197bool used_empty()
198{ 198{
199 unsigned short last_used_idx = guest.last_used_idx;
199#ifdef RING_POLL 200#ifdef RING_POLL
200 unsigned head = (ring_size - 1) & guest.last_used_idx; 201 unsigned short head = last_used_idx & (ring_size - 1);
202 unsigned index = ring.used->ring[head].id;
201 203
202 for (;;) { 204 return (index ^ last_used_idx ^ 0x8000) & ~(ring_size - 1);
203 unsigned index = ring.used->ring[head].id;
204
205 if ((index ^ guest.last_used_idx ^ 0x8000) & ~(ring_size - 1))
206 busy_wait();
207 else
208 break;
209 }
210#else 205#else
211 unsigned head = guest.last_used_idx; 206 return ring.used->idx == last_used_idx;
212
213 while (ring.used->idx == head)
214 busy_wait();
215#endif 207#endif
216} 208}
217 209
@@ -224,22 +216,11 @@ void disable_call()
224 216
225bool enable_call() 217bool enable_call()
226{ 218{
227 unsigned short last_used_idx; 219 vring_used_event(&ring) = guest.last_used_idx;
228
229 vring_used_event(&ring) = (last_used_idx = guest.last_used_idx);
230 /* Flush call index write */ 220 /* Flush call index write */
231 /* Barrier D (for pairing) */ 221 /* Barrier D (for pairing) */
232 smp_mb(); 222 smp_mb();
233#ifdef RING_POLL 223 return used_empty();
234 {
235 unsigned short head = last_used_idx & (ring_size - 1);
236 unsigned index = ring.used->ring[head].id;
237
238 return (index ^ last_used_idx ^ 0x8000) & ~(ring_size - 1);
239 }
240#else
241 return ring.used->idx == last_used_idx;
242#endif
243} 224}
244 225
245void kick_available(void) 226void kick_available(void)
@@ -266,36 +247,21 @@ void disable_kick()
266 247
267bool enable_kick() 248bool enable_kick()
268{ 249{
269 unsigned head = host.used_idx; 250 vring_avail_event(&ring) = host.used_idx;
270
271 vring_avail_event(&ring) = head;
272 /* Barrier C (for pairing) */ 251 /* Barrier C (for pairing) */
273 smp_mb(); 252 smp_mb();
274#ifdef RING_POLL 253 return avail_empty();
275 {
276 unsigned index = ring.avail->ring[head & (ring_size - 1)];
277
278 return (index ^ head ^ 0x8000) & ~(ring_size - 1);
279 }
280#else
281 return head == ring.avail->idx;
282#endif
283} 254}
284 255
285void poll_avail(void) 256bool avail_empty()
286{ 257{
287 unsigned head = host.used_idx; 258 unsigned head = host.used_idx;
288#ifdef RING_POLL 259#ifdef RING_POLL
289 for (;;) { 260 unsigned index = ring.avail->ring[head & (ring_size - 1)];
290 unsigned index = ring.avail->ring[head & (ring_size - 1)]; 261
291 if ((index ^ head ^ 0x8000) & ~(ring_size - 1)) 262 return ((index ^ head ^ 0x8000) & ~(ring_size - 1));
292 busy_wait();
293 else
294 break;
295 }
296#else 263#else
297 while (ring.avail->idx == head) 264 return head == ring.avail->idx;
298 busy_wait();
299#endif 265#endif
300} 266}
301 267