Hello Thomas,

On 12/08/2016 09:12 AM, Thomas Graf wrote:
On 7 December 2016 at 22:06, Mauricio Vasquez via iovisor-dev
<[email protected]> wrote:
BPF_TABLE("array", u32, struct rt_entry, routing_table, ROUTING_TABLE_DIM);

static int handle_rx(void *skb, struct metadata *md) {
   u8 *cursor = 0;
   struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));

   int i = 0;
   struct rt_entry *rt_entry_p = 0;
   u32 ip_dst_masked = 0;

   //#pragma unroll
   #pragma clang loop unroll(full)
   for (i = 0; i < ROUTING_TABLE_DIM; i++) {
     rt_entry_p = routing_table.lookup(&i);
Might be because you pass a pointer here?

We have been analyzing it into more detail, effectively passing a pointer to that function prevents the loop unrolling. My guessing is that in some way the compiler thinks that the counter could be modify in that function then the unrolling is not possible. We implemented the loop in the following way, it works. However we still consider that it is a workaround and that a solution without workarounds should exist.

  #pragma unroll
  for (int i = 0; i < ROUTING_TABLE_DIM; i++) {
    int xxx = i;
    rt_entry_p = routing_table.lookup(&xxx);
    if (rt_entry_p) {
      ip_dst_masked = ip->dst & rt_entry_p->netmask;
      if (ip_dst_masked == rt_entry_p->network) {
        goto FORWARD;
      }
    }
  }

We think that this behavior is caused by the lack of the const qualifier for the key argument in the lookup function [1].

Thanks very much for your help.

Mauricio

[1] https://lists.iovisor.org/pipermail/iovisor-dev/2016-December/000559.html


     if (rt_entry_p) {
       ip_dst_masked = ip->dst & rt_entry_p->netmask;
       if (ip_dst_masked == rt_entry_p->network) {
         goto FORWARD;
       }
     }
   }

DROP:
   return RX_DROP;

FORWARD:
   pkt_redirect(skb,md, rt_entry_p->port);
   return RX_REDIRECT;
}

Do you have any idea why clang is not unrolling that loop?
It is working fine for us here and we're just using the standard unroll pragma:
https://github.com/cilium/cilium/blob/master/bpf/lib/l3.h#L131


_______________________________________________
iovisor-dev mailing list
[email protected]
https://lists.iovisor.org/mailman/listinfo/iovisor-dev

Reply via email to