From nobody Tue Dec 16 19:40:37 2025 Received: from enterprise02.smtp.diehl.com (enterprise02.smtp.diehl.com [193.201.238.220]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3239B209F23 for ; Fri, 21 Feb 2025 11:54:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.201.238.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740138888; cv=none; b=CT6/woSSqabf8eGg3qB/5bZLcYLt5UBGPWx+7Ngr98HTqcwW/V+p6Gy7pzVLSDev0DcpWqCI31voomwDE9eBGe4zKfskKaEAleF4QIcsDiMSzUhdkjGKq3vpbgncG06NY/KcNW81deFvIQRnISRD6EVJu9Tfl43eFZ4+PN8XFCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740138888; c=relaxed/simple; bh=V3HtsOgYNCZKgNbPs5iAUL5SPYrjrTt9UG8en/LEUig=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=uZ7ZeZUbWVlgObUJ/cri70dvPYLQVGvrvYBU35iN+nMweBqpaJDNqdsm3MTXPJ+ew8+EzqL1mCxZ56zu3gSKFJiKNOO9QpSOExV1XBh04dF0Wr8WiYY5xzkBu1QL01fTZA/phw2YPjcv3px/yqzPFsISTiBpTzFdlp8PL3cqXL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=diehl.com; spf=pass smtp.mailfrom=diehl.com; dkim=pass (2048-bit key) header.d=diehl.com header.i=@diehl.com header.b=Ba/Hjyva; arc=none smtp.client-ip=193.201.238.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=diehl.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=diehl.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=diehl.com header.i=@diehl.com header.b="Ba/Hjyva" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diehl.com; i=@diehl.com; q=dns/txt; s=default; t=1740138885; x=1771674885; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=V3HtsOgYNCZKgNbPs5iAUL5SPYrjrTt9UG8en/LEUig=; b=Ba/Hjyva6dVQhEgV7pbUd0icjfKwYIw0dIO69UwnZzUWPyNaQBfvbK/m +YBsZgIB0MFSlg2KAo8FWqnoT9n0d5h7YK1PV9aD8Co6dKtaWHqM2tchP KJyVK8wC4wckgtHDJxu6ecCWEfLniTbKRAy7p6Ty9r5dlAVnzwvlg+a8G jZvleSjoGSpduG3HoKuSoFHZk9/3eUHJpUb/JQFz9HlpH9c1F0E9TEM1G UGnhbFcw8YJLAtQ5Pey5432bsmdlCOhVBwDIH61FPYCmFW22kvgyMzrfq m0AgsA3Kf2AqCBaj4bzkNhKEPSQAO7ourTvPm2cn3cM8C2B55191Tw+kQ A==; X-CSE-ConnectionGUID: 1utCJZiBSDaHtOHE46srmQ== X-CSE-MsgGUID: we5KumSQQK+twI1O6zWwFA== X-ThreatScanner-Verdict: Negative IronPort-Data: A9a23:FHbuhqzqTmUEj2Jzwbt6t+dcxyrEfRIJ4+MujC+fZmUNrF6WrkUHm mJJUW+AM6mMajf3fN53bY+2oUICu5bTn4MxTlFkqy00HyNBpPSeCIXCJC8cHc8wwu7rERg7t ZVOMrEsCOhuExcwcz/0auCJQUFUjP/OHvykTraZZkidfCc8IA85kxVvhuUltYBhhNm9Emult Mj7yyHlEAbNNwVcbCRNsMpvlDs15K6v4GlC5wRnDRx2lAS2e0c9Xct3yZ6ZfyOQrrl8RoaSW +vFxbelyWLVlz9FIs+liLvybnoRSbfUOwWU4lIOM0R1qkEfzsCa+v9T2Ms0MS+7uR3Q9zxC4 IwlWaiLdOscFvakdNLx8fVvO3oW0aVuoNcrKJUk2CCZ5xWun3DEm52CAKyqVGGxFyke7Wxmr JQlxD4xgh+r3v+q65CJS8NXqs0DMO7LEd9BoWtl9GSMZRomacirr6Ti3/R093IVr+FqRq+Yb M0DcXxjbRnAZ1tEPVJ/5JAWxb/u3ySkNWYe8QnMzUY0yzG7IAhZ3LXrMcGTfceWSN9Rl0CUj m7H8mT9RBodMbRzzBLcqi3x17Cexn6TtIQ6C7Dl1eNvu2Sq5S8PFzxPcgWpnuaXoxvrMz5YA wlOksY0loA99UuuQ8XhXjW1pniJsxgaVpxbFOhSwAWMzLfEpgWUHG4JShZfZ9E88sw7Xzon0 hmOhdyBONB0mOTNDyvArfHP62rpYED5MFM/WMPNdiNdi/GLnW35pkmnogpLeEJtsuDIJA== IronPort-HdrOrdr: A9a23:OKI5OKNRVWjkKMBcTiOjsMiBIKoaSvp037By7TEXdfRUGvb2qy ncpoV86faSskdsZJhAo6H8BEDuewK+yXcY2+Qs1PKZLW3bUQiTXf5fBOnZsl/d8kTFn4Y3v5 uIMZIObeEYZmIVsS+O2mmF+qEboeVvnprFuc7ui1lHd0VSUIdLhj0JdDqzIwlZbzMDPKEePr m7zaN81kudkD8sH72G7zE+LpD+jsyOmZL9axsPBxoq8xCUizml8qT3HnGjr20juh10sMwfzV Q= X-Talos-CUID: 9a23:SqR3L21/GkKzlIwtTSOzVrxfQ905WV/vzV3rD0aYFUFJZeHLUkWVwfYx X-Talos-MUID: 9a23:xAmt1gnbNgmBAGgDAvvidnp9OZpL/qGVMXku0okZmpCjaz5PJBm02WE= X-IronPort-AV: E=Sophos;i="6.13,304,1732575600"; d="scan'208";a="107597935" From: Denis OSTERLAND-HEIM To: Rodolfo Giometti CC: "linux-kernel@vger.kernel.org" Subject: RE: Re: [PATCH] pps: add epoll support Thread-Topic: Re: [PATCH] pps: add epoll support Thread-Index: AQHbhFdkiqh8EX+2I0muv+s0b0fRyQ== Date: Fri, 21 Feb 2025 11:54:42 +0000 Message-ID: References: <40322dd7ce0243b6bc89b21d8884980b@diehl.com> <9d9f2a9a-ab90-4fbf-bc0e-d4c8b83d7082@enneenne.com> In-Reply-To: <9d9f2a9a-ab90-4fbf-bc0e-d4c8b83d7082@enneenne.com> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-disclaimerprocessed: True Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GBS-PROC: xcNMAi9YeeX/adnz0FLyVb5gOQPWKsNltjJPSmPANwhySv0bSK1VkW7ePEkY8CFI X-GBS-PROCJOB: P13z75B5ahmzyTDzQgmrOAEzjaQ0zne3pEQpqN1UwGUYADi8d4RdAl2YPQe8cRhU Hi, Thanks! I will test your suggentions and report next week ;-) Have a nice weekend. Regards, Denis -----Original Message----- From: Rodolfo Giometti Sent: Friday, February 21, 2025 12:40 PM To: Denis OSTERLAND-HEIM Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] pps: add epoll support On 21/02/25 11:49, Denis OSTERLAND-HEIM wrote: > Hi, > > Okay, if poll is expected to work, than we have a bug. > Actually a pretty old one. > > pps_cdev_poll() uncoditionally returns (EPOLLIN | EPOLLRDNORM), which res= ults in poll() will return immediately with data available > (EPOLLIN | EPOLLRDNORM). > To avoid this, you need conditionally return 0. I think you are right! Looking at the code I think the correct patch should be: diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 6a02245ea35f..7a52bb9f835b 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -41,7 +41,7 @@ static __poll_t pps_cdev_poll(struct file *file, poll_tab= le *wait) poll_wait(file, &pps->queue, wait); - return EPOLLIN | EPOLLRDNORM; + return pps->info.mode & PPS_CANWAIT ? 0 : EPOLLIN | EPOLLRDNORM; } static int pps_cdev_fasync(int fd, struct file *file, int on) > My patch adds a context per open file to store the last_ev value when ioc= tl(PPS_FETCH) is invoked and uses this last_ev in poll as > condition. > > Sorry, for the missing memset(&fdata, 0, sizeof(fdata)). > Intention was set to 0, yes. OK > ```c > #include > #include ///home/giometti/Projects/ailux/imx9/linux/linux-imx > #include > #include > #include "timepps.h" > > int main(int argc, const char* argv[]) { > struct pollfd instance =3D { .fd =3D open((argc > 1) ? argv[1] : "/d= ev/pps0", O_RDONLY), .events =3D POLLIN|POLLERR , .revents =3D 0 }; > pps_handle_t pps_handle; > static const struct timespec timeout =3D { 0, 0 }; > if (time_pps_create(instance.fd, &pps_handle)) { > perror("failed to create pps handle"); > return 1; > } > for (int loops =3D 4; --loops; ) { > pps_info_t pps_info; > memset(&pps_info, 0, sizeof(pps_info)); > if (!poll(&instance, 1, 2000/*ms*/)) { > printf("timeout"); > continue; > } > if ((instance.revents & POLLIN) !=3D POLLIN) { > printf("nothing to read?"); > continue; > } > if (time_pps_fetch(pps_handle, PPS_TSFMT_TSPEC, &pps_info, &time= out)) { > perror("failed to fetch"); > return 1; > } > > printf( > "assert: %lu\ntime: %ld.%09ld\n", > pps_info.assert_sequence, > pps_info.assert_tu.tspec.tv_sec, > pps_info.assert_tu.tspec.tv_nsec > ); > } > return 0; > } > ``` > > Currently output looks like: > ``` > $ cat /sys/class/pps/pps0/assert; ./test /dev/pps0 > 1520598954.468882076#60 > assert: 60 > time: 1520598954.468882076 > assert: 60 > time: 1520598954.468882076 > assert: 60 > time: 1520598954.468882076 > ``` > > You see no waits between the loops. Please, try again with the above patch. However, before doing the test, you should consider to add this patch too: diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 6a02245ea35f..7a52bb9f835b 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -56,10 +56,13 @@ static int pps_cdev_pps_fetch(struct pps_device *pps, s= truct pps_fdata *fdata) int err =3D 0; /* Manage the timeout */ - if (fdata->timeout.flags & PPS_TIME_INVALID) - err =3D wait_event_interruptible(pps->queue, + if (fdata->timeout.flags & PPS_TIME_INVALID) { + if (pps->info.mode & PPS_CANWAIT) + err =3D wait_event_interruptible(pps->queue, ev !=3D pps->last_ev); - else { + else + return -EOPNOTSUPP; + } else { unsigned long ticks; dev_dbg(&pps->dev, "timeout %lld.%09d\n", @@ -69,12 +72,15 @@ static int pps_cdev_pps_fetch(struct pps_device *pps, s= truct pps_fdata *fdata) ticks +=3D fdata->timeout.nsec / (NSEC_PER_SEC / HZ); if (ticks !=3D 0) { - err =3D wait_event_interruptible_timeout( + if (pps->info.mode & PPS_CANWAIT) { + err =3D wait_event_interruptible_timeout( pps->queue, ev !=3D pps->last_ev, ticks); - if (err =3D=3D 0) - return -ETIMEDOUT; + if (err =3D=3D 0) + return -ETIMEDOUT; + } else + return -EOPNOTSUPP; } } In fact RFC2783 states: 3.4.3 New functions: access to PPS timestamps ... Support for blocking behavior is an implementation option. If the PPS_CANWAIT mode bit is clear, and the timeout parameter is either NULL or points to a non-zero value, the function returns an EOPNOTSUPP error. An application can discover whether the feature is implemented by using time_pps_getcap() to see if the PPS_CANWAIT mode bit is set. ... Ciao, Rodolfo -- GNU/Linux Solutions e-mail: giometti@enneenne.com Linux Device Driver giometti@linux.it Embedded Systems phone: +39 349 2432127 UNIX programming Diehl Metering GmbH, Donaustrasse 120, 90451 Nuernberg Sitz der Gesellschaft: Ansbach, Registergericht: Ansbach HRB 69 Geschaeftsfuehrer: Dr. Christof Bosbach (Sprecher), Dipl.-Dolm. Annette Geu= ther, Dipl.-Kfm. Reiner Edel, Jean-Claude Luttringer Bitte denken Sie an die Umwelt, bevor Sie diese E-Mail drucken. Diese E-Mai= l kann vertrauliche Informationen enthalten. Sollten die in dieser E-Mail e= nthaltenen Informationen nicht f=C3=BCr Sie bestimmt sein, informieren Sie = bitte unverzueglich den Absender per E-Mail und loeschen Sie diese E-Mail i= n Ihrem System. Jede unberechtigte Form der Reproduktion, Bekanntgabe, Aend= erung, Verteilung und/oder Publikation dieser E-Mail ist strengstens unters= agt. Informationen zum Datenschutz finden Sie auf unserer Homepage. Before printing, think about environmental responsibility.This message may = contain confidential information. If you are not authorized to receive this= information please advise the sender immediately by reply e-mail and delet= e this message without making any copies. Any form of unauthorized use, pub= lication, reproduction, copying or disclosure of the e-mail is not permitte= d. Information about data protection can be found on our homepage.