From 3b7e0318a4eda679f2409ebe9a0327ceda6ff1ea Mon Sep 17 00:00:00 2001 From: "Komal, Jain" Date: Thu, 24 Oct 2024 09:01:55 +0530 Subject: [PATCH] Addressed comments Signed-off-by: Komal, Jain --- backends/tc/ebpfCodeGen.h | 1 - backends/tc/tcExterns.cpp | 6 +- backends/tc/tcExterns.h | 4 +- .../digest_parser_meta_parser.h | 92 ------------------- .../hash_control_blocks.c | 2 +- 5 files changed, 9 insertions(+), 96 deletions(-) diff --git a/backends/tc/ebpfCodeGen.h b/backends/tc/ebpfCodeGen.h index 3c45ae1f4b..12cfabe8ec 100644 --- a/backends/tc/ebpfCodeGen.h +++ b/backends/tc/ebpfCodeGen.h @@ -293,7 +293,6 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA { } EBPFHashPNA *getHash(cstring name) const { auto result = ::P4::get(pna_hashes, name); - BUG_CHECK(result != nullptr, "No hash named %1%", name); return result; } void emitExternDefinition(EBPF::CodeBuilder *builder) { diff --git a/backends/tc/tcExterns.cpp b/backends/tc/tcExterns.cpp index c607f9998b..ea9b4ec974 100644 --- a/backends/tc/tcExterns.cpp +++ b/backends/tc/tcExterns.cpp @@ -481,7 +481,11 @@ void EBPFHashPNA::calculateHash(EBPF::CodeBuilder *builder, const IR::MethodCall } void CRCChecksumAlgorithmPNA::emitGet(EBPF::CodeBuilder *builder) { - builder->appendFormat("%s", registerVar.c_str()); + if (crcWidth == 16) { + builder->appendFormat("%s", registerVar.c_str()); + } else { + builder->appendFormat("%s ^ 0xFFFFFFFF", registerVar.c_str()); + } } void CRCChecksumAlgorithmPNA::emitAddData(EBPF::CodeBuilder *builder, int dataPos, diff --git a/backends/tc/tcExterns.h b/backends/tc/tcExterns.h index e26e65f1a8..0cc14e9e42 100644 --- a/backends/tc/tcExterns.h +++ b/backends/tc/tcExterns.h @@ -192,12 +192,14 @@ class CRCChecksumAlgorithmPNA : public EBPF::CRCChecksumAlgorithm { public: CRCChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name, int width) : EBPF::CRCChecksumAlgorithm(program, name, width) { + BUG_CHECK(width == 16 || width == 32, "Must be 16 bits width or 32 bits width."); initialValue = "0"_cs; } void emitGet(EBPF::CodeBuilder *builder) override; void emitAddData(EBPF::CodeBuilder *builder, const ArgumentsList &arguments, const IR::MethodCallExpression *expr); - void emitAddData(EBPF::CodeBuilder *builder, int dataPos, const IR::MethodCallExpression *expr); + void emitAddData(EBPF::CodeBuilder *builder, int dataPos, + const IR::MethodCallExpression *expr) override; }; class EBPFDigestPNA : public EBPF::EBPFDigestPSA { diff --git a/testdata/p4tc_samples_outputs/digest_parser_meta_parser.h b/testdata/p4tc_samples_outputs/digest_parser_meta_parser.h index ff5a50baff..3f9ca35c9c 100644 --- a/testdata/p4tc_samples_outputs/digest_parser_meta_parser.h +++ b/testdata/p4tc_samples_outputs/digest_parser_meta_parser.h @@ -66,95 +66,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/hash_control_blocks.c b/testdata/p4tc_samples_outputs/hash_control_blocks.c index d208b44851..9a924b31d5 100644 --- a/testdata/p4tc_samples_outputs/hash_control_blocks.c +++ b/testdata/p4tc_samples_outputs/hash_control_blocks.c @@ -39,7 +39,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head bpf_p4tc_ext_hash_crc32(&hdr->crc.f3, sizeof(hdr->crc.f3), ingress_h_reg); bpf_p4tc_ext_hash_crc32(&hdr->crc.f4, sizeof(hdr->crc.f4), ingress_h_reg); hdr->crc.crc = /* h_0.get_hash({hdr->crc.f1, hdr->crc.f2, hdr->crc.f3, hdr->crc.f4}) */ -ingress_h_reg; +ingress_h_reg ^ 0xFFFFFFFF; } } {