Linux Documentation
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: akiyano@amazon.com
Cc: davem@davemloft.net, kuba@kernel.org, richardcochran@gmail.com,
	netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	dwmw2@infradead.org, tglx@linutronix.de, mlichvar@redhat.com,
	maciek@machnikowski.net, andrew+netdev@lunn.ch, andrew@lunn.ch,
	cjubran@nvidia.com, guwen@linux.alibaba.com,
	xuanzhuo@linux.alibaba.com, dwmw@amazon.com, ysarna@amazon.com,
	zorik@amazon.com, matua@amazon.com, saeedb@amazon.com,
	msw@amazon.com, aliguori@amazon.com, nafea@amazon.com,
	evgenys@amazon.com, netanel@amazon.com, alisaidi@amazon.com,
	benh@amazon.com, ndagan@amazon.com, darinzon@amazon.com,
	evostrov@amazon.com, ofirt@amazon.com, amitbern@amazon.com,
	linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
	shuah@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
	horms@kernel.org, bhelgaas@google.com, vadim.fedorenko@linux.dev,
	dwmw@amazon.co.uk
Subject: Re: [PATCH v7 net-next 3/7] selftests/ptp: Add testptp support for attributes ioctls
Date: Thu, 10 Sep 2026 08:31:28 +0000	[thread overview]
Message-ID: <178902908829.219967.3668712303469402253@kernel.org> (raw)
In-Reply-To: <20260909073136.12863-4-akiyano@amazon.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider:

Critical: 0 · High: 0 · Medium: 1 · Low: 1

- [Medium] The new `-x N -a` (PTP_SYS_OFFSET_EXTENDED_ATTRS) print loop
  in `main()` (tools/testing/selftests/ptp/testptp.c lines 671-722)…
- [Low] In `main()` of tools/testing/selftests/ptp/testptp.c, the new
  `-a` modifier is accepted and sets `use_attrs = 1` (line 327-329) but…

--

selftests/ptp: Add testptp support for attributes ioctls

This adds a "-a" modifier to testptp so that the new
PTP_SYS_OFFSET_EXTENDED_ATTRS and PTP_SYS_OFFSET_PRECISE_ATTRS ioctls can
be exercised alongside the existing -x and -X requests. It also prints the
new extended_attrs/precise_attrs capabilities and reports unrecognized
clock ids in print_system_timestamp().

A couple of questions below.

> diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
> index d603d9f82237..62b1d0340d71 100644
> --- a/tools/testing/selftests/ptp/testptp.c
> +++ b/tools/testing/selftests/ptp/testptp.c
> @@ -148,6 +148,8 @@ static void usage(char *progname)
>  		" -T val     set the ptp clock time to 'val' seconds\n"
>  		" -x val     get an extended ptp clock time with the desired number of samples (up to %d)\n"
>  		" -X         get a ptp clock cross timestamp\n"
> +		" -a         also report clock quality attributes (error_bound,\n"
> +		"            status, timescale); use together with -x or -X\n"
>  		" -y val     pre/post tstamp timebase to use {realtime|monotonic|monotonic-raw}\n"
>  		" -z         test combinations of rising/falling external time stamp flags\n",
>  		progname, PTP_MAX_SAMPLES);

[ ... ]

> @@ -317,6 +324,9 @@ int main(int argc, char *argv[])
>  				return -1;
>  			}
>  			break;
> +		case 'a':
> +			use_attrs = 1;
> +			break;

[Severity: Low]
The usage text states that -a must be used "together with -x or -X", but is
that requirement enforced anywhere in main()?

Both new request blocks are gated on a companion option:

	if (getextended && use_attrs) {
	...
	if (getcross && use_attrs) {

and the two legacy blocks are now additionally gated on !use_attrs, so
"testptp -d /dev/ptp0 -a" (or -a combined with something unrelated like -k
or -g) issues no attrs ioctl, prints nothing about attributes, and exits 0.

main() already diagnoses the analogous dependency for -w and -H:

	if (pulsewidth >= 0 && perout < 0) {
		puts("-w can only be specified together with -p");
		return -1;
	}

	if (perout_phase >= 0 && perout < 0) {
		puts("-H can only be specified together with -p");
		return -1;
	}

Would it make sense to add the equivalent check for -a without -x or -X?

>  		case 'X':
>  			getcross = 1;
>  			break;

[ ... ]

> @@ -654,7 +668,60 @@ int main(int argc, char *argv[])
>  		free(soe);
>  	}
>  
> -	if (getcross) {
> +	if (getextended && use_attrs) {
> +		attrs_data = calloc(1, sizeof(*attrs_data) +
> +				    getextended * sizeof(struct ptp_timestamp));
> +		if (!attrs_data) {
> +			perror("calloc");
> +			return -1;
> +		}
> +
> +		attrs_data->request.num_samples = getextended;
> +		attrs_data->request.clock_id = ext_clockid;
> +
> +		if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED_ATTRS, attrs_data)) {
> +			perror("PTP_SYS_OFFSET_EXTENDED_ATTRS");
> +		} else {
> +			printf("extended attrs timestamp request returned %d samples\n",
> +			       getextended);
> +
> +			for (i = 0; i < getextended; i++) {
> +				struct ptp_timestamp *ts = &attrs_data->timestamps[i];
> +
> +				printf("  sample #%u:\n", i);
> +				printf("    sys before: %lld ns\n",
> +				       (long long)ts->pre_systime.sys_time);
> +				printf("    sys_counter_id: %u\n",
> +				       ts->pre_systime.sys_counter_id);
> +				printf("    sys_counter:    %llu\n",
> +				       (unsigned long long)ts->pre_systime.sys_counter);
> +				printf("    phc time:   %lld.%09u\n",
> +				       ts->devtime.device_time.sec,
> +				       ts->devtime.device_time.nsec);
> +				if (ts->devtime.attrs.valid & PTP_ATTRS_VALID_ERROR_BOUND)
> +					printf("    error_bound: %u ns\n",
> +					       ts->devtime.attrs.error_bound);
> +				else
> +					printf("    error_bound: not reported\n");
> +				if (ts->devtime.attrs.valid & PTP_ATTRS_VALID_STATUS)
> +					printf("    status: %u\n",
> +					       ts->devtime.attrs.status);
> +				else
> +					printf("    status: not reported\n");
> +				if (ts->devtime.attrs.valid & PTP_ATTRS_VALID_TIMESCALE)
> +					printf("    timescale: %u\n",
> +					       ts->devtime.attrs.timescale);
> +				else
> +					printf("    timescale: not reported\n");
> +				printf("    sys after:  %lld ns\n",
> +				       (long long)ts->post_systime.sys_time);

[Severity: Medium]
Should the post snapshot print the counter fields too?

This loop prints pre_systime.sys_time, pre_systime.sys_counter_id and
pre_systime.sys_counter, but for the post snapshot only sys_time. It also
never prints sys_rawtime for either snapshot, although the kernel side fills
all four fields of both snapshots in ptp_sys_offset_extended_attrs():

drivers/ptp/ptp_chardev.c:ptp_sys_offset_extended_attrs() {
	...
	tstamp->post_systime.sys_time = ktime_to_ns(sts.post_sts.systime);
	tstamp->post_systime.sys_rawtime = ktime_to_ns(sts.post_sts.monoraw);
	ptp_fill_sys_counter(&tstamp->post_systime, sts.post_sts.cycles,
			     sts.post_sts.cs_id);
	...
}

The -X -a printer added in the same patch does surface those fields:

	printf("raw time:    %lld ns\n",
	       (long long)ts->systime.sys_rawtime);
	printf("sys_counter_id: %u\n",
	       ts->systime.sys_counter_id);
	printf("sys_counter:    %llu\n",
	       (unsigned long long)ts->systime.sys_counter);

so the two new consumers of struct ptp_sys_time disagree about which
returned fields are shown. As it stands, "-x N -a" output is identical
whether the post-read counter source is correctly identified or left at
zero.

The commit message says:

    Also print the system counter value and its identifier (sys_counter,
    sys_counter_id) returned in struct ptp_sys_time, so the counter source
    is visible

Does that hold for the extended path, given that post_systime.sys_counter
and post_systime.sys_counter_id are not printed?

> +			}
> +		}
> +
> +		free(attrs_data);
> +	}
> +

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260909073136.12863-1-akiyano%40amazon.com

  reply	other threads:[~2026-09-10  8:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  7:31 [PATCH v7 net-next 0/7] ptp: Add PHC timestamp quality attributes Arthur Kiyanovski
2026-09-09  7:31 ` [PATCH v7 net-next 1/7] ptp: Add ioctls for PHC timestamps with " Arthur Kiyanovski
2026-09-10  8:31   ` netdev-bot+sashiko
2026-09-09  7:31 ` [PATCH v7 net-next 2/7] selftests/ptp: Extract print_system_timestamp helper in testptp Arthur Kiyanovski
2026-09-09  7:31 ` [PATCH v7 net-next 3/7] selftests/ptp: Add testptp support for attributes ioctls Arthur Kiyanovski
2026-09-10  8:31   ` netdev-bot+sashiko [this message]
2026-09-09  7:31 ` [PATCH v7 net-next 4/7] ptp: ptp_vmclock: Implement " Arthur Kiyanovski
2026-09-10  8:31   ` netdev-bot+sashiko
2026-09-09  7:31 ` [PATCH v7 net-next 5/7] net: ena: Update PHC admin interface for error bound support Arthur Kiyanovski
2026-09-10  8:31   ` netdev-bot+sashiko
2026-09-09  7:31 ` [PATCH v7 net-next 6/7] net: ena: Add error bound to PHC communication layer Arthur Kiyanovski
2026-09-09  7:31 ` [PATCH v7 net-next 7/7] net: ena: Implement gettimexattrs64 callback for PTP attributes Arthur Kiyanovski
2026-09-10  8:31   ` netdev-bot+sashiko

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=178902908829.219967.3668712303469402253@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=akiyano@amazon.com \
    --cc=aliguori@amazon.com \
    --cc=alisaidi@amazon.com \
    --cc=amitbern@amazon.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=benh@amazon.com \
    --cc=bhelgaas@google.com \
    --cc=cjubran@nvidia.com \
    --cc=corbet@lwn.net \
    --cc=darinzon@amazon.com \
    --cc=davem@davemloft.net \
    --cc=dwmw2@infradead.org \
    --cc=dwmw@amazon.co.uk \
    --cc=dwmw@amazon.com \
    --cc=edumazet@google.com \
    --cc=evgenys@amazon.com \
    --cc=evostrov@amazon.com \
    --cc=guwen@linux.alibaba.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maciek@machnikowski.net \
    --cc=matua@amazon.com \
    --cc=mlichvar@redhat.com \
    --cc=msw@amazon.com \
    --cc=nafea@amazon.com \
    --cc=ndagan@amazon.com \
    --cc=netanel@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=ofirt@amazon.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=saeedb@amazon.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@linutronix.de \
    --cc=vadim.fedorenko@linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=ysarna@amazon.com \
    --cc=zorik@amazon.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox