[RFC 2/4] Add eventfd option to --decode-fds
Masatake YAMATO
yamato at redhat.com
Mon Apr 29 23:11:39 UTC 2024
Hi,
From: Sahil Siddiq <icegambit91 at gmail.com>
Subject: [RFC 2/4] Add eventfd option to --decode-fds
Date: Mon, 29 Apr 2024 09:01:45 +0530
> Having an eventfd option for --decode-fds will help
> examine the eventfd counter associated with an eventfd
> file descriptor.
>
> * src/filter_qualify.c
> (decode_fd_str_to_uint): Add "eventfd" option.
> (parse_inject_token): Pass base 10 as argument.
> * src/number_set.h: Add DECODE_FD_EVENTFD.
> * src/strace.c: Add "eventfd" option.
> * src/util.c: Parse eventfd counter value.
>
> Signed-off-by: Sahil Siddiq <icegambit91 at gmail.com>
> ---
> src/filter_qualify.c | 5 +++--
> src/number_set.h | 1 +
> src/strace.c | 3 ++-
> src/util.c | 37 +++++++++++++++++++++++++++++++++++++
> 4 files changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/src/filter_qualify.c b/src/filter_qualify.c
> index be383a5c9..a79045468 100644
> --- a/src/filter_qualify.c
> +++ b/src/filter_qualify.c
> @@ -105,6 +105,7 @@ decode_fd_str_to_uint(const char *str)
> { DECODE_FD_PATH, "path" },
> { DECODE_FD_SOCKET, "socket" },
> { DECODE_FD_DEV, "dev" },
> + { DECODE_FD_EVENTFD, "eventfd" },
> { DECODE_FD_PIDFD, "pidfd" },
> { DECODE_FD_SIGNALFD, "signalfd" },
> };
> @@ -273,7 +274,7 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts,
> * F..L+S
> */
> char *end;
> - intval = string_to_uint_ex(val, &end, 0xffff, "+.");
> + intval = string_to_uint_ex(val, &end, 0xffff, "+.", 10);
> if (intval < 1)
> return false;
>
> @@ -287,7 +288,7 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts,
> * F..L+S
> */
> val = end + 2;
> - intval = string_to_uint_ex(val, &end, 0xffff, "+");
> + intval = string_to_uint_ex(val, &end, 0xffff, "+", 10);
> if (intval < fopts->first || intval == INJECT_LAST_INF)
> return false;
> fopts->last = intval;
> diff --git a/src/number_set.h b/src/number_set.h
> index 0ce2b2db6..d28ac0cdd 100644
> --- a/src/number_set.h
> +++ b/src/number_set.h
> @@ -75,6 +75,7 @@ enum decode_fd_bits {
> DECODE_FD_PATH,
> DECODE_FD_SOCKET,
> DECODE_FD_DEV,
> + DECODE_FD_EVENTFD,
> DECODE_FD_PIDFD,
> DECODE_FD_SIGNALFD,
>
> diff --git a/src/strace.c b/src/strace.c
> index c8f76cada..a5f87c3bb 100644
> --- a/src/strace.c
> +++ b/src/strace.c
> @@ -378,7 +378,8 @@ Output format:\n\
> print exit reason of kvm vcpu\n\
> -e decode-fds=SET, --decode-fds=SET\n\
> what kinds of file descriptor information details to decode\n\
> - details: dev (device major/minor for block/char device files)\n\
> + details: dev (device major/minor for block/char device files),\n\
> + eventfd (associated eventfd counter for eventfds),\n\
> path (file path),\n\
> pidfd (associated PID for pidfds),\n\
> socket (protocol-specific information for socket descriptors),\n\
> diff --git a/src/util.c b/src/util.c
> index 4140cb718..edcdf440c 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -858,6 +858,40 @@ printsignalfd(pid_t pid_of_fd, int fd, const char *path)
> print_fdinfo_sigmask, NULL);
> }
>
> +static bool
> +parse_fdinfo_efd_counter(const char *value, void *data)
> +{ uint64_t *efd_counter = data;
> + *efd_counter = string_to_uint_ex(value, NULL, ULLONG_MAX, "\n", 16);
> + return true;
> +}
> +
> +static bool
> +printeventfd(pid_t pid_of_fd, int fd, const char *path)
> +{
> + static const char eventfd_path[] = "anon_inode:[eventfd]";
> + static const char efd_counter_pfx[] = "eventfd-count:";
In addition to "count", I think printing "id" is useful.
$ cat /proc/56214/fdinfo/42
pos: 0
flags: 02004002
mnt_id: 16
ino: 72
eventfd-count: 0
eventfd-id: 114
eventfd-semaphore: 0
All eventfds have the same inode number. On the other hand
eventfd-id can be used to identify eventfd instances.
See https://patchwork.kernel.org/project/linux-fsdevel/patch/20180520201823.14293-1-yamato@redhat.com/
I expect strace repots the above example as
42<eventfd count:0 id:114">
> + if (strcmp(path, eventfd_path))
> + return false;
> +
> + uint64_t efd_counter = -1ULL;
> +
> + scan_fdinfo(pid_of_fd, fd, efd_counter_pfx, sizeof(efd_counter_pfx) - 1,
> + parse_fdinfo_efd_counter, &efd_counter);
> +
> + if (efd_counter != -1ULL) {
> + tprint_associated_info_begin();
> + tprints_string("eventfd-count:");
> + PRINT_VAL_U(efd_counter);
> + tprint_associated_info_end();
> + } else {
> + ;
> + // print_string_in_angle_brackets(path);
> + }
> +
> + return true;
> +}
> +
> static void
> print_quoted_string_in_angle_brackets(const char *str, const bool deleted)
> {
> @@ -886,6 +920,9 @@ printfd_pid_with_finfo(struct tcb *tcp, pid_t pid, int fd, const struct finfo *f
> if (is_number_in_set(DECODE_FD_DEV, decode_fd_set) &&
> printdev(tcp, fd, path, finfo))
> goto printed;
> + if (is_number_in_set(DECODE_FD_EVENTFD, decode_fd_set) &&
> + printeventfd(pid, fd, path))
> + goto printed;
> if (is_number_in_set(DECODE_FD_PIDFD, decode_fd_set) &&
> printpidfd(pid, fd, path))
> goto printed;
> --
> 2.44.0
>
> --
> Strace-devel mailing list
> Strace-devel at lists.strace.io
> https://lists.strace.io/mailman/listinfo/strace-devel
>
Masatake YAMATO
More information about the Strace-devel
mailing list