Skip to content

Commit

Permalink
selftests/resctrl: Cleanup properly when an error occurs in CAT test
Browse files Browse the repository at this point in the history
After creating a child process with fork() in CAT test, if an error
occurs when parent process runs cat_val() or check_results(), the child
process will not be killed and also resctrlfs is not unmounted. Also if
an error occurs when child process runs cat_val() or check_results(),
the parent process will wait for the pipe message from the child process
which will never be sent by the child process and the parent process
cannot proceed to unmount resctrlfs.

Synchronize the exits between the parent and child. An error could
occur whether in parent process or child process. The parent process
always kills the child process and runs umount_resctrlfs(). The
child process always waits to be killed by the parent process.

Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Shaopeng Tan authored and Shuah Khan committed Apr 13, 2023
1 parent a080b6e commit 39e34dd
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tools/testing/selftests/resctrl/cat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,20 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
remove(param.filename);

ret = cat_val(&param);
if (ret)
return ret;

ret = check_results(&param);
if (ret)
return ret;
if (ret == 0)
ret = check_results(&param);

if (bm_pid == 0) {
/* Tell parent that child is ready */
close(pipefd[0]);
pipe_message = 1;
if (write(pipefd[1], &pipe_message, sizeof(pipe_message)) <
sizeof(pipe_message)) {
close(pipefd[1]);
sizeof(pipe_message))
/*
* Just print the error message.
* Let while(1) run and wait for itself to be killed.
*/
perror("# failed signaling parent process");
return errno;
}

close(pipefd[1]);
while (1)
Expand All @@ -226,5 +223,5 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
if (bm_pid)
umount_resctrlfs();

return 0;
return ret;
}

0 comments on commit 39e34dd

Please sign in to comment.