From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 3A46B5A026D for ; Thu, 14 Mar 2024 16:54:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710431648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J1Vg+k+P41C75AIP1V/UZrGxQdAkze/WMIcMLQDgBys=; b=ACF2H0iobXgPhjAQsCGilxUPAYIHfIAwjcvvahXfQos5rLduR9CF9PlqdLiAXBwilhCYAW eBCkUNprHVVweKK8w3gWKkIxcDqaHLc+p9AQPC4IxgqIJd5kEhCA5pkRjfOjQUkwN6w4/d Zk43jIl77w1+RGFyOMQr/ChsFtN7gZ8= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-v8b8J_G0PE-eAlQB3Zi56Q-1; Thu, 14 Mar 2024 11:54:06 -0400 X-MC-Unique: v8b8J_G0PE-eAlQB3Zi56Q-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-513d125058eso746284e87.2 for ; Thu, 14 Mar 2024 08:54:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710431644; x=1711036444; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J1Vg+k+P41C75AIP1V/UZrGxQdAkze/WMIcMLQDgBys=; b=r7hs4SqITUwG4TwW6jAlsmDuFiXA/JhLsYXs+h/LNrWDtLRh1uETat4LOvqJMcwdlJ KUweDGyz2EMO6df82XCFd+rpQvMTkdeofw42ecOYuI9PnXtY8HS7YtVILlqFlndVuIFx n5wrMZYYDhVDtTI4XITaqDhnlxV9RGVc9whdniWBNKhefSE2xByn6sRrsnV/P0efUJ7B 3H1tuBaTY5pbYp3Sc4PiwWNzeEoFq++FIdA4pNMIjtFLPWUHrsbFOWLZAV2p1gUkPjpl 4xTC/7SREPE+3NMzP7JiczbevbN/Q1oEe1RyHZxUY9VpQfFSoUldX3gAMr0ex6h3hYtl OBLg== X-Gm-Message-State: AOJu0YzfqYfPhdYQ1oAteX1kDO3PrjeKSBQ7XiQcvmL4x56c4SC7w79q DXVCSNztGQIsngW5UU7EqLfCZlFvq+cVxSzlgCzAWWF9slpLRoiTnimZmj+H70hovL83YZ+KgoI k9MEtIl6gXgeGlRBJ9RLXzQ9aLqdzfMrACu9gVcR8ek2fYQtMUA== X-Received: by 2002:a05:6512:704:b0:513:cc18:d4c6 with SMTP id b4-20020a056512070400b00513cc18d4c6mr396666lfs.41.1710431644455; Thu, 14 Mar 2024 08:54:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEO7b45Xt0A063+Hq+JUXKpzCh43sEQlo0TlPHq5qfBLef+LMO4GABQlxDW/jrGmYl6yP50Ng== X-Received: by 2002:a05:6512:704:b0:513:cc18:d4c6 with SMTP id b4-20020a056512070400b00513cc18d4c6mr396655lfs.41.1710431644041; Thu, 14 Mar 2024 08:54:04 -0700 (PDT) Received: from [192.168.100.30] ([82.142.8.70]) by smtp.gmail.com with ESMTPSA id u9-20020a05600c138900b00412f2136793sm5985572wmf.44.2024.03.14.08.54.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 08:54:03 -0700 (PDT) Message-ID: <893d5b17-cb92-49bf-8752-7ba1d798ceeb@redhat.com> Date: Thu, 14 Mar 2024 16:54:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC] tcp: Replace TCP buffer structure by an iovec array To: Stefano Brivio References: <20240311133356.1405001-1-lvivier@redhat.com> <20240313123725.7a37f311@elisabeth> <84cadd0b-4102-4bde-bad6-45705cca34ce@redhat.com> <20240314164707.75ee6501@elisabeth> From: Laurent Vivier In-Reply-To: <20240314164707.75ee6501@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: HXOUXTUBZAVNWXLXZEHCWHVGQAJFPSLR X-Message-ID-Hash: HXOUXTUBZAVNWXLXZEHCWHVGQAJFPSLR X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 3/14/24 16:47, Stefano Brivio wrote: > On Thu, 14 Mar 2024 15:07:48 +0100 > Laurent Vivier wrote: > >> On 3/13/24 12:37, Stefano Brivio wrote: >> ... >>>> @@ -390,6 +414,42 @@ static size_t tap_send_frames_passt(const struct ctx *c, >>>> return i; >>>> } >>>> >>>> +/** >>>> + * tap_send_iov_passt() - Send out multiple prepared frames >>> >>> ...I would argue that this function prepares frames as well. Maybe: >>> >>> * tap_send_iov_passt() - Prepare TCP_IOV_VNET parts and send multiple frames >>> >>>> + * @c: Execution context >>>> + * @iov: Array of frames, each frames is divided in an array of iovecs. >>>> + * The first entry of the iovec is updated to point to an >>>> + * uint32_t storing the frame length. >>> >>> * @iov: Array of frames, each one a vector of parts, TCP_IOV_VNET blank >>> >>>> + * @n: Number of frames in @iov >>>> + * >>>> + * Return: number of frames actually sent >>>> + */ >>>> +static size_t tap_send_iov_passt(const struct ctx *c, >>>> + struct iovec iov[][TCP_IOV_NUM], >>>> + size_t n) >>>> +{ >>>> + unsigned int i; >>>> + >>>> + for (i = 0; i < n; i++) { >>>> + uint32_t vnet_len; >>>> + int j; >>>> + >>>> + vnet_len = 0; >>> >>> This could be initialised in the declaration (yes, it's "reset" at >>> every loop iteration). >>> >>>> + for (j = TCP_IOV_ETH; j < TCP_IOV_NUM; j++) >>>> + vnet_len += iov[i][j].iov_len; >>>> + >>>> + vnet_len = htonl(vnet_len); >>>> + iov[i][TCP_IOV_VNET].iov_base = &vnet_len; >>>> + iov[i][TCP_IOV_VNET].iov_len = sizeof(vnet_len); >>>> + >>>> + if (!tap_send_frames_passt(c, iov[i], TCP_IOV_NUM)) >>> >>> ...which would now send a single frame at a time, but actually it can >>> already send everything in one shot because it's using sendmsg(), if you >>> move it outside of the loop and do something like (untested): >>> >>> return tap_send_frames_passt(c, iov, TCP_IOV_NUM * n); >>> >>>> + break; >>>> + } >>>> + >>>> + return i; >>>> + >>>> +} >>>> + >> >> I tried to do something like that but I have a performance drop: >> >> static size_t tap_send_iov_passt(const struct ctx *c, >> struct iovec iov[][TCP_IOV_NUM], >> size_t n) >> { >> unsigned int i; >> uint32_t vnet_len[n]; >> >> for (i = 0; i < n; i++) { >> int j; >> >> vnet_len[i] = 0; >> for (j = TCP_IOV_ETH; j < TCP_IOV_NUM; j++) >> vnet_len[i] += iov[i][j].iov_len; >> >> vnet_len[i] = htonl(vnet_len[i]); >> iov[i][TCP_IOV_VNET].iov_base = &vnet_len[i]; >> iov[i][TCP_IOV_VNET].iov_len = sizeof(uint32_t); >> } >> >> return tap_send_frames_passt(c, &iov[0][0], TCP_IOV_NUM * n) / TCP_IOV_NUM; >> } >> >> iperf3 -c localhost -p 10001 -t 60 -4 >> >> berfore >> [ ID] Interval Transfer Bitrate Retr >> [ 5] 0.00-60.00 sec 33.0 GBytes 4.72 Gbits/sec 1 sender >> [ 5] 0.00-60.06 sec 33.0 GBytes 4.72 Gbits/sec receiver >> >> after: >> [ ID] Interval Transfer Bitrate Retr >> [ 5] 0.00-60.00 sec 18.2 GBytes 2.60 Gbits/sec 0 sender >> [ 5] 0.00-60.07 sec 18.2 GBytes 2.60 Gbits/sec receiver > > Weird, it looks like doing one sendmsg() per frame results in a higher > throughput than one sendmsg() per multiple frames, which sounds rather > absurd. Perhaps we should start looking into what perf(1) reports, in > terms of both syscall overhead and cache misses. > > I'll have a look later today or tomorrow -- unless you have other > ideas as to why this might happen... > Perhaps in first case we only update one vnet_len and in the second case we have to update an array of vnet_len, so there is an use of more cache lines? Thanks, Laurent