> On Fri,  7 Feb 2025 15:21:45 -0800
> lon...@linuxonhyperv.com wrote:
> 
> > +   /* At least one eth_dev is probed, init shared data */
> > +   if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
> > +           rte_spinlock_lock(&mana_shared_data_lock);
> > +           mana_local_data.primary_cnt++;
> > +           rte_spinlock_unlock(&mana_shared_data_lock);
> > +   } else {
> > +           rte_spinlock_lock(&mana_shared_data_lock);
> > +           mana_local_data.secondary_cnt++;
> > +           rte_spinlock_unlock(&mana_shared_data_lock);
> > +
> > +           rte_spinlock_lock(&mana_shared_data->lock);
> > +           mana_shared_data->secondary_cnt++;
> > +           rte_spinlock_unlock(&mana_shared_data->lock);
> 
> If all you are doing is wanting a MP safe counter, use atomic operations 
> instead of
> the overhead of a spin lock.

mana_shared_data_lock is also used to protect init_done, mana_shared_mz and 
mana_shared_data.  That's why I'm reusing it for primary_cnt and secondary_cnt 
as those values are initialized in locked context at the beginning for the 
local process. I think this will make the code look clean. 

I can remove mana_shared_data->lock and use atomic for 
mana_shared_data->secondary_cnt.

Will send v2.

Thanks,

Long

Reply via email to