@@ -2303,13 +2303,39 @@ ff_hook_fork(void)
23032303#ifdef FF_MULTI_SC
23042304 current_worker_id ++ ;
23052305 ERR_LOG ("parent process, current_worker_id++:%d\n" , current_worker_id );
2306+ #endif
2307+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2308+ sc -> forking = 1 ;
2309+ /* Loop until child fork done. */
2310+ while (sc -> forking );
23062311#endif
23072312 }
23082313 else if (pid == 0 ) {
23092314 ERR_LOG ("chilid process, sc:%p, sc->refcount:%d, ff_so_zone:%p\n" ,
23102315 sc , sc -> refcount , ff_so_zone );
23112316#ifdef FF_MULTI_SC
23122317 ERR_LOG ("chilid process, current_worker_id:%d\n" , current_worker_id );
2318+ #endif
2319+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2320+ struct ff_so_context * parent_sc = sc ;
2321+
2322+ /* Child process attach new sc */
2323+ ff_adapter_child_process_init ();
2324+
2325+ /*
2326+ * The fork system call duplicates the file
2327+ * descriptors that were open in the parent process
2328+ */
2329+ DEFINE_REQ_ARGS (fork );
2330+ args -> parent_thread_handle = parent_sc -> ff_thread_handle ;
2331+ /* Output value */
2332+ args -> child_thread_handle = NULL ;
2333+ SYSCALL (FF_SO_FORK , args );
2334+ if (ret == 0 ) {
2335+ sc -> ff_thread_handle = args -> child_thread_handle ;
2336+ }
2337+
2338+ parent_sc -> forking = 0 ;
23132339#endif
23142340 }
23152341
@@ -2608,6 +2634,16 @@ thread_destructor(void *sc)
26082634 }
26092635}
26102636
2637+ static inline int
2638+ ff_application_exit (struct ff_so_context * sc )
2639+ {
2640+ DEFINE_REQ_ARGS (exit_application );
2641+ args -> sc = sc ;
2642+ SYSCALL (FF_SO_EXIT_APPLICATION , args );
2643+
2644+ return ret ;
2645+ }
2646+
26112647void __attribute__((destructor ))
26122648ff_adapter_exit ()
26132649{
@@ -2621,13 +2657,19 @@ ff_adapter_exit()
26212657 for (i = 0 ; i < worker_id ; i ++ ) {
26222658 ERR_LOG ("pthread self tid:%lu, detach sc:%p\n" , pthread_self (), scs [i ].sc );
26232659 ff_so_zone = ff_so_zones [i ];
2624- ff_detach_so_context (scs [i ].sc );
2660+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2661+ ff_application_exit (scs [i ].sc );
2662+ #endif
2663+ ff_detach_so_context (scs [i ].sc );
26252664 }
26262665 } else
26272666#endif
26282667 {
26292668 ERR_LOG ("pthread self tid:%lu, detach sc:%p\n" , pthread_self (), sc );
2630- ff_detach_so_context (sc );
2669+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2670+ ff_application_exit (sc );
2671+ #endif
2672+ ff_detach_so_context (sc );
26312673 sc = NULL ;
26322674 }
26332675#endif
@@ -2784,11 +2826,40 @@ ff_adapter_init()
27842826
27852827 rte_spinlock_unlock (& worker_id_lock );
27862828
2829+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2830+ /*
2831+ * Request to fstack, alloc sc->ff_thread_handle
2832+ * Every appliaction
2833+ */
2834+ {
2835+ DEFINE_REQ_ARGS (register_application );
2836+ args -> sc = sc ;
2837+ SYSCALL (FF_SO_REGISTER_APPLICATION , args );
2838+ if (ret < 0 ) {
2839+ return -1 ;
2840+ }
2841+ }
2842+ #endif
2843+
27872844 ERR_LOG ("ff_adapter_init success, sc:%p, status:%d, ops:%d\n" , sc , sc -> status , sc -> ops );
27882845
27892846 return 0 ;
27902847}
27912848
2849+ int
2850+ ff_adapter_child_process_init (void )
2851+ {
2852+ sc = ff_attach_so_context (0 );
2853+ if (sc == NULL ) {
2854+ ERR_LOG ("ff_attach_so_context failed\n" );
2855+ return -1 ;
2856+ }
2857+
2858+ ERR_LOG ("ff_adapter_child_process_init success, sc:%p, status:%d, ops:%d\n" , sc , sc -> status , sc -> ops );
2859+
2860+ return 0 ;
2861+ }
2862+
27922863void
27932864alarm_event_sem ()
27942865{
0 commit comments