From nobody Wed Nov 5 13:41:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497410322914592.3631711676459; Tue, 13 Jun 2017 20:18:42 -0700 (PDT) Received: from localhost ([::1]:46179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKypM-0002xZ-KK for importer@patchew.org; Tue, 13 Jun 2017 23:18:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKyoU-0002fR-CJ for qemu-devel@nongnu.org; Tue, 13 Jun 2017 23:17:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKyoR-0006n6-81 for qemu-devel@nongnu.org; Tue, 13 Jun 2017 23:17:46 -0400 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:33870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKyoR-0006mb-1n for qemu-devel@nongnu.org; Tue, 13 Jun 2017 23:17:43 -0400 Received: by mail-it0-x244.google.com with SMTP id 201so14557248itu.1 for ; Tue, 13 Jun 2017 20:17:41 -0700 (PDT) Received: from [192.168.0.6] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id z33sm7433813ioi.37.2017.06.13.20.17.39 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 20:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:subject:date:message-id:cc:to :mime-version; bh=M6b9RTqNq2h035KgWYDPOI+FjttWK6hzKogvlTFSYgo=; b=QCRokHOMSfJZfS31yOPps8cwlVdbBoe3EE0n4jEUkpoY2TzQMrY1Surizl0zU87xG4 P1+nBiGW5v3le7dRHytc5SKH3jvE2TiIgU0Ww1F2904zclwdwxqyWr2nG5CPc4C0ZluY KV+Br/nH5Ls4rluGkZKY+y/N3yW8pPStMUALjporzB84GNIbujm1TD6DxNMGuttfzav5 Pf2NgoKug/dv/dmwXc7mnK2acTxhut4VP9YYTjoNf5qxUYIYWayZcbFDQxwQIw247BwG nQTxLdnUUvtRGjkiWpkzTxSRLCPMHTj9zicRsh1iSAZs/9uzX5cuOTGfsoxz3gV87+Db IOZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:subject:date :message-id:cc:to:mime-version; bh=M6b9RTqNq2h035KgWYDPOI+FjttWK6hzKogvlTFSYgo=; b=J/C7AHFC3RE4RUMDxKZOnFg+EF3SGoF86BbF2NC+IjBOHUtBosTmeOHCGf+Iz/ZM8T WCR1u7nVe8T+7gWkkEVm/YeKVuT6PMUxYmEn1dffjU7lhexY4Hme6Q66Rc5AgbOfGaP1 +nOwfwPIbWNnS6m2fK73h4qT1ePXzr59Y8Mkr+Nmd6oPTtfDrc91etsfD1Qv3BXe+jQj 4ZqiIGwpdTBab9y6Ne+d/u15NgCePsQxjC1IFyIi7kNWMjBkx300Bt3xv7LeAK7ubwqw xng+7a0N7k+tf6a10+IAmp+2zGPdW8MAWj3nb+r2Ml/zrIJ05HnswuAfn8ghhLpIL8k8 RbFw== X-Gm-Message-State: AKS2vOzN8CnRVIB9zj+SQBdChoOGPES2GXIDoHVWzTZHe2Az6gLrpFZA DPJeJVPDpyHpjw== X-Received: by 10.36.98.206 with SMTP id d197mr15014554itc.50.1497410260871; Tue, 13 Jun 2017 20:17:40 -0700 (PDT) From: Programmingkid Content-Transfer-Encoding: quoted-printable Date: Tue, 13 Jun 2017 23:17:38 -0400 Message-Id: To: Peter Maydell , Gerd Hoffmann Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::244 Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: add Speed menu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "qemu-devel@nongnu.org qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Programs running inside of QEMU can sometimes use more CPU time than is rea= lly needed. To solve this problem, we just need to throttle the virtual CPU. Th= is feature will stop laptops from burning up.=20 This patch adds a menu called Speed that has menu items from 100% to 1% that represent the speed options. 100% is full speed and 1% is slowest. Signed-off-by: John Arbuckle --- v3 changes: Changed the item deselection loop. Moved speed calculation equation to main function. Replaced "%c" with "%%". Changed how 100% menu item is made. v2 changes: Fixed missing space with 'if' and 'for' structures. Fixed tab damage. Use loop to create menu items. Changed name of menu items to use percentages. Use tags to determine selected menu item. ui/cocoa.m | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 004ec27..a866a66 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -35,6 +35,7 @@ #include "sysemu/blockdev.h" #include "qemu-version.h" #include +#include "qom/cpu.h" =20 #ifndef MAC_OS_X_VERSION_10_5 #define MAC_OS_X_VERSION_10_5 1050 @@ -857,6 +858,7 @@ QemuCocoaView *cocoaView; - (void)openDocumentation:(NSString *)filename; - (IBAction) do_about_menu_item: (id) sender; - (void)make_about_window; +- (void)adjustSpeed:(id)sender; @end =20 @implementation QemuCocoaAppController @@ -1263,6 +1265,34 @@ QemuCocoaView *cocoaView; [superView addSubview: copyright_label]; } =20 +/* Used by the Speed menu items */ +- (void)adjustSpeed:(id)sender +{ + int throttle_pct; /* throttle percentage */ + NSMenu *menu; + + menu =3D [sender menu]; + if (menu !=3D nil) + { + /* Unselect the currently selected item */ + for (NSMenuItem *item in [menu itemArray]) { + if (item.state =3D=3D NSOnState) { + [item setState: NSOffState]; + break; + } + } + } + + // check the menu item + [sender setState: NSOnState]; + + // get the throttle percentage + throttle_pct =3D [sender tag]; + + cpu_throttle_set(throttle_pct); + COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(),= '%'); +} + @end =20 =20 @@ -1345,6 +1375,31 @@ int main (int argc, const char * argv[]) { [menuItem setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem]; =20 + // Speed menu + menu =3D [[NSMenu alloc] initWithTitle:@"Speed"]; + + // Add the rest of the Speed menu items + int p, percentage, throttle_pct; + for (p =3D 10; p >=3D 0; p--) + { + percentage =3D p * 10 > 1 ? p * 10 : 1; // prevent a 0% menu item + + if (percentage =3D=3D 100) { + [menuItem setState: NSOnState]; + } + menuItem =3D [[[NSMenuItem alloc] + initWithTitle: [NSString stringWithFormat: @"%d%%", per= centage] action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease]; + + /* Calculate the throttle percentage */ + throttle_pct =3D -1 * percentage + 100; + + [menuItem setTag: throttle_pct]; + [menu addItem: menuItem]; + } + menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"Speed" action:nil ke= yEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] addItem:menuItem]; + // Window menu menu =3D [[NSMenu alloc] initWithTitle:@"Window"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@= selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniatu= rize --=20 2.7.2