From: Programmingkid <programmingkidx@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>,
Gerd Hoffmann <kraxel@redhat.com>
Cc: "qemu-devel@nongnu.org qemu-devel" <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: add Speed menu
Date: Tue, 13 Jun 2017 23:17:38 -0400 [thread overview]
Message-ID: <D6FAAABF-064D-49C0-B572-C73679F34052@gmail.com> (raw)
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 <programmingkidx@gmail.com>
---
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 <Carbon/Carbon.h>
+#include "qom/cpu.h"
#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
@implementation QemuCocoaAppController
@@ -1263,6 +1265,34 @@ QemuCocoaView *cocoaView;
[superView addSubview: copyright_label];
}
+/* Used by the Speed menu items */
+- (void)adjustSpeed:(id)sender
+{
+ int throttle_pct; /* throttle percentage */
+ NSMenu *menu;
+
+ menu = [sender menu];
+ if (menu != nil)
+ {
+ /* Unselect the currently selected item */
+ for (NSMenuItem *item in [menu itemArray]) {
+ if (item.state == NSOnState) {
+ [item setState: NSOffState];
+ break;
+ }
+ }
+ }
+
+ // check the menu item
+ [sender setState: NSOnState];
+
+ // get the throttle percentage
+ throttle_pct = [sender tag];
+
+ cpu_throttle_set(throttle_pct);
+ COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(), '%');
+}
+
@end
@@ -1345,6 +1375,31 @@ int main (int argc, const char * argv[]) {
[menuItem setSubmenu:menu];
[[NSApp mainMenu] addItem:menuItem];
+ // Speed menu
+ menu = [[NSMenu alloc] initWithTitle:@"Speed"];
+
+ // Add the rest of the Speed menu items
+ int p, percentage, throttle_pct;
+ for (p = 10; p >= 0; p--)
+ {
+ percentage = p * 10 > 1 ? p * 10 : 1; // prevent a 0% menu item
+
+ if (percentage == 100) {
+ [menuItem setState: NSOnState];
+ }
+ menuItem = [[[NSMenuItem alloc]
+ initWithTitle: [NSString stringWithFormat: @"%d%%", percentage] action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease];
+
+ /* Calculate the throttle percentage */
+ throttle_pct = -1 * percentage + 100;
+
+ [menuItem setTag: throttle_pct];
+ [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
--
2.7.2
next reply other threads:[~2017-06-14 3:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-14 3:17 Programmingkid [this message]
2017-06-14 3:28 ` [Qemu-devel] [PATCH v3] ui/cocoa.m: add Speed menu no-reply
2017-06-21 15:19 ` Peter Maydell
2017-06-23 14:03 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D6FAAABF-064D-49C0-B572-C73679F34052@gmail.com \
--to=programmingkidx@gmail.com \
--cc=kraxel@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).