[dpdk-dev] 回复:RE: 回复:RE: 回复:RE: 回复:RE: Thread safety in rte_acl

真我风采 1534057243 at qq.com
Mon Jan 15 11:41:10 CET 2018


Yes, but now there is only one process doing classify() in our case, so it just suitable.


thanks !!!




------------------ 原始邮件 ------------------
发件人: "Ananyev, Konstantin";<konstantin.ananyev at intel.com>;
发送时间: 2018年1月15日(星期一) 晚上6:34
收件人: "真我风采"<1534057243 at qq.com>;"Ramia, Kannan Babu"<kannan.babu.ramia at intel.com>;"dev"<dev at dpdk.org>;

主题: RE: 回复:RE: 回复:RE: 回复:RE: [dpdk-dev] Thread safety in rte_acl



  
That should work too I think…
 
But in that case your data-plane would have to grab exclusive lock
 
(in case you have multiple threads/processes) doing classify()
 
over the same context in parallel.
 
Konstantin
 
 
    
From: 真我风采 [mailto:1534057243 at qq.com] 
 Sent: Monday, January 15, 2018 2:01 AM
 To: Ananyev, Konstantin <konstantin.ananyev at intel.com>; Ramia, Kannan Babu <kannan.babu.ramia at intel.com>; dev <dev at dpdk.org>
 Subject: 回复:RE: 回复:RE: 回复:RE: [dpdk-dev] Thread safety in rte_acl
 
 
 
 
  
Thanks for providing idea to me! I will refer to that.
 
  
 
 
  
I have another way feeling that it should works too. switchover active and standby pointer on forward plane, rather than on control plane. when update ctx in control plane(add rule, build on standby, meanwhile add rule on active not build),  set flag=1, and on forward plane if flag==1 then switchover and set flag=0. 
 
  
 
 
  
 
 
  
 
 
   
 
 
  
 
 
  
------------------ 原始邮件 ------------------
 
   
发件人: "Ananyev, Konstantin";<konstantin.ananyev at intel.com>;
 
  
发送时间: 2018年1月10日(星期三) 晚上7:46
 
  
收件人: "真我风采"<1534057243 at qq.com>;"Ramia,  Kannan Babu"<kannan.babu.ramia at intel.com>;"dev"<dev at dpdk.org>;
 
  
主题: RE: 回复:RE: 回复:RE: [dpdk-dev] Thread safety in rte_acl
 
 
  
 
 
  
 
 
The simplest one would be to have rwlock to read/write active index.
 
Also something like that I think should work (just a sample, not tested or compiled):
 
 
 
struct acl {
 
       rte_acl_ctx *ctx[2];
 
       rte_atomic32_t use;
 
       uint32_t active;
 
};
 
 
 
update(struct acl *acl, …)
 
{
 
   <update/rebuild  non-acive copy>
 
   /* make sure all stores are visible */
 
   rte_smp_wmb();
 
  
 
   uint32_t  active = acl->active;
 
   acl->active = active ^ 1;
 
    /* to avoid store/load reorder */
 
   rte_smp_mb();
 
 
 
   while (rte_atomic32_read(&acl->use) != 0)
 
      rte_pause();
 
  
 
   <free old active copy here>
 
}
 
 
 
classify(struct acl *acl, …)
 
{
 
     rte_atomic32_inc(&acl->use);
 
     rte_acl_classify(acl->ctx[acl->active}, …);
 
     rte_atomic32_dec(&acl->use);
 
}
 
 
 
Konstantin
 
 
    
From:  真我风采 [mailto:1534057243 at qq.com] 
 Sent: Wednesday, January 10, 2018 2:50 AM
 To: Ananyev, Konstantin <konstantin.ananyev at intel.com>; Ramia, Kannan Babu <kannan.babu.ramia at intel.com>; dev <dev at dpdk.org>
 Subject:  回复:RE:  回复:RE: [dpdk-dev] Thread safety in rte_acl
 
 
 
 
  

 >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.ananyev at intel.com>;
 
  
 发送时间: 2018年1月8日(星期一) 晚上8:17
 
  
 收件人: "真我风采"<1534057243 at qq.com>;"dev"<dev at 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.ananyev at intel.com>;
 发送时间: 2018年1月8日(星期一) 晚上7:42
 收件人: "真我风采"<1534057243 at qq.com>;"dev"<dev at 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


More information about the dev mailing list