af-packet: only ref mpeer if needed in tpacket v2

We only use it in autofp mode, for reference counting purposes.

Removes 2 atomic operations per packet in the more common workers
runmode.
pull/6633/head
Victor Julien 4 years ago committed by Victor Julien
parent d272075da0
commit 8a5b945c7b

@ -679,6 +679,7 @@ finalize:
if (active_runmode == NULL || strcmp("workers", active_runmode) != 0) {
/* If we are using copy mode we need a lock */
aconf->flags |= AFP_SOCK_PROTECT;
aconf->flags |= AFP_NEED_PEER;
}
return aconf;
}

@ -779,8 +779,12 @@ static void AFPReadFromRingSetupPacket(
p->ReleasePacket = AFPReleasePacket;
p->afp_v.relptr = h.raw;
p->afp_v.mpeer = ptv->mpeer;
AFPRefSocket(ptv->mpeer);
if (ptv->flags & AFP_NEED_PEER) {
p->afp_v.mpeer = ptv->mpeer;
AFPRefSocket(ptv->mpeer);
} else {
p->afp_v.mpeer = NULL;
}
p->afp_v.copy_mode = ptv->copy_mode;
p->afp_v.peer = (p->afp_v.copy_mode == AFP_COPY_MODE_NONE) ? NULL : ptv->mpeer->peer;

@ -55,7 +55,7 @@ struct ebpf_timeout_config {
#endif
/* value for flags */
// (1<<0) vacant
#define AFP_NEED_PEER (1 << 0)
// (1<<1) vacant
#define AFP_SOCK_PROTECT (1<<2)
#define AFP_EMERGENCY_MODE (1<<3)

Loading…
Cancel
Save