diff mbox series

[net-next,06/13] net/sched: move police action structures to header

Message ID 20190504114628.14755-7-jakub.kicinski@netronome.com
State Accepted
Delegated to: David Miller
Headers show
Series net: act_police offload support | expand

Commit Message

Jakub Kicinski May 4, 2019, 11:46 a.m. UTC
From: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>

Move tcf_police_params, tcf_police and tc_police_compat structures to a
header. Making them usable to other code for example drivers that would
offload police actions to hardware.

Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 include/net/tc_act/tc_police.h | 70 ++++++++++++++++++++++++++++++++++
 net/sched/act_police.c         | 37 +-----------------
 2 files changed, 71 insertions(+), 36 deletions(-)
 create mode 100644 include/net/tc_act/tc_police.h

Comments

Jiri Pirko May 4, 2019, 1:04 p.m. UTC | #1
Sat, May 04, 2019 at 01:46:21PM CEST, jakub.kicinski@netronome.com wrote:
>From: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
>
>Move tcf_police_params, tcf_police and tc_police_compat structures to a
>header. Making them usable to other code for example drivers that would
>offload police actions to hardware.
>
>Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
>Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>

Note that Joergen Andreasen is pushing similar patch as a part of his
patchset:
[PATCH net-next 1/3] net/sched: act_police: move police parameters into separate header file



>---
> include/net/tc_act/tc_police.h | 70 ++++++++++++++++++++++++++++++++++
> net/sched/act_police.c         | 37 +-----------------
> 2 files changed, 71 insertions(+), 36 deletions(-)
> create mode 100644 include/net/tc_act/tc_police.h
>
>diff --git a/include/net/tc_act/tc_police.h b/include/net/tc_act/tc_police.h
>new file mode 100644
>index 000000000000..8b9ef3664262
>--- /dev/null
>+++ b/include/net/tc_act/tc_police.h
>@@ -0,0 +1,70 @@
>+/* SPDX-License-Identifier: GPL-2.0 */
>+#ifndef __NET_TC_POLICE_H
>+#define __NET_TC_POLICE_H
>+
>+#include <net/act_api.h>
>+
>+struct tcf_police_params {
>+	int			tcfp_result;
>+	u32			tcfp_ewma_rate;
>+	s64			tcfp_burst;
>+	u32			tcfp_mtu;
>+	s64			tcfp_mtu_ptoks;
>+	struct psched_ratecfg	rate;
>+	bool			rate_present;
>+	struct psched_ratecfg	peak;
>+	bool			peak_present;
>+	struct rcu_head rcu;
>+};
>+
>+struct tcf_police {
>+	struct tc_action	common;
>+	struct tcf_police_params __rcu *params;
>+
>+	spinlock_t		tcfp_lock ____cacheline_aligned_in_smp;
>+	s64			tcfp_toks;
>+	s64			tcfp_ptoks;
>+	s64			tcfp_t_c;
>+};
>+
>+#define to_police(pc) ((struct tcf_police *)pc)
>+
>+/* old policer structure from before tc actions */
>+struct tc_police_compat {

Why do you need this in header?


>+	u32			index;
>+	int			action;
>+	u32			limit;
>+	u32			burst;
>+	u32			mtu;
>+	struct tc_ratespec	rate;
>+	struct tc_ratespec	peakrate;
>+};
>+
>+static inline bool is_tcf_police(const struct tc_action *act)
>+{
>+#ifdef CONFIG_NET_CLS_ACT
>+	if (act->ops && act->ops->id == TCA_ID_POLICE)
>+		return true;
>+#endif
>+	return false;
>+}
>+
>+static inline u64 tcf_police_rate_bytes_ps(const struct tc_action *act)
>+{
>+	struct tcf_police *police = to_police(act);
>+	struct tcf_police_params *params;
>+
>+	params = rcu_dereference_bh(police->params);
>+	return params->rate.rate_bytes_ps;
>+}
>+
>+static inline s64 tcf_police_tcfp_burst(const struct tc_action *act)
>+{
>+	struct tcf_police *police = to_police(act);
>+	struct tcf_police_params *params;
>+
>+	params = rcu_dereference_bh(police->params);
>+	return params->tcfp_burst;
>+}
>+
>+#endif /* __NET_TC_POLICE_H */
>diff --git a/net/sched/act_police.c b/net/sched/act_police.c
>index b48e40c69ad0..e33bcab75d1f 100644
>--- a/net/sched/act_police.c
>+++ b/net/sched/act_police.c
>@@ -22,42 +22,7 @@
> #include <net/act_api.h>
> #include <net/netlink.h>
> #include <net/pkt_cls.h>
>-
>-struct tcf_police_params {
>-	int			tcfp_result;
>-	u32			tcfp_ewma_rate;
>-	s64			tcfp_burst;
>-	u32			tcfp_mtu;
>-	s64			tcfp_mtu_ptoks;
>-	struct psched_ratecfg	rate;
>-	bool			rate_present;
>-	struct psched_ratecfg	peak;
>-	bool			peak_present;
>-	struct rcu_head rcu;
>-};
>-
>-struct tcf_police {
>-	struct tc_action	common;
>-	struct tcf_police_params __rcu *params;
>-
>-	spinlock_t		tcfp_lock ____cacheline_aligned_in_smp;
>-	s64			tcfp_toks;
>-	s64			tcfp_ptoks;
>-	s64			tcfp_t_c;
>-};
>-
>-#define to_police(pc) ((struct tcf_police *)pc)
>-
>-/* old policer structure from before tc actions */
>-struct tc_police_compat {
>-	u32			index;
>-	int			action;
>-	u32			limit;
>-	u32			burst;
>-	u32			mtu;
>-	struct tc_ratespec	rate;
>-	struct tc_ratespec	peakrate;
>-};
>+#include <net/tc_act/tc_police.h>
> 
> /* Each policer is serialized by its individual spinlock */
> 
>-- 
>2.21.0
>
diff mbox series

Patch

diff --git a/include/net/tc_act/tc_police.h b/include/net/tc_act/tc_police.h
new file mode 100644
index 000000000000..8b9ef3664262
--- /dev/null
+++ b/include/net/tc_act/tc_police.h
@@ -0,0 +1,70 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NET_TC_POLICE_H
+#define __NET_TC_POLICE_H
+
+#include <net/act_api.h>
+
+struct tcf_police_params {
+	int			tcfp_result;
+	u32			tcfp_ewma_rate;
+	s64			tcfp_burst;
+	u32			tcfp_mtu;
+	s64			tcfp_mtu_ptoks;
+	struct psched_ratecfg	rate;
+	bool			rate_present;
+	struct psched_ratecfg	peak;
+	bool			peak_present;
+	struct rcu_head rcu;
+};
+
+struct tcf_police {
+	struct tc_action	common;
+	struct tcf_police_params __rcu *params;
+
+	spinlock_t		tcfp_lock ____cacheline_aligned_in_smp;
+	s64			tcfp_toks;
+	s64			tcfp_ptoks;
+	s64			tcfp_t_c;
+};
+
+#define to_police(pc) ((struct tcf_police *)pc)
+
+/* old policer structure from before tc actions */
+struct tc_police_compat {
+	u32			index;
+	int			action;
+	u32			limit;
+	u32			burst;
+	u32			mtu;
+	struct tc_ratespec	rate;
+	struct tc_ratespec	peakrate;
+};
+
+static inline bool is_tcf_police(const struct tc_action *act)
+{
+#ifdef CONFIG_NET_CLS_ACT
+	if (act->ops && act->ops->id == TCA_ID_POLICE)
+		return true;
+#endif
+	return false;
+}
+
+static inline u64 tcf_police_rate_bytes_ps(const struct tc_action *act)
+{
+	struct tcf_police *police = to_police(act);
+	struct tcf_police_params *params;
+
+	params = rcu_dereference_bh(police->params);
+	return params->rate.rate_bytes_ps;
+}
+
+static inline s64 tcf_police_tcfp_burst(const struct tc_action *act)
+{
+	struct tcf_police *police = to_police(act);
+	struct tcf_police_params *params;
+
+	params = rcu_dereference_bh(police->params);
+	return params->tcfp_burst;
+}
+
+#endif /* __NET_TC_POLICE_H */
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index b48e40c69ad0..e33bcab75d1f 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -22,42 +22,7 @@ 
 #include <net/act_api.h>
 #include <net/netlink.h>
 #include <net/pkt_cls.h>
-
-struct tcf_police_params {
-	int			tcfp_result;
-	u32			tcfp_ewma_rate;
-	s64			tcfp_burst;
-	u32			tcfp_mtu;
-	s64			tcfp_mtu_ptoks;
-	struct psched_ratecfg	rate;
-	bool			rate_present;
-	struct psched_ratecfg	peak;
-	bool			peak_present;
-	struct rcu_head rcu;
-};
-
-struct tcf_police {
-	struct tc_action	common;
-	struct tcf_police_params __rcu *params;
-
-	spinlock_t		tcfp_lock ____cacheline_aligned_in_smp;
-	s64			tcfp_toks;
-	s64			tcfp_ptoks;
-	s64			tcfp_t_c;
-};
-
-#define to_police(pc) ((struct tcf_police *)pc)
-
-/* old policer structure from before tc actions */
-struct tc_police_compat {
-	u32			index;
-	int			action;
-	u32			limit;
-	u32			burst;
-	u32			mtu;
-	struct tc_ratespec	rate;
-	struct tc_ratespec	peakrate;
-};
+#include <net/tc_act/tc_police.h>
 
 /* Each policer is serialized by its individual spinlock */