Hello,

Please find attached a proposal using atomic_fetchadd.

Best Regards,

Emeric

----- Mail original -----
De: "Adrian Chadd" <adr...@freebsd.org>
À: "Hans Petter Selasky" <h...@selasky.org>
Cc: "Emeric POUPON" <emeric.pou...@stormshield.eu>, "freebsd-net" 
<freebsd-net@freebsd.org>
Envoyé: Vendredi 20 Mars 2015 20:04:44
Objet: Re: Fragment questions

On 20 March 2015 at 11:56, Hans Petter Selasky <h...@selasky.org> wrote:
> On 03/20/15 19:02, Adrian Chadd wrote:
>>
>> On 20 March 2015 at 10:58, Hans Petter Selasky <h...@selasky.org> wrote:
>>>
>>> On 03/20/15 14:31, Emeric POUPON wrote:
>>>>
>>>>
>>>> - in the ip_newid macro, we do "htons(V_ip_id++))" if we do not use
>>>> randomized id.
>>>
>>>
>>>> In multi core systems, we may emit successive packets with the same id.
>>>
>>>
>>> Will using a mutex or an atomic macro fix this issue when incrementing
>>> the
>>> V_ip_id ?
>>
>>
>> It will, but it'll ping-pong between multiple cores and slow things
>> down at high pps.
>>
>
> Hi,
>
> Maybe we can have the V_ip_id per CPU and use the lower 8-bits as random CPU
> core number?

Hm, someone with more cycles to spend on analysing the repercussions
from this should investigate it.

I think in the short term using an atomic is fine, as it's no worse
than what is currently there. But as we get more PPS unlocked and
happening we may need to fix it.



-adrian
--- sys/netinet/ip_var.h.orig	2015-03-23 17:57:40.601072200 +0100
+++ sys/netinet/ip_var.h	2015-03-23 17:58:31.093715177 +0100
@@ -174,7 +174,7 @@ struct inpcb;
 struct route;
 struct sockopt;
 
-VNET_DECLARE(u_short, ip_id);			/* ip packet ctr, for ids */
+VNET_DECLARE(u_int32_t, ip_id);			/* ip packet ctr, for ids */
 VNET_DECLARE(int, ip_defttl);			/* default IP ttl */
 VNET_DECLARE(int, ipforwarding);		/* ip forwarding */
 #ifdef IPSTEALTH
@@ -306,7 +306,7 @@ extern int	(*ip_dn_io_ptr)(struct mbuf *
 VNET_DECLARE(int, ip_do_randomid);
 #define	V_ip_do_randomid	VNET(ip_do_randomid)
 #define	ip_newid()	((V_ip_do_randomid != 0) ? ip_randomid() : \
-			    htons(V_ip_id++))
+			    htons(atomic_fetchadd_32(&V_ip_id, 1) & 0xFFFF))
 
 #endif /* _KERNEL */
 
--- sys/netinet/ip_output.c.orig	2015-03-23 17:57:46.514498846 +0100
+++ sys/netinet/ip_output.c	2015-03-23 17:58:52.124426760 +0100
@@ -91,7 +91,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/ip_
 
 #include <security/mac/mac_framework.h>
 
-VNET_DEFINE(u_short, ip_id);
+VNET_DEFINE(u_int32_t, ip_id);
 
 #ifdef MBUF_STRESS_TEST
 static int mbuf_frag_size = 0;
_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

Reply via email to