]> git.proxmox.com Git - mirror_qemu.git/blob - accel.c
accel: Move accel code to accel.c
[mirror_qemu.git] / accel.c
1 /*
2 * QEMU System Emulator, accelerator interfaces
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright (c) 2014 Red Hat Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26 #include "sysemu/accel.h"
27 #include "qemu-common.h"
28 #include "sysemu/arch_init.h"
29 #include "sysemu/sysemu.h"
30 #include "sysemu/kvm.h"
31 #include "sysemu/qtest.h"
32 #include "hw/xen/xen.h"
33
34 int tcg_tb_size;
35 static bool tcg_allowed = true;
36
37 static int tcg_init(MachineClass *mc)
38 {
39 tcg_exec_init(tcg_tb_size * 1024 * 1024);
40 return 0;
41 }
42
43 static struct {
44 const char *opt_name;
45 const char *name;
46 int (*available)(void);
47 int (*init)(MachineClass *mc);
48 bool *allowed;
49 } accel_list[] = {
50 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
51 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
52 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
53 { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
54 };
55
56 int configure_accelerator(MachineClass *mc)
57 {
58 const char *p;
59 char buf[10];
60 int i, ret;
61 bool accel_initialised = false;
62 bool init_failed = false;
63
64 p = qemu_opt_get(qemu_get_machine_opts(), "accel");
65 if (p == NULL) {
66 /* Use the default "accelerator", tcg */
67 p = "tcg";
68 }
69
70 while (!accel_initialised && *p != '\0') {
71 if (*p == ':') {
72 p++;
73 }
74 p = get_opt_name(buf, sizeof(buf), p, ':');
75 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
76 if (strcmp(accel_list[i].opt_name, buf) == 0) {
77 if (!accel_list[i].available()) {
78 printf("%s not supported for this target\n",
79 accel_list[i].name);
80 break;
81 }
82 *(accel_list[i].allowed) = true;
83 ret = accel_list[i].init(mc);
84 if (ret < 0) {
85 init_failed = true;
86 fprintf(stderr, "failed to initialize %s: %s\n",
87 accel_list[i].name,
88 strerror(-ret));
89 *(accel_list[i].allowed) = false;
90 } else {
91 accel_initialised = true;
92 }
93 break;
94 }
95 }
96 if (i == ARRAY_SIZE(accel_list)) {
97 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
98 }
99 }
100
101 if (!accel_initialised) {
102 if (!init_failed) {
103 fprintf(stderr, "No accelerator found!\n");
104 }
105 exit(1);
106 }
107
108 if (init_failed) {
109 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
110 }
111
112 return !accel_initialised;
113 }