Skip to content

Commit

Permalink
tc: Set 'no_percpu' flag for compatible actions
Browse files Browse the repository at this point in the history
Recent changes in Linux kernel TC action subsystem introduced new
TCA_ACT_FLAGS_NO_PERCPU_STATS flag. The purpose of the flag is to request
action implementation to skip allocating action stats with expensive percpu
allocator and use regular built-in action stats instead. Such approach
significantly improves rule insertion rate and reduce memory usage for
hardware-offloaded rules that don't need benefits provided by percpu
allocated stats (improved software TC fast-path performance). Set the flag
for all compatible actions.

Modify acinclude.m4 to use OVS-internal pkt_cls.h implementation when
TCA_ACT_FLAGS is not defined by kernel headers and to manually define
struct nla_bitfield32 in netlink.h (new file) when it is not defined by
kernel headers.

Signed-off-by: Vlad Buslov <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
w1ldptr authored and shorman-netronome committed Nov 11, 2019
1 parent c0a1df2 commit 292d5bd
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
18 changes: 15 additions & 3 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,28 @@ AC_DEFUN([OVS_CHECK_LINUX], [
AM_CONDITIONAL(LINUX_ENABLED, test -n "$KBUILD")
])

dnl OVS_CHECK_LINUX_NETLINK
dnl
dnl Configure Linux netlink compat.
AC_DEFUN([OVS_CHECK_LINUX_NETLINK], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([#include <linux/netlink.h>], [
struct nla_bitfield32 x = { 0 };
])],
[AC_DEFINE([HAVE_NLA_BITFIELD32], [1],
[Define to 1 if struct nla_bitfield32 is available.])])
])

dnl OVS_CHECK_LINUX_TC
dnl
dnl Configure Linux tc compat.
AC_DEFUN([OVS_CHECK_LINUX_TC], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([#include <linux/pkt_cls.h>], [
int x = TCA_FLOWER_KEY_ENC_IP_TTL_MASK;
int x = TCA_ACT_FLAGS;
])],
[AC_DEFINE([HAVE_TCA_FLOWER_KEY_ENC_IP_TTL_MASK], [1],
[Define to 1 if TCA_FLOWER_KEY_ENC_IP_TTL_MASK is available.])])
[AC_DEFINE([HAVE_TCA_ACT_FLAGS], [1],
[Define to 1 if TCA_ACT_FLAGS is available.])])
AC_CHECK_MEMBERS([struct tcf_t.firstuse], [], [], [#include <linux/pkt_cls.h>])
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ OVS_CTAGS_IDENTIFIERS
AC_ARG_VAR(KARCH, [Kernel Architecture String])
AC_SUBST(KARCH)
OVS_CHECK_LINUX
OVS_CHECK_LINUX_NETLINK
OVS_CHECK_LINUX_TC
OVS_CHECK_LINUX_SCTP_CT
OVS_CHECK_DPDK
Expand Down
1 change: 1 addition & 0 deletions include/linux/automake.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
noinst_HEADERS += \
include/linux/netlink.h \
include/linux/netfilter/nf_conntrack_sctp.h \
include/linux/pkt_cls.h \
include/linux/tc_act/tc_mpls.h \
Expand Down
30 changes: 30 additions & 0 deletions include/linux/netlink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef __UAPI_LINUX_NETLINK_WRAPPER_H
#define __UAPI_LINUX_NETLINK_WRAPPER_H 1

#if !defined(__KERNEL__) && !defined(HAVE_NLA_BITFIELD32)

#include <linux/types.h>

/* Generic 32 bitflags attribute content sent to the kernel.
*
* The value is a bitmap that defines the values being set
* The selector is a bitmask that defines which value is legit
*
* Examples:
* value = 0x0, and selector = 0x1
* implies we are selecting bit 1 and we want to set its value to 0.
*
* value = 0x2, and selector = 0x2
* implies we are selecting bit 2 and we want to set its value to 1.
*
*/
struct nla_bitfield32 {
__u32 value;
__u32 selector;
};

#endif /* !__KERNEL__ && !HAVE_NLA_BITFIELD32 */

#include_next <linux/netlink.h>

#endif /* __UAPI_LINUX_NETLINK_WRAPPER_H */
7 changes: 6 additions & 1 deletion include/linux/pkt_cls.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __LINUX_PKT_CLS_WRAPPER_H
#define __LINUX_PKT_CLS_WRAPPER_H 1

#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_ENC_IP_TTL_MASK)
#if defined(__KERNEL__) || defined(HAVE_TCA_ACT_FLAGS)
#include_next <linux/pkt_cls.h>
#else

Expand All @@ -17,9 +17,14 @@ enum {
TCA_ACT_STATS,
TCA_ACT_PAD,
TCA_ACT_COOKIE,
TCA_ACT_FLAGS,
__TCA_ACT_MAX
};

#define TCA_ACT_FLAGS_NO_PERCPU_STATS 1 /* Don't use percpu allocator for
* actions stats.
*/

#define TCA_ACT_MAX __TCA_ACT_MAX
#define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
#define TCA_ACT_MAX_PRIO 32
Expand Down
15 changes: 15 additions & 0 deletions lib/tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,14 @@ nl_msg_put_act_cookie(struct ofpbuf *request, struct tc_cookie *ck) {
}
}

static inline void
nl_msg_put_act_flags(struct ofpbuf *request) {
struct nla_bitfield32 act_flags = { TCA_ACT_FLAGS_NO_PERCPU_STATS,
TCA_ACT_FLAGS_NO_PERCPU_STATS };

nl_msg_put_unspec(request, TCA_ACT_FLAGS, &act_flags, sizeof act_flags);
}

/* Given flower, a key_to_pedit map entry, calculates the rest,
* where:
*
Expand Down Expand Up @@ -2129,6 +2137,7 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
if (flower->tunnel) {
act_offset = nl_msg_start_nested(request, act_index++);
nl_msg_put_act_tunnel_key_release(request);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}

Expand All @@ -2146,6 +2155,7 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
if (flower->csum_update_flags) {
act_offset = nl_msg_start_nested(request, act_index++);
nl_msg_put_act_csum(request, flower->csum_update_flags);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}
}
Expand All @@ -2163,12 +2173,14 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
action->encap.ttl,
action->encap.data,
action->encap.no_csum);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}
break;
case TC_ACT_VLAN_POP: {
act_offset = nl_msg_start_nested(request, act_index++);
nl_msg_put_act_pop_vlan(request);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}
break;
Expand All @@ -2178,6 +2190,7 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
action->vlan.vlan_push_tpid,
action->vlan.vlan_push_id,
action->vlan.vlan_push_prio);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}
break;
Expand Down Expand Up @@ -2239,6 +2252,7 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
}
}
nl_msg_put_act_cookie(request, &flower->act_cookie);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}
break;
Expand All @@ -2249,6 +2263,7 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
act_offset = nl_msg_start_nested(request, act_index++);
nl_msg_put_act_drop(request);
nl_msg_put_act_cookie(request, &flower->act_cookie);
nl_msg_put_act_flags(request);
nl_msg_end_nested(request, act_offset);
}
nl_msg_end_nested(request, offset);
Expand Down

0 comments on commit 292d5bd

Please sign in to comment.