Changeset d48008d


Ignore:
Timestamp:
05/16/10 21:34:48 (11 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
c3f597e
Parents:
9da93dc
Message:

Add JITting of BPF bytecode using LLVM

Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • configure.in

    rf1ab057 rd48008d  
    5555if test "$GCC" = "yes"; then
    5656        CFLAGS="$CFLAGS -Wall -Wextra -Wmissing-prototypes -O2"
     57        CXXFLAGS="$CXXFLAGS -Wall -Wextra -O2"
    5758# We assume that gcc knows about -fvisibility and friends, as I can't see
    5859# a good easy way of testing for it here.
     
    6061        LIBCFLAGS="$LIBCFLAGS -DLT_BUILDING_DLL=1"
    6162        LIBCFLAGS="$LIBCFLAGS -fvisibility=hidden"
     63        LIBCXXFLAGS="$CXXFLAGS"
     64        LIBCXXFLAGS="$CXXFLAGS -DLT_BUILDING_DLL=1"
     65        LIBCXXFLAGS="$CXXFLAGS -fvisibility=hidden"
    6266fi
    6367
     
    277281AC_SEARCH_LIBS(mvprintw, ncurses, [], [ AC_MSG_ERROR([NCurses library not available]) ])
    278282
     283AC_ARG_WITH([llvm],
     284        [AC_HELP_STRING([--with-llvm],
     285                [support Just In Time compiler])],
     286        use_llvm="yes",
     287        use_llvm="check")
     288
     289AC_PATH_PROG(llvm_config, llvm-config)
     290
     291if (test "$use_llvm" != "no"); then
     292        AC_PATH_PROG(LLVM_CONFIG, llvm-config, no)
     293        if test "$LLVM_CONFIG" = "no" ; then
     294                AC_MSG_NOTICE([Unable to find llvm-config.  JIT support disabled.])
     295                JIT=no
     296        else
     297                LIBCXXFLAGS="`$LLVM_CONFIG --cxxflags` $CXXFLAGS"
     298                ADD_LIBS="$ADD_LIBS `$LLVM_CONFIG --libs all`";
     299                LDFLAGS="`$LLVM_CONFIG --ldflags` $LDFLAGS";
     300                JIT=yes
     301                AC_DEFINE(HAVE_LLVM, 1, [Set to 1 if you have LLVM installed])
     302        fi
     303fi
     304
     305
    279306AM_CONDITIONAL([HAVE_BPF_CAPTURE], [test "$ac_cv_have_decl_BIOCSETIF" = yes ])
    280307AM_CONDITIONAL([HAVE_DAG], [test "$libtrace_dag" = true])
     
    287314AM_CONDITIONAL([HAVE_NETPACKET_PACKET_H], [test "$libtrace_netpacket_packet_h" = true])
    288315AM_CONDITIONAL([HAVE_LIBGDC], [test "$ac_cv_header_gdc_h" = yes])
     316AM_CONDITIONAL([HAVE_LLVM], [test "x$LLVM_CONFIG" != "xno" ])
    289317
    290318# Check for miscellaneous programs
     
    305333AC_SUBST([HAVE_BPF_CAPTURE])
    306334AC_SUBST([HAVE_LIBGDC])
     335AC_SUBST([HAVE_LLVM])
    307336AC_SUBST([LIBCFLAGS])
     337AC_SUBST([LIBCXXFLAGS])
    308338dnl and finally, output our Makefiles
    309339AC_OUTPUT
     
    334364        AC_MSG_NOTICE([Compiled with DAG live capture support: No])
    335365fi
     366reportopt "Compiled with LLVM BPF JIT support" $JIT
    336367reportopt "Building man pages/documentation" $libtrace_doxygen
    337368
  • lib/Makefile.am

    rf1ab057 rd48008d  
    33
    44AM_CFLAGS=@LIBCFLAGS@
     5AM_CXXFLAGS=@LIBCXXFLAGS@
    56
    67extra_DIST = format_template.c
     
    4647EXTRA_DIST=format_dag24.c format_dag25.c
    4748
     49if HAVE_LLVM
     50BPFJITSOURCE=bpf-jit/bpf-jit.cc
     51else
     52BPFJITSOURCE=
     53endif
     54
     55
    4856libtrace_la_SOURCES = trace.c common.h \
    4957                format_erf.c format_pcap.c format_legacy.c \
     
    5664                protocols_transport.c protocols.h \
    5765                $(DAGSOURCE) format_erf.h \
     66                $(BPFJITSOURCE) \
    5867                $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO) \
    5968                ior-peek.c ior-stdio.c ior-thread.c \
     
    7483dagopts.c:
    7584        cp @DAG_TOOLS_DIR@/dagopts.c .
     85
     86if HAVE_LLVM
     87# Rules to build the llvm .cc file from a C description of each opcode.
     88bpf-jit/bpf-opcodes.llvm.bc: bpf-jit/bpf-opcodes.c
     89        `$(LLVM_CONFIG) --bindir`/llvm-gcc -std=c99 -c -O0 -emit-llvm $< -o $@
     90
     91bpf-jit/bpf-opcodes.llvm.cc: bpf-jit/bpf-opcodes.llvm.bc
     92        `$(LLVM_CONFIG) --bindir`/llc -f -march=cpp -cppgen=module $< -o $@
     93
     94bpf-jit/bpf-jit.cc: bpf-jit/bpf-opcodes.llvm.cc
     95
     96EXTRA_DIST+=bpf-jit/bpf-opcodes.c
     97BUILT_SOURCES=bpf-jit/bpf-opcodes.llvm.cc
     98endif
     99CLEANFILES=bpf-jit/bpf-opcodes.llvm.cc bpf-jit/bpf-opcodes.llvm.bc
  • lib/trace.c

    rf6e8d46 rd48008d  
    11031103        filter->filter.bf_len = bf_len;
    11041104        filter->filterstring = NULL;
     1105        filter->jitfilter = NULL;
    11051106        /* "flag" indicates that the filter member is valid */
    11061107        filter->flag = 1;
     
    11191120                                malloc(sizeof(libtrace_filter_t));
    11201121        filter->filterstring = strdup(filterstring);
     1122        filter->jitfilter = NULL;
    11211123        filter->flag = 0;
    11221124        return filter;
     
    11331135        if (filter->flag)
    11341136                pcap_freecode(&filter->filter);
     1137#ifdef HAVE_LLVM
     1138        if (filter->jitfilter)
     1139                destroy_program(filter->jitfilter);
     1140#endif
    11351141        free(filter);
    11361142#else
     
    12571263        }
    12581264
     1265        /* If we're jitting, we may need to JIT the BPF code now too */
     1266#if HAVE_LLVM
     1267        if (!filter->jitfilter) {
     1268                filter->jitfilter = compile_program(filter->filter.bf_insns, filter->filter.bf_len);
     1269        }
     1270#endif
     1271
    12591272        assert(filter->flag);
     1273        /* Now execute the filter */
     1274#if HAVE_LLVM
     1275        ret=filter->jitfilter->bpf_run((unsigned char *)linkptr, clen);
     1276#else
    12601277        ret=bpf_filter(filter->filter.bf_insns,(u_char*)linkptr,(unsigned int)clen,(unsigned int)clen);
     1278#endif
    12611279
    12621280        /* If we copied the packet earlier, make sure that we free it */
Note: See TracChangeset for help on using the changeset viewer.