Em Tue, Jan 08, 2019 at 11:10:10PM -0500, Michael S. Tsirkin escreveu:
> On Tue, Jan 08, 2019 at 04:59:10PM -0300, Arnaldo Carvalho de Melo wrote:
> > +++ b/tools/include/uapi/linux/vhost.h
> > @@ -11,94 +11,9 @@
> >   * device configuration.
> >   */

> > +#include <linux/vhost_types.h>
 
> Don't you then also need to import vhost_types.h?

If we were using this file as an include in a C source file, yes, but
we're just using it to generate a string table using regular
expressions:

[acme@quaco perf]$ tools/perf/trace/beauty/vhost_virtio_ioctl.sh
static const char *vhost_virtio_ioctl_cmds[] = {
        [0x00] = "SET_FEATURES",
        [0x01] = "SET_OWNER",
        [0x02] = "RESET_OWNER",
        [0x03] = "SET_MEM_TABLE",
        [0x04] = "SET_LOG_BASE",
        [0x07] = "SET_LOG_FD",
        [0x10] = "SET_VRING_NUM",
        [0x11] = "SET_VRING_ADDR",
        [0x12] = "SET_VRING_BASE",
        [0x13] = "SET_VRING_ENDIAN",
        [0x14] = "GET_VRING_ENDIAN",
        [0x20] = "SET_VRING_KICK",
        [0x21] = "SET_VRING_CALL",
        [0x22] = "SET_VRING_ERR",
        [0x23] = "SET_VRING_BUSYLOOP_TIMEOUT",
        [0x24] = "GET_VRING_BUSYLOOP_TIMEOUT",
        [0x25] = "SET_BACKEND_FEATURES",
        [0x30] = "NET_SET_BACKEND",
        [0x40] = "SCSI_SET_ENDPOINT",
        [0x41] = "SCSI_CLEAR_ENDPOINT",
        [0x42] = "SCSI_GET_ABI_VERSION",
        [0x43] = "SCSI_SET_EVENTS_MISSED",
        [0x44] = "SCSI_GET_EVENTS_MISSED",
        [0x60] = "VSOCK_SET_GUEST_CID",
        [0x61] = "VSOCK_SET_RUNNING",
};
static const char *vhost_virtio_ioctl_read_cmds[] = {
        [0x00] = "GET_FEATURES",
        [0x12] = "GET_VRING_BASE",
        [0x26] = "GET_BACKEND_FEATURES",
};
[acme@quaco perf]$

[acme@quaco perf]$ cat tools/perf/trace/beauty/vhost_virtio_ioctl.sh 
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1

[ $# -eq 1 ] && header_dir=$1 || header_dir=tools/include/uapi/linux/

printf "static const char *vhost_virtio_ioctl_cmds[] = {\n"
regex='^#[[:space:]]*define[[:space:]]+VHOST_(\w+)[[:space:]]+_IOW?\([[:space:]]*VHOST_VIRTIO[[:space:]]*,[[:space:]]*(0x[[:xdigit:]]+).*'
egrep $regex ${header_dir}/vhost.h | \
        sed -r "s/$regex/\2 \1/g"       | \
        sort | xargs printf "\t[%s] = \"%s\",\n"
printf "};\n"

printf "static const char *vhost_virtio_ioctl_read_cmds[] = {\n"
regex='^#[[:space:]]*define[[:space:]]+VHOST_(\w+)[[:space:]]+_IOW?R\([[:space:]]*VHOST_VIRTIO[[:space:]]*,[[:space:]]*(0x[[:xdigit:]]+).*'
egrep $regex ${header_dir}/vhost.h | \
        sed -r "s/$regex/\2 \1/g"       | \
        sort | xargs printf "\t[%s] = \"%s\",\n"
printf "};\n"
[acme@quaco perf]$

This ends up being used in tools/perf/trace/beauty/ioctl.c, after that
trace/beauty/generated/ioctl/vhost_virtio_ioctl_array.c file (with the
vhost_virtio_ioctl_read_cmds and vhost_virtio_ioctl_cmds arrays) gets
generated by the tools/perf/Makefile.perf build process:

static size_t ioctl__scnprintf_vhost_virtio_cmd(int nr, int dir, char *bf, 
size_t size)
{
#include "trace/beauty/generated/ioctl/vhost_virtio_ioctl_array.c"
        static DEFINE_STRARRAY(vhost_virtio_ioctl_cmds, "");
        static DEFINE_STRARRAY(vhost_virtio_ioctl_read_cmds, "");
        struct strarray *s = (dir & _IOC_READ) ? 
&strarray__vhost_virtio_ioctl_read_cmds : &strarray__vhost_virtio_ioctl_cmds;

        if (nr < s->nr_entries && s->entries[nr] != NULL)
                return scnprintf(bf, size, "VHOST_%s", s->entries[nr]);

        return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAF, nr, dir);
}

So, if at some point a tool needs to really #include that file, yeah,
then we will need to import vhost_types.h too.

- Arnaldo

Reply via email to