Re: [PATCH] perf stat: fix case where guest/host monitoring is not supported by kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Em Fri, Apr 27, 2012 at 02:45:38PM +0200, Stephane Eranian escreveu:
> 
> By default, perf stat sets exclude_guest = 1. But when you run perf on a kernel
> which does not support  host/guest filtering, then you get an error saying
> the event in unsupported. This comes from the fact that when the
> perf_event_attr struct passed by the user is larger than the one known to 
> the kernel there is safety check which ensures that all unknown bits are
> zero. But here, exclude_guest is 1 (part of the unknown bits) and thus the
> perf_event_open() syscall return EINVAL.
> 
> To my surprise, running perf record on the same kernel did not exhibit
> the problem. The reason is that perf record handles the problem by
> catching the error and retrying with guest/host excludes set to zero.
> For some reason, this was not done with perf stat. This patch fixes
> this problem.

yeah, I have to sit down and finish perf_evlist__open, i.e. get all this
capability queries.

Thanks, applying to my perf/urgent branch.

- Arnaldo
 
> Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
> ---
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index dde9e17..6e1c1f9 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -283,6 +283,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
>  {
>  	struct perf_event_attr *attr = &evsel->attr;
>  	struct xyarray *group_fd = NULL;
> +	bool exclude_guest_missing = false;
> +	int ret;
>  
>  	if (group && evsel != first)
>  		group_fd = first->fd;
> @@ -293,16 +295,39 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
>  
>  	attr->inherit = !no_inherit;
>  
> -	if (system_wide)
> -		return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
> +retry:
> +	if (exclude_guest_missing)
> +		evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
> +
> +	if (system_wide) {
> +		ret = perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
>  						group, group_fd);
> +		if (ret)
> +			goto check_ret;
> +		return 0;
> +	}
> +
>  	if (!target_pid && !target_tid && (!group || evsel == first)) {
>  		attr->disabled = 1;
>  		attr->enable_on_exec = 1;
>  	}
>  
> -	return perf_evsel__open_per_thread(evsel, evsel_list->threads,
> -					   group, group_fd);
> +	ret = perf_evsel__open_per_thread(evsel, evsel_list->threads,
> +					  group, group_fd);
> +	if (!ret)
> +		return 0;
> +	/* fall through */
> +check_ret:
> +	if (ret && errno == EINVAL) {
> +		if (!exclude_guest_missing &&
> +		    (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
> +			pr_debug("Old kernel, cannot exclude "
> +				 "guest or host samples.\n");
> +			exclude_guest_missing = true;
> +			goto retry;
> +		}
> +	}
> +	return ret;
>  }
>  
>  /*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[Other Archives]     [Linux Kernel Newbies]     [Linux Driver Development]     [Fedora Kernel]     [Linux Kernel Testers]     [Linux SH]     [Linux Omap]     [Linux Kbuild]     [Linux Tape]     [Linux Input]     [Linux Kernel Janitors]     [Linux Kernel Packagers]     [Linux Doc]     [Linux Man Pages]     [Linux API]     [Linux Memory Management]     [Linux Modules]     [Linux Standards]     [Kernel Announce]     [Netdev]     [Git]     [Linux PCI]     Linux CAN Development     [Linux I2C]     [Linux RDMA]     [Linux NUMA]     [Netfilter]     [Netfilter Devel]     [SELinux]     [Bugtraq]     [FIO]     [Linux Perf Users]     [Linux Serial]     [Linux PPP]     [Linux ISDN]     [Linux Next]     [Kernel Stable Commits]     [Linux Tip Commits]     [Kernel MM Commits]     [Linux Security Module]     [AutoFS]     [Filesystem Development]     [Ext3 Filesystem]     [Linux bcache]     [Ext4 Filesystem]     [Linux BTRFS]     [Linux CEPH Filesystem]     [Linux XFS]     [XFS]     [Linux NFS]     [Linux CIFS]     [Ecryptfs]     [Linux NILFS]     [Linux Cachefs]     [Reiser FS]     [Initramfs]     [Linux FB Devel]     [Linux OpenGL]     [DRI Devel]     [Fastboot]     [Linux RT Users]     [Linux RT Stable]     [eCos]     [Corosync]     [Linux Clusters]     [LVS Devel]     [Hot Plug]     [Linux Virtualization]     [KVM]     [KVM PPC]     [KVM ia64]     [Linux Containers]     [Linux Hexagon]     [Linux Cgroups]     [Util Linux]     [Wireless]     [Linux Bluetooth]     [Bluez Devel]     [Ethernet Bridging]     [Embedded Linux]     [Barebox]     [Linux MMC]     [Linux IIO]     [Sparse]     [Smatch]     [Linux Arch]     [x86 Platform Driver]     [Linux ACPI]     [Linux IBM ACPI]     [LM Sensors]     [CPU Freq]     [Linux Power Management]     [Linmodems]     [Linux DCCP]     [Linux SCTP]     [ALSA Devel]     [Linux USB]     [Linux PA RISC]     [Linux Samsung SOC]     [MIPS Linux]     [IBM S/390 Linux]     [ARM Linux]     [ARM Kernel]     [ARM MSM]     [Tegra Devel]     [Sparc Linux]     [Linux Security]     [Linux Sound]     [Linux Media]     [Video 4 Linux]     [Linux IRDA Users]     [Linux for the blind]     [Linux RAID]     [Linux ATA RAID]     [Device Mapper]     [Linux SCSI]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Linux IDE]     [Linux SMP]     [Linux AXP]     [Linux Alpha]     [Linux M68K]     [Linux ia64]     [Linux 8086]     [Linux x86_64]     [Linux Config]     [Linux Apps]     [Linux MSDOS]     [Linux X.25]     [Linux Crypto]     [DM Crypt]     [Linux Trace Users]     [Linux Btrace]     [Linux Watchdog]     [Utrace Devel]     [Linux C Programming]     [Linux Assembly]     [Dash]     [DWARVES]     [Hail Devel]     [Linux Kernel Debugger]     [Linux gcc]     [Gcc Help]     [X.Org]     [Wine]

Add to Google Powered by Linux

[Older Kernel Discussion]     [Yosemite National Park Forum]     [Large Format Photos]     [Gimp]     [Yosemite Photos]     [Stuff]