@@ -542,143 +542,10 @@ static void qemu_kvm_eat_signals(CPUState *env)
542
542
#endif /* !CONFIG_LINUX */
543
543
544
544
#ifndef _WIN32
545
- static int io_thread_fd = -1 ;
546
-
547
- static void qemu_event_increment (void )
548
- {
549
- /* Write 8 bytes to be compatible with eventfd. */
550
- static const uint64_t val = 1 ;
551
- ssize_t ret ;
552
-
553
- if (io_thread_fd == -1 ) {
554
- return ;
555
- }
556
- do {
557
- ret = write (io_thread_fd , & val , sizeof (val ));
558
- } while (ret < 0 && errno == EINTR );
559
-
560
- /* EAGAIN is fine, a read must be pending. */
561
- if (ret < 0 && errno != EAGAIN ) {
562
- fprintf (stderr , "qemu_event_increment: write() failed: %s\n" ,
563
- strerror (errno ));
564
- exit (1 );
565
- }
566
- }
567
-
568
- static void qemu_event_read (void * opaque )
569
- {
570
- int fd = (intptr_t )opaque ;
571
- ssize_t len ;
572
- char buffer [512 ];
573
-
574
- /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
575
- do {
576
- len = read (fd , buffer , sizeof (buffer ));
577
- } while ((len == -1 && errno == EINTR ) || len == sizeof (buffer ));
578
- }
579
-
580
- static int qemu_event_init (void )
581
- {
582
- int err ;
583
- int fds [2 ];
584
-
585
- err = qemu_eventfd (fds );
586
- if (err == -1 ) {
587
- return - errno ;
588
- }
589
- err = fcntl_setfl (fds [0 ], O_NONBLOCK );
590
- if (err < 0 ) {
591
- goto fail ;
592
- }
593
- err = fcntl_setfl (fds [1 ], O_NONBLOCK );
594
- if (err < 0 ) {
595
- goto fail ;
596
- }
597
- qemu_set_fd_handler2 (fds [0 ], NULL , qemu_event_read , NULL ,
598
- (void * )(intptr_t )fds [0 ]);
599
-
600
- io_thread_fd = fds [1 ];
601
- return 0 ;
602
-
603
- fail :
604
- close (fds [0 ]);
605
- close (fds [1 ]);
606
- return err ;
607
- }
608
-
609
545
static void dummy_signal (int sig )
610
546
{
611
547
}
612
548
613
- /* If we have signalfd, we mask out the signals we want to handle and then
614
- * use signalfd to listen for them. We rely on whatever the current signal
615
- * handler is to dispatch the signals when we receive them.
616
- */
617
- static void sigfd_handler (void * opaque )
618
- {
619
- int fd = (intptr_t )opaque ;
620
- struct qemu_signalfd_siginfo info ;
621
- struct sigaction action ;
622
- ssize_t len ;
623
-
624
- while (1 ) {
625
- do {
626
- len = read (fd , & info , sizeof (info ));
627
- } while (len == -1 && errno == EINTR );
628
-
629
- if (len == -1 && errno == EAGAIN ) {
630
- break ;
631
- }
632
-
633
- if (len != sizeof (info )) {
634
- printf ("read from sigfd returned %zd: %m\n" , len );
635
- return ;
636
- }
637
-
638
- sigaction (info .ssi_signo , NULL , & action );
639
- if ((action .sa_flags & SA_SIGINFO ) && action .sa_sigaction ) {
640
- action .sa_sigaction (info .ssi_signo ,
641
- (siginfo_t * )& info , NULL );
642
- } else if (action .sa_handler ) {
643
- action .sa_handler (info .ssi_signo );
644
- }
645
- }
646
- }
647
-
648
- static int qemu_signal_init (void )
649
- {
650
- int sigfd ;
651
- sigset_t set ;
652
-
653
- /*
654
- * SIG_IPI must be blocked in the main thread and must not be caught
655
- * by sigwait() in the signal thread. Otherwise, the cpu thread will
656
- * not catch it reliably.
657
- */
658
- sigemptyset (& set );
659
- sigaddset (& set , SIG_IPI );
660
- pthread_sigmask (SIG_BLOCK , & set , NULL );
661
-
662
- sigemptyset (& set );
663
- sigaddset (& set , SIGIO );
664
- sigaddset (& set , SIGALRM );
665
- sigaddset (& set , SIGBUS );
666
- pthread_sigmask (SIG_BLOCK , & set , NULL );
667
-
668
- sigfd = qemu_signalfd (& set );
669
- if (sigfd == -1 ) {
670
- fprintf (stderr , "failed to create signalfd\n" );
671
- return - errno ;
672
- }
673
-
674
- fcntl_setfl (sigfd , O_NONBLOCK );
675
-
676
- qemu_set_fd_handler2 (sigfd , NULL , sigfd_handler , NULL ,
677
- (void * )(intptr_t )sigfd );
678
-
679
- return 0 ;
680
- }
681
-
682
549
static void qemu_kvm_init_cpu_signals (CPUState * env )
683
550
{
684
551
int r ;
@@ -722,38 +589,6 @@ static void qemu_tcg_init_cpu_signals(void)
722
589
}
723
590
724
591
#else /* _WIN32 */
725
-
726
- HANDLE qemu_event_handle ;
727
-
728
- static void dummy_event_handler (void * opaque )
729
- {
730
- }
731
-
732
- static int qemu_event_init (void )
733
- {
734
- qemu_event_handle = CreateEvent (NULL , FALSE, FALSE, NULL );
735
- if (!qemu_event_handle ) {
736
- fprintf (stderr , "Failed CreateEvent: %ld\n" , GetLastError ());
737
- return -1 ;
738
- }
739
- qemu_add_wait_object (qemu_event_handle , dummy_event_handler , NULL );
740
- return 0 ;
741
- }
742
-
743
- static void qemu_event_increment (void )
744
- {
745
- if (!SetEvent (qemu_event_handle )) {
746
- fprintf (stderr , "qemu_event_increment: SetEvent failed: %ld\n" ,
747
- GetLastError ());
748
- exit (1 );
749
- }
750
- }
751
-
752
- static int qemu_signal_init (void )
753
- {
754
- return 0 ;
755
- }
756
-
757
592
static void qemu_kvm_init_cpu_signals (CPUState * env )
758
593
{
759
594
abort ();
@@ -779,33 +614,16 @@ static QemuCond qemu_cpu_cond;
779
614
static QemuCond qemu_pause_cond ;
780
615
static QemuCond qemu_work_cond ;
781
616
782
- int qemu_init_main_loop (void )
617
+ void qemu_init_cpu_loop (void )
783
618
{
784
- int ret ;
785
-
786
619
qemu_init_sigbus ();
787
-
788
- ret = qemu_signal_init ();
789
- if (ret ) {
790
- return ret ;
791
- }
792
-
793
- /* Note eventfd must be drained before signalfd handlers run */
794
- ret = qemu_event_init ();
795
- if (ret ) {
796
- return ret ;
797
- }
798
-
799
620
qemu_cond_init (& qemu_cpu_cond );
800
621
qemu_cond_init (& qemu_pause_cond );
801
622
qemu_cond_init (& qemu_work_cond );
802
623
qemu_cond_init (& qemu_io_proceeded_cond );
803
624
qemu_mutex_init (& qemu_global_mutex );
804
- qemu_mutex_lock (& qemu_global_mutex );
805
625
806
626
qemu_thread_get_self (& io_thread );
807
-
808
- return 0 ;
809
627
}
810
628
811
629
void qemu_main_loop_start (void )
@@ -1129,11 +947,6 @@ void qemu_init_vcpu(void *_env)
1129
947
}
1130
948
}
1131
949
1132
- void qemu_notify_event (void )
1133
- {
1134
- qemu_event_increment ();
1135
- }
1136
-
1137
950
void cpu_stop_current (void )
1138
951
{
1139
952
if (cpu_single_env ) {
0 commit comments