diff mbox

[RFC,v2,05/34] translate: Listify tcg_exec_init

Message ID f9bc8e15a7166ec38943d1c16c662fa58f35c0d4.1433052532.git.crosthwaite.peter@gmail.com
State New
Headers show

Commit Message

Peter Crosthwaite May 31, 2015, 6:11 a.m. UTC
Create a global list of tcg_exec_init functions that is populated at
startup. Multiple translation engines can register an init function
and all will be called on the master call to tcg_exec_init.

Introduce a new module, translate-common. This is a common-obj for
translation functionality such as this.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
---
 Makefile.objs         |  1 +
 include/qemu-common.h |  1 +
 translate-all.c       |  7 ++++++-
 translate-common.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 translate-common.c

Comments

Richard Henderson June 1, 2015, 7:17 p.m. UTC | #1
On 05/30/2015 11:11 PM, Peter Crosthwaite wrote:
> Create a global list of tcg_exec_init functions that is populated at
> startup. Multiple translation engines can register an init function
> and all will be called on the master call to tcg_exec_init.
> 
> Introduce a new module, translate-common. This is a common-obj for
> translation functionality such as this.
> 
> Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
> ---
>  Makefile.objs         |  1 +
>  include/qemu-common.h |  1 +
>  translate-all.c       |  7 ++++++-
>  translate-common.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 58 insertions(+), 1 deletion(-)
>  create mode 100644 translate-common.c

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~
Peter Crosthwaite July 10, 2015, 10:15 a.m. UTC | #2
On Sat, May 30, 2015 at 11:11 PM, Peter Crosthwaite
<crosthwaitepeter@gmail.com> wrote:
> Create a global list of tcg_exec_init functions that is populated at
> startup. Multiple translation engines can register an init function
> and all will be called on the master call to tcg_exec_init.
>
> Introduce a new module, translate-common. This is a common-obj for
> translation functionality such as this.
>
> Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
> ---
>  Makefile.objs         |  1 +
>  include/qemu-common.h |  1 +
>  translate-all.c       |  7 ++++++-
>  translate-common.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 58 insertions(+), 1 deletion(-)
>  create mode 100644 translate-common.c
>
> diff --git a/Makefile.objs b/Makefile.objs
> index 4881d2c..294016e 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -67,6 +67,7 @@ common-obj-y += dma-helpers.o
>  common-obj-y += vl.o
>  vl.o-cflags := $(GPROF_CFLAGS) $(SDL_CFLAGS)
>  common-obj-y += tpm.o
> +common-obj-y += translate-common.o
>

The functions added to this module needed to accessible from
linux-user so this has to be an obj-y.

Regards,
Peter

>  common-obj-$(CONFIG_SLIRP) += slirp/
>
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 6b373ff..88fbcfa 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -263,6 +263,7 @@ typedef struct PCIHostDeviceAddress {
>      unsigned int function;
>  } PCIHostDeviceAddress;
>
> +void tcg_exec_init_add(void (*fn)(unsigned long));
>  void tcg_exec_init(unsigned long tb_size);
>  bool tcg_enabled(void);
>
> diff --git a/translate-all.c b/translate-all.c
> index 62042af..b2edfb4 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -677,7 +677,7 @@ static inline void code_gen_alloc(size_t tb_size)
>  /* Must be called before using the QEMU cpus. 'tb_size' is the size
>     (in bytes) allocated to the translation buffer. Zero means default
>     size. */
> -void tcg_exec_init(unsigned long tb_size)
> +static void do_tcg_exec_init(unsigned long tb_size)
>  {
>      cpu_gen_init();
>      code_gen_alloc(tb_size);
> @@ -691,6 +691,11 @@ void tcg_exec_init(unsigned long tb_size)
>  #endif
>  }
>
> +static __attribute__((constructor)) void register_tcg_exec_init(void)
> +{
> +    tcg_exec_init_add(do_tcg_exec_init);
> +}
> +
>  bool tcg_enabled(void)
>  {
>      return tcg_ctx.code_gen_buffer != NULL;
> diff --git a/translate-common.c b/translate-common.c
> new file mode 100644
> index 0000000..563ae5a
> --- /dev/null
> +++ b/translate-common.c
> @@ -0,0 +1,50 @@
> +/*
> + *  Host code generation common components
> + *
> + *  Copyright (c) 2015 Peter Crosthwaite <crosthwaite.peter@gmail.com>
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "qemu-common.h"
> +
> +typedef struct TCGExecInitFn {
> +    void (*do_tcg_exec_init)(unsigned long tb_size);
> +    QLIST_ENTRY(TCGExecInitFn) list;
> +} TCGExecInitFn;
> +
> +static QLIST_HEAD(, TCGExecInitFn) tcg_exec_init_list;
> +
> +void tcg_exec_init_add(void (*fn)(unsigned long))
> +{
> +    static bool inited;
> +    TCGExecInitFn *lelem = g_malloc0(sizeof *lelem);
> +
> +    if (!inited) {
> +        inited = true;
> +        QLIST_INIT(&tcg_exec_init_list);
> +    }
> +
> +    lelem->do_tcg_exec_init = fn;
> +    QLIST_INSERT_HEAD(&tcg_exec_init_list, lelem, list);
> +}
> +
> +void tcg_exec_init(unsigned long tb_size)
> +{
> +    TCGExecInitFn *t;
> +
> +    QLIST_FOREACH(t, &tcg_exec_init_list, list) {
> +        t->do_tcg_exec_init(tb_size);
> +    }
> +}
> --
> 1.9.1
>
>
Peter Crosthwaite July 11, 2015, 9:16 a.m. UTC | #3
On Fri, Jul 10, 2015 at 3:15 AM, Peter Crosthwaite
<peter.crosthwaite@xilinx.com> wrote:
> On Sat, May 30, 2015 at 11:11 PM, Peter Crosthwaite
> <crosthwaitepeter@gmail.com> wrote:
>> Create a global list of tcg_exec_init functions that is populated at
>> startup. Multiple translation engines can register an init function
>> and all will be called on the master call to tcg_exec_init.
>>
>> Introduce a new module, translate-common. This is a common-obj for
>> translation functionality such as this.
>>
>> Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
>> ---
>>  Makefile.objs         |  1 +
>>  include/qemu-common.h |  1 +
>>  translate-all.c       |  7 ++++++-
>>  translate-common.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>  4 files changed, 58 insertions(+), 1 deletion(-)
>>  create mode 100644 translate-common.c
>>
>> diff --git a/Makefile.objs b/Makefile.objs
>> index 4881d2c..294016e 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -67,6 +67,7 @@ common-obj-y += dma-helpers.o
>>  common-obj-y += vl.o
>>  vl.o-cflags := $(GPROF_CFLAGS) $(SDL_CFLAGS)
>>  common-obj-y += tpm.o
>> +common-obj-y += translate-common.o
>>
>
> The functions added to this module needed to accessible from
> linux-user so this has to be an obj-y.
>

Fixed.

Regards,
Peter
diff mbox

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 4881d2c..294016e 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -67,6 +67,7 @@  common-obj-y += dma-helpers.o
 common-obj-y += vl.o
 vl.o-cflags := $(GPROF_CFLAGS) $(SDL_CFLAGS)
 common-obj-y += tpm.o
+common-obj-y += translate-common.o
 
 common-obj-$(CONFIG_SLIRP) += slirp/
 
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 6b373ff..88fbcfa 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -263,6 +263,7 @@  typedef struct PCIHostDeviceAddress {
     unsigned int function;
 } PCIHostDeviceAddress;
 
+void tcg_exec_init_add(void (*fn)(unsigned long));
 void tcg_exec_init(unsigned long tb_size);
 bool tcg_enabled(void);
 
diff --git a/translate-all.c b/translate-all.c
index 62042af..b2edfb4 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -677,7 +677,7 @@  static inline void code_gen_alloc(size_t tb_size)
 /* Must be called before using the QEMU cpus. 'tb_size' is the size
    (in bytes) allocated to the translation buffer. Zero means default
    size. */
-void tcg_exec_init(unsigned long tb_size)
+static void do_tcg_exec_init(unsigned long tb_size)
 {
     cpu_gen_init();
     code_gen_alloc(tb_size);
@@ -691,6 +691,11 @@  void tcg_exec_init(unsigned long tb_size)
 #endif
 }
 
+static __attribute__((constructor)) void register_tcg_exec_init(void)
+{
+    tcg_exec_init_add(do_tcg_exec_init);
+}
+
 bool tcg_enabled(void)
 {
     return tcg_ctx.code_gen_buffer != NULL;
diff --git a/translate-common.c b/translate-common.c
new file mode 100644
index 0000000..563ae5a
--- /dev/null
+++ b/translate-common.c
@@ -0,0 +1,50 @@ 
+/*
+ *  Host code generation common components
+ *
+ *  Copyright (c) 2015 Peter Crosthwaite <crosthwaite.peter@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu-common.h"
+
+typedef struct TCGExecInitFn {
+    void (*do_tcg_exec_init)(unsigned long tb_size);
+    QLIST_ENTRY(TCGExecInitFn) list;
+} TCGExecInitFn;
+
+static QLIST_HEAD(, TCGExecInitFn) tcg_exec_init_list;
+
+void tcg_exec_init_add(void (*fn)(unsigned long))
+{
+    static bool inited;
+    TCGExecInitFn *lelem = g_malloc0(sizeof *lelem);
+
+    if (!inited) {
+        inited = true;
+        QLIST_INIT(&tcg_exec_init_list);
+    }
+
+    lelem->do_tcg_exec_init = fn;
+    QLIST_INSERT_HEAD(&tcg_exec_init_list, lelem, list);
+}
+
+void tcg_exec_init(unsigned long tb_size)
+{
+    TCGExecInitFn *t;
+
+    QLIST_FOREACH(t, &tcg_exec_init_list, list) {
+        t->do_tcg_exec_init(tb_size);
+    }
+}