Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jul 2021 21:16:14 -0500
From:      Mike Karels <mike@karels.net>
To:        stable@freebsd.org
Subject:   Re: aarch64 and kqueue timer events
Message-ID:  <da434512-64f9-c93b-65d7-ed7c539826b0@karels.net>
In-Reply-To: <cc96ff22-ea1c-7e0f-6581-a7565c580b67@shrew.net>
References:  <03ff40c7-b755-8421-713c-90aa4d8535fe@shrew.net> <cc96ff22-ea1c-7e0f-6581-a7565c580b67@shrew.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On 7/27/21 8:43 PM, Matthew Grooms wrote:
> On 7/24/2021 8:18 PM, Matthew Grooms wrote:
>> Hi all,
>>
>> I'm seeing some strange behavior with kqueue timers on my aarch64=20
>> host. Here is a simple test program that I've compiled on both amd64=20
>> and aarch64. It just sets up a simple kqueue timer with a loop that=20
>> waits for the event to fire every 3 seconds ...
>>
>> #include <err.h>
>> #include <time.h>
>> #include <stdio.h>
>> #include <unistd.h>
>> #include <sys/event.h>
>>
>> int main( int argc, char *argv[] )
>> {
>> =C2=A0=C2=A0=C2=A0 int kq =3D kqueue();
>> =C2=A0=C2=A0=C2=A0 if( kq < 0 )
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 err( 1, "failed to obtain k=
queue handle" );
>>
>> =C2=A0=C2=A0=C2=A0 struct kevent ke;
>> =C2=A0=C2=A0=C2=A0 EV_SET( &ke, 1, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0=
, 3000, 0 );
>> =C2=A0=C2=A0=C2=A0 if( kevent( kq, &ke, 1, NULL, 0, NULL ) < 0 )
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 err( 1, "failed to add keve=
nt timer filter" );
>>
>> =C2=A0=C2=A0=C2=A0 printf( "started at %i\n", (int)time(NULL) );
>>
>> =C2=A0=C2=A0=C2=A0 while( true )
>> =C2=A0=C2=A0=C2=A0 {
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int r =3D kevent( kq, NULL,=
 0, &ke, 1, NULL );
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if( r < 0 )
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 err=
( 1, "failed to read kevent list" );
>>
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 printf( "timer fired %i tim=
es at %i\n", r, (int)time(NULL) );
>> =C2=A0=C2=A0=C2=A0 }
>>
>> =C2=A0=C2=A0=C2=A0 return 0;
>> }
>>
>> When I compile and run the code on an amd64 host, everything works as=20
>> expected. The event timer expires once every 3 seconds ...
>>
>> mgrooms@amd64:~/devel$ cc test.cpp -o test && ./test
>> started at 1627175311
>> timer fired 1 times at 1627175314
>> timer fired 1 times at 1627175317
>> timer fired 1 times at 1627175320
>> Thanks in advance,
>>
>> -Matthew
>>
>>
>>
>> However, when I compile and run the same code on an aarch64 host (=20
>> rpi4b ), something very different happens. The event timer expires=20
>> after 3 seconds the first time. But each subsequent expiration is for=20
>> exactly twice the defined interval, 6 seconds ...
>>
>> mgrooms@aarch64:~/devel$ cc test.cpp -o test && ./test
>> started at 1625789207
>> timer fired 1 times at 1625789210
>> timer fired 1 times at 1625789216
>> timer fired 1 times at 1625789222
>>
>> Any idea what's going on here? Seems like a bug somewhere on the arm=20
>> side.
>>
>> Thanks in advance,
>>
> Hi Everyone,
>
> Sorry for the cross post. I started by asking this question in=20
> freebsd-arm but didn't get a response. I figured, since aarch64 is=20
> Tier1 now, asking wrt stable is fair game. Another user ( Jos=C3=A9 P=C3=
=A9rez )=20
> confirmed that this issue was also present on current but my testing=20
> was on 13 ...
>
> FreeBSD generic 13.0-STABLE FreeBSD 13.0-STABLE #8=20
> stable/13-n246015-ade8b810b02-dirty: Tue Jun 15 21:04:38 CDT 202
>
> Any help would be greatly appreciated.

Another data point: the program runs correctly on 13.0-RELEASE-p3 on rpi4=
b.

 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 Mike





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?da434512-64f9-c93b-65d7-ed7c539826b0>