From patchwork Thu Dec 29 19:37:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 709557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tqKg13wBdz9sXx for ; Fri, 30 Dec 2016 06:39:23 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L7w+5D+v"; dkim-atps=neutral Received: from localhost ([::1]:37048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMgXm-0004KZ-Dy for incoming@patchwork.ozlabs.org; Thu, 29 Dec 2016 14:39:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMgWw-0003xh-4C for qemu-devel@nongnu.org; Thu, 29 Dec 2016 14:38:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMgWt-0007qI-01 for qemu-devel@nongnu.org; Thu, 29 Dec 2016 14:38:26 -0500 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:36778) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cMgWs-0007q4-Rc for qemu-devel@nongnu.org; Thu, 29 Dec 2016 14:38:22 -0500 Received: by mail-io0-x241.google.com with SMTP id m204so14138446ioe.3 for ; Thu, 29 Dec 2016 11:38:22 -0800 (PST) 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=tlcCYE+cTzg3kE/28cQW5ZDv0WDb2Sw9awBpDNa5ix0=; b=L7w+5D+vY7EDKZqyfrAXz1/byEDtDMSzS6+7SYuJc28DrPWBIHQ5zNvm3+PAXeWz1r 2TRLZtAnu04PVwNIKWAXlcpoE6PgV1jn+7Of61BkTtCrj2XyFey/8z0TyRvyIGO4OjnZ 47RZv0HRtz/GqFT5FYQrsKohKPMDC6wcmqH1HzqzkO3BP2l8teZsIwbfpClP36RF6ay+ 73dNJ0mIe4EJ/Glk4Q09y/WJBJmnCX994JH/mzNyGfbda1qUA17spcZWSIKhqSEqiQEf tO4CUGv3kk0von+2PKzs3zD1XWtCZ0T5l3lP6ivPD7AnLK4WqDoKM0LT6p6AJ7UmVhYj XijQ== 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=tlcCYE+cTzg3kE/28cQW5ZDv0WDb2Sw9awBpDNa5ix0=; b=GHAtUN9PwdMU5F0QGMcOdbcGzNCL0aISNXgzsMdu2rbxQiROo+6Kd/iaQzmaXUufYP 9z5ggPek5ey63Zp+dihQHx0wqkmum5W53V8n11ROnrVI7XGR7WcZSHxb0uvm4c6hgUkl 7Rl7GVwCqh8MLKdCD77z2nyPvhHfXIFo5tnHMVgFbYgqlODfbx/sMWvzxIH8mYqwQCQV u49GVI+Z2X68TmYhSzdzvWPzX77+IkBSb4g62RR9ODm7k3HpZQH+y/zFrcUdL9tlMatu MvQrJN+TUpOk1HLuqvL6D8Vg7blNQd68raDcViCbRMCX/hVtZbxsfe4EahVqW4zZINKo Qybw== X-Gm-Message-State: AIkVDXIZgNJrFLbG6FqXA1IT+1QmIcEAEvmGBEy6unke89zJEmG5PYat5pccG/UJQYPUzg== X-Received: by 10.107.59.88 with SMTP id i85mr34274924ioa.198.1483040302084; Thu, 29 Dec 2016 11:38:22 -0800 (PST) Received: from [192.168.0.7] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id d25sm14886833ioj.25.2016.12.29.11.38.20 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Dec 2016 11:38:21 -0800 (PST) From: Programmingkid Date: Thu, 29 Dec 2016 14:37:58 -0500 Message-Id: To: Peter Maydell , Eric Blake Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::241 Subject: [Qemu-devel] [PATCH v2] 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 qemu-devel Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Programs running inside of QEMU can sometimes use more CPU time than is really needed. To solve this problem, we just need to throttle the virtual CPU. This feature will stop laptops from burning up. 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 --- 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 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 26d4a1c..772629e 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" #ifndef MAC_OS_X_VERSION_10_5 #define MAC_OS_X_VERSION_10_5 1050 @@ -828,6 +829,7 @@ QemuCocoaView *cocoaView; - (void)openDocumentation:(NSString *)filename; - (IBAction) do_about_menu_item: (id) sender; - (void)make_about_window; +- (void)adjustSpeed:(id)sender; @end @implementation QemuCocoaAppController @@ -1234,6 +1236,35 @@ QemuCocoaView *cocoaView; [superView addSubview: copyright_label]; } +/* Used by the Speed menu items */ +- (void)adjustSpeed:(id)sender +{ + int speed, menu_number, count, item; + NSMenu *menu; + NSArray *itemArray; + + // uncheck all the menu items in the Speed menu + menu = [sender menu]; + if (menu != nil) + { + count = [[menu itemArray] count]; + itemArray = [menu itemArray]; + for (item = 0; item < count; item++) // unselect each item + [[itemArray objectAtIndex: item] setState: NSOffState]; + } + + // check the menu item + [sender setState: NSOnState]; + + // get the menu number + menu_number = [sender tag]; + + /* Calculate the speed */ + speed = -1 * menu_number + 100; + cpu_throttle_set(speed); + COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(), '%'); +} + @end @@ -1316,6 +1347,29 @@ int main (int argc, const char * argv[]) { [menuItem setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem]; + // Speed menu + menu = [[NSMenu alloc] initWithTitle:@"Speed"]; + + // The 100% menu item has to be checked at the start + menuItem = [[[NSMenuItem alloc] initWithTitle:@"100%" action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease]; + [menuItem setTag: 100]; + [menuItem setState: NSOnState]; + [menu addItem: menuItem]; + + // Add the rest of the menu items + int p, percentage; + for (p = 9; p >= 0; p--) + { + percentage = p * 10 > 1 ? p * 10 : 1; // prevent a 0% menu item + menuItem = [[[NSMenuItem alloc] + initWithTitle: [NSString stringWithFormat: @"%d%c", percentage, '%'] action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease]; + [menuItem setTag: percentage]; + [menu addItem: menuItem]; + } + menuItem = [[[NSMenuItem alloc] initWithTitle:@"Speed" action:nil keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] addItem:menuItem]; + // Window menu menu = [[NSMenu alloc] initWithTitle:@"Window"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniaturize