From a7837d6c93d8d49510ab1e05ee41250c5765bb98 Mon Sep 17 00:00:00 2001 From: yangwei Date: Thu, 1 Aug 2024 03:00:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(clock=5Fgettime):=20COARSE?= =?UTF-8?q?=20to=20reduce=20overhead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packet/packet_craft.cpp | 2 +- src/packet_io/marsio_io.cpp | 2 +- src/times/times.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/packet/packet_craft.cpp b/src/packet/packet_craft.cpp index e6ac39a..61bf0ac 100644 --- a/src/packet/packet_craft.cpp +++ b/src/packet/packet_craft.cpp @@ -37,7 +37,7 @@ static inline void calc_packet_fingerprint(struct fingerprint *finger) { #define RANGE(rand, start, end) (start + rand % (end - start + 1)) // [start, end] struct timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); + clock_gettime(CLOCK_MONOTONIC_COARSE, &time); uint64_t random = 0x013579ABCDEF ^ time.tv_nsec; finger->ip_id = (uint16_t)(RANGE(random, 32767, 65535)); finger->ip_ttl = (uint8_t)(RANGE(random, 48, 120)); diff --git a/src/packet_io/marsio_io.cpp b/src/packet_io/marsio_io.cpp index 012db3b..9cfaa2b 100644 --- a/src/packet_io/marsio_io.cpp +++ b/src/packet_io/marsio_io.cpp @@ -297,7 +297,7 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet } pkt = &pkts[nr_parsed]; - memset(pkt, 0, sizeof(struct packet)); + //memset(pkt, 0, sizeof(struct packet)); packet_parse(pkt, data, len); metadata_from_mbuff_to_packet(mbuff, pkt); nr_parsed++; diff --git a/src/times/times.cpp b/src/times/times.cpp index be4cdec..70343c5 100644 --- a/src/times/times.cpp +++ b/src/times/times.cpp @@ -34,7 +34,7 @@ uint64_t stellar_get_monotonic_time_sec() { struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); + clock_gettime(CLOCK_MONOTONIC_COARSE, &now); return TIMESPEC_TO_SEC(now); } @@ -42,7 +42,7 @@ uint64_t stellar_get_monotonic_time_sec() uint64_t stellar_get_monotonic_time_msec() { struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); + clock_gettime(CLOCK_MONOTONIC_COARSE, &now); return TIMESPEC_TO_MSEC(now); } @@ -50,7 +50,7 @@ uint64_t stellar_get_monotonic_time_msec() uint64_t stellar_get_real_time_sec() { struct timespec now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_REALTIME_COARSE, &now); return TIMESPEC_TO_SEC(now); }