>Yes, you'll need some sort of synchronization.
>Lock (or rwlock) is one option, but as build could take quite long time - 
>probably not the best one.
>Another way - have a struct cthat ontains pointers to 2 ctx and an index for 
>active one.
>Then you can do classify() on active one while doing add_rules/build on second 
>one.
>Then when the second one is re-build you can switch an active index to it.
>I think librte_table uses that method.
>Of course you might need a reference counter or some other way to deternine 
>that
>no-one is using old copy anymore and it is free to update it again.
>Konstantin 


I have look at the source of samplevnf as below doc, it switchover active and 
standby directlt without ensuring old copy not used anymore.
https://github.com/opnfv/samplevnf/blob/master/VNFs/vACL/pipeline/pipeline_acl.c:
 cmd_acl_applyruleset_parsed


So, my question is that how to ensure that no-one is using old copy anymore ? 


thanks!
------------------ ???????? ------------------
??????: "Ananyev, Konstantin";<konstantin.anan...@intel.com>;
????????: 2018??1??8??(??????) ????8:17
??????: "????????"<1534057...@qq.com>;"dev"<dev@dpdk.org>;

????: RE: ??????RE: [dpdk-dev] Thread safety in rte_acl






>> 2. Is it safe that one
>> thread will run  "rte_acl_classify" when another thread tries to add new 
>> rules to same ctx? thanks,

>Just add new rules is safe, but applying them (calling rte_acl_build()) is not.

> In my case, there are two process sharing hugepage memory??struct 
> rte_acl_ctx??,  one process call 'rte_acl_build' to add and apply rule, 
> another process call  frequently 'rte_acl_classify' to > match rule, does it 
> need to add lock? if not, is there other method to implement this safely?

Yes, you'll need some sort of synchronization.
Lock (or rwlock) is one option, but as build could take quite long time - 
probably not the best one.
Another way - have a struct cthat ontains pointers to 2 ctx and an index for 
active one.
Then you can do classify() on active one while doing add_rules/build on second 
one.
Then when the second one is re-build you can switch an active index to it.
I think librte_table uses that method.
Of course you might need a reference counter or some other way to deternine that
no-one is using old copy anymore and it is free to update it again.
Konstantin 


------------------ ???????? ------------------
??????: "Ananyev, Konstantin";<konstantin.anan...@intel.com>;
????????: 2018??1??8??(??????) ????7:42
??????: "????????"<1534057...@qq.com>;"dev"<dev@dpdk.org>;
????: RE: [dpdk-dev] Thread safety in rte_acl

> 
> Hi, I have two questions : 1. Is it safe that multiple threads will run 
> "rte_acl_classify" in parallel  (on the same ctx )?

Yes.

> 2. Is it safe that one
> thread will run  "rte_acl_classify" when another thread tries to add new 
> rules to same ctx? thanks,

Just add new rules is safe, but applying them (calling rte_acl_build()) is not.
Konstantin

Reply via email to