Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1307239rbb; Mon, 26 Feb 2024 05:36:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV2VmX1w0qYS7vvXRIadWrJyEMKoYc4v3dCsOXsQzeys6Kcw5ZUnmD4o4BCaC2+2+kZDpDhw+qSLglMh5NJZ5ZmUhPIB1yDwILOGK3AEA== X-Google-Smtp-Source: AGHT+IG2Re51qeaIqzjGKhn4YXKpcpBOt6FTXKm8UyQ37b1finNHt/xD7H+E2tt2EYLExy5eenqs X-Received: by 2002:a17:903:2347:b0:1d9:a4a5:7a6c with SMTP id c7-20020a170903234700b001d9a4a57a6cmr10027517plh.57.1708954583680; Mon, 26 Feb 2024 05:36:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708954583; cv=pass; d=google.com; s=arc-20160816; b=Xa2tQ3Mbc02wV6dNisK97SjCykx4eTN9Eya09pM29ORibciuVB4lLCr0IrIULTNE4W XUoR+3StCcztRCJJkaoTENtAIjKw9gntBrZefgOiEioTXoHeYqaQMdhtZ6PbCreITaOc AN83EOZnYE6HKJWqST0cPqYq7+y9Jqr2Gc+pauXFfgdMZJEIPdpLb/6mcohYCpsAcbcx w2B8evD0848cXzgeMZlmNr6u0VRaBWe2PB93KxgkOynmS22RkfR1bqj9zzM3wdH/56P5 fy3AgdfaiJ9DRkM7OR81Q56KDC1BepQLPHUKi8Yrv3YwaVgTe79L4X5D4TGgjV9hnwf8 mijQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nKK055mv1j/Z9vKql8/G9L+FsnZ6ZSRNmb0WnX+x8Qw=; fh=/pACME0x50g4vorTSG5vEdNwgU981WFvy8LGbk4DPBk=; b=R0erxxidV6lUTR9vUgEFs69gTuZv0kAfrurSvQi0TtOzFnmCQOmbHy7B4jQdoyzHxo 1Wiy1W6FoQNPN7jZmuibE3AsuAPTTV4ugRX4pfHimGLkoByKrZQbRMX9qFbPTibWhBBv jnDfNLTDZpjQChiqaB4isHiMtSeDQIbzjer+omZpGO7otNWEIhFcH3jjwxF4wyI+Z2D+ FGvS28foT4sfhubE/Ey/nIBrgeXKVxCvVm9S4u1rcTTjAzdbD5PhNFy43PRTEZRHMV8B YuIaZF8DhNWxRKX03pZmge0aJ4Lj7CV5X43OY+a4SbEW4dnCq0pNL/afzEaaAfNgHjXZ X/rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hgleoIV7; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-81442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e12-20020a170903240c00b001dbc1be3778si3690602plo.383.2024.02.26.05.36.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 05:36:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hgleoIV7; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-81442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E6993B25EEC for ; Mon, 26 Feb 2024 13:07:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC58E8289F; Mon, 26 Feb 2024 13:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hgleoIV7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 848F680BED; Mon, 26 Feb 2024 13:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708952826; cv=none; b=iX88P2wCtSDM4gWNnW+6/oCf0nM3yXx5z3EwhBQNc9ta08MwHigiDykstIKhQxlOZkmwZZ9bW2a96y9IYb06wFc/zQCB/kR8ZtgHewPyevq9rtb8+2fvv1dYIqLuyqkW2fFW3GVM7WuV9sr9MmlA8ClTtQYPgtK6Maouk6aKyGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708952826; c=relaxed/simple; bh=g0yR6WYCfEXEviJaKQNvbY0qMoOFIzumiw2MxAGGP1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S0X/USeLTE6HvZFIvCDLzawj2rgT8CSneBmhr7GtXBvw6+0BcgmTMK1gAziGpqtMJI5S2Vq8AXcDCVmXBqzDRCJuFBhrOKeZv8bTRcRyANSsx685T8Dmy8Qc1ywVzVbgUAgeA9JZKPGDDly5GM06uEzLdyvwxz6yQtSJS5CD87M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hgleoIV7; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708952825; x=1740488825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g0yR6WYCfEXEviJaKQNvbY0qMoOFIzumiw2MxAGGP1c=; b=hgleoIV7vY8cLCxHH5D0PXpdcbTx98RcwO6Gz4A7hooT1qhfLH51YvXP s9K0ULOm4gtpbycPjVwlfX0ngij0ouzzpJegL9TK5CIhkm6PKUch2nAjA 2J6q9uGYWptTzekHJIl7G3ApZBSz+6F7e6LfzsSCY+oiQQVBm7IQQRt2u hvrIGmZlrkI/DYg/KrKPkN4uUDIIyhNzYPzJbh/5tSxfj0U1yLgZkgRzB 7qUPJCl+deEdlPpa6FtPul9ztnRd/YCIVftxkxsTMSwMmrOigB2dYEsFg ZDIBFvac8asl3wduVkd/jBLQt8/YmuukxmpDCisNtD6p/7yZFKjwHQ+HL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="14669182" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="14669182" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 05:06:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6586251" Received: from pkwiatko-mobl.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.23.220]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 05:06:34 -0800 From: Maciej Wieczor-Retman To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v4 2/3] selftests/resctrl: Simplify cleanup in ctrl-c handler Date: Mon, 26 Feb 2024 14:05:49 +0100 Message-ID: <8ebd39230ab62eea7e1357c56e1d416e85b54c52.1708949785.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Ctrl-c handler isn't aware of what test is currently running. Because of that it executes all cleanups even if they aren't necessary. Since the ctrl-c handler uses the sa_sigaction system no parameters can be passed to it as function arguments. Add a global variable to make ctrl-c handler aware of the currently run test and only execute the correct cleanup callback. Signed-off-by: Maciej Wieczor-Retman --- Changelog v4: - Reset current_test pointer and check if it's not NULL before calling. (Reinette) Changelog v3: - Make current_test static. (Ilpo) - Add callback NULL pointer guard in ctrl-c handler. (Ilpo) Changelog v2: - Remove tests_cleanup() from resctrl.h. - Make current_test a const pointer only inside resctrl_val.c. (Ilpo) tools/testing/selftests/resctrl/resctrl.h | 3 +-- tools/testing/selftests/resctrl/resctrl_tests.c | 14 +++----------- tools/testing/selftests/resctrl/resctrl_val.c | 8 ++++++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 0f49df4961ea..826783b29c9d 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -153,7 +153,6 @@ int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, const char * const *benchmark_cmd, struct resctrl_val_param *param); -void tests_cleanup(void); void mbm_test_cleanup(void); void mba_test_cleanup(void); unsigned long create_bit_mask(unsigned int start, unsigned int len); @@ -162,7 +161,7 @@ int get_full_cbm(const char *cache_type, unsigned long *mask); int get_mask_no_shareable(const char *cache_type, unsigned long *mask); int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); -int signal_handler_register(void); +int signal_handler_register(const struct resctrl_test *test); void signal_handler_unregister(void); void cat_test_cleanup(void); unsigned int count_bits(unsigned long n); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 75fc49ba3efb..161f5365b4f0 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -75,19 +75,11 @@ static void cmd_help(void) printf("\t-h: help\n"); } -void tests_cleanup(void) -{ - mbm_test_cleanup(); - mba_test_cleanup(); - cmt_test_cleanup(); - cat_test_cleanup(); -} - -static int test_prepare(void) +static int test_prepare(const struct resctrl_test *test) { int res; - res = signal_handler_register(); + res = signal_handler_register(test); if (res) { ksft_print_msg("Failed to register signal handler\n"); return res; @@ -130,7 +122,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p ksft_print_msg("Starting %s test ...\n", test->name); - if (test_prepare()) { + if (test_prepare(test)) { ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); return; } diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 5a49f07a6c85..445f306d4c2f 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -62,6 +62,7 @@ struct imc_counter_config { static char mbm_total_path[1024]; static int imcs; static struct imc_counter_config imc_counters_config[MAX_IMCS][2]; +static const struct resctrl_test *current_test; void membw_initialize_perf_event_attr(int i, int j) { @@ -472,7 +473,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr) if (bm_pid) kill(bm_pid, SIGKILL); umount_resctrlfs(); - tests_cleanup(); + if (current_test && current_test->cleanup) + current_test->cleanup(); ksft_print_msg("Ending\n\n"); exit(EXIT_SUCCESS); @@ -482,13 +484,14 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr) * Register CTRL-C handler for parent, as it has to kill * child process before exiting. */ -int signal_handler_register(void) +int signal_handler_register(const struct resctrl_test *test) { struct sigaction sigact = {}; int ret = 0; bm_pid = 0; + current_test = test; sigact.sa_sigaction = ctrlc_handler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = SA_SIGINFO; @@ -510,6 +513,7 @@ void signal_handler_unregister(void) { struct sigaction sigact = {}; + current_test = NULL; sigact.sa_handler = SIG_DFL; sigemptyset(&sigact.sa_mask); if (sigaction(SIGINT, &sigact, NULL) || -- 2.43.2