From 0545c3738438dedbbec4650b5c0e4aa28a1b38ef Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 19 Nov 2018 18:44:35 +0000 Subject: [PATCH 1/2] *: only use 32-bit atomics Signed-off-by: Quentin Young --- bgpd/bgpd.h | 2 +- lib/thread.h | 2 +- zebra/zebra_dplane.c | 8 ++++---- zebra/zserv.c | 2 +- zebra/zserv.h | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 70193104b4..606da03a8d 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1004,7 +1004,7 @@ struct peer { struct thread *t_process_packet; /* Thread flags. */ - _Atomic uint16_t thread_flags; + _Atomic uint32_t thread_flags; #define PEER_THREAD_WRITES_ON (1 << 0) #define PEER_THREAD_READS_ON (1 << 1) #define PEER_THREAD_KEEPALIVES_ON (1 << 2) diff --git a/lib/thread.h b/lib/thread.h index 70090cf784..4de9a65562 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -125,7 +125,7 @@ struct cpu_thread_history { _Atomic unsigned long total, max; } real; struct time_stats cpu; - _Atomic uint8_t types; + _Atomic uint32_t types; const char *funcname; }; diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 61eba92c98..3e61418b64 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -135,8 +135,8 @@ struct zebra_dplane_provider { dplane_provider_fini_fp dp_fini; - _Atomic uint64_t dp_in_counter; - _Atomic uint64_t dp_error_counter; + _Atomic uint32_t dp_in_counter; + _Atomic uint32_t dp_error_counter; /* Embedded list linkage */ TAILQ_ENTRY(zebra_dplane_provider) dp_q_providers; @@ -171,10 +171,10 @@ static struct zebra_dplane_globals { /* Limit number of pending, unprocessed updates */ _Atomic uint32_t dg_max_queued_updates; - _Atomic uint64_t dg_routes_in; + _Atomic uint32_t dg_routes_in; _Atomic uint32_t dg_routes_queued; _Atomic uint32_t dg_routes_queued_max; - _Atomic uint64_t dg_route_errors; + _Atomic uint32_t dg_route_errors; /* Event-delivery context 'master' for the dplane */ struct thread_master *dg_master; diff --git a/zebra/zserv.c b/zebra/zserv.c index 3c3bf4077b..b40e9e2af5 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -875,7 +875,7 @@ static void zebra_show_client_detail(struct vty *vty, struct zserv *client) char cbuf[ZEBRA_TIME_BUF], rbuf[ZEBRA_TIME_BUF]; char wbuf[ZEBRA_TIME_BUF], nhbuf[ZEBRA_TIME_BUF], mbuf[ZEBRA_TIME_BUF]; time_t connect_time, last_read_time, last_write_time; - uint16_t last_read_cmd, last_write_cmd; + uint32_t last_read_cmd, last_write_cmd; vty_out(vty, "Client: %s", zebra_route_string(client->proto)); if (client->instance) diff --git a/zebra/zserv.h b/zebra/zserv.h index f21ea17fe8..f7967f54f0 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -157,9 +157,9 @@ struct zserv { /* monotime of last message sent */ _Atomic uint32_t last_write_time; /* command code of last message read */ - _Atomic uint16_t last_read_cmd; + _Atomic uint32_t last_read_cmd; /* command code of last message written */ - _Atomic uint16_t last_write_cmd; + _Atomic uint32_t last_write_cmd; }; #define ZAPI_HANDLER_ARGS \ From 11b5117007a8a83f08a0dd8baf4aeaacfd1b50ed Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 19 Nov 2018 18:48:42 +0000 Subject: [PATCH 2/2] tools: add non-32 bit atomic warning to checkpatch Signed-off-by: Quentin Young --- tools/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index 22354c1e88..547a4b2137 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -6367,6 +6367,13 @@ sub process { ERROR("NONSTANDARD_INTEGRAL_TYPES", "Please, no nonstandard integer types in new code.\n" . $herecurr) } + +# check for usage of non-32 bit atomics + if ($line =~ /_Atomic [u]?int(?!32)[0-9]+_t/) { + WARN("NON_32BIT_ATOMIC", + "Please, only use 32 bit atomics.\n" . $herecurr); + } + } # If we have no input at all, then there is nothing to report on