On Tue, Mar 08, 2022 at 11:46:59AM +0100, Miroslav Lichvar wrote:
> Add a function using ethtool netlink to check whether a PHC is a virtual
> clock of an interface.
>
> Signed-off-by: Miroslav Lichvar <[email protected]>
> Acked-by: Hangbin Liu <[email protected]>
> ---
> incdefs.sh | 4 +++
> missing.h | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> rtnl.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
> rtnl.h | 9 +++++
> 4 files changed, 199 insertions(+)
>
> diff --git a/incdefs.sh b/incdefs.sh
> index 19e620e..21333e5 100755
> --- a/incdefs.sh
> +++ b/incdefs.sh
> @@ -86,6 +86,10 @@ kernel_flags()
> if grep -q HWTSTAMP_TX_ONESTEP_P2P ${prefix}${tstamp}; then
> printf " -DHAVE_ONESTEP_P2P"
> fi
> +
> + if grep -q SOF_TIMESTAMPING_BIND_PHC ${prefix}${tstamp}; then
> + printf " -DHAVE_VCLOCKS"
> + fi
> }
> diff --git a/rtnl.c b/rtnl.c
> index f8bdbe6..fa02388 100644
> --- a/rtnl.c
> +++ b/rtnl.c
> @@ -19,6 +19,9 @@
> #include <asm/types.h>
> #include <sys/socket.h> /* Must come before linux/netlink.h on some systems.
> */
> #include <linux/netlink.h>
> +#ifdef HAVE_VCLOCKS
> +#include <linux/ethtool_netlink.h>
> +#endif
> #include <linux/rtnetlink.h>
> #include <linux/genetlink.h>
> #include <linux/if_team.h>
I will take this opportunity to state that incdefs.h is broken with
cross-compilation, because it wants me to set $KBUILD_OUTPUT to the
sysroot path, otherwise it searches the system-wide
/usr/include/linux/net_tstamp.h
for SOF_TIMESTAMPING_BIND_PHC, and finds it, and says "oh, yeah, I have
vclocks". Then when I go ahead and compile linuxptp, it fails to find
linux/ethtool_netlink.h, because the actual _sysroot_ doesn't have
vclock support (only the system kernel headers do).
You're probably going to say "just set KBUILD_OUTPUT", which I am indeed
forced to do. But in fact I have an environment script that I just source
for cross-compilation. And this variable isn't only used by linuxptp, it
also affects where the Linux kernel output gets compiled to.
Simply put, KBUILD_OUTPUT is _not_ the right choice to determine whether
linuxptp will be compiled with kernel headers that have a certain symbol
exported. It's also frustrating to have an env file that works for cross
compiling everything, including the kernel itself, except linuxptp.
What I usually do when I need to determine whether a feature is
available is to compile a dummy C program using the same CFLAGS as the
main program itself. No dumpster diving through paths on the host
system, depending on variables you're not supposed to, etc.
Like this:
cat toolchain_deps.sh
#!/bin/bash
CC="$1"
CFLAGS="$2"
EXTRA_CFLAGS=""
${CC} ${CFLAGS} -x c -c -o $(mktemp) - > /dev/null 2>&1 << EOF
#include <linux/net_tstamp.h>
int main(void)
{
return SOF_TIMESTAMPING_BIND_PHC;
}
EOF
if [ $? = 0 ]; then
EXTRA_CFLAGS="${EXTRA_CFLAGS} -DHAVE_VCLOCKS"
fi
echo ${EXTRA_CFLAGS}
Used like this:
cat Makefile
CFLAGS += $(shell ./toolchain_deps.sh "$(CC)" "$(CFLAGS)")
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel