netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] tc: unify clockid handling
@ 2024-01-19 16:40 Stephen Hemminger
  2024-01-19 18:58 ` Vinicius Costa Gomes
  2024-01-21 17:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Hemminger @ 2024-01-19 16:40 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

There are three places in tc which all have same code for
handling clockid (copy/paste). Move it into tc_util.c.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
Motivated by (rejected) pull request to deal with missing
clockid's on really old versions of glibc.

 tc/m_gate.c   | 41 -----------------------------------------
 tc/q_etf.c    | 43 -------------------------------------------
 tc/q_taprio.c | 43 -------------------------------------------
 tc/tc_util.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 tc/tc_util.h  |  4 ++++
 5 files changed, 44 insertions(+), 127 deletions(-)

diff --git a/tc/m_gate.c b/tc/m_gate.c
index c091ae19c1cc..37afa426a2c8 100644
--- a/tc/m_gate.c
+++ b/tc/m_gate.c
@@ -20,18 +20,6 @@ struct gate_entry {
 	int32_t maxoctets;
 };
 
-#define CLOCKID_INVALID (-1)
-static const struct clockid_table {
-	const char *name;
-	clockid_t clockid;
-} clockt_map[] = {
-	{ "REALTIME", CLOCK_REALTIME },
-	{ "TAI", CLOCK_TAI },
-	{ "BOOTTIME", CLOCK_BOOTTIME },
-	{ "MONOTONIC", CLOCK_MONOTONIC },
-	{ NULL }
-};
-
 static void explain(void)
 {
 	fprintf(stderr,
@@ -78,35 +66,6 @@ struct action_util gate_action_util = {
 	.print_aopt = print_gate,
 };
 
-static int get_clockid(__s32 *val, const char *arg)
-{
-	const struct clockid_table *c;
-
-	if (strcasestr(arg, "CLOCK_") != NULL)
-		arg += sizeof("CLOCK_") - 1;
-
-	for (c = clockt_map; c->name; c++) {
-		if (strcasecmp(c->name, arg) == 0) {
-			*val = c->clockid;
-			return 0;
-		}
-	}
-
-	return -1;
-}
-
-static const char *get_clock_name(clockid_t clockid)
-{
-	const struct clockid_table *c;
-
-	for (c = clockt_map; c->name; c++) {
-		if (clockid == c->clockid)
-			return c->name;
-	}
-
-	return "invalid";
-}
-
 static int get_gate_state(__u8 *val, const char *arg)
 {
 	if (!strcasecmp("OPEN", arg)) {
diff --git a/tc/q_etf.c b/tc/q_etf.c
index 572e2bc89fc1..d16188daabbd 100644
--- a/tc/q_etf.c
+++ b/tc/q_etf.c
@@ -19,18 +19,6 @@
 #include "utils.h"
 #include "tc_util.h"
 
-#define CLOCKID_INVALID (-1)
-static const struct static_clockid {
-	const char *name;
-	clockid_t clockid;
-} clockids_sysv[] = {
-	{ "REALTIME", CLOCK_REALTIME },
-	{ "TAI", CLOCK_TAI },
-	{ "BOOTTIME", CLOCK_BOOTTIME },
-	{ "MONOTONIC", CLOCK_MONOTONIC },
-	{ NULL }
-};
-
 static void explain(void)
 {
 	fprintf(stderr,
@@ -51,37 +39,6 @@ static void explain_clockid(const char *val)
 		val);
 }
 
-static int get_clockid(__s32 *val, const char *arg)
-{
-	const struct static_clockid *c;
-
-	/* Drop the CLOCK_ prefix if that is being used. */
-	if (strcasestr(arg, "CLOCK_") != NULL)
-		arg += sizeof("CLOCK_") - 1;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (strcasecmp(c->name, arg) == 0) {
-			*val = c->clockid;
-
-			return 0;
-		}
-	}
-
-	return -1;
-}
-
-static const char* get_clock_name(clockid_t clockid)
-{
-	const struct static_clockid *c;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (clockid == c->clockid)
-			return c->name;
-	}
-
-	return "invalid";
-}
-
 static int etf_parse_opt(struct qdisc_util *qu, int argc,
 			 char **argv, struct nlmsghdr *n, const char *dev)
 {
diff --git a/tc/q_taprio.c b/tc/q_taprio.c
index ef8fc7a05fc2..c47fe244369f 100644
--- a/tc/q_taprio.c
+++ b/tc/q_taprio.c
@@ -29,18 +29,6 @@ struct sched_entry {
 	uint8_t cmd;
 };
 
-#define CLOCKID_INVALID (-1)
-static const struct static_clockid {
-	const char *name;
-	clockid_t clockid;
-} clockids_sysv[] = {
-	{ "REALTIME", CLOCK_REALTIME },
-	{ "TAI", CLOCK_TAI },
-	{ "BOOTTIME", CLOCK_BOOTTIME },
-	{ "MONOTONIC", CLOCK_MONOTONIC },
-	{ NULL }
-};
-
 static void explain(void)
 {
 	fprintf(stderr,
@@ -60,37 +48,6 @@ static void explain_clockid(const char *val)
 	fprintf(stderr, "It must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
 }
 
-static int get_clockid(__s32 *val, const char *arg)
-{
-	const struct static_clockid *c;
-
-	/* Drop the CLOCK_ prefix if that is being used. */
-	if (strcasestr(arg, "CLOCK_") != NULL)
-		arg += sizeof("CLOCK_") - 1;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (strcasecmp(c->name, arg) == 0) {
-			*val = c->clockid;
-
-			return 0;
-		}
-	}
-
-	return -1;
-}
-
-static const char* get_clock_name(clockid_t clockid)
-{
-	const struct static_clockid *c;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (clockid == c->clockid)
-			return c->name;
-	}
-
-	return "invalid";
-}
-
 static const char *entry_cmd_to_str(__u8 cmd)
 {
 	switch (cmd) {
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 8c0e19e452d5..a799a6299c04 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -596,6 +596,46 @@ char *sprint_linklayer(unsigned int linklayer, char *buf)
 	return buf;
 }
 
+static const struct clockid_table {
+	const char *name;
+	clockid_t clockid;
+} clockt_map[] = {
+	{ "REALTIME", CLOCK_REALTIME },
+	{ "TAI", CLOCK_TAI },
+	{ "BOOTTIME", CLOCK_BOOTTIME },
+	{ "MONOTONIC", CLOCK_MONOTONIC },
+	{ NULL }
+};
+
+int get_clockid(__s32 *val, const char *arg)
+{
+	const struct clockid_table *c;
+
+	if (strcasestr(arg, "CLOCK_") != NULL)
+		arg += sizeof("CLOCK_") - 1;
+
+	for (c = clockt_map; c->name; c++) {
+		if (strcasecmp(c->name, arg) == 0) {
+			*val = c->clockid;
+			return 0;
+		}
+	}
+
+	return -1;
+}
+
+const char *get_clock_name(clockid_t clockid)
+{
+	const struct clockid_table *c;
+
+	for (c = clockt_map; c->name; c++) {
+		if (clockid == c->clockid)
+			return c->name;
+	}
+
+	return "invalid";
+}
+
 void print_tm(FILE *f, const struct tcf_t *tm)
 {
 	int hz = get_user_hz();
diff --git a/tc/tc_util.h b/tc/tc_util.h
index c535dccbc200..aaf10e433fd1 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -121,6 +121,10 @@ int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
 int cls_names_init(char *path);
 void cls_names_uninit(void);
 
+#define CLOCKID_INVALID (-1)
+int get_clockid(__s32 *val, const char *arg);
+const char *get_clock_name(clockid_t clockid);
+
 int action_a2n(char *arg, int *result, bool allow_num);
 
 bool tc_qdisc_block_exists(__u32 block_index);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2] tc: unify clockid handling
  2024-01-19 16:40 [PATCH iproute2] tc: unify clockid handling Stephen Hemminger
@ 2024-01-19 18:58 ` Vinicius Costa Gomes
  2024-01-21 17:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Vinicius Costa Gomes @ 2024-01-19 18:58 UTC (permalink / raw)
  To: Stephen Hemminger, netdev; +Cc: Stephen Hemminger

Stephen Hemminger <stephen@networkplumber.org> writes:

> There are three places in tc which all have same code for
> handling clockid (copy/paste). Move it into tc_util.c.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---

Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

-- 
Vinicius

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2] tc: unify clockid handling
  2024-01-19 16:40 [PATCH iproute2] tc: unify clockid handling Stephen Hemminger
  2024-01-19 18:58 ` Vinicius Costa Gomes
@ 2024-01-21 17:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-21 17:30 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Fri, 19 Jan 2024 08:40:20 -0800 you wrote:
> There are three places in tc which all have same code for
> handling clockid (copy/paste). Move it into tc_util.c.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> Motivated by (rejected) pull request to deal with missing
> clockid's on really old versions of glibc.
> 
> [...]

Here is the summary with links:
  - [iproute2] tc: unify clockid handling
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=91cca2aee76b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-21 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19 16:40 [PATCH iproute2] tc: unify clockid handling Stephen Hemminger
2024-01-19 18:58 ` Vinicius Costa Gomes
2024-01-21 17:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).