From: Denis OSTERLAND-HEIM <denis.osterland@diehl.com>
To: Rodolfo Giometti <giometti@enneenne.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: Re: [PATCH] pps: add epoll support
Date: Fri, 21 Feb 2025 11:54:42 +0000 [thread overview]
Message-ID: <e2f96f41643f4295812f43e801c8d70e@diehl.com> (raw)
In-Reply-To: <9d9f2a9a-ab90-4fbf-bc0e-d4c8b83d7082@enneenne.com>
Hi,
Thanks!
I will test your suggentions and report next week ;-)
Have a nice weekend.
Regards, Denis
-----Original Message-----
From: Rodolfo Giometti <giometti@enneenne.com>
Sent: Friday, February 21, 2025 12:40 PM
To: Denis OSTERLAND-HEIM <denis.osterland@diehl.com>
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 results 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_table *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 ioctl(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 <stdio.h>
> #include <string.h>///home/giometti/Projects/ailux/imx9/linux/linux-imx
> #include <poll.h>
> #include <fcntl.h>
> #include "timepps.h"
>
> int main(int argc, const char* argv[]) {
> struct pollfd instance = { .fd = open((argc > 1) ? argv[1] : "/dev/pps0", O_RDONLY), .events = POLLIN|POLLERR , .revents = 0 };
> pps_handle_t pps_handle;
> static const struct timespec timeout = { 0, 0 };
> if (time_pps_create(instance.fd, &pps_handle)) {
> perror("failed to create pps handle");
> return 1;
> }
> for (int loops = 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) != POLLIN) {
> printf("nothing to read?");
> continue;
> }
> if (time_pps_fetch(pps_handle, PPS_TSFMT_TSPEC, &pps_info, &timeout)) {
> 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, struct
pps_fdata *fdata)
int err = 0;
/* Manage the timeout */
- if (fdata->timeout.flags & PPS_TIME_INVALID)
- err = wait_event_interruptible(pps->queue,
+ if (fdata->timeout.flags & PPS_TIME_INVALID) {
+ if (pps->info.mode & PPS_CANWAIT)
+ err = wait_event_interruptible(pps->queue,
ev != 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, struct
pps_fdata *fdata)
ticks += fdata->timeout.nsec / (NSEC_PER_SEC / HZ);
if (ticks != 0) {
- err = wait_event_interruptible_timeout(
+ if (pps->info.mode & PPS_CANWAIT) {
+ err = wait_event_interruptible_timeout(
pps->queue,
ev != pps->last_ev,
ticks);
- if (err == 0)
- return -ETIMEDOUT;
+ if (err == 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 Geuther, Dipl.-Kfm. Reiner Edel, Jean-Claude Luttringer
Bitte denken Sie an die Umwelt, bevor Sie diese E-Mail drucken. Diese E-Mail kann vertrauliche Informationen enthalten. Sollten die in dieser E-Mail enthaltenen Informationen nicht für Sie bestimmt sein, informieren Sie bitte unverzueglich den Absender per E-Mail und loeschen Sie diese E-Mail in Ihrem System. Jede unberechtigte Form der Reproduktion, Bekanntgabe, Aenderung, Verteilung und/oder Publikation dieser E-Mail ist strengstens untersagt. Informationen zum Datenschutz finden Sie auf unserer Homepage<https://www.diehl.com/metering/de/impressum-und-rechtliche-hinweise/>.
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 delete this message without making any copies. Any form of unauthorized use, publication, reproduction, copying or disclosure of the e-mail is not permitted. Information about data protection can be found on our homepage<https://www.diehl.com/metering/en/data-protection/>.
next prev parent reply other threads:[~2025-02-21 11:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-21 10:49 [EXT] Re: [PATCH] pps: add epoll support Denis OSTERLAND-HEIM
2025-02-21 11:39 ` Rodolfo Giometti
2025-02-21 11:54 ` Denis OSTERLAND-HEIM [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-02-25 16:34 Denis OSTERLAND-HEIM
2025-02-25 13:39 Denis OSTERLAND-HEIM
2025-02-24 11:38 Denis OSTERLAND-HEIM
2025-02-24 17:38 ` Rodolfo Giometti
2025-02-25 12:47 ` Denis OSTERLAND-HEIM
2025-02-19 12:21 Denis OSTERLAND-HEIM
2025-02-20 8:50 ` Rodolfo Giometti
2025-02-20 16:45 ` Denis OSTERLAND-HEIM
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2f96f41643f4295812f43e801c8d70e@diehl.com \
--to=denis.osterland@diehl.com \
--cc=giometti@enneenne.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.