setitimer() doesn't work properly starting with 4.8-rc1
From: Andrei Vagin
Date: Wed Aug 17 2016 - 15:03:32 EST
Hello,
I found that setitimer() doesn't work properly on out test AMD fitlet.
It works correctly in the 4.7 kernel and doesn't work in 4.8-rc1.
A small test is attached to this message.
[root@usr-LAN-dhcp-38 ~]# uname -a
Linux usr-LAN-dhcp-38.99.sw.ru 4.8.0-0.rc2.git1.1.fc25.x86_64 #1 SMP
Tue Aug 16 22:08:16 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@usr-LAN-dhcp-38 ~]# strace ./test-timers
...
rt_sigaction(SIGVTALRM, {0x400606, [VTALRM], SA_RESTORER|SA_RESTART,
0x7f51e0d67770}, {SIG_DFL, [], 0}, 8) = 0
setitimer(ITIMER_VIRTUAL, {it_interval={0, 100000}, it_value={0,
100}}, NULL) = 0
exit_group(0) = ?
+++ exited with 0 +++
We can see that a test didn't get any signals. When timers works, this
output looks like this:
rt_sigaction(SIGALRM, {0x400606, [ALRM], SA_RESTORER|SA_RESTART,
0x7f9e21b1b770}, {SIG_DFL, [], 0}, 8) = 0
setitimer(ITIMER_REAL, {it_interval={0, 100000}, it_value={0, 100}}, NULL) = 0
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]}) = 6295208
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]}) = 0
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]}) = 1
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]}) = 1
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]}) = 1471459909
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]}) = 1
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
Only ITIMER_PROF and ITIMER_VIRTUAL doesn't work properly. ITIMER_REAL
works as expected.
[root@usr-LAN-dhcp-38 ~]# cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 22
model : 48
model name : AMD A10 Micro-6700T APU+AMD Radeon R6 Graphics
stepping : 1
microcode : 0x7030105
cpu MHz : 1000.000
cache size : 2048 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt
pdpe1gb rdtscp lm constant_tsc rep_good acc_power nopl nonstop_tsc
extd_apicid aperfmperf eagerfpu pni pclmulqdq monitor ssse3 cx16
sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm
cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch
osvw ibs skinit wdt topoext perfctr_nb bpext ptsc perfctr_l2 cpb
hw_pstate vmmcall bmi1 xsaveopt arat npt lbrv svm_lock nrip_save
tsc_scale flushbyasid decodeassists pausefilter pfthreshold
overflow_recov
bugs : fxsave_leak sysret_ss_attrs null_seg
bogomips : 2395.40
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb acc_power [13]
This problem was caught by criu tests:
https://github.com/xemul/criu/issues/200
Thanks,
Andrei
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
static struct {
const int timer_type;
const int signal;
volatile sig_atomic_t count;
} timer_tests[] = { /* from slowest to fastest */
{ ITIMER_VIRTUAL, SIGVTALRM },
{ ITIMER_PROF, SIGPROF },
{ ITIMER_REAL, SIGALRM },
};
static int count;
static void timer_tick(int sig)
{
count++;
}
int main()
{
struct itimerval tv = {
.it_interval = {
.tv_sec = 0,
.tv_usec = 100000
},
.it_value = {
.tv_sec = 0,
.tv_usec = 100
},
};
int i = 0;
time_t start;
if (signal(timer_tests[i].signal, timer_tick) == SIG_ERR)
exit(1);
if (setitimer(timer_tests[i].timer_type, &tv, NULL) < 0)
exit(1);
start = time(NULL);
for (;;)
if (time(NULL) - start > 10)
break;
return 0;
}