Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Murphy <[email protected]>
  • Loading branch information
murphyjacob4 committed Jan 11, 2025
1 parent 359728f commit 89e614e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 53 deletions.
18 changes: 9 additions & 9 deletions src/ae.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,15 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags) {
if (fe->mask & mask & event_order[i]) {
aeFileProc *to_fire = NULL;
switch (event_order[i]) {
case AE_READABLE:
to_fire = fe->rfileProc;
break;
case AE_WRITABLE:
to_fire = fe->wfileProc;
break;
case AE_ERROR_QUEUE:
to_fire = fe->errfileproc;
break;
case AE_READABLE:
to_fire = fe->rfileProc;
break;
case AE_WRITABLE:
to_fire = fe->wfileProc;
break;
case AE_ERROR_QUEUE:
to_fire = fe->errfileproc;
break;
}
int already_fired = 0;
for (int j = 0; j < i; j++) {
Expand Down
22 changes: 11 additions & 11 deletions src/ae.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
#define AE_OK 0
#define AE_ERR -1

#define AE_NONE 0 /* No events registered. */
#define AE_READABLE 1<<0 /* Fire when descriptor is readable. */
#define AE_WRITABLE 1<<1 /* Fire when descriptor is writable. */
#define AE_BARRIER 1<<2 /* With WRITABLE, never fire the event if the \
READABLE event already fired in the same event \
loop iteration. Useful when you want to persist \
things to disk before sending replies, and want \
to do that in a group fashion. */
#define AE_ERROR_QUEUE 1<<3 /* Fire when descriptor has a message on the \
message queue. */
#define AE_NUM_EVENT_TYPES 3 /* Total number of events we can fire in one pass */
#define AE_NONE 0 /* No events registered. */
#define AE_READABLE 1 << 0 /* Fire when descriptor is readable. */
#define AE_WRITABLE 1 << 1 /* Fire when descriptor is writable. */
#define AE_BARRIER 1 << 2 /* With WRITABLE, never fire the event if the \
READABLE event already fired in the same event \
loop iteration. Useful when you want to persist \
things to disk before sending replies, and want \
to do that in a group fashion. */
#define AE_ERROR_QUEUE 1 << 3 /* Fire when descriptor has a message on the \
message queue. */
#define AE_NUM_EVENT_TYPES 3 /* Total number of events we can fire in one pass */

#define AE_FILE_EVENTS (1 << 0)
#define AE_TIME_EVENTS (1 << 1)
Expand Down
6 changes: 3 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2546,16 +2546,16 @@ static int updateExtendedRedisCompat(const char **err) {
}

static int applyTcpTxZerocopy(const char **err) {
#ifndef HAVE_MSG_ZEROCOPY
#ifndef HAVE_MSG_ZEROCOPY
if (server.tcp_tx_zerocopy) {
*err = "TCP zerocopy is not supported by this system";
return 0;
}
return 1;
#else
#else
UNUSED(err);
return 1;
#endif
#endif
}

static int updateSighandlerEnabled(const char **err) {
Expand Down
4 changes: 2 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -5939,8 +5939,8 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
"eventloop_duration_cmd_sum:%llu\r\n", server.duration_stats[EL_DURATION_TYPE_CMD].sum,
"instantaneous_eventloop_cycles_per_sec:%llu\r\n", getInstantaneousMetric(STATS_METRIC_EL_CYCLE),
"instantaneous_eventloop_duration_usec:%llu\r\n", getInstantaneousMetric(STATS_METRIC_EL_DURATION),
"zero_copy_writes_processed:%lld\r\n",server.stat_zero_copy_writes_processed,
"zero_copy_writes_in_flight:%lld\r\n",server.stat_zero_copy_writes_in_flight));
"zero_copy_writes_processed:%lld\r\n", server.stat_zero_copy_writes_processed,
"zero_copy_writes_in_flight:%lld\r\n", server.stat_zero_copy_writes_in_flight));
info = genValkeyInfoStringACLStats(info);
}

Expand Down
30 changes: 15 additions & 15 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ struct hdr_histogram;
#else
#define CONFIG_ACTIVE_DEFRAG_DEFAULT 1
#endif
# ifdef HAVE_MSG_ZEROCOPY
# define CONFIG_DEFAULT_TCP_TX_ZEROCOPY 1
# else
# define CONFIG_DEFAULT_TCP_TX_ZEROCOPY 0
# endif
#define CONFIG_DEFAULT_ZERO_COPY_MIN_WRITE_SIZE 10*1024 /* https://docs.kernel.org/networking/msg_zerocopy.html */
#ifdef HAVE_MSG_ZEROCOPY
#define CONFIG_DEFAULT_TCP_TX_ZEROCOPY 1
#else
#define CONFIG_DEFAULT_TCP_TX_ZEROCOPY 0
#endif
#define CONFIG_DEFAULT_ZERO_COPY_MIN_WRITE_SIZE 10 * 1024 /* https://docs.kernel.org/networking/msg_zerocopy.html */

/* Bucket sizes for client eviction pools. Each bucket stores clients with
* memory usage of up to twice the size of the bucket below it. */
Expand Down Expand Up @@ -1255,13 +1255,13 @@ typedef struct client {
* before adding it the new value. */
size_t last_memory_usage;
/* Fields after this point are less frequently used */
listNode *client_list_node; /* list node in client list */
listNode *client_list_node; /* list node in client list */
zeroCopyTracker *zero_copy_tracker; /* Circular buffer of active writes, indexed
* by sequence number. */
mstime_t buf_peak_last_reset_time; /* keeps the last time the buffer peak value was reset */
size_t querybuf_peak; /* Recent (100ms or more) peak of querybuf size. */
dictEntry *cur_script; /* Cached pointer to the dictEntry of the script being executed. */
user *user; /* User associated with this connection */
* by sequence number. */
mstime_t buf_peak_last_reset_time; /* keeps the last time the buffer peak value was reset */
size_t querybuf_peak; /* Recent (100ms or more) peak of querybuf size. */
dictEntry *cur_script; /* Cached pointer to the dictEntry of the script being executed. */
user *user; /* User associated with this connection */
time_t obuf_soft_limit_reached_time;
list *deferred_reply_errors; /* Used for module thread safe contexts. */
robj *name; /* As set by CLIENT SETNAME. */
Expand Down Expand Up @@ -1998,10 +1998,10 @@ struct valkeyServer {
/* Import Mode */
int import_mode; /* If true, server is in import mode and forbid expiration and eviction. */
/* TCP Zero Copy */
int tcp_tx_zerocopy; /* If true, use zero copy for writes when possible. */
int tcp_zerocopy_min_write_size; /* Minimum size for a write before we go through zerocopy. */
int tcp_tx_zerocopy; /* If true, use zero copy for writes when possible. */
int tcp_zerocopy_min_write_size; /* Minimum size for a write before we go through zerocopy. */
int debug_zerocopy_bypass_loopback_check; /* Used to test zerocopy on loopback connections */
int debug_pause_errqueue_events; /* Used to pause zerocopy notifications */
int debug_pause_errqueue_events; /* Used to pause zerocopy notifications */
unsigned int draining_clients;
/* Synchronous replication. */
list *clients_waiting_acks; /* Clients waiting in WAIT or WAITAOF. */
Expand Down
24 changes: 13 additions & 11 deletions src/zerocopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ int shouldUseZeroCopy(connection *conn, size_t len) {
UNUSED(len);
return 0;
}
ssize_t zeroCopyWriteToConn(connection *conn, char* data, size_t len) {
ssize_t zeroCopyWriteToConn(connection *conn, char *data, size_t len) {
UNUSED(conn);
UNUSED(data);
UNUSED(len);
return -1;
}
zeroCopyTracker *createZeroCopyTracker(void) { return NULL; }
zeroCopyTracker *createZeroCopyTracker(void) {
return NULL;
}
zeroCopyRecord *zeroCopyTrackerGet(zeroCopyTracker *tracker, uint32_t index) {
UNUSED(tracker);
UNUSED(index);
Expand Down Expand Up @@ -57,21 +59,21 @@ void processZeroCopyMessages(connection *conn) {
* that are over the configured minimum size. */
int shouldUseZeroCopy(connection *conn, size_t len) {
return server.tcp_tx_zerocopy && conn->type == connectionTypeTcp() &&
len >= (size_t) server.tcp_zerocopy_min_write_size &&
len >= (size_t)server.tcp_zerocopy_min_write_size &&
(!connIsLocal(conn) || server.debug_zerocopy_bypass_loopback_check);
}

ssize_t zeroCopyWriteToConn(connection *conn, char* data, size_t len) {
ssize_t zeroCopyWriteToConn(connection *conn, char *data, size_t len) {
return connSend(conn, data, len, MSG_ZEROCOPY);
}

zeroCopyTracker *createZeroCopyTracker(void) {
zeroCopyTracker *result = (zeroCopyTracker *) zmalloc(sizeof(zeroCopyTracker));
zeroCopyTracker *result = (zeroCopyTracker *)zmalloc(sizeof(zeroCopyTracker));
result->start = 0;
result->len = 0;
result->capacity = ZERO_COPY_RECORD_TRACKER_INIT_SIZE;
size_t records_size = sizeof(zeroCopyRecord) * ZERO_COPY_RECORD_TRACKER_INIT_SIZE;
result->records = (zeroCopyRecord *) zmalloc(records_size);
result->records = (zeroCopyRecord *)zmalloc(records_size);
result->draining = 0;
server.stat_zero_copy_tracking_memory += sizeof(zeroCopyTracker) + records_size;
return result;
Expand All @@ -85,12 +87,12 @@ zeroCopyRecord *zeroCopyTrackerGet(zeroCopyTracker *tracker, uint32_t index) {
serverAssert(
tracker->start + tracker->len < tracker->start ||
(index >= tracker->start &&
index < tracker->start + tracker->len));
index < tracker->start + tracker->len));
/* Wraparound case */
serverAssert(
(tracker->start + tracker->len > tracker->start ||
index >= tracker->start ||
index < tracker->start + tracker->len));
index >= tracker->start ||
index < tracker->start + tracker->len));
return &(tracker->records[index % tracker->capacity]);
}

Expand Down Expand Up @@ -185,7 +187,7 @@ void zeroCopyTrackerProcessNotifications(zeroCopyTracker *tracker, connection *c
if (cmsg->cmsg_level != SOL_IP || cmsg->cmsg_type != IP_RECVERR) {
continue;
}
serr = (struct sock_extended_err *) CMSG_DATA(cmsg);
serr = (struct sock_extended_err *)CMSG_DATA(cmsg);
if (serr->ee_errno != 0 || serr->ee_origin != SO_EE_ORIGIN_ZEROCOPY) {
continue;
}
Expand Down Expand Up @@ -237,7 +239,7 @@ void zeroCopyStartDraining(client *c) {
}

void processZeroCopyMessages(connection *conn) {
client * c = (client *) connGetPrivateData(conn);
client *c = (client *)connGetPrivateData(conn);
serverAssert(c->zero_copy_tracker);
zeroCopyTrackerProcessNotifications(c->zero_copy_tracker, conn);
if (c->zero_copy_tracker->draining && c->zero_copy_tracker->len == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/zerocopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ZERO_COPY_RECORD_TRACKER_INIT_SIZE 1024
#define ZERO_COPY_DOWNSIZE_UTILIZATION_WATERMARK 0.4

int shouldUseZeroCopy(connection * conn, size_t len);
int shouldUseZeroCopy(connection *conn, size_t len);
ssize_t zeroCopyWriteToConn(connection *conn, char *buf, size_t len);
zeroCopyTracker *createZeroCopyTracker(void);
void freeZeroCopyTracker(zeroCopyTracker *tracker);
Expand All @@ -21,4 +21,4 @@ void zeroCopyStartDraining(client *c);
* Assumes that the client object is stored as private data in the connection. */
void processZeroCopyMessages(connection *conn);

#endif /* ZEROCOPY_H */
#endif /* ZEROCOPY_H */

0 comments on commit 89e614e

Please sign in to comment.