Re: [RFC PATCH 3/5] LoongArch: Add BPF JIT support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/09/2022 10:52 AM, Tiezhu Yang wrote:

BPF programs are normally handled by a BPF interpreter, add BPF JIT
support for LoongArch to allow the kernel to generate native code
when a program is loaded into the kernel, this will significantly
speed-up processing of BPF programs.

Co-developed-by: Youling Tang <tangyouling@xxxxxxxxxxx>
Signed-off-by: Youling Tang <tangyouling@xxxxxxxxxxx>
Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
  arch/loongarch/Kbuild        |    1 +
  arch/loongarch/Kconfig       |    1 +
  arch/loongarch/net/Makefile  |    7 +
  arch/loongarch/net/bpf_jit.c | 1119 ++++++++++++++++++++++++++++++++++++++++++
  arch/loongarch/net/bpf_jit.h |  946 +++++++++++++++++++++++++++++++++++
  5 files changed, 2074 insertions(+)
  create mode 100644 arch/loongarch/net/Makefile
  create mode 100644 arch/loongarch/net/bpf_jit.c
  create mode 100644 arch/loongarch/net/bpf_jit.h
[...]
+static inline void emit_ldbu(union loongarch_instruction *insn,
+			     enum loongarch_gpr rd, enum loongarch_gpr rj, int imm)
+{
+	insn->reg2i12_format.opcode = ldbu_op;
+	insn->reg2i12_format.immediate = imm;
+	insn->reg2i12_format.rd = rd;
+	insn->reg2i12_format.rj = rj;
+}
+
+static inline void emit_ldhu(union loongarch_instruction *insn,
+			     enum loongarch_gpr rd, enum loongarch_gpr rj, int imm)
+{
+	insn->reg2i12_format.opcode = ldhu_op;
+	insn->reg2i12_format.immediate = imm;
+	insn->reg2i12_format.rd = rd;
+	insn->reg2i12_format.rj = rj;
+}
+
Hi, Tiezhu,

These emit_* functions are similar to each other. I'd suggest that
using macro warpper them and keep them in 'inst.h'.

One of ways like follows,

#define DEF_EMIT_REG2I12_FORMAT(NAME,OP) \
static inline void emit_##NAME(union loongarch_instruction *insn, \
                 enum loongarch_gpr rd, enum loongarch_gpr rj, int imm) \
{ \
    insn->reg2i12_format.opcode = OP; \
    insn->reg2i12_format.immediate = imm; \
    insn->reg2i12_format.rd = rd; \
    insn->reg2i12_format.rj = rj; \
}

DEF_EMIT_REG2I12_FORMAT(ldbu, ldbu_op)
DEF_EMIT_REG2I12_FORMAT(ldhu, ldhu_op)
...
[...]

Thanks,
Jinyang




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux