Commit e6cda8e299318e0e54fabea4c74c0bd839547ea7

Authored by bellard
1 parent b56bdb32

win32 tap poll suppression (kazu)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2127 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 3 changed files with 9 additions and 22 deletions
tap-win32.c
@@ -97,6 +97,7 @@ typedef struct tap_win32_overlapped { @@ -97,6 +97,7 @@ typedef struct tap_win32_overlapped {
97 HANDLE write_event; 97 HANDLE write_event;
98 HANDLE output_queue_semaphore; 98 HANDLE output_queue_semaphore;
99 HANDLE free_list_semaphore; 99 HANDLE free_list_semaphore;
  100 + HANDLE tap_semaphore;
100 CRITICAL_SECTION output_queue_cs; 101 CRITICAL_SECTION output_queue_cs;
101 CRITICAL_SECTION free_list_cs; 102 CRITICAL_SECTION free_list_cs;
102 OVERLAPPED read_overlapped; 103 OVERLAPPED read_overlapped;
@@ -445,6 +446,10 @@ static void tap_win32_overlapped_init(tap_win32_overlapped_t* const overlapped, @@ -445,6 +446,10 @@ static void tap_win32_overlapped_init(tap_win32_overlapped_t* const overlapped,
445 overlapped->free_list = element; 446 overlapped->free_list = element;
446 } 447 }
447 } 448 }
  449 + /* To count buffers, initially no-signal. */
  450 + overlapped->tap_semaphore = CreateSemaphore(NULL, 0, TUN_MAX_BUFFER_COUNT, NULL);
  451 + if(!overlapped->tap_semaphore)
  452 + fprintf(stderr, "error creating tap_semaphore.\n");
448 } 453 }
449 454
450 static int tap_win32_write(tap_win32_overlapped_t *overlapped, 455 static int tap_win32_write(tap_win32_overlapped_t *overlapped,
@@ -526,6 +531,7 @@ static DWORD WINAPI tap_win32_thread_entry(LPVOID param) @@ -526,6 +531,7 @@ static DWORD WINAPI tap_win32_thread_entry(LPVOID param)
526 if(read_size > 0) { 531 if(read_size > 0) {
527 buffer->read_size = read_size; 532 buffer->read_size = read_size;
528 put_buffer_on_output_queue(overlapped, buffer); 533 put_buffer_on_output_queue(overlapped, buffer);
  534 + ReleaseSemaphore(overlapped->tap_semaphore, 1, NULL);
529 buffer = get_buffer_from_free_list(overlapped); 535 buffer = get_buffer_from_free_list(overlapped);
530 } 536 }
531 } 537 }
@@ -620,8 +626,6 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle, @@ -620,8 +626,6 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
620 626
621 hThread = CreateThread(NULL, 0, tap_win32_thread_entry, 627 hThread = CreateThread(NULL, 0, tap_win32_thread_entry,
622 (LPVOID)&tap_overlapped, 0, &idThread); 628 (LPVOID)&tap_overlapped, 0, &idThread);
623 - SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);  
624 -  
625 return 0; 629 return 0;
626 } 630 }
627 631
@@ -630,11 +634,8 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle, @@ -630,11 +634,8 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
630 typedef struct TAPState { 634 typedef struct TAPState {
631 VLANClientState *vc; 635 VLANClientState *vc;
632 tap_win32_overlapped_t *handle; 636 tap_win32_overlapped_t *handle;
633 - HANDLE tap_event;  
634 } TAPState; 637 } TAPState;
635 638
636 -static TAPState *tap_win32_state = NULL;  
637 -  
638 static void tap_receive(void *opaque, const uint8_t *buf, int size) 639 static void tap_receive(void *opaque, const uint8_t *buf, int size)
639 { 640 {
640 TAPState *s = opaque; 641 TAPState *s = opaque;
@@ -642,22 +643,17 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size) @@ -642,22 +643,17 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size)
642 tap_win32_write(s->handle, buf, size); 643 tap_win32_write(s->handle, buf, size);
643 } 644 }
644 645
645 -/* XXX: horrible, suppress this by using proper thread signaling */  
646 -void tap_win32_poll(void) 646 +static void tap_win32_send(void *opaque)
647 { 647 {
648 - TAPState *s = tap_win32_state; 648 + TAPState *s = opaque;
649 uint8_t *buf; 649 uint8_t *buf;
650 int max_size = 4096; 650 int max_size = 4096;
651 int size; 651 int size;
652 652
653 - if (!s)  
654 - return;  
655 -  
656 size = tap_win32_read(s->handle, &buf, max_size); 653 size = tap_win32_read(s->handle, &buf, max_size);
657 if (size > 0) { 654 if (size > 0) {
658 qemu_send_packet(s->vc, buf, size); 655 qemu_send_packet(s->vc, buf, size);
659 tap_win32_free_buffer(s->handle, buf); 656 tap_win32_free_buffer(s->handle, buf);
660 - SetEvent(s->tap_event);  
661 } 657 }
662 } 658 }
663 659
@@ -677,12 +673,7 @@ int tap_win32_init(VLANState *vlan, const char *ifname) @@ -677,12 +673,7 @@ int tap_win32_init(VLANState *vlan, const char *ifname)
677 673
678 snprintf(s->vc->info_str, sizeof(s->vc->info_str), 674 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
679 "tap: ifname=%s", ifname); 675 "tap: ifname=%s", ifname);
680 - tap_win32_state = s;  
681 676
682 - s->tap_event = CreateEvent(NULL, FALSE, FALSE, NULL);  
683 - if (!s->tap_event) {  
684 - fprintf(stderr, "tap-win32: Failed CreateEvent\n");  
685 - }  
686 - qemu_add_wait_object(s->tap_event, NULL, NULL); 677 + qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
687 return 0; 678 return 0;
688 } 679 }
@@ -5715,9 +5715,6 @@ void main_loop_wait(int timeout) @@ -5715,9 +5715,6 @@ void main_loop_wait(int timeout)
5715 slirp_select_poll(&rfds, &wfds, &xfds); 5715 slirp_select_poll(&rfds, &wfds, &xfds);
5716 } 5716 }
5717 #endif 5717 #endif
5718 -#ifdef _WIN32  
5719 - tap_win32_poll();  
5720 -#endif  
5721 qemu_aio_poll(); 5718 qemu_aio_poll();
5722 qemu_bh_poll(); 5719 qemu_bh_poll();
5723 5720
@@ -348,7 +348,6 @@ void do_info_network(void); @@ -348,7 +348,6 @@ void do_info_network(void);
348 348
349 /* TAP win32 */ 349 /* TAP win32 */
350 int tap_win32_init(VLANState *vlan, const char *ifname); 350 int tap_win32_init(VLANState *vlan, const char *ifname);
351 -void tap_win32_poll(void);  
352 351
353 /* NIC info */ 352 /* NIC info */
354 353