Received: by 2002:a17:505:610b:b0:1be9:327d:8ee3 with SMTP id tt11csp2656602njc; Mon, 4 Nov 2024 23:45:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXWH5YJEgYncvvaicpvGmquxGfmEelTJ52PX1nV6Hv+4SymD+LS3WuSlwTxqvzpwzbmYtIy1oihOL89ZA==@linaro.org X-Google-Smtp-Source: AGHT+IEVUyTrkCNKoeiXbe2X1xKln3JLgPjZQ5CHLsqAqDHNRLZ/tmAzY8eqt95IQfO2uhnP9JqD X-Received: by 2002:a05:6102:4408:b0:493:bb35:d8f9 with SMTP id ada2fe7eead31-4a962d73838mr14448308137.5.1730792716405; Mon, 04 Nov 2024 23:45:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730792716; cv=none; d=google.com; s=arc-20240605; b=WufO0pRWQlo24NtpZZquHMZTzkWeT0e3pDVLLpHX7U8HakyQF3ehnLuBX67XN1Phni jhmfjnYEH5dV9TrmWw0rH+oS227e5fTYCBJ20ibshtTzoznYg/I0TmlnGcSHitqo5dnt Foel8Ipqg75P9v6FHciZ5pR7/exBaBFOhBd1S3kWqOFXdwCpuuxiXw47FAYUUkQwGhnk zWeGmRfgFEJvF3YOD2sZFvFsBBAQsGVx28L27HrLDtdEpJqx9UoHwDKvkHozVmvgdMp9 fcmdfWhy67SNu3d07iZwF5OuojYy/kuN96o14yZjmXIn2lZXvGJDwMaDg2i85qliIrzH bRAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=RMKlRRvn82mT8R/GjyiywQBWv99O2uNSf7ONsN0FFAc=; fh=F35uLknyZh5n/UYyj7NgZvR/n7wkJPLiTN8QOx3KqlY=; b=Dc+PTvhOOtczqgOzvWHwqE2O7lM/KTXiPJ5SE3/C14OvcosZina2+ETgFrS1Bau55+ eAHhUjbjcAcudeGD4gZEx5nW4h2h/pucpHhtcGnverCU2yMm8oLq1iT/SnIJQJyalZ7d ArF9Z/Wu1Q/3fzCRGntHrDlMTLU68IvCAoMwjjfrOFkDJuPmFtKjuOmY0uPiSb26lV2G J65t9jjUcSSlwrlC9BF13vq7LBZBf0BcK72tDDskXIC1C1LcRs9yULehftkgnnMFqY6C 7MoiD7i2DEKCSlrepHunjHB2ndx2RgFjnNfKMZuSxZpCbzvaUOw1QeD/Qa/isXonm/hw Lfxw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b=2O61IH7c; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-462ad1a1320si137787701cf.280.2024.11.04.23.45.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Nov 2024 23:45:16 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b=2O61IH7c; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8EFL-0005JV-DE; Tue, 05 Nov 2024 02:45:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8EFJ-0005IJ-3Z for qemu-devel@nongnu.org; Tue, 05 Nov 2024 02:45:01 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8EFH-0000pd-JH for qemu-devel@nongnu.org; Tue, 05 Nov 2024 02:45:00 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-20ce5e3b116so40381615ad.1 for ; Mon, 04 Nov 2024 23:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1730792697; x=1731397497; darn=nongnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=RMKlRRvn82mT8R/GjyiywQBWv99O2uNSf7ONsN0FFAc=; b=2O61IH7cJtPGrUlfNr6dsQf+R3bbKHZ7rkMyV/oIRCTWqtRkfWXYGoihMPSzuKCVX3 mVrz2mnQPDbSnaChT2vnOry2/LjtBrA1twmdxItJnE2g81M78GOuQJbUG9JE9nqBupPw u1TS4vF3T5+Su5std54p4aWduAQaCqdb5bRLfWSngpcF6n6rVtX4qIsGT87TwNYxA9l8 /pbgi8vzhcwlb9moTLSDNGso1mOWca8LEoyGgacdK1m2GDKSz2UoHLJ8QIuKtiN8faB4 e4SnctQnm+8X9adoVQLA20qzmFc99BJJ8Lmhrsguael3sm9sEFAiB1wUN2Q+LfX2DUyq O55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730792697; x=1731397497; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RMKlRRvn82mT8R/GjyiywQBWv99O2uNSf7ONsN0FFAc=; b=W7oTe/G+zs0xIKEbE0g+fZslv26HL16td+D4sg0CH74fJGfjH1l02HoNRz7UNy8sFm CXe9STGMN8Igwd6K1tP4lutNdmvixL9z1BMeSNGbQZI14hZ3AETNmXDwCwr9mezZRGdi iv5OrCNMvyCKZRhh05m/xTD53DAEILtnD0fn1NpokXtW0rLPjibC8gv14YtYSsImbtA3 aYqsc+EcBc85mPnzEHutSRXOcleGv+xCOv01USneyg7CQ6BC/+DsFiBVD/j2W3XM+Lww 55yMRpNq6XNkl6C0f7FkfkRZoO5byv3HJDLko3UZ4TP+mABNotYfob4rWoV1TmLTw+g2 X6dA== X-Forwarded-Encrypted: i=1; AJvYcCVH2lbj8gk4pWa9IazQP5WNzv5YTKPl7yHGr0tNtjD/FnnOd+NFdHg0OVQIWjgSRRbXMNI4Yrd5Mirh@nongnu.org X-Gm-Message-State: AOJu0Yz9gE2GZrUPTF7eCwSQLtza9nfRsYcmZhcdbQDSNf+by/KnDSgA x37zXbNiys7owvTt0jCVFmiTh+/VDBuwVY5dmn/3qh24IkiVfFefqCBEoZaJiOY= X-Received: by 2002:a17:902:dac4:b0:20b:a9f3:796d with SMTP id d9443c01a7336-2111afd6c25mr175705165ad.44.1730792697401; Mon, 04 Nov 2024 23:44:57 -0800 (PST) Received: from [157.82.207.107] ([157.82.207.107]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057d44cesm73005705ad.255.2024.11.04.23.44.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Nov 2024 23:44:57 -0800 (PST) Message-ID: Date: Tue, 5 Nov 2024 16:44:49 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 01/15] ui & main loop: Redesign of system-specific main thread event handling To: Phil Dennis-Jordan , qemu-devel@nongnu.org Cc: agraf@csgraf.de, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org References: <20241103150037.48194-1-phil@philjordan.eu> <20241103150037.48194-2-phil@philjordan.eu> Content-Language: en-US From: Akihiko Odaki In-Reply-To: <20241103150037.48194-2-phil@philjordan.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: none client-ip=2607:f8b0:4864:20::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: 2+aX2aVGUiTV On 2024/11/04 0:00, Phil Dennis-Jordan wrote: > macOS's Cocoa event handling must be done on the initial (main) thread > of the process. Furthermore, if library or application code uses > libdispatch, the main dispatch queue must be handling events on the main > thread as well. > > So far, this has affected Qemu in both the Cocoa and SDL UIs, although > in different ways: the Cocoa UI replaces the default qemu_main function > with one that spins Qemu's internal main event loop off onto a > background thread. SDL (which uses Cocoa internally) on the other hand > uses a polling approach within Qemu's main event loop. Events are > polled during the SDL UI's dpy_refresh callback, which happens to run > on the main thread by default. > > As UIs are mutually exclusive, this works OK as long as nothing else > needs platform-native event handling. In the next patch, a new device is > introduced based on the ParavirtualizedGraphics.framework in macOS. > This uses libdispatch internally, and only works when events are being > handled on the main runloop. With the current system, it works when > using either the Cocoa or the SDL UI. However, it does not when running > headless. Moreover, any attempt to install a similar scheme to the > Cocoa UI's main thread replacement fails when combined with the SDL > UI. > > This change tidies up main thread management to be more flexible. > > * The qemu_main global function pointer is a custom function for the > main thread, and it may now be NULL. When it is, the main thread > runs the main Qemu loop. This represents the traditional setup. > * When non-null, spawning the main Qemu event loop on a separate > thread is now done centrally rather than inside the Cocoa UI code. > * For most platforms, qemu_main is indeed NULL by default, but on > Darwin, it defaults to a function that runs the CFRunLoop. > * The Cocoa UI sets qemu_main to a function which runs the > NSApplication event handling runloop, as is usual for a Cocoa app. > * The SDL UI overrides the qemu_main function to NULL, thus > specifying that Qemu's main loop must run on the main > thread. > * For other UIs, or in the absence of UIs, the platform's default > behaviour is followed. > > This means that on macOS, the platform's runloop events are always > handled, regardless of chosen UI. The new PV graphics device will > thus work in all configurations. There is no functional change on other > operating systems. > > Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki