From patchwork Mon Mar 4 18:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13580979 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875A361694 for ; Mon, 4 Mar 2024 18:11:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575914; cv=none; b=jwT8K5U4GCoIZYhDpMpp378NqDzapYjboMzAS+UWjjYP12c1hWQUjBsawwSaWL4UK4XSpCvfvERXSaV3II5hbH64dbKXyCnMjVvbXikCfD8RRPisZliTXpk5gUOvYtMTPmXdyuWOvwUpAkHrV3Ncn1KrpeVYBdtLtTe+x+rZEZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575914; c=relaxed/simple; bh=CC+iy3zkI7zBVRFWIq21TO6LNko9XBBY5WLB//p8GHg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fo986BRF0RghVELnBcV+TS44QDETAqMW7r6hqOkOQoTDjWfCOboFY3GZ6aZPNiAcjt/O43HZ8V6/tx0RyfUXD4C68e5Mxd0D9X/owwUEv0JWK3Z4QF1rRVkQGRsYWY2Dcca5TkqgT1GKRwqnZB9ABv55+jVZagf4Y0TeYRD+TmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OeBX8bue; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OeBX8bue" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5dcab65d604so4177280a12.3 for ; Mon, 04 Mar 2024 10:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709575912; x=1710180712; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LIR4tpXfm1Zf9xB2dvSMHOKf+DsIJbzUCheSmbqVnZ4=; b=OeBX8buewaY1kn0YxAr60HF8GT+bam5EAHRrzD1UD9WzYaAFTdHvLa6G05VdOIyPQ9 TWy6Eais3lPUwiPxFBeTmXROOqZBFFT175/urypfiVHcZIKKrmfPSFcNJBTADO6I9Hqa cT7ZzZvykcGOwL+GFvhGR+cD0H4aPtrNgeh6GlnnyIh2IqZ7ZL665v9/m4/P+wieY140 MbIetNTiWmm/9LpZ6AIJuI59a8HojXIVC6GsxeWRTLhI3qkESE3Lno9a/lskoSUqL7Fr btN/mlWjkWhc5dJs5vpWj2fZa+BxjCEeJDzgAbh7gZlgYgeyu6aRfM/FYnowm3DlxsJw 40fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709575912; x=1710180712; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LIR4tpXfm1Zf9xB2dvSMHOKf+DsIJbzUCheSmbqVnZ4=; b=w1uU60YAUInW87LptF2w/NHUlO5nzW86Hwp20PXIUIJGJMWOGDaUqHiYW7HRVA6gX+ SOyKIijiY+msuioWlt4lyVeHrvekl8w5i1D4s/zg2tDcv/VAbXmO4uXOQDubWL8JZmUE WbYbSxQvfJ2zoT+ynRzPQDeK4R7kdy/HdSI6uqszZLDKZtDo4K/JbfMQ1uYKZWgri31U EnOKOM3wGgrB9cWX/1hqE8DWmyV7TnLtE9EkwAbC5A4MYMIQ4KsZyedSB32Ga3hURf+p 3h88B1ctgQ59FvVXR3KPHq6IclboRLP/EK1u0nutNEF5nlUA5EDUmo422eOJ8Phoj46b wy7g== X-Gm-Message-State: AOJu0Yy8NFmj2ArYVroM9L+PcRa6isL/yFLZ3wrZMyLzfBj+pupFjFac 75O7cMtMWSOhZK/xvpGXePubsGkBK7yIbxW3LrhMRI2iiLjgZ3HJ3EM/0Ae6vo6tWFjDS9q/HNj d7w== X-Google-Smtp-Source: AGHT+IGIW0ufgJvmiSiJkJzOrk9GFG7bJv+6od4sTBFNYKROiEAkCjdjVmtZBIbw5QLdFBP3IxMZvCRuZms= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:902:db02:b0:1dc:b7d2:453e with SMTP id m2-20020a170902db0200b001dcb7d2453emr168006plx.0.1709575911467; Mon, 04 Mar 2024 10:11:51 -0800 (PST) Date: Mon, 4 Mar 2024 18:11:32 +0000 In-Reply-To: <20240304181140.644212-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304181140.644212-1-edliaw@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240304181140.644212-2-edliaw@google.com> Subject: [PATCH v1 1/3] selftests/timers/posix_timers: Make signal distribution test less fragile From: Edward Liaw To: linux-kernel@vger.kernel.org, John Stultz , Thomas Gleixner , Stephen Boyd , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-kselftest@vger.kernel.org, kernel-team@android.com, Edward Liaw , llvm@lists.linux.dev The signal distribution test has a tendency to hang for a long time as the signal delivery is not really evenly distributed. Increasing the timer interval to 10ms makes this less likely. Add a timeout to catch the case where it hangs and terminate the test gracefully. While at it get rid of the pointless atomic operation on a the thread local variable in the signal handler. Signed-off-by: Thomas Gleixner [edliaw: Rebase and fix checkpatch recommendations] Signed-off-by: Edward Liaw --- tools/testing/selftests/timers/posix_timers.c | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c index d49dd3ffd0d9..03779b6b3c20 100644 --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -24,7 +24,8 @@ static volatile int done; /* Busy loop in userspace to elapse ITIMER_VIRTUAL */ static void user_loop(void) { - while (!done); + while (!done) + continue; } /* @@ -184,18 +185,19 @@ static int check_timer_create(int which) return 0; } -int remain; -__thread int got_signal; +static int remain; +static __thread int got_signal; static void *distribution_thread(void *arg) { - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED) && !done) + continue; return NULL; } static void distribution_handler(int nr) { - if (!__atomic_exchange_n(&got_signal, 1, __ATOMIC_RELAXED)) + if (++got_signal == 1) __atomic_fetch_sub(&remain, 1, __ATOMIC_RELAXED); } @@ -205,17 +207,19 @@ static void distribution_handler(int nr) */ static int check_timer_distribution(void) { - int err, i; - timer_t id; const int nthreads = 10; pthread_t threads[nthreads]; struct itimerspec val = { .it_value.tv_sec = 0, - .it_value.tv_nsec = 1000 * 1000, + .it_value.tv_nsec = 20 * 1000 * 1000, .it_interval.tv_sec = 0, - .it_interval.tv_nsec = 1000 * 1000, + .it_interval.tv_nsec = 20 * 1000 * 1000, }; + time_t start, now; + int err, i; + timer_t id; + done = 0; remain = nthreads + 1; /* worker threads + this thread */ signal(SIGALRM, distribution_handler); err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); @@ -240,7 +244,18 @@ static int check_timer_distribution(void) } /* Wait for all threads to receive the signal. */ - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + now = start = time(NULL); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED)) { + now = time(NULL); + if (now - start > 5) + break; + } + done = 1; + + if (timer_delete(id)) { + ksft_perror("Can't delete timer\n"); + return -1; + } for (i = 0; i < nthreads; i++) { err = pthread_join(threads[i], NULL); @@ -251,12 +266,8 @@ static int check_timer_distribution(void) } } - if (timer_delete(id)) { - ksft_perror("Can't delete timer"); - return -1; - } + ksft_test_result((now - start <= 5), "%s\n", __func__); - ksft_test_result_pass("check_timer_distribution\n"); return 0; } @@ -265,7 +276,7 @@ int main(int argc, char **argv) ksft_print_header(); ksft_set_plan(6); - ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n"); + ksft_print_msg("Testing posix timers. False negative may happen on CPU execution\n"); ksft_print_msg("based timers if other threads run on the CPU...\n"); if (check_itimer(ITIMER_VIRTUAL) < 0) From patchwork Mon Mar 4 18:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13580980 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 650D5626A2 for ; Mon, 4 Mar 2024 18:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575917; cv=none; b=c1TaaL7zDV+iU2MEkjqcHkd54tQlc0KrRjZWbBhZWLeC2o+2nLYlPEEWZJdcyH/9vBmE0rNySAL+6K+O2I5aiDNmjuVdvo+nWMGozGfDeoxWtF1LdGyKm2M73YJkc4qrsXeBx5Oa31aeY6B5axPBaAIkfLO9vGMz2fMKxJi8RTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575917; c=relaxed/simple; bh=MScqXbgh2ejjfIy/Sp3FOyl/aojS0G+mf0C488clcqM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gs3C89aH8Hu4Kgx0aAY8e3Ga6e7noDwzFWLy+m6Ja+I90dyICY9beJEZ8JhVngPaewlTug1Vhm1XQDqI5bL+o5R5211UtcW3YGmEvE2cMBu+bCGOQs6xACVxSPIxcsMXosMthCJ63OLBsDDsFqdwbeCbXcVS86b80HRKquon3U8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MBRadz7n; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MBRadz7n" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-6e5ef8a99c3so1444683b3a.1 for ; Mon, 04 Mar 2024 10:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709575914; x=1710180714; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Fs5vwdtP3lE2gaF2HIymTQhqiVBDxVfpiBYTXFLcGDM=; b=MBRadz7nigWYpyo8/CbRPu96WLBxFTKw0iHAhZvpSgYEO1egBlm1G+8nLznqvJuFn+ 2DCRaP0+batPwFl1b97h3eiywqtFiXMLaZ+0lAQAPvbMw/Wjs7CcnrzryvuVme0q4y7x 2LFgBepljtx0iNZYX5Bo1jC53EgDccItYeOkCAaad4fMkmCT6J/pqGjHrltEmQ/nJZR/ uq5vVGhGmeE9jQC1VFAK72ITDftadM3TkF2YYuDXaIHZNyOGpOaJbyekUrtvc4o8VWX7 e4T7nflLq1/CJvQmmcysIc2FqHqf+10yJInRsme58RuDAX+uK3szv1nNL0Yc0KKEkkBr eVtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709575914; x=1710180714; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fs5vwdtP3lE2gaF2HIymTQhqiVBDxVfpiBYTXFLcGDM=; b=lj2NsFtRRH3rsR7YZogmii2a0iifOyAbihSbO2ODur4HdDlJ36lsXs9M5o3blrHDvd foIPtZjKJhbZyrU0i1FxSRBGJM6ZT/U6cv52qTFb/WlJ63SV4veTVnkL1LQ/hB97bjeo DWZtaIgWSyy+S3Wmif9pZ/VI4AvCTErNnj8S7Gk2yuucwwVSTYLy2SblQej5UF+IY7fw IkNySDDqa90ku8yKHUUSw5wKD1ugN8or5xi0Gfg3ukFSF4BGVW7CxPukisAM1rViKuZk XjCkm6wEMU7Y9NgYKj6Q1ap9PJlPWSy8WIXf9PSqj37f22roLsPzCCeztesBUBdOY7KB 0ujg== X-Gm-Message-State: AOJu0YzL6Jmrq4dC9IBP9q/tfDahIkGpQJKebDs2k2gEw5YJTvjFYbJ5 riJPi1JikCA/NSkuI+yqGbb4767OuuURRnH5/WTJvEO5Yp9suYB8iyFz1RJX++a4+slGBX+a223 isQ== X-Google-Smtp-Source: AGHT+IF7KqVnyc41EkIolVtSQO6rbDjjbbUw9e2d1bsUL0JqfeSVikRN4mrRaBo+n6JY/DRESTPhKhoP27U= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:aa7:888a:0:b0:6e6:2541:8b4a with SMTP id z10-20020aa7888a000000b006e625418b4amr24416pfe.5.1709575914639; Mon, 04 Mar 2024 10:11:54 -0800 (PST) Date: Mon, 4 Mar 2024 18:11:33 +0000 In-Reply-To: <20240304181140.644212-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304181140.644212-1-edliaw@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240304181140.644212-3-edliaw@google.com> Subject: [PATCH v1 2/3] selftests/timers/posix_timers: Use TAP reporting format From: Edward Liaw To: linux-kernel@vger.kernel.org, John Stultz , Thomas Gleixner , Stephen Boyd , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-kselftest@vger.kernel.org, kernel-team@android.com, Edward Liaw , llvm@lists.linux.dev No functional change. Signed-off-by: Thomas Gleixner [edliaw: Fix checkpatch recommendations] Signed-off-by: Edward Liaw --- tools/testing/selftests/timers/posix_timers.c | 161 +++++++----------- 1 file changed, 66 insertions(+), 95 deletions(-) diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c index 03779b6b3c20..0f550fc9e879 100644 --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,20 @@ #define DELAY 2 #define USECS_PER_SEC 1000000 +static void __fatal_error(const char *test, const char *name, const char *what) +{ + char buf[64]; + + strerror_r(errno, buf, sizeof(buf)); + + if (name && strlen(name)) + ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, buf); + else + ksft_exit_fail_msg("%s %s %s\n", test, what, buf); +} + +#define fatal_error(name, what) __fatal_error(__func__, name, what) + static volatile int done; /* Busy loop in userspace to elapse ITIMER_VIRTUAL */ @@ -67,15 +82,13 @@ static int check_diff(struct timeval start, struct timeval end) diff = end.tv_usec - start.tv_usec; diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; - if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { - printf("Diff too high: %lld..", diff); + if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) return -1; - } return 0; } -static int check_itimer(int which) +static void check_itimer(int which) { const char *name; int err; @@ -91,7 +104,7 @@ static int check_itimer(int which) else if (which == ITIMER_REAL) name = "ITIMER_REAL"; else - return -1; + ksft_exit_fail_msg("Unknown setitimer() type %d\n", which); done = 0; @@ -103,16 +116,12 @@ static int check_itimer(int which) signal(SIGALRM, sig_handler); err = gettimeofday(&start, NULL); - if (err < 0) { - ksft_perror("Can't call gettimeofday()"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); err = setitimer(which, &val, NULL); - if (err < 0) { - ksft_perror("Can't set timer"); - return -1; - } + if (err < 0) + fatal_error(name, "setitimer()"); if (which == ITIMER_VIRTUAL) user_loop(); @@ -122,19 +131,15 @@ static int check_itimer(int which) idle_loop(); err = gettimeofday(&end, NULL); - if (err < 0) { - ksft_perror("Can't call gettimeofday()"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); - ksft_test_result(check_diff(start, end) == 0, "%s\n", name); - - return 0; + ksft_test_result(!check_diff(start, end), "%s %s\n", __func__, name); } -static int check_timer_create(int which) +static void check_timer_create(int which) { - const char *type; + const char *name; int err; timer_t id; struct timeval start, end; @@ -142,47 +147,37 @@ static int check_timer_create(int which) .it_value.tv_sec = DELAY, }; - if (which == CLOCK_THREAD_CPUTIME_ID) { - type = "thread"; - } else if (which == CLOCK_PROCESS_CPUTIME_ID) { - type = "process"; - } else { - ksft_print_msg("Unknown timer_create() type %d\n", which); - return -1; - } + if (which == CLOCK_THREAD_CPUTIME_ID) + name = "thread"; + else if (which == CLOCK_PROCESS_CPUTIME_ID) + name = "process"; + else + ksft_exit_fail_msg("Unknown timer_create() type %d\n", which); done = 0; err = timer_create(which, NULL, &id); - if (err < 0) { - ksft_perror("Can't create timer"); - return -1; - } - signal(SIGALRM, sig_handler); + if (err < 0) + fatal_error(name, "timer_create()"); + + if (signal(SIGALRM, sig_handler) == SIG_ERR) + fatal_error(name, "signal()"); err = gettimeofday(&start, NULL); - if (err < 0) { - ksft_perror("Can't call gettimeofday()"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); err = timer_settime(id, 0, &val, NULL); - if (err < 0) { - ksft_perror("Can't set timer"); - return -1; - } + if (err < 0) + fatal_error(name, "timer_settime()"); user_loop(); err = gettimeofday(&end, NULL); - if (err < 0) { - ksft_perror("Can't call gettimeofday()"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); ksft_test_result(check_diff(start, end) == 0, - "timer_create() per %s\n", type); - - return 0; + "%s %s\n", __func__, name); } static int remain; @@ -205,7 +200,7 @@ static void distribution_handler(int nr) * Test that all running threads _eventually_ receive CLOCK_PROCESS_CPUTIME_ID * timer signals. This primarily tests that the kernel does not favour any one. */ -static int check_timer_distribution(void) +static void check_timer_distribution(void) { const int nthreads = 10; pthread_t threads[nthreads]; @@ -221,26 +216,20 @@ static int check_timer_distribution(void) done = 0; remain = nthreads + 1; /* worker threads + this thread */ - signal(SIGALRM, distribution_handler); + if (signal(SIGALRM, distribution_handler) == SIG_ERR) + fatal_error(NULL, "signal()"); + err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); - if (err < 0) { - ksft_perror("Can't create timer"); - return -1; - } + if (err < 0) + fatal_error(NULL, "timer_create()"); + err = timer_settime(id, 0, &val, NULL); - if (err < 0) { - ksft_perror("Can't set timer"); - return -1; - } + if (err < 0) + fatal_error(NULL, "timer_settime()"); for (i = 0; i < nthreads; i++) { - err = pthread_create(&threads[i], NULL, distribution_thread, - NULL); - if (err) { - ksft_print_msg("Can't create thread: %s (%d)\n", - strerror(errno), errno); - return -1; - } + if (pthread_create(&threads[i], NULL, distribution_thread, NULL)) + fatal_error(NULL, "pthread_create()"); } /* Wait for all threads to receive the signal. */ @@ -252,23 +241,15 @@ static int check_timer_distribution(void) } done = 1; - if (timer_delete(id)) { - ksft_perror("Can't delete timer\n"); - return -1; - } + if (timer_delete(id)) + fatal_error(NULL, "timer_delete()"); for (i = 0; i < nthreads; i++) { - err = pthread_join(threads[i], NULL); - if (err) { - ksft_print_msg("Can't join thread: %s (%d)\n", - strerror(errno), errno); - return -1; - } + if (pthread_join(threads[i], NULL)) + fatal_error(NULL, "pthread_join()"); } ksft_test_result((now - start <= 5), "%s\n", __func__); - - return 0; } int main(int argc, char **argv) @@ -279,17 +260,10 @@ int main(int argc, char **argv) ksft_print_msg("Testing posix timers. False negative may happen on CPU execution\n"); ksft_print_msg("based timers if other threads run on the CPU...\n"); - if (check_itimer(ITIMER_VIRTUAL) < 0) - return ksft_exit_fail(); - - if (check_itimer(ITIMER_PROF) < 0) - return ksft_exit_fail(); - - if (check_itimer(ITIMER_REAL) < 0) - return ksft_exit_fail(); - - if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0) - return ksft_exit_fail(); + check_itimer(ITIMER_VIRTUAL); + check_itimer(ITIMER_PROF); + check_itimer(ITIMER_REAL); + check_timer_create(CLOCK_THREAD_CPUTIME_ID); /* * It's unfortunately hard to reliably test a timer expiration @@ -300,11 +274,8 @@ int main(int argc, char **argv) * to ensure true parallelism. So test only one thread until we * find a better solution. */ - if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) - return ksft_exit_fail(); - - if (check_timer_distribution() < 0) - return ksft_exit_fail(); + check_timer_create(CLOCK_PROCESS_CPUTIME_ID); + check_timer_distribution(); ksft_finished(); } From patchwork Mon Mar 4 18:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13580981 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A558626C7 for ; Mon, 4 Mar 2024 18:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575919; cv=none; b=lXO8MSgafTYz51yV/Du2Sh64qZQHh1Szt3K25kLC8yglEoC7XUs1vBx0XIXMbYjEMH9QHiS5eMbddzYLacQScm7oi1/SDbUWmCHWlX4mPIYfMjDgQdtuR1/5Hc627HruiQyPNgzIel+LaAf56BgAY9fgkBUFS5TqKhoLByqTKRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575919; c=relaxed/simple; bh=FqLV9lNiSU7gSVzmh0RUNwWYr0jxygkZHnJe2yCKIHk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EnY+e2Np1EepXK2W+IAcl4DnQENcd/gVFBe0l9DNvXQj8xUmF2P9ysvFCoQk0oxRSYe8lfd8eQ0Dpzdl+0WDeDQj7pEfmGVI18QRPWkgEN3EGgthLRJ00NMpHSXsoWVyggeUbWB2Ot2k+cNn1oomFB0Mt35hlKmLx1ItiQB0Msg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iD/WO5Y8; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iD/WO5Y8" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6e4867c8ea5so4741842b3a.1 for ; Mon, 04 Mar 2024 10:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709575917; x=1710180717; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+K8qGGJZU0dVFlAnq42rJW59Laz5svfdA3lu6VKJprE=; b=iD/WO5Y8KkmuAscQ9e4EZbwDgCDT9i4D9nGIF0YtbxoP7oW8KvKsLvxBMqkE++Y65Y 5XsHf0AwxpAcwakxfWmtNn82Umw/Zsc9cVo6rlDrf5e3twXtnZA/ssoaSulfpSnROXfO uTy0aUCEFi7L0UlINx5ILgOyJFlOSKlS1IQGbBLt4Up8xI0sQGERCb27i6odUYEoiWkB HAaRlXQ/yHC4Fh+9DCSyIkZEDmhE0emyPQs9QFFKT7W0hfrp/X7cW2xRf+JOgl2vmKC8 BBYxSY48k+LjHTnyRAsy8h1a0jnOKP+rb/OW+zUBgm5N5H17SRy4dV6HE925MFd3tsBT Awvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709575917; x=1710180717; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+K8qGGJZU0dVFlAnq42rJW59Laz5svfdA3lu6VKJprE=; b=UOmx/zErVgYnPns0/FBAODkFhl0agEwqCzujwnhhAF8/DX0qqTfZ0sfay9RgPAJeCu gsS1bezw4uo2KhzrM94GDOdVwONLPOrxRRhKr1EM3kDsXhcBvdcmwbJs/cILIAAIR5wQ xYfG03NtcCFdgqRxN8E62psP5tsF9eSsvxmakhvcjcZQwSTvpeITZvQ/zdMucx3+zSQC Vse+H5jvPEN/iyfxUaFJGjZs0ctA+kfEelaYEmodD99wAEOV1/xvhGnCkrY3LqIGPwuz tjy6Ptp6fXZaQ2FIwKz5LT1hhpHpmayUK42nnsswao8yE3RLpnMsIaFEjjSj45HZV/Y7 62kw== X-Gm-Message-State: AOJu0YwiUqB7IXTyEjxujXEYsbH8Btwr5g1CudjJ7/zy4KTNwpsgo74T rDmXUIyqxkurVXxwpzcascLpbeEDN1o/WzQs3V4xTYBGeQMI3LAA9BayBobkYkOnwULwqK+owNK thQ== X-Google-Smtp-Source: AGHT+IEBwRfcpn5x9AGNzJLGA/hp7XJkS1FIgFGPUMaa1opevJ7wVveO9HifQjBfzJMQbCakv4yNwPEcBGY= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:27a0:b0:6e5:8053:af92 with SMTP id bd32-20020a056a0027a000b006e58053af92mr788006pfb.4.1709575917445; Mon, 04 Mar 2024 10:11:57 -0800 (PST) Date: Mon, 4 Mar 2024 18:11:34 +0000 In-Reply-To: <20240304181140.644212-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304181140.644212-1-edliaw@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240304181140.644212-4-edliaw@google.com> Subject: [PATCH v1 3/3] selftests/timers/posix_timers: Use llabs for long long From: Edward Liaw To: linux-kernel@vger.kernel.org, John Stultz , Thomas Gleixner , Stephen Boyd , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-kselftest@vger.kernel.org, kernel-team@android.com, Edward Liaw , llvm@lists.linux.dev Fixes clang warning: absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value. Signed-off-by: Edward Liaw --- tools/testing/selftests/timers/posix_timers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c index 0f550fc9e879..78b4b2d3dc44 100644 --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -82,7 +82,7 @@ static int check_diff(struct timeval start, struct timeval end) diff = end.tv_usec - start.tv_usec; diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; - if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) + if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) return -1; return 0;