debuggers.hg

view tools/ioemu/patches/ide-hd-multithread @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 Index: ioemu/hw/ide.c
2 ===================================================================
3 --- ioemu.orig/hw/ide.c 2007-05-03 15:03:18.000000000 +0100
4 +++ ioemu/hw/ide.c 2007-05-03 15:06:48.000000000 +0100
5 @@ -22,6 +22,7 @@
6 * THE SOFTWARE.
7 */
8 #include "vl.h"
9 +#include <pthread.h>
11 /* debug IDE devices */
12 //#define DEBUG_IDE
13 @@ -390,6 +391,89 @@
14 int type; /* see IDE_TYPE_xxx */
15 } PCIIDEState;
17 +#define DMA_MULTI_THREAD
18 +
19 +#ifdef DMA_MULTI_THREAD
20 +
21 +static pthread_t ide_dma_thread;
22 +static int file_pipes[2];
23 +
24 +static void ide_dma_loop(BMDMAState *bm);
25 +static void dma_thread_loop(BMDMAState *bm);
26 +
27 +extern int suspend_requested;
28 +static void *dma_thread_func(void* opaque)
29 +{
30 + BMDMAState* req;
31 + fd_set fds;
32 + int rv, nfds = file_pipes[0] + 1;
33 + struct timeval tm;
34 +
35 + while (1) {
36 +
37 + /* Wait at most a second for the pipe to become readable */
38 + FD_ZERO(&fds);
39 + FD_SET(file_pipes[0], &fds);
40 + tm.tv_sec = 1;
41 + tm.tv_usec = 0;
42 + rv = select(nfds, &fds, NULL, NULL, &tm);
43 +
44 + if (rv != 0) {
45 + if (read(file_pipes[0], &req, sizeof(req)) == 0)
46 + return NULL;
47 + dma_thread_loop(req);
48 + } else {
49 + if (suspend_requested) {
50 + /* Need to tidy up the DMA thread so that we don't end up
51 + * finishing operations after the domain's ioreqs are
52 + * drained and its state saved */
53 + return NULL;
54 + }
55 + }
56 + }
57 +
58 + return NULL;
59 +}
60 +
61 +static void dma_create_thread(void)
62 +{
63 + int rt;
64 + pthread_attr_t a;
65 +
66 + if (pipe(file_pipes) != 0) {
67 + fprintf(stderr, "create pipe failed\n");
68 + exit(1);
69 + }
70 +
71 + if ((rt = pthread_attr_init(&a))
72 + || (rt = pthread_attr_setdetachstate(&a, PTHREAD_CREATE_JOINABLE))) {
73 + fprintf(stderr, "Oops, dma thread attr setup failed, errno=%d\n", rt);
74 + exit(1);
75 + }
76 +
77 + if ((rt = pthread_create(&ide_dma_thread, &a, dma_thread_func, NULL))) {
78 + fprintf(stderr, "Oops, dma thread creation failed, errno=%d\n", rt);
79 + exit(1);
80 + }
81 +}
82 +
83 +void ide_stop_dma_thread(void)
84 +{
85 + int rc;
86 + /* Make sure the IDE DMA thread is stopped */
87 + if ( (rc = pthread_join(ide_dma_thread, NULL)) != 0 )
88 + {
89 + fprintf(stderr, "Oops, error collecting IDE DMA thread (%s)\n",
90 + strerror(rc));
91 + }
92 +}
93 +
94 +#else
95 +void ide_stop_dma_thread(void)
96 +{
97 +}
98 +#endif /* DMA_MULTI_THREAD */
99 +
100 static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb);
102 static void padstr(char *str, const char *src, int len)
103 @@ -695,7 +779,9 @@
104 }
105 if (s->io_buffer_index >= s->io_buffer_size && s->nsector == 0) {
106 s->status = READY_STAT | SEEK_STAT;
107 +#ifndef DMA_MULTI_THREAD
108 ide_set_irq(s);
109 +#endif /* !DMA_MULTI_THREAD */
110 #ifdef DEBUG_IDE_ATAPI
111 printf("dma status=0x%x\n", s->status);
112 #endif
113 @@ -795,7 +881,11 @@
114 qemu_get_clock(vm_clock) + (ticks_per_sec / 1000));
115 } else
116 #endif
117 +#ifndef DMA_MULTI_THREAD
118 ide_set_irq(s);
119 +#else /* !DMA_MULTI_THREAD */
120 + ;
121 +#endif /* DMA_MULTI_THREAD */
122 return 0;
123 }
124 if (n > MAX_MULT_SECTORS)
125 @@ -1046,7 +1136,9 @@
126 if (s->packet_transfer_size <= 0) {
127 s->status = READY_STAT;
128 s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD;
129 +#ifndef DMA_MULTI_THREAD
130 ide_set_irq(s);
131 +#endif /* !DMA_MULTI_THREAD */
132 #ifdef DEBUG_IDE_ATAPI
133 printf("dma status=0x%x\n", s->status);
134 #endif
135 @@ -2103,9 +2195,30 @@
136 }
137 }
139 +static void ide_dma_finish(BMDMAState *bm)
140 +{
141 + IDEState *s = bm->ide_if;
142 +
143 + bm->status &= ~BM_STATUS_DMAING;
144 + bm->status |= BM_STATUS_INT;
145 + bm->dma_cb = NULL;
146 + bm->ide_if = NULL;
147 +#ifdef DMA_MULTI_THREAD
148 + ide_set_irq(s);
149 +#endif /* DMA_MULTI_THREAD */
150 +}
151 +
152 /* XXX: full callback usage to prepare non blocking I/Os support -
153 error handling */
154 +#ifdef DMA_MULTI_THREAD
155 +static void ide_dma_loop(BMDMAState *bm)
156 +{
157 + write(file_pipes[1], &bm, sizeof(bm));
158 +}
159 +static void dma_thread_loop(BMDMAState *bm)
160 +#else /* DMA_MULTI_THREAD */
161 static void ide_dma_loop(BMDMAState *bm)
162 +#endif /* !DMA_MULTI_THREAD */
163 {
164 struct {
165 uint32_t addr;
166 @@ -2141,10 +2254,7 @@
167 }
168 /* end of transfer */
169 the_end:
170 - bm->status &= ~BM_STATUS_DMAING;
171 - bm->status |= BM_STATUS_INT;
172 - bm->dma_cb = NULL;
173 - bm->ide_if = NULL;
174 + ide_dma_finish(bm);
175 }
177 static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb)
178 @@ -2370,6 +2480,9 @@
179 cmd646_set_irq, d, 0);
180 ide_init2(&d->ide_if[2], hd_table[2], hd_table[3],
181 cmd646_set_irq, d, 1);
182 +#ifdef DMA_MULTI_THREAD
183 + dma_create_thread();
184 +#endif /* DMA_MULTI_THREAD */
185 }
187 static void pci_ide_save(QEMUFile* f, void *opaque)
188 @@ -2522,6 +2635,10 @@
190 register_savevm("ide_pci", 0, 1, generic_pci_save, generic_pci_load, d);
191 register_savevm("ide", 0, 1, pci_ide_save, pci_ide_load, d);
192 +
193 +#ifdef DMA_MULTI_THREAD
194 + dma_create_thread();
195 +#endif //DMA_MULTI_THREAD
196 }
198 /***********************************************************/
199 Index: ioemu/target-i386-dm/helper2.c
200 ===================================================================
201 --- ioemu.orig/target-i386-dm/helper2.c 2007-05-03 15:03:18.000000000 +0100
202 +++ ioemu/target-i386-dm/helper2.c 2007-05-03 15:06:41.000000000 +0100
203 @@ -556,6 +556,9 @@
204 handle_buffered_io(env);
205 main_loop_wait(1); /* For the select() on events */
207 + /* Stop the IDE thread */
208 + ide_stop_dma_thread();
209 +
210 /* Save the device state */
211 sprintf(qemu_file, "/tmp/xen.qemu-dm.%d", domid);
212 if (qemu_savevm(qemu_file) < 0)
213 Index: ioemu/vl.h
214 ===================================================================
215 --- ioemu.orig/vl.h 2007-05-03 15:03:18.000000000 +0100
216 +++ ioemu/vl.h 2007-05-03 15:06:42.000000000 +0100
217 @@ -797,6 +797,7 @@
218 void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn);
219 int pmac_ide_init (BlockDriverState **hd_table,
220 SetIRQFunc *set_irq, void *irq_opaque, int irq);
221 +void ide_stop_dma_thread(void);
223 /* cdrom.c */
224 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);