Explorar o código

src: starpu catches signal SIGINT and SIGSEGV to do its own stuff, for now, it justs dump the fxt trace file

Nathalie Furmento %!s(int64=7) %!d(string=hai) anos
pai
achega
1ee76fc697
Modificáronse 3 ficheiros con 50 adicións e 3 borrados
  1. 10 2
      src/common/fxt.c
  2. 3 0
      src/common/fxt.h
  3. 37 1
      src/core/workers.c

+ 10 - 2
src/common/fxt.c

@@ -162,8 +162,6 @@ void _starpu_fxt_init_profiling(unsigned trace_buffer_size)
 
 	threadid = _starpu_gettid();
 
-	atexit(_starpu_stop_fxt_profiling);
-
 	if (fut_setup(trace_buffer_size / sizeof(unsigned long), initial_key_mask, threadid) < 0)
 	{
 		perror("fut_setup");
@@ -193,6 +191,16 @@ static void _starpu_generate_paje_trace(char *input_fxt_filename, char *output_p
 	starpu_fxt_generate_trace(&options);
 }
 
+void _starpu_fxt_dump_file(void)
+{
+	if (!_starpu_fxt_started)
+		return;
+#ifdef STARPU_VERBOSE
+	_STARPU_MSG("Writing FxT traces into file %s\n", _STARPU_PROF_FILE_USER);
+#endif
+	fut_endup(_STARPU_PROF_FILE_USER);
+}
+
 void _starpu_stop_fxt_profiling(void)
 {
 	if (!_starpu_fxt_started)

+ 3 - 0
src/common/fxt.h

@@ -279,6 +279,9 @@ void _starpu_fxt_init_profiling(unsigned trace_buffer_size);
 /* Stop the FxT library, and generate the trace file. */
 void _starpu_stop_fxt_profiling(void);
 
+/* Generate the trace file. Used when catching signals SIGINT and SIGSEGV */
+void _starpu_fxt_dump_file(void);
+
 /* Associate the current processing unit to the identifier of the LWP that runs
  * the worker. */
 void _starpu_fxt_register_thread(unsigned);

+ 37 - 1
src/core/workers.c

@@ -1153,6 +1153,40 @@ static void _starpu_build_tree(void)
 #endif
 }
 
+static struct sigaction act_sigint;
+static struct sigaction act_sigsegv;
+
+void _starpu_handler(int sig)
+{
+#ifdef STARPU_VERBOSE
+	_STARPU_MSG("Catching signal '%s'\n", sys_siglist[sig]);
+#endif
+#ifdef STARPU_USE_FXT
+	_starpu_fxt_dump_file();
+#endif
+	if (sig == SIGINT)
+	{
+		sigaction(SIGINT, &act_sigint, NULL);
+	}
+	if (sig == SIGSEGV)
+	{
+		sigaction(SIGSEGV, &act_sigsegv, NULL);
+	}
+#ifdef STARPU_VERBOSE
+	_STARPU_MSG("Rearming signal '%s'\n", sys_siglist[sig]);
+#endif
+	raise(sig);
+}
+
+void _starpu_catch_signals(void)
+{
+	struct sigaction act;
+	act.sa_handler = _starpu_handler;
+
+	sigaction(SIGINT, &act, &act_sigint);
+	sigaction(SIGSEGV, &act, &act_sigsegv);
+}
+
 int starpu_init(struct starpu_conf *user_conf)
 {
 	return starpu_initialize(user_conf, NULL, NULL);
@@ -1439,6 +1473,8 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 	}
 #endif
 
+	_starpu_catch_signals();
+
 	return 0;
 }
 
@@ -1630,7 +1666,7 @@ void starpu_shutdown(void)
 
 	/* tell all workers to shutdown */
 	_starpu_kill_all_workers(&_starpu_config);
-	
+
 	unsigned i;
 	unsigned nb_numa_nodes = starpu_memory_nodes_get_numa_count();
 	for (i=0; i<nb_numa_nodes; i++)