Skip to contentSkip to conversation

tb-annotation: Added annotation XML file parser

RFC PATCH New Peer Adelt 1 participant 3 messages Jan 8, 2016 Kbuild

lore
Share & tools
lore

Peer Adelt

author
#0 lore raw

RFC PATCH 1/3 tb-annotation: Added annotation XML file parser

The XML file contains a control flow graph, where each edge is annotated with a context-dependent value. The parser reads this information into a data structure within CPUState.

---
 include/qom/cpu.h                            |   9 ++
 include/tb-annotation/tb-annotation-parser.h |  29 +++++
 include/tb-annotation/tb-annotation.h        |  64 ++++++++++
 tb-annotation/tb-annotation-parser.c         | 174 +++++++++++++++++++++++++++
 4 files changed, 276 insertions(+)
 create mode 100644 include/tb-annotation/tb-annotation-parser.h
 create mode 100644 include/tb-annotation/tb-annotation.h
 create mode 100644 tb-annotation/tb-annotation-parser.c
include/qom/cpu.h +9 -0
index 51a1323..afc532b 100644
@@ -30,6 +30,10 @@
 #include "qemu/thread.h"
 #include "qemu/typedefs.h"
 
+#ifdef CONFIG_TB_ANNOTATION
+#include "tb-annotation/tb-annotation.h"
+#endif
+
 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
                                      void *opaque);
 
@@ -329,6 +333,11 @@ struct CPUState {
      */
     bool throttle_thread_scheduled;
 
+#ifdef CONFIG_TB_ANNOTATION
+    /* Used to annotate cpu state during tb execution */
+    TbAnnotation *tb_annotation;
+#endif
+
     /* Note that this is accessed at the start of every TB via a negative
        offset from AREG0.  Leave this field at the end so as to make the
        (absolute value) offset as small as possible.  This reduces code
include/tb-annotation/tb-annotation-parser.h new file +29 -0
new file mode 100644
index 0000000..aacab8e
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (c) 2015-2016 Bastian Koppelmann
+ *                          Peer Adelt
+ *                          C-Lab/Paderborn University
+ *
+ * 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/>.
+ */
+
+#ifndef INCLUDE_TB_ANNOTATION_PARSER_H_
+#define INCLUDE_TB_ANNOTATION_PARSER_H_
+
+#include "tb-annotation/tb-annotation.h"
+
+void tb_annotation_xml_init(const char *filename);
+void tb_annotation_xml_close(void);
+TbAnnotation *tb_annotation_parse(const char *filename);
+
+#endif /* INCLUDE_TB_ANNOTATION_PARSER_H_ */
include/tb-annotation/tb-annotation.h new file +64 -0

64 lines not on this page · raw message

tb-annotation/tb-annotation-parser.c new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
2.5.0
author
#1 lore raw

RFC PATCH 2/3 tb-annotation: Add control flow graph mapper

Added helper function at the start of every TranslationBlock that maps the sequence of static basic blocks (obtained from the XML file) to the current TranslationBlock. The helper also accumulates the values that are annotated on the corresponding edges of the control flow graph.

---
 include/exec/gen-icount.h | 18 +++++++++
 tcg-runtime.c             | 99 +++++++++++++++++++++++++++++++++++++++++++++++
 tcg/tcg-runtime.h         |  4 ++
 3 files changed, 121 insertions(+)
include/exec/gen-icount.h +18 -0
index 05d89d3..0b8821b 100644
@@ -14,6 +14,11 @@ static inline void gen_tb_start(TranslationBlock *tb)
     TCGv_i32 count, flag, imm;
     int i;
 
+#ifdef CONFIG_TB_ANNOTATION
+    TCGv_ptr annotation_ptr;
+    TCGv_i64 pc;
+#endif
+
     exitreq_label = gen_new_label();
     flag = tcg_temp_new_i32();
     tcg_gen_ld_i32(flag, cpu_env,
@@ -21,6 +26,17 @@ static inline void gen_tb_start(TranslationBlock *tb)
     tcg_gen_brcondi_i32(TCG_COND_NE, flag, 0, exitreq_label);
     tcg_temp_free_i32(flag);
 
+#ifdef CONFIG_TB_ANNOTATION
+    pc = tcg_const_i64(tb->pc);
+    annotation_ptr = tcg_temp_new_ptr();
+    tcg_gen_ld_ptr(annotation_ptr, cpu_env,
+                   -ENV_OFFSET + offsetof(CPUState, tb_annotation));
+
+    gen_helper_annotation(pc, annotation_ptr);
+    tcg_temp_free_i64(pc);
+    tcg_temp_free_ptr(annotation_ptr);
+#endif
+
     if (!(tb->cflags & CF_USE_ICOUNT)) {
         return;
     }
@@ -45,6 +61,8 @@ static inline void gen_tb_start(TranslationBlock *tb)
     tcg_gen_st16_i32(count, cpu_env,
                      -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low));
     tcg_temp_free_i32(count);
+
+
 }
 
 static void gen_tb_end(TranslationBlock *tb, int num_insns)
tcg-runtime.c +99 -0

108 lines not on this page · raw message

tcg/tcg-runtime.h +4 -0
index 23a0c37..004bf8f 100644
@@ -14,3 +14,7 @@ DEF_HELPER_FLAGS_2(sar_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
 
 DEF_HELPER_FLAGS_2(mulsh_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
 DEF_HELPER_FLAGS_2(muluh_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
+
+#ifdef CONFIG_TB_ANNOTATION
+DEF_HELPER_2(annotation, void, i64, ptr)
+#endif
Signature · 1 line
2.5.0
author
#2 lore raw

RFC PATCH 3/3 tb-annotation: Activate annotation extension

In reply to Peer Adelt

This changeset activates the TranslationBlock annotation mechanism for the QEMU system mode.

---
 Makefile                    |  5 +++--
 Makefile.objs               |  4 ++++
 Makefile.target             |  4 +++-
 configure                   | 13 +++++++++++++
 qemu-options.hx             |  8 ++++++++
 tb-annotation/Makefile.objs |  1 +
 vl.c                        | 25 +++++++++++++++++++++++++
 7 files changed, 57 insertions(+), 3 deletions(-)
 create mode 100644 tb-annotation/Makefile.objs
Makefile +3 -2
index 82b2fc8..c351b31 100644
@@ -161,7 +161,8 @@ dummy := $(call unnest-vars,, \
                 qom-obj-y \
                 io-obj-y \
                 common-obj-y \
-                common-obj-m)
+                common-obj-m \
+		annotation-obj-y)
 
 ifneq ($(wildcard config-host.mak),)
 include $(SRC_PATH)/tests/Makefile
@@ -204,7 +205,7 @@ subdir-dtc:dtc/libfdt dtc/tests
 dtc/%:
 	mkdir -p $@
 
-$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY))
+$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) $(annotation-obj-$(CONFIG_TB_ANNOTATION))
 
 ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
 romsubdir-%:
Makefile.objs +4 -0
index dac2c02..9b64358 100644
@@ -116,3 +116,7 @@ qga-vss-dll-obj-y = qga/
 # contrib
 ivshmem-client-obj-y = contrib/ivshmem-client/
 ivshmem-server-obj-y = contrib/ivshmem-server/
+
+######################################################################
+# annotation
+annotation-obj-y = tb-annotation/
\ No newline at end of file
Makefile.target +3 -1
index 34ddb7e..50a969d 100644
@@ -178,7 +178,8 @@ dummy := $(call unnest-vars,.., \
                qom-obj-y \
                io-obj-y \
                common-obj-y \
-               common-obj-m)
+               common-obj-m \
+               annotation-obj-y)
 target-obj-y := $(target-obj-y-save)
 all-obj-y += $(common-obj-y)
 all-obj-y += $(target-obj-y)
@@ -187,6 +188,7 @@ all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
 all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
+all-obj-$(CONFIG_TB_ANNOTATION) += $(annotation-obj-y)
 
 $(QEMU_PROG_BUILD): config-devices.mak
 
configure +13 -0
index 83b40fc..5e72e06 100755
@@ -345,6 +345,7 @@ vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
+tbannotation="no"
 
 # parse CC options first
 for opt do
@@ -1169,6 +1170,10 @@ for opt do
   ;;
   --enable-jemalloc) jemalloc="yes"
   ;;
+  --disable-tbannotation) tbannotation="no"
+  ;;
+  --enable-tbannotation) tbannotation="yes"
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1391,6 +1396,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   numa            libnuma support
   tcmalloc        tcmalloc support
   jemalloc        jemalloc support
+  tbannotation    TB annotation support
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -4855,6 +4861,7 @@ echo "bzip2 support     $bzip2"
 echo "NUMA host support $numa"
 echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
+echo "TB annotation support $tbannotation"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -5400,6 +5407,12 @@ if test "$rdma" = "yes" ; then
   echo "CONFIG_RDMA=y" >> $config_host_mak
 fi
 
+if test "$tbannotation" = "yes" ; then
+  echo "CONFIG_TB_ANNOTATION=y" >> $config_host_mak
+  echo "LIBS+=-lxml2" >> $config_host_mak
+  QEMU_CFLAGS="-I/usr/include/libxml2 $QEMU_CFLAGS"
+fi
+
 # Hold two types of flag:
 #   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
 #                                     a thread we have a handle to
qemu-options.hx +8 -0
index 215d00d..e3d9df9 100644
@@ -2737,6 +2737,14 @@ Use @var{bzImage} as kernel image. The kernel can be either a Linux kernel
 or in multiboot format.
 ETEXI
 
+DEF("annotation", HAS_ARG, QEMU_OPTION_annotation, \
+    "-annotation tbAnnotation use 'tbAnnotation' as annotation file\n", QEMU_ARCH_ALL)
+STEXI
+@item -annotation @var{tbAnnotation}
+@findex -annotation
+Use @var{tbAnnotation} as annotation file. TODO: specify file format...
+ETEXI
+
 DEF("append", HAS_ARG, QEMU_OPTION_append, \
     "-append cmdline use 'cmdline' as kernel command line\n", QEMU_ARCH_ALL)
 STEXI
tb-annotation/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..468cd42
@@ -0,0 +1 @@
+annotation-obj-y += tb-annotation-parser.o
\ No newline at end of file
vl.c +25 -0
index 5aaea77..02bb11e 100644
@@ -125,6 +125,8 @@ int main(int argc, char **argv)
 #include "sysemu/replay.h"
 #include "qapi/qmp/qerror.h"
 
+#include "tb-annotation/tb-annotation-parser.h"
+
 #define MAX_VIRTIO_CONSOLES 1
 #define MAX_SCLP_CONSOLES 1
 
@@ -2971,6 +2973,10 @@ int main(int argc, char **argv, char **envp)
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;
+#ifdef CONFIG_TB_ANNOTATION
+    CPUState *cpu = NULL;
+    const char *annotation_filename = NULL;
+#endif
     const char *boot_order = NULL;
     const char *boot_once = NULL;
     DisplayState *ds;
@@ -4017,6 +4023,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+#ifdef CONFIG_TB_ANNOTATION
+            case QEMU_OPTION_annotation:
+                annotation_filename = optarg;
+                break;
+#endif
             default:
                 os_parse_cmd_args(popt->index, optarg);
             }
@@ -4629,6 +4640,20 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_creation_done();
 
+#ifdef CONFIG_TB_ANNOTATION
+    if (annotation_filename && (smp_cpus > 1 || smp_cores > 1)) {
+        perror("At the moment only single CPU/core systems are supported " \
+               "by the annotation extension.");
+        exit(1);
+    }
+    if (annotation_filename) {
+        cpu = qemu_get_cpu(0);
+        if (cpu != NULL) {
+            cpu->tb_annotation = tb_annotation_parse(annotation_filename);
+        }
+    }
+#endif
+
     /* TODO: once all bus devices are qdevified, this should be done
      * when bus is created by qdev.c */
     qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
Signature · 1 line
2.5.0