🎈 perf(clock_gettime): COARSE to reduce overhead

This commit is contained in:
yangwei
2024-08-01 03:00:27 +08:00
committed by luwenpeng
parent 2ff76d6598
commit a7837d6c93
3 changed files with 5 additions and 5 deletions

View File

@@ -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));

View File

@@ -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++;

View File

@@ -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);
}