[netsniff-ng] Re: [RFC] trafgen: Alloc cpus regarding to number of packets

2015-03-30 Thread Vadim Kochan
On Mon, Mar 30, 2015 at 02:00:25PM +0200, Tobias Klauser wrote:
> On 2015-03-24 at 12:20:39 +0100, Vadim Kochan  wrote:
> > From: Vadim Kochan 
> > 
> > Trafgen uses all the online cpus even if number of packets specified
> > by -n is less than numbers of selected cpus.
> > Such behaviour leads to issues:
> > 
> > - trafgen re-calculates number of packets per cpu which
> >   leads to rounding it to 0 then no packets will be sent.
> > 
> > - trafgen might send more packets than specified by -n because
> >   of using all the online cpus.
> 
> Good catch!
> 
> > Fixed by calculation the minimum number of cpus for generation
> > number of packets specified by -n.
> > 
> > Signed-off-by: Vadim Kochan 
> > ---
> >  cpus.h| 7 +++
> >  trafgen.c | 3 +++
> >  2 files changed, 10 insertions(+)
> > 
> > diff --git a/cpus.h b/cpus.h
> > index 0626726..be33884 100644
> > --- a/cpus.h
> > +++ b/cpus.h
> > @@ -25,4 +25,11 @@ static inline unsigned int get_number_cpus_online(void)
> > return ret;
> >  }
> >  
> > +static inline unsigned int alloc_cpus_by_n_pkts(int npkts)
> > +{
> > +   unsigned int cpus = get_number_cpus_online();
> > +
> > +   return min_t(unsigned int, ((double)npkts / cpus) * cpus, cpus);
> 
> Why the divide & multiply? Wouldn't min_t(unsigned int, npkt, cpus) be
> enough?
> > +}
> > +
> >  #endif /* CPUS_H */
> > diff --git a/trafgen.c b/trafgen.c
> > index 9151b5d..5403d47 100644
> > --- a/trafgen.c
> > +++ b/trafgen.c
> > @@ -1038,6 +1038,9 @@ int main(int argc, char **argv)
> > }
> > }
> >  
> > +   if (ctx.num && ctx.num < ctx.cpus && ctx.cpus > 1)
> > +   ctx.cpus = alloc_cpus_by_n_pkts(ctx.num);
> 
> I'd rather just inline the min_t here instead of having an own function.
> Maybe put a short comment outlining the two issue you mention in the
> patch description.
> 
> Thanks a lot!
> Tobias
> > +
> > if (argc < 5)
> > help();
> > if (ctx.device == NULL)
> > -- 
> > 2.3.1
> > 

I will follow all your suggestions and I'll re-send a new patch.

Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [netsniff-ng] Re: [PATCH] mz cli: Make pcap init funcs thread safer

2015-03-30 Thread Tobias Klauser
On 2015-03-30 at 11:54:40 +0200, Vadim Kochan  wrote:
> On Sun, Mar 22, 2015 at 01:48:50PM +0200, Vadim Kochan wrote:
> > From: Vadim Kochan 
> > 
> > mz fails start in cli mode and prints each time different pcap errors:
> > 
> > $ mz -x -V
> > fatal flex scanner internal error--end of buffer missed
> > rx_arp: [ERROR] Error calling pcap_compile
> > 
> > or simply shutdowns. Sometimes it successfully gets up.
> > Seems some initialization pcap funcs are not thread safer.
> > 
> > Fixed by using mutex locking before entering pcap loop.
> > 
> > Signed-off-by: Vadim Kochan 
> > ---
> >  locking.h|  2 ++
> >  staging/mopsrx_arp.c | 21 -
> >  2 files changed, 18 insertions(+), 5 deletions(-)
> > 
> > 
> 
> Hi,
> 
> Just pinging if it was missed.

Sorry for the delay, I had quite a large backlog at work.

Applied now. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] Re: [RFC] trafgen: Alloc cpus regarding to number of packets

2015-03-30 Thread Tobias Klauser
On 2015-03-24 at 12:20:39 +0100, Vadim Kochan  wrote:
> From: Vadim Kochan 
> 
> Trafgen uses all the online cpus even if number of packets specified
> by -n is less than numbers of selected cpus.
> Such behaviour leads to issues:
> 
> - trafgen re-calculates number of packets per cpu which
>   leads to rounding it to 0 then no packets will be sent.
> 
> - trafgen might send more packets than specified by -n because
>   of using all the online cpus.

Good catch!

> Fixed by calculation the minimum number of cpus for generation
> number of packets specified by -n.
> 
> Signed-off-by: Vadim Kochan 
> ---
>  cpus.h| 7 +++
>  trafgen.c | 3 +++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/cpus.h b/cpus.h
> index 0626726..be33884 100644
> --- a/cpus.h
> +++ b/cpus.h
> @@ -25,4 +25,11 @@ static inline unsigned int get_number_cpus_online(void)
>   return ret;
>  }
>  
> +static inline unsigned int alloc_cpus_by_n_pkts(int npkts)
> +{
> + unsigned int cpus = get_number_cpus_online();
> +
> + return min_t(unsigned int, ((double)npkts / cpus) * cpus, cpus);

Why the divide & multiply? Wouldn't min_t(unsigned int, npkt, cpus) be
enough?
> +}
> +
>  #endif /* CPUS_H */
> diff --git a/trafgen.c b/trafgen.c
> index 9151b5d..5403d47 100644
> --- a/trafgen.c
> +++ b/trafgen.c
> @@ -1038,6 +1038,9 @@ int main(int argc, char **argv)
>   }
>   }
>  
> + if (ctx.num && ctx.num < ctx.cpus && ctx.cpus > 1)
> + ctx.cpus = alloc_cpus_by_n_pkts(ctx.num);

I'd rather just inline the min_t here instead of having an own function.
Maybe put a short comment outlining the two issue you mention in the
patch description.

Thanks a lot!
Tobias
> +
>   if (argc < 5)
>   help();
>   if (ctx.device == NULL)
> -- 
> 2.3.1
> 

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] Re: [PATCH] mz cli: Make pcap init funcs thread safer

2015-03-30 Thread Vadim Kochan
On Sun, Mar 22, 2015 at 01:48:50PM +0200, Vadim Kochan wrote:
> From: Vadim Kochan 
> 
> mz fails start in cli mode and prints each time different pcap errors:
> 
>   $ mz -x -V
>   fatal flex scanner internal error--end of buffer missed
>   rx_arp: [ERROR] Error calling pcap_compile
> 
> or simply shutdowns. Sometimes it successfully gets up.
> Seems some initialization pcap funcs are not thread safer.
> 
> Fixed by using mutex locking before entering pcap loop.
> 
> Signed-off-by: Vadim Kochan 
> ---
>  locking.h|  2 ++
>  staging/mopsrx_arp.c | 21 -
>  2 files changed, 18 insertions(+), 5 deletions(-)
> 
> 

Hi,

Just pinging if it was missed.

Thanks,
Vadim Kochan

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.