From owner-freebsd-ipfw@freebsd.org Fri Apr 10 06:50:07 2020 Return-Path: Delivered-To: freebsd-ipfw@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 85CA52B425E; Fri, 10 Apr 2020 06:50:07 +0000 (UTC) (envelope-from ozkan.kirik@gmail.com) Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48z7tQ61WPz4sd6; Fri, 10 Apr 2020 06:50:06 +0000 (UTC) (envelope-from ozkan.kirik@gmail.com) Received: by mail-vs1-xe2f.google.com with SMTP id z63so830859vsz.2; Thu, 09 Apr 2020 23:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NTwHza1u6b+yBmZ78FAaw25N6tPR3oz5c1qG88t/lcs=; b=uAnOQeqvVjaYv2qwMTrmJmIWz8EwiWrZCV1xTDSjtXem6R4R3n7G+X1Aa/cOqFMwhJ 4WZPNfTTsYeSXMDM4dg5CpiOX3+KrcpKN2c9/R2ppntRzW9lFG8u8G5S4tUd+E48YxQk V2ilA4eKilyUP1sRE8w6m0Hw8YZbzKY0pPhxvgqplhTtFvOYH1McvNtLSSRdf7oIRCxC qqWO2PHeSUw17YekJ4wf9wpwXE+5+7Yok2YE1O1ufziTifb7+bEZEoodig10Hww6YLbh okaV2dCiKRlCqqbNx0HGvbis9vDGTB6EMCwi+SSgcs7OXTuOlHiahX6T382YW26iGLGV zPdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NTwHza1u6b+yBmZ78FAaw25N6tPR3oz5c1qG88t/lcs=; b=UDDcKnrp/yrHTlrDnWYq2dbYCBVPgYyrXj0LF7k7kpXYhOrZCGFGoSBrEXPJyahLWS DJTHbZKwq8V2v5y2BIKHOkrqYspr+6a+jpyrzjvdxR+OSYV246amiNo/zOrcUgbuxAmA l6dZucocPOsJctUFI59fq94ZGcaOsCvHWT+XY4x6+eHuF77weR47MK14iU9X9JJVULxo LiNQHU10l4KD4wb122DVjwpDp/WdZ1sY26PIN5uPVEh2izo4xiunKPjWmFrnpyVWeui6 l6SDs8eX/bSB74j4Q1P/abjrThPkIR94KD3Y7jnGJbx9q1g8NMphqgijKr+NKsCwZm4T Swag== X-Gm-Message-State: AGi0PuYCRGow2Y+9PpiczZDFCMgHytAFcIAc75qO/YYoi0pGGN1rX53O Rl/qOQPJL3ENr7IAaodCYZliLVsO87hBo1JiAro= X-Google-Smtp-Source: APiQypLJVtGw/w3u+DsawnbE+BVr+JMm2BUGyitChGct2zLSr8Cirvrir52zHTjAPCW/WaYoZw1YwpjrFCDpXHevh58= X-Received: by 2002:a05:6102:10c9:: with SMTP id t9mr2654873vsr.41.1586501405689; Thu, 09 Apr 2020 23:50:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?B?w5Z6a2FuIEtJUklL?= Date: Fri, 10 Apr 2020 09:49:51 +0300 Message-ID: Subject: Re: dummynet performance To: Luigi Rizzo Cc: "freebsd-net@freebsd.org" , freebsd-ipfw , "Andrey V. Elsukov" X-Rspamd-Queue-Id: 48z7tQ61WPz4sd6 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=uAnOQeqv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of ozkankirik@gmail.com designates 2607:f8b0:4864:20::e2f as permitted sender) smtp.mailfrom=ozkankirik@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; IP_SCORE(0.00)[ip: (-9.54), ipnet: 2607:f8b0::/32(-0.33), asn: 15169(-0.43), country: US(-0.05)]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; TO_DN_SOME(0.00)[]; IP_SCORE_FREEMAIL(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[f.2.e.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Apr 2020 06:50:07 -0000 Thanks! On Thu, Apr 9, 2020 at 8:29 PM Luigi Rizzo wrote: > On Thu, Apr 9, 2020 at 2:18 AM =C3=96zkan KIRIK w= rote: > > > > Hello, > > > > I wonder if it is possible to update dummynet code multi-threading > capable > > practically? > > My idea is below: > > - A new sysctl tunable will be defined as > > "net.inet.ip.dummynet.thread_count" (default 1) > > - To distribute tasks along threads, each sched instance can be assigne= d > to > > different thread. > > - By default, all schedulers assigned to thread 0 if no thread_id is se= t. > > With a new option named "thr_id" affinity can be set. as below: > > ipfw sched 1 config type QFQ (by defaut thr_id =3D 0) > > ipfw sched 2 config type QFQ thr_id 1 > > ipfw sched 3 config type QFQ thr_id 2 > > ipfw sched 4 config type FIFO thr_id 3 > > ipfw sched 5 config type FIFO thr_id 3 ( sched 4 & 5 assigned to sam= e > > thread 3 ) > > > > I think this approach is more easy then completely rewrite or other > > solutions. > > > > This change may not be completely trivial given that dummynet was designe= d > as > single threaded and protected by a single lock. > > If you want to proceed, you should do as follows: > - some members of struct dn_parms need to be duplicated for each thread, > including prev_t, evheap, curr_time, the locks, and perhaps others. > Probably may be useful to create a new struct for them, with a back > pointer to the parent dn_parms, and include a refcount. > > - add another rwlock to protect access to dn_cfg > > - dummynet_io() does the initial demultiplexing calling dn_ht_find(), > currently protected DN_BH_WLOCK(). This could be changed to an RWLOCK > and I believe this initial step could be protected by a read lock > (maybe there are corner cases where you need to create a new entry > so you need to drop the lock, acquire in write mode and retry...) > > - once the demux has returned a dn_fsk, maybe you can use a refcount > to avoid the object being destroyed, release the read lock on > dn_cfg.fshash, acquire an exclusive lock on the thread handling the > dn_fsk, and proceed from there. > > - the kernel thread that process the heap should now run each on > one instance of the evheap > > cheers > luigi >