All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Shaopeng Tan (Fujitsu)" <tan.shaopeng@fujitsu.com>
To: 'Reinette Chatre' <reinette.chatre@intel.com>,
	Fenghua Yu <fenghua.yu@intel.com>, Shuah Khan <shuah@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: RE: [PATCH v4 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Date: Fri, 16 Dec 2022 08:20:10 +0000	[thread overview]
Message-ID: <OSZPR01MB632837AC9133DFBD2061637D8BE69@OSZPR01MB6328.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <9801fa7f-5971-1f5f-1b63-0d672c32fcf1@intel.com>

Hi Reinette

> On 12/1/2022 12:20 AM, Shaopeng Tan (Fujitsu) wrote:
> > Hi Reinette,
> >
> >> On 11/30/2022 12:32 AM, Shaopeng Tan (Fujitsu) wrote:
> >>
> >>> Removing ctrl_handler() is only part of the fix in the next version(v5).
> >>> All fixes as follows.
> >>>
> >>> --- a/tools/testing/selftests/resctrl/cat_test.c
> >>> +++ b/tools/testing/selftests/resctrl/cat_test.c
> >>> @@ -98,12 +98,17 @@ void cat_test_cleanup(void)
> >>>         remove(RESULT_FILE_NAME2);
> >>>  }
> >>>
> >>> +static void ctrlc_handler_child(int signum, siginfo_t *info, void
> >>> +*ptr) {
> >>> +       exit(EXIT_SUCCESS);
> >>> +}
> >>> +
> >>
> >> Could you please elaborate why this is necessary?
> >
> > If enter "ctrl-c" when running "resctrl_tests -t cat", SIGINT will be
> > sent to all processes (parent&child).
> >
> > At this time, the child process receives a SIGINT signal, but does not take any
> action.
> > In this case the parent process may not call ctrlc_handler() as expected.
> 
> Apologies, but I am not able to follow. My understanding is that the ideal in
> working an failing case is for the parent to kill the child.
> Could you please elaborate why the ctrlc_handler() may not be called?

Apologies for the late replay.

The problem is that at the time of running CAT test, 
previous ctrlc_handler from MBM/MBA/CMT test will be inherited to child process.

Let me explain in detail:
In resctrl_tests,the default run order of the tests is MBM->MBA->CMT->CAT.
When running MBM, MBA, CMT, signal handler(ctrlc_handler) was set to the parent process.
After these tests, when fork() is executed in CAT, 
the signal handler set by MBM/MBA/CMT is inherited by the parent&child process of CAT.
At this time, if "ctrl+c" SIGINT is sent to parent&child process,
according to the inherited signal handler,
the child process may kill parent process before parent process kills child process.
Therefore, when running all tests(MBM->MBA->CMT->CAT),
signal handler of child process need to be overridden in CAT.

Also, when running CAT test only,
since there are no signal handler that can be inherited from other tests,
signal handler of parent process need to be set.

> > Therefore, ctrlc_handler_child() is necessary.
> >
> > It may be better to ignore the signal, then code can be simple as follows.
> > ----
> >         if (bm_pid == 0) {
> >                 param.mask = l_mask_1;
> >                 strcpy(param.ctrlgrp, "c1");
> >                 strcpy(param.mongrp, "m1");
> >                 param.span = cache_size * n / count_of_bits;
> >                 strcpy(param.filename, RESULT_FILE_NAME1);
> >                 param.num_of_runs = 0;
> >                 param.cpu_no = sibling_cpu_no;
> >                 /* Ignore the signal,and wait to be cleaned up by the parent
> process */
> >                 sigfillset(&sigact.sa_mask);
> >                 sigact.sa_handler = SIG_IGN;
> >                 //sigact.sa_sigaction = ctrlc_handler_child;  //delete
> >                 if (sigaction(SIGINT, &sigact, NULL) ||
> >                     sigaction(SIGTERM, &sigact, NULL) ||
> >                     sigaction(SIGHUP, &sigact, NULL))
> >                         perror("# sigaction");
> >         } else {

Best regards,
Shaopeng

  reply	other threads:[~2022-12-16  8:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17  1:05 [PATCH v4 0/5] Some improvements of resctrl selftest Shaopeng Tan
2022-11-17  1:05 ` [PATCH v4 1/5] selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test Shaopeng Tan
2022-11-17  1:05 ` [PATCH v4 2/5] selftests/resctrl: Return MBA check result and make it to output message Shaopeng Tan
2022-11-17  1:05 ` [PATCH v4 3/5] selftests/resctrl: Flush stdout file buffer before executing fork() Shaopeng Tan
2022-11-17  1:05 ` [PATCH v4 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test Shaopeng Tan
2022-11-23 17:48   ` Reinette Chatre
2022-11-24  8:17     ` Shaopeng Tan (Fujitsu)
2022-11-28 17:11       ` Reinette Chatre
2022-11-30  8:32         ` Shaopeng Tan (Fujitsu)
2022-11-30 16:33           ` Reinette Chatre
2022-12-01  8:20             ` Shaopeng Tan (Fujitsu)
2022-12-01 18:12               ` Reinette Chatre
2022-12-16  8:20                 ` Shaopeng Tan (Fujitsu) [this message]
2022-12-16 19:08                   ` Reinette Chatre
2022-11-17  1:05 ` [PATCH v4 5/5] selftests/resctrl: Remove duplicate codes that clear each test result file Shaopeng Tan
2022-11-23 17:49   ` Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OSZPR01MB632837AC9133DFBD2061637D8BE69@OSZPR01MB6328.jpnprd01.prod.outlook.com \
    --to=tan.shaopeng@fujitsu.com \
    --cc=fenghua.yu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.