From patchwork Fri Jun 9 15:02:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 9778763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B83676034B for ; Fri, 9 Jun 2017 15:03:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B79F12864C for ; Fri, 9 Jun 2017 15:03:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABE9E28651; Fri, 9 Jun 2017 15:03:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F30C2864C for ; Fri, 9 Jun 2017 15:03:02 +0000 (UTC) Received: from localhost ([::1]:55221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJLRF-0000IK-D1 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Jun 2017 11:03:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJLQW-0000Ck-Er for qemu-devel@nongnu.org; Fri, 09 Jun 2017 11:02:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJLQR-0007QX-PE for qemu-devel@nongnu.org; Fri, 09 Jun 2017 11:02:16 -0400 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:34752) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dJLQR-0007PS-IG for qemu-devel@nongnu.org; Fri, 09 Jun 2017 11:02:11 -0400 Received: by mail-io0-x244.google.com with SMTP id a96so5812187ioj.1 for ; Fri, 09 Jun 2017 08:02:08 -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:to :mime-version; bh=tlcCYE+cTzg3kE/28cQW5ZDv0WDb2Sw9awBpDNa5ix0=; b=P/itzwgbY+acRrPNJvpcX7B8JV8e0u1ejCJXeLNywx7ftE1J9S5VTxaUgxP6LB7G3O wc+rDBrknfqcGdDBdVN1KyHudSMAajdolXVzMMPKpRK76LPbuy4Y3FlCxu/oLSBoBu04 yGVEVkFxwh3cfINEFyPBe04OIKU1zcq+NsCr8wDJDxNRBp7Z4SLPvFgbYDAKlwb9/1M8 9vlhvW3Tx+THPiN4zUMstMwFJvShgaugsstj5yNjfRzNV8gQlncOwFLW+bRuwcbQcgqV cNbt65+HD8V6sEJwLrbbcLSKTUYotQMIRKZGoZ7rSPoM/tM+p6IVq2ppGQjZmL2LYUYl amgQ== 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:to:mime-version; bh=tlcCYE+cTzg3kE/28cQW5ZDv0WDb2Sw9awBpDNa5ix0=; b=NZoDPSpdI8j3qCp/2KHmQv7vJ4deiRacIrmsZ8yiHygOIWfB07iTtnR/0lXYsU0jBx 8t+zFeBrbLq9cIdcsdDVUENfjxKB1iH20awqdEBODYtyA3gcRRGyCtsPUf6mNn0R16K5 tKsQXmpb1eO9109CyKzm76PirfUlz7UEG9CxUS5Wjfm0H2dxeO8iguNM8MX02QdMaUuO wdZ9zZxZJA/1NXsQYP3oSV3vaG3+MsJepQj2vSgMwU34iZtXrNkSRsyogXZxfXXuS3vl EG91KoRphQoeKvTwauOGfX14groUinUce9FnxTrKQ/bw6h08MB9nMMXFEebcqxOdzd61 c2ew== X-Gm-Message-State: AODbwcDWSee3KNDNoSlGDIAID9JLF5pu13SJffzzLKapc+3Mj+fbU97W +OIc+m4fjwEvDg== X-Received: by 10.107.58.136 with SMTP id h130mr12928635ioa.205.1497020527133; Fri, 09 Jun 2017 08:02:07 -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 w70sm757307itb.18.2017.06.09.08.02.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Jun 2017 08:02:06 -0700 (PDT) From: Programmingkid Date: Fri, 9 Jun 2017 11:02:04 -0400 Message-Id: <659939DD-F3BB-4FB9-B242-E0BB624EFED8@gmail.com> To: Gerd Hoffmann , "qemu-devel@nongnu.org qemu-devel" 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:c06::244 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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