Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* set_timer latency test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *		John Stultz (john.stultz@linaro.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *              (C) Copyright Linaro 2014
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *              Licensed under the GPLv2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *   This test makes sure the set_timer api is correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  To build:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	$ gcc set-timer-lat.c -o set-timer-lat -lrt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *   This program is free software: you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *   the Free Software Foundation, either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *   (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *   GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <pthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "../kselftest.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define CLOCK_REALTIME			0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define CLOCK_MONOTONIC			1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define CLOCK_PROCESS_CPUTIME_ID	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define CLOCK_THREAD_CPUTIME_ID		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define CLOCK_MONOTONIC_RAW		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define CLOCK_REALTIME_COARSE		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define CLOCK_MONOTONIC_COARSE		6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define CLOCK_BOOTTIME			7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define CLOCK_REALTIME_ALARM		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define CLOCK_BOOTTIME_ALARM		9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define CLOCK_HWSPECIFIC		10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define CLOCK_TAI			11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define NR_CLOCKIDS			12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define NSEC_PER_SEC 1000000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define TIMER_SECS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) int alarmcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) int clock_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) struct timespec start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) long long max_latency_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) int timer_fired_early;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) char *clockstring(int clockid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	switch (clockid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	case CLOCK_REALTIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return "CLOCK_REALTIME";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	case CLOCK_MONOTONIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return "CLOCK_MONOTONIC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	case CLOCK_PROCESS_CPUTIME_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return "CLOCK_PROCESS_CPUTIME_ID";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	case CLOCK_THREAD_CPUTIME_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return "CLOCK_THREAD_CPUTIME_ID";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	case CLOCK_MONOTONIC_RAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return "CLOCK_MONOTONIC_RAW";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	case CLOCK_REALTIME_COARSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return "CLOCK_REALTIME_COARSE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	case CLOCK_MONOTONIC_COARSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return "CLOCK_MONOTONIC_COARSE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	case CLOCK_BOOTTIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return "CLOCK_BOOTTIME";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	case CLOCK_REALTIME_ALARM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return "CLOCK_REALTIME_ALARM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	case CLOCK_BOOTTIME_ALARM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return "CLOCK_BOOTTIME_ALARM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	case CLOCK_TAI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return "CLOCK_TAI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return "UNKNOWN_CLOCKID";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) long long timespec_sub(struct timespec a, struct timespec b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) void sigalarm(int signo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	long long delta_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct timespec ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	clock_gettime(clock_id, &ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	alarmcount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	delta_ns = timespec_sub(start_time, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	delta_ns -= NSEC_PER_SEC * TIMER_SECS * alarmcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (delta_ns < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		timer_fired_early = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (delta_ns > max_latency_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		max_latency_ns = delta_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void describe_timer(int flags, int interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	printf("%-22s %s %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			clockstring(clock_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			flags ? "ABSTIME":"RELTIME",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			interval ? "PERIODIC":"ONE-SHOT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct sigevent se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct itimerspec its1, its2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* Set up timer: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	memset(&se, 0, sizeof(se));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	se.sigev_notify = SIGEV_SIGNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	se.sigev_signo = SIGRTMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	se.sigev_value.sival_int = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	max_latency_ns = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	alarmcount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	timer_fired_early = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	err = timer_create(clock_id, &se, tm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		if ((clock_id == CLOCK_REALTIME_ALARM) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		    (clock_id == CLOCK_BOOTTIME_ALARM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			printf("%-22s %s missing CAP_WAKE_ALARM?    : [UNSUPPORTED]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 					clockstring(clock_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					flags ? "ABSTIME":"RELTIME");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			/* Indicate timer isn't set, so caller doesn't wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		printf("%s - timer_create() failed\n", clockstring(clock_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	clock_gettime(clock_id, &start_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		its1.it_value = start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		its1.it_value.tv_sec += TIMER_SECS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		its1.it_value.tv_sec = TIMER_SECS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		its1.it_value.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	its1.it_interval.tv_sec = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	its1.it_interval.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	err = timer_settime(*tm1, flags, &its1, &its2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		printf("%s - timer_settime() failed\n", clockstring(clock_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int check_timer_latency(int flags, int interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	describe_timer(flags, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	printf("timer fired early: %7d : ", timer_fired_early);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!timer_fired_early) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		printf("[OK]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		printf("[FAILED]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	describe_timer(flags, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	printf("max latency: %10lld ns : ", max_latency_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (max_latency_ns < UNRESONABLE_LATENCY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		printf("[OK]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		printf("[FAILED]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int check_alarmcount(int flags, int interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	describe_timer(flags, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	printf("count: %19d : ", alarmcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (alarmcount == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		printf("[OK]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	printf("[FAILED]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int do_timer(int clock_id, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	timer_t tm1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	const int interval = TIMER_SECS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	err = setup_timer(clock_id, flags, interval, &tm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* Unsupported case - return 0 to not fail the test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return err == 1 ? 0 : err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	while (alarmcount < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		sleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	timer_delete(tm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return check_timer_latency(flags, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int do_timer_oneshot(int clock_id, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	timer_t tm1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	const int interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct timeval timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	err = setup_timer(clock_id, flags, interval, &tm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* Unsupported case - return 0 to not fail the test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return err == 1 ? 0 : err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	memset(&timeout, 0, sizeof(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	timeout.tv_sec = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		err = select(0, NULL, NULL, NULL, &timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	} while (err == -1 && errno == EINTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	timer_delete(tm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	err = check_timer_latency(flags, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	err |= check_alarmcount(flags, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int main(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct sigaction act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int signum = SIGRTMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* Set up signal handler: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	sigfillset(&act.sa_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	act.sa_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	act.sa_handler = sigalarm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	sigaction(signum, &act, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	printf("Setting timers for every %i seconds\n", TIMER_SECS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	for (clock_id = 0; clock_id < NR_CLOCKIDS; clock_id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if ((clock_id == CLOCK_PROCESS_CPUTIME_ID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 				(clock_id == CLOCK_THREAD_CPUTIME_ID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				(clock_id == CLOCK_MONOTONIC_RAW) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				(clock_id == CLOCK_REALTIME_COARSE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				(clock_id == CLOCK_MONOTONIC_COARSE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				(clock_id == CLOCK_HWSPECIFIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		ret |= do_timer(clock_id, TIMER_ABSTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		ret |= do_timer(clock_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		ret |= do_timer_oneshot(clock_id, TIMER_ABSTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		ret |= do_timer_oneshot(clock_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return ksft_exit_fail();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return ksft_exit_pass();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }