Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1787156rdb; Tue, 20 Feb 2024 07:05:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVdlUiLwlO9fMsCt9chPKzrN15wxVqvMdrPx3nry6H/8VDXZ9qyCG6+by0e9sOoi6XEkH2v+PJKw/E/K7eFZLyGqK8foYwuaPy9LYwgTQ== X-Google-Smtp-Source: AGHT+IF9X94dj2YYaGd3URIqKz2/bRr9ccNv4or8jo2fcUrFMUBILrva8P+Xwr2JJyPwqxp8C8QD X-Received: by 2002:a37:c205:0:b0:787:1873:efc0 with SMTP id i5-20020a37c205000000b007871873efc0mr17537700qkm.48.1708441519520; Tue, 20 Feb 2024 07:05:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708441519; cv=pass; d=google.com; s=arc-20160816; b=YUc4G44FqMmHDH32KDryaX0fC+6lypmhiVw78o7HvI6Pu+SZqhCw8hl2JE7QQd3hBB QwzRK/5qGTCvNhcnsI9Sl1W3epeeik1eAocdw5LC9VQwHTN3zbYPbe8znjCNnxqmAk1T 7zYFxi2jcwbPzc66ZeL+6MGhMBlC0D98lvecRciq3ltANL9hJtQLWFYV+lY+XnYn0rrf ZIizx53AmJxHlZjU3VDVVOPhEH6moMR/wI60urK7KSv9unEfztRhcFuZ5rc9k8NClD3N ncHTAY4s8UlRP5zNvBT9WOakxSi/U4GYOpur4VaXouTXcR0Yu0fnUaIAnX7C/uCkjsd5 D2Pg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:date:from :dkim-signature; bh=8gtCm+ZqXJFn4KOLD/glZmgaWgYtzd4fxM7lIy1pJ74=; fh=jU5jGJ5usTD08gfMkYbEKRhikPRGxP3z78On/gtBHH0=; b=cCIRCXg9NdEGvpEhi0o8oui+amIytFUBrdzRBbzio0Uj1V5FN0mV97t2jSmgAMkljX pgMvpCYERiqe+H6+h2MAjVOlpJ6OXuYNMR0Cj0HbajF5Gg47zrX8MqZUUe/jD0r4MiMG j77TFw40KTbUPvczGox2iYmiBoJIKqJaRi/+D842I2vplLfslgYv4nRc1E4Rt8BYafVR lYn1OnSiZdm9byswSEEw8ZLW8mXk19pglAj/vSBS3dyNAM2WfvSd+V4TEzB73L5FhSHo GITI+hPrGkjug/gh8TPCA4ygnxAeDOn9yNlj0QTRyfFvN6xPzGeLUeFVO3bTzERArzU+ e/Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=A30U9cD9; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-73092-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73092-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m12-20020a05620a220c00b0078732f4e6absi8494095qkh.763.2024.02.20.07.05.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:05:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73092-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=A30U9cD9; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-73092-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73092-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2EFF91C225F9 for ; Tue, 20 Feb 2024 13:45:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AE306A34C; Tue, 20 Feb 2024 13:45:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="A30U9cD9" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 A1C7E5B1E6; Tue, 20 Feb 2024 13:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708436753; cv=none; b=M3smIV9rvokQVDvf6lOIKxtDMalQrVBM000e+oc8PSuVLZbJsO+LShMs3ApPnKDB9V+0fT9WTsNBLgshI419FaZZGPR+R9ycK7ekBGNvEd/Hfri9mhy4tbJccZWEUdbs7Ti9Et9MU8j/b5V5v4CGh61Eih831Tz1y5G8YIVNpe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708436753; c=relaxed/simple; bh=0L+oqvPLfVCK7Ieg6wTiU99ZpvE789Oat2RVeiUpHzs=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=JM5AQK2iefORirx5Tiy+WDFgC9Eo0Q0QOjx9HcHtxL2mIYpysQZsNsvETCAHNqMBsd7eGLcDg8wuv1m1DGiI9LVFz+7ZJ5zxRyKpFtIN+S/6KO9s3eyEJOOYu5UgbhyToWgm0GuBGzhb1oFbgmb/bbY5ampIVmLYn9H8oOxrIFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=A30U9cD9; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708436752; x=1739972752; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=0L+oqvPLfVCK7Ieg6wTiU99ZpvE789Oat2RVeiUpHzs=; b=A30U9cD9Zu8Wxg0FdAk+1paS2Pkg/SS9mxPn4NgDrbJ/ic1lrkBShgYQ hILBwz4qwlJlBYSZHWuNiq9BGAYGxUUe9IRWzTqwYKbCwYLQ62PWy326w 0al3gXJy0biHzuN8FpSRkiz+2IqhWwhT64/XHd6vnesQ2i89kCvQp9r3+ xjNjr8Er5MPArzyDaF5clYkYEZ5k4hHphk4WDFrOcgU0PK9bmaMYcK6Fo c0FCvYxToBzjWmixz5uLxVsIMA47woTxghAryinXpf32/pghX1OII84pk ZJ/UF+8BqxRYSdKftqh3eQNupiPsG1kNeIqBeu3MUty0G28BLD6+9UUNx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13095751" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13095751" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 05:45:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5016328" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.249.21]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 05:45:28 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 20 Feb 2024 15:45:23 +0200 (EET) To: Maciej Wieczor-Retman cc: Fenghua Yu , Reinette Chatre , Shuah Khan , LKML , linux-kselftest@vger.kernel.org Subject: Re: [PATCH 2/3] selftests/resctrl: Simplify cleanup in ctrl-c handler In-Reply-To: <8c4fcfb6b4e38a0f0e400be88ecf1af0d20e12e7.1708434017.git.maciej.wieczor-retman@intel.com> Message-ID: <5f251bcd-a343-bb6e-a947-7605dc59f9ea@linux.intel.com> References: <8c4fcfb6b4e38a0f0e400be88ecf1af0d20e12e7.1708434017.git.maciej.wieczor-retman@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Tue, 20 Feb 2024, Maciej Wieczor-Retman wrote: > 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 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 > --- > tools/testing/selftests/resctrl/resctrl.h | 2 ++ > .../testing/selftests/resctrl/resctrl_tests.c | 20 +++++++++---------- > tools/testing/selftests/resctrl/resctrl_val.c | 2 +- > 3 files changed, 13 insertions(+), 11 deletions(-) > > diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h > index 0f49df4961ea..79b45cbeb628 100644 > --- a/tools/testing/selftests/resctrl/resctrl.h > +++ b/tools/testing/selftests/resctrl/resctrl.h > @@ -128,6 +128,8 @@ extern pid_t bm_pid, ppid; > > extern char llc_occup_path[1024]; > > +extern struct resctrl_test current_test; Why this is not just a pointer? > + > int get_vendor(void); > bool check_resctrlfs_support(void); > int filter_dmesg(void); > diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c > index 75fc49ba3efb..b17f7401892c 100644 > --- a/tools/testing/selftests/resctrl/resctrl_tests.c > +++ b/tools/testing/selftests/resctrl/resctrl_tests.c > @@ -14,6 +14,12 @@ > static volatile int sink_target; > volatile int *value_sink = &sink_target; > > +/* > + * Set during test preparation for the cleanup function pointer used in > + * ctrl-c sa_sigaction > + */ > +struct resctrl_test current_test; > + > static struct resctrl_test *resctrl_tests[] = { > &mbm_test, > &mba_test, > @@ -75,18 +81,12 @@ 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(); > -} This should be removed from resctrl.h too. > - > -static int test_prepare(void) > +static int test_prepare(const struct resctrl_test *test) > { > int res; > > + current_test = *test; I'd prefer to keep this internal to signal handling functions so that either the struct resctrl_test or just the cleanup handler is passed to signal_handler_register(). It'd also allow current_test (or the cleanup function ptr) to be static. -- i.