From nobody Mon Nov 21 21:55:00 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NGLlt0yrzz4hdFP for ; Mon, 21 Nov 2022 21:55:06 +0000 (UTC) (envelope-from bz@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NGLls5c4cz45vm; Mon, 21 Nov 2022 21:55:05 +0000 (UTC) (envelope-from bz@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669067705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UjOHjnp9qH4XH1h+RpaXuUfV9vp3wkxllHHGPELKwDc=; b=HiWjjl7U+Jo5D/wMNAyD4Po4WwgbiXiwEWTKVKn36x7AxKZ45tggZvKZlH0vFa1jazqB/e 3mh5rublDVBUVCI95dunx9eXku5s4C1t4P8zVb069R+24d7cKZfgbOW+dl3NIiU8Ljyuyr zFVoYVTltBSTa5MBvM5dnaskznxKwgL3M6oybCACaUAnC37M+xrA5Iu3j07naMVEd7DE/J 87bjaqF2OCjHABxZB5ud4bas+PfhtUPXHSpM+Faz57OtwvrxYisroxqYH42XRvhdNAIA6M fiqMo0fuiFjnlxBqW19a4WUOUov8YPog0wnq8BUIm8FijRkaVVrYhK9Hy2nMEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669067705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UjOHjnp9qH4XH1h+RpaXuUfV9vp3wkxllHHGPELKwDc=; b=bg7t+odx6gWjHZsa3XOB+nM7PMkTLqguxMgTJs2SLvqSrS2XVbUEkg0a2DZzX3F0X5DD0s HDOopuLgcT0qNTs7ZjEOwK7TfN2dyL6toRwm0uqTdFA6eWHPAFWwtJg7U7xci5nwPZSFEp SJ5VPoCBSbB/ei6UWM7t9U0cu3OTvllUC1nbwjQErd5BUNYRHVgoxQDnE+GCKzVNKaSNM9 V3DIN9rpBA8yzGXIzOs4gUo4KrhILxWfx5sGC9z1yeNd/R0uxENmmhcUNXHCvJ55R37A16 g+gtKA5k8wvFSHc0VjsKAcIML/KylBHkVlQ3rnBn2YN49JaEaHtEPYBxaPOcVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669067705; a=rsa-sha256; cv=none; b=dPW1KA1cOBbZAZBSHQM4ERzurkdg0rWr6ziUJDmyeTUOVYqjNwk7h0QL1puJ0zhMaNUEtJ epVfgTbR007BzwMvoOVo2M1IY1na7/gQNOvIK7aE/RqrmaEI070famyy5082WpyNd9tfbw L68CdsYaf27ygBR4LkAN9k6SATypUXZ8dQhb4QsS1KPDiQbfqIkmLIyrNeSabFRfg+QDA2 D9f1N1gBehbD3i6Zwa/g4f3nC2N6XsPzRY8dDZphRuX9NHBsPGC0ygapmEAHNa/XemyKc5 j1o9o4lcHPtUkzke/sRQlcrW0ETLuWAyguitM57g5kYfXjgVV1/t7s3epKrrVg== Received: from mx1.sbone.de (cross.sbone.de [195.201.62.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx1.sbone.de", Issuer "SBone.DE" (not verified)) (Authenticated sender: bz/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4NGLls34k0z1N9r; Mon, 21 Nov 2022 21:55:05 +0000 (UTC) (envelope-from bz@freebsd.org) Received: from mail.sbone.de (mail.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:1025]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sbone.de (Postfix) with ESMTPS id D78CA8D4A212; Mon, 21 Nov 2022 21:55:03 +0000 (UTC) Received: from content-filter.t4-02.sbone.de (content-filter.t4-02.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:2742]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPS id 2BEDA5C3A833; Mon, 21 Nov 2022 21:55:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at sbone.de Received: from mail.sbone.de ([IPv6:fde9:577b:c1a9:4902:0:7404:2:1025]) by content-filter.t4-02.sbone.de (content-filter.t4-02.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:2742]) (amavisd-new, port 10024) with ESMTP id gY8tRPk51fRH; Mon, 21 Nov 2022 21:55:01 +0000 (UTC) Received: from strong-iwl0.sbone.de (strong-iwl0.sbone.de [IPv6:fde9:577b:c1a9:4902:b66b:fcff:fef3:e3d2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPSA id 4C6955C3A830; Mon, 21 Nov 2022 21:55:01 +0000 (UTC) Date: Mon, 21 Nov 2022 21:55:00 +0000 (UTC) From: "Bjoern A. Zeeb" To: Mark Johnston cc: Konstantin Belousov , freebsd-hackers@freebsd.org Subject: Re: Can we "pause" in loader and ddb>? In-Reply-To: Message-ID: <94p665qn-nr81-89rp-8rr3-61r348q14s3@serrofq.bet> References: X-OpenPGP-Key-Id: 0x14003F198FEFA3E77207EE8D2B58B8F83CCF1842 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-ThisMailContainsUnwantedMimeParts: N On Mon, 21 Nov 2022, Mark Johnston wrote: Hi, > On Mon, Nov 21, 2022 at 09:37:36PM +0200, Konstantin Belousov wrote: >> On Mon, Nov 21, 2022 at 02:06:47PM -0500, Mark Johnston wrote: >>> On Mon, Nov 21, 2022 at 06:42:44PM +0000, Bjoern A. Zeeb wrote: >>>> Hi, >>>> >>>> having a VM sitting (a) in loader prompt or (b) in ddb> makes the fans >>>> go loud on a test-laptop which makes one wonder if we can avoid that. >>>> Note -- I assume also on real HW though that's less likely observered >>>> here. >>>> >>>> For example I am sitting in a 4 vCPU bhyve current in ddb> and two >>>> threads are at 100% on the base system. Do we need to heat up the >>>> planet doing that or are there alternatives? > > I forgot to mention: in this situation my "solution" is to attach gdb to > the running VM, which I usually want to do anyway. This causes all vCPU > threads to pause. > >>>> I haven't looke dta the >>>> code in ages and I assume we need to poll in these situations on the >>>> console and for interactivity often enough? Can we "pause"? And why >>>> would two [v]CPUs be at 100% and not just one as I would expect all but >>>> one to be stopped? >>> >>> When DDB is active, one CPU is going to be spinning in cncheckc() >>> waiting for input, and the others will be in cpustop_handler(). For the >>> latter, there is an option to use MWAIT/MONITOR to pause the CPU instead >>> of calling pause in a loop, but bhyve hides the MWAIT/MONITOR CPU >>> capability from guests (I'm not sure exactly why), so they just execute >>> "pause" in a loop, which won't help the apparent CPU usage. >> We do not want the guest thread eating CPU time in MWAIT, it is the host >> scheduler that should decide that there is nothing to do and schedule >> idle thread. >> >> In other words, MWAIT should be emulated, perhaps by revoking the monitoring >> page on MONITOR, and waking up the MWAIT-ing thread on write to the armed >> range. >> >> Additional complication is that the range to arm is usually equal to the cache >> line, doing dumb emulation by interpreting any write to the monitor page >> might be too harsh. >> >> There is also non-trivial cooperation with atomic interrupt delivery. >> >> These complexities are perhaps the reason to not enable M* for guests. > > I see. Maybe instead we could allow stopped CPUs to execute "hlt" with > interrupts disabled, and when exiting DDB, the last CPU resumes all of > the others by raising NMIs. Then only one vCPU thread will be consuming > host CPU time when in DDB. > >>> Note that when the kernel panics, cpustop_handler() will execute "hlt", >>> which should result in a vmexit if you started bhyve with -H, and you'll >>> see only one vCPU thread consuming 100% when sitting at the DDB prompt. >>> But when you enter DDB without a panic, we need some mechanism to resume >>> the stopped CPUs when exiting DDB. Nonwithstanding, the problem also is loader and the problem probably also is on a bare metal so focusing on bhyve is certainly a partial win but only part of the solution whihc ideally works in both situations. -- Bjoern A. Zeeb r15:7