Changeset d48008d for lib


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

Location:
lib
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • 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.