[RFC PATCH 02/16] MIPS: bpf: Add emit_load_cpu helper to load current CPU ID

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

 



Add a helper function to load rA with the current CPU ID. This replaces
the inline version. The SEEN_OFF flag appears redundant as the offset is
a compile time constant and can be inlined into the emitted load
instruction.

Signed-off-by: Matt Redfearn <matt.redfearn@xxxxxxxx>
---

 arch/mips/net/bpf_jit.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
index 44b925005dd3..ae2ff1f08d5a 100644
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -518,6 +518,14 @@ static inline void emit_jr(unsigned int reg, struct jit_ctx *ctx)
 	emit_instr(ctx, jr, reg);
 }
 
+static inline void emit_load_cpu(unsigned int reg, struct jit_ctx *ctx)
+{
+	/* A = current_thread_info()->cpu */
+	BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info, cpu) != 4);
+	/* $28/gp points to the thread_info struct */
+	emit_load(reg, 28, offsetof(struct thread_info, cpu), ctx);
+}
+
 static inline u16 align_sp(unsigned int num)
 {
 	/* Double word alignment for 32-bit, quadword for 64-bit */
@@ -1115,14 +1123,9 @@ static int build_body(struct jit_ctx *ctx)
 			}
 #endif
 			break;
-		case BPF_ANC | SKF_AD_CPU:
-			ctx->flags |= SEEN_A | SEEN_OFF;
-			/* A = current_thread_info()->cpu */
-			BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info,
-						  cpu) != 4);
-			off = offsetof(struct thread_info, cpu);
-			/* $28/gp points to the thread_info struct */
-			emit_load(r_A, 28, off, ctx);
+		case BPF_ANC |  SKF_AD_CPU:
+			ctx->flags |= SEEN_A;
+			emit_load_cpu(r_A, ctx);
 			break;
 		case BPF_ANC | SKF_AD_IFINDEX:
 			/* A = skb->dev->ifindex */
-- 
2.7.4



[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux