Real life sort of benchmark

This commit is contained in:
Jason A. Donenfeld 2018-09-23 18:12:43 +02:00
parent bcec13ea5a
commit 193c752557
5 changed files with 28 additions and 7 deletions

View File

@ -50,7 +50,7 @@ enum limits {
MAX_TIMER_HANDSHAKES = 90 / REKEY_TIMEOUT,
MAX_QUEUED_INCOMING_HANDSHAKES = 4096, /* TODO: replace this with DQL */
MAX_STAGED_PACKETS = 128,
MAX_QUEUED_PACKETS = 1024 /* TODO: replace this with DQL */
MAX_QUEUED_PACKETS = 102400 /* TODO: replace this with DQL */
};
enum message_type {

View File

@ -580,6 +580,8 @@ void packet_receive(struct wireguard_device *wg, struct sk_buff *skb)
break;
}
case cpu_to_le32(MESSAGE_DATA):
if (skb->len > MESSAGE_MINIMUM_LENGTH)
goto err;
PACKET_CB(skb)->ds = ip_tunnel_get_dsfield(ip_hdr(skb), skb);
packet_consume_data(wg, skb);
break;

View File

@ -291,6 +291,12 @@ void packet_tx_worker(struct work_struct *work)
}
}
static inline void report_bench(unsigned int bytes, cycles_t duration)
{
cycles_t cCPB = duration * 100;
pr_err("%u bytes in %u cycles (%u cCPB)\n", bytes, duration, cCPB / bytes);
}
void packet_encrypt_worker(struct work_struct *work)
{
struct crypt_queue *queue =
@ -298,11 +304,16 @@ void packet_encrypt_worker(struct work_struct *work)
struct sk_buff *first, *skb, *next;
simd_context_t simd_context;
unsigned int bytes = 0;
cycles_t start;
simd_get(&simd_context);
start = get_cycles();
while ((first = ptr_ring_consume_bh(&queue->ring)) != NULL) {
enum packet_state state = PACKET_STATE_CRYPTED;
skb_walk_null_queue_safe (first, skb, next) {
bytes += skb->len;
if (likely(skb_encrypt(skb, PACKET_CB(first)->keypair,
&simd_context)))
skb_reset(skb);
@ -311,11 +322,18 @@ void packet_encrypt_worker(struct work_struct *work)
break;
}
}
if (bytes >= 1024 * 1024 * 5) {
report_bench(bytes, get_cycles() - start);
bytes = 0;
start = get_cycles();
}
queue_enqueue_per_peer(&PACKET_PEER(first)->tx_queue, first,
state);
simd_relax(&simd_context);
}
if (bytes > 1024 * 10)
report_bench(bytes, get_cycles() - start);
simd_put(&simd_context);
}

View File

@ -140,10 +140,11 @@ tests() {
big_mtu=$(( 34816 - 1500 + $orig_mtu ))
# Test using IPv4 as outer transport
n1 wg set wg0 peer "$pub2" endpoint 127.0.0.1:2
n1 wg set wg0 peer "$pub2" endpoint 127.0.0.1:2 persistent-keepalive 5
n2 wg set wg0 peer "$pub1" endpoint 127.0.0.1:1
# Before calling tests, we first make sure that the stats counters are working
n2 ping -c 10 -f -W 1 192.168.241.1
n2 ncat -u 192.168.241.1 1234 < /dev/zero
{ read _; read _; read _; read rx_bytes _; read _; read tx_bytes _; } < <(ip2 -stats link show dev wg0)
(( rx_bytes == 1372 && (tx_bytes == 1428 || tx_bytes == 1460) ))
{ read _; read _; read _; read rx_bytes _; read _; read tx_bytes _; } < <(ip1 -stats link show dev wg0)

View File

@ -187,7 +187,7 @@ qemu: $(KERNEL_BZIMAGE)
-nographic \
-smp $(NR_CPUS) \
$(QEMU_MACHINE) \
-m $$(grep -q CONFIG_DEBUG_KMEMLEAK=y $(KERNEL_PATH)/.config && echo 1G || echo 192M) \
-m 1G \
-serial stdio \
-serial file:$(BUILD_PATH)/result \
-no-reboot \