Skip to content

Commit 8c15f6e

Browse files
committed
plugins/loader: compile loader only once
There is very little in loader that is different between builds save for a tiny user/system mode difference in the plugin_info structure. Create two new files, user and system to hold mode specific helpers and move loader into common_ss. Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent 5dd09b8 commit 8c15f6e

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

plugins/loader.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
#include "qemu/memalign.h"
3232
#include "hw/core/cpu.h"
3333
#include "exec/tb-flush.h"
34-
#ifndef CONFIG_USER_ONLY
35-
#include "hw/boards.h"
36-
#endif
3734

3835
#include "plugin.h"
3936

@@ -300,14 +297,8 @@ int qemu_plugin_load_list(QemuPluginList *head, Error **errp)
300297
info->target_name = target_name();
301298
info->version.min = QEMU_PLUGIN_MIN_VERSION;
302299
info->version.cur = QEMU_PLUGIN_VERSION;
303-
#ifndef CONFIG_USER_ONLY
304-
MachineState *ms = MACHINE(qdev_get_machine());
305-
info->system_emulation = true;
306-
info->system.smp_vcpus = ms->smp.cpus;
307-
info->system.max_vcpus = ms->smp.max_cpus;
308-
#else
309-
info->system_emulation = false;
310-
#endif
300+
301+
qemu_plugin_fillin_mode_info(info);
311302

312303
QTAILQ_FOREACH_SAFE(desc, head, entry, next) {
313304
int err;

plugins/meson.build

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ if host_os == 'windows'
5757
command: dlltool_cmd
5858
)
5959
endif
60+
61+
user_ss.add(files('user.c'))
62+
system_ss.add(files('system.c'))
63+
64+
common_ss.add(files('loader.c'))
65+
6066
specific_ss.add(files(
61-
'loader.c',
6267
'core.c',
6368
'api.c',
6469
))

plugins/plugin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,10 @@ struct qemu_plugin_scoreboard *plugin_scoreboard_new(size_t element_size);
119119

120120
void plugin_scoreboard_free(struct qemu_plugin_scoreboard *score);
121121

122+
/**
123+
* qemu_plugin_fillin_mode_info() - populate mode specific info
124+
* info: pointer to qemu_info_t structure
125+
*/
126+
void qemu_plugin_fillin_mode_info(qemu_info_t *info);
127+
122128
#endif /* PLUGIN_H */

plugins/system.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* QEMU Plugin system-emulation helpers
3+
*
4+
* Helpers that are specific to system emulation.
5+
*
6+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
7+
* Copyright (C) 2019-2025, Linaro
8+
*
9+
* SPDX-License-Identifier: GPL-2.0-or-later
10+
*/
11+
12+
#include "qemu/osdep.h"
13+
#include "qemu/plugin.h"
14+
#include "hw/boards.h"
15+
16+
#include "plugin.h"
17+
18+
void qemu_plugin_fillin_mode_info(qemu_info_t *info)
19+
{
20+
MachineState *ms = MACHINE(qdev_get_machine());
21+
info->system_emulation = true;
22+
info->system.smp_vcpus = ms->smp.cpus;
23+
info->system.max_vcpus = ms->smp.max_cpus;
24+
}

plugins/user.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* QEMU Plugin user-mode helpers
3+
*
4+
* Helpers that are specific to user-mode.
5+
*
6+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
7+
* Copyright (C) 2019-2025, Linaro
8+
*
9+
* SPDX-License-Identifier: GPL-2.0-or-later
10+
*/
11+
12+
#include "qemu/osdep.h"
13+
#include "qemu/plugin.h"
14+
#include "plugin.h"
15+
16+
void qemu_plugin_fillin_mode_info(qemu_info_t *info)
17+
{
18+
info->system_emulation = false;
19+
}

0 commit comments

Comments
 (0)