@@ -2137,13 +2137,39 @@ ff_hook_fork(void)
21372137#ifdef FF_MULTI_SC
21382138 current_worker_id ++ ;
21392139 ERR_LOG ("parent process, current_worker_id++:%d\n" , current_worker_id );
2140+ #endif
2141+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2142+ sc -> forking = 1 ;
2143+ /* Loop until child fork done. */
2144+ while (sc -> forking );
21402145#endif
21412146 }
21422147 else if (pid == 0 ) {
21432148 ERR_LOG ("chilid process, sc:%p, sc->refcount:%d, ff_so_zone:%p\n" ,
21442149 sc , sc -> refcount , ff_so_zone );
21452150#ifdef FF_MULTI_SC
21462151 ERR_LOG ("chilid process, current_worker_id:%d\n" , current_worker_id );
2152+ #endif
2153+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2154+ struct ff_so_context * parent_sc = sc ;
2155+
2156+ /* Child process attach new sc */
2157+ ff_adapter_child_process_init ();
2158+
2159+ /*
2160+ * The fork system call duplicates the file
2161+ * descriptors that were open in the parent process
2162+ */
2163+ DEFINE_REQ_ARGS (fork );
2164+ args -> parent_thread_handle = parent_sc -> ff_thread_handle ;
2165+ /* Output value */
2166+ args -> child_thread_handle = NULL ;
2167+ SYSCALL (FF_SO_FORK , args );
2168+ if (ret == 0 ) {
2169+ sc -> ff_thread_handle = args -> child_thread_handle ;
2170+ }
2171+
2172+ parent_sc -> forking = 0 ;
21472173#endif
21482174 }
21492175
@@ -2442,6 +2468,16 @@ thread_destructor(void *sc)
24422468 }
24432469}
24442470
2471+ static inline int
2472+ ff_application_exit (struct ff_so_context * sc )
2473+ {
2474+ DEFINE_REQ_ARGS (exit_application );
2475+ args -> sc = sc ;
2476+ SYSCALL (FF_SO_EXIT_APPLICATION , args );
2477+
2478+ return ret ;
2479+ }
2480+
24452481void __attribute__((destructor ))
24462482ff_adapter_exit ()
24472483{
@@ -2455,13 +2491,19 @@ ff_adapter_exit()
24552491 for (i = 0 ; i < worker_id ; i ++ ) {
24562492 ERR_LOG ("pthread self tid:%lu, detach sc:%p\n" , pthread_self (), scs [i ].sc );
24572493 ff_so_zone = ff_so_zones [i ];
2458- ff_detach_so_context (scs [i ].sc );
2494+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2495+ ff_application_exit (scs [i ].sc );
2496+ #endif
2497+ ff_detach_so_context (scs [i ].sc );
24592498 }
24602499 } else
24612500#endif
24622501 {
24632502 ERR_LOG ("pthread self tid:%lu, detach sc:%p\n" , pthread_self (), sc );
2464- ff_detach_so_context (sc );
2503+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2504+ ff_application_exit (sc );
2505+ #endif
2506+ ff_detach_so_context (sc );
24652507 sc = NULL ;
24662508 }
24672509#endif
@@ -2618,11 +2660,40 @@ ff_adapter_init()
26182660
26192661 rte_spinlock_unlock (& worker_id_lock );
26202662
2663+ #ifdef FF_USE_THREAD_STRUCT_HANDLE
2664+ /*
2665+ * Request to fstack, alloc sc->ff_thread_handle
2666+ * Every appliaction
2667+ */
2668+ {
2669+ DEFINE_REQ_ARGS (register_application );
2670+ args -> sc = sc ;
2671+ SYSCALL (FF_SO_REGISTER_APPLICATION , args );
2672+ if (ret < 0 ) {
2673+ return -1 ;
2674+ }
2675+ }
2676+ #endif
2677+
26212678 ERR_LOG ("ff_adapter_init success, sc:%p, status:%d, ops:%d\n" , sc , sc -> status , sc -> ops );
26222679
26232680 return 0 ;
26242681}
26252682
2683+ int
2684+ ff_adapter_child_process_init (void )
2685+ {
2686+ sc = ff_attach_so_context (0 );
2687+ if (sc == NULL ) {
2688+ ERR_LOG ("ff_attach_so_context failed\n" );
2689+ return -1 ;
2690+ }
2691+
2692+ ERR_LOG ("ff_adapter_child_process_init success, sc:%p, status:%d, ops:%d\n" , sc , sc -> status , sc -> ops );
2693+
2694+ return 0 ;
2695+ }
2696+
26262697void
26272698alarm_event_sem ()
26282699{
0 commit comments