perfmon2 minimal: generic headers
PATCH 2/21 perfmon2 minimal: generic headers
This patch adds the generic perfmon2 headers including the public head perfmon.h which can be used by applications. The other headers are for kernel use only.
--
include/linux/perfmon.h new file +65 -0
@@ -0,0 +1,65 @@ +/* +* Copyright (c) 2001-2006 Hewlett-Packard Development Company, L.P. +* Contributed by Stephane Eranian <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +* 02111-1307 USA +*/ + +#ifndef __LINUX_PERFMON_H__ +#define __LINUX_PERFMON_H__ + +/* +* This file contains all the user visible generic definitions for the +* interface. Model-specific user-visible definitions are located in +* the asm/perfmon.h file. +*/ + +/* +* include arch-specific user interface definitions +*/ +#include <asm/perfmon.h> + +/* +* defined by each arch +*/ +#define PFM_MAX_PMCS PFM_ARCH_MAX_PMCS +#define PFM_MAX_PMDS PFM_ARCH_MAX_PMDS + +/* +* number of elements for each type of bitvector +* all bitvectors use u64 fixed size type on all architectures. +*/ +#define PFM_BVSIZE (x) (((x)+(sizeof(u64)<<3)-1) / (sizeof(u64)<<3)) +#define PFM_PMD_BV PFM_BVSIZE(PFM_MAX_PMDS) +#define PFM_PMC_BV PFM_BVSIZE(PFM_MAX_PMCS) + +/* +* default value for the user and group security parameters in +* /proc/sys/kernel/perfmon/sys_group +* /proc/sys/kernel/perfmon/task_group +*/ +#define PFM_GROUP_PERM_ANY -1/* any user/group */ + +/* +* perfmon version number +*/ +#define PFM_VERSION_MAJ 2U +#define PFM_VERSION_MIN 99U +#define PFM_VERSION (((PFM_VERSION_MAJ&0xffff)<<16)|\ + (PFM_VERSION_MIN & 0xffff)) +#define PFM_VERSION_MAJOR (x) (((x)>>16) & 0xffff) +#define PFM_VERSION_MINOR (x) ((x) & 0xffff) + +#endif /* __LINUX_PERFMON_H__ */
include/linux/perfmon_kern.h new file +257 -0
257 lines not on this page · raw message
include/linux/perfmon_pmu.h new file +158 -0
158 lines not on this page · raw message
Quoted 5 lines · On Mon, 09 Jun 2008 15:33:40 -0700 (PDT) [email protected] wrote:
include/linux/perfmon.h new file +5
-0+#ifndef __LINUX_PERFMON_H__ +#define __LINUX_PERFMON_H__ + +/* +* This file contains all the user visible generic definitions for
Quoted 7 lines
the
+ * interface. Model-specific user-visible definitions are located in
+ * theasm/perfmon.hfile.
+ */
+ */
+#definePFM_BVSIZE(x)(((x)+(sizeof(u64)<<3)-1) /
(sizeof(u64)<<3)) +#definePFM_PMD_BVPFM_BVSIZE(PFM_MAX_PMDS)
can't use u64 in userspace headers; must use __u64
Quoted 3 lines
+ * default value for the user and group security parameters in
+ */proc/sys/kernel/perfmon/sys_group
+ */proc/sys/kernel/perfmon/task_group
hmmm that smells funky.
include/linux/perfmon.h line 63
Quoted 9 lines
include/linux/perfmon.h new file +9
-0+/* +* perfmon version number +*/ +#define PFM_VERSION_MAJ 2U +#define PFM_VERSION_MIN 99U +#define PFM_VERSION (((PFM_VERSION_MAJ&0xffff)<<16)|\ + (PFM_VERSION_MIN & 0xffff)) +#define PFM_VERSION_MAJOR (x) (((x)>>16) & 0xffff) +#define PFM_VERSION_MINOR (x) ((x) & 0xffff)
I'm very nervous when seeing something like this in userspace headers; you need to assume that the app has been compiled with a very different version of the headers than the currently running kernel.... either the version of perfmon doesn't matter, in which case these don't belong here, or it does and it should be a runtime query.
Quoted 10 lines
include/linux/perfmon_kern.h new file +4
-0+#ifndef __LINUX_PERFMON_KERN_H__ +#define __LINUX_PERFMON_KERN_H__ +/* +* This file contains all the definitions of data structures, variables, macros
+ * that are to be shared between generic code and arch-specific code
+ *
+ * For generic only definitions, useperfmon/perfmon_priv.h
+ */
+#ifdef__KERNEL__
no need for #ifdef __KERNEL__, just don't expose the header to userspace.
Quoted 8 lines
include/linux/perfmon_kern.h new file +4
-0+/* +* logging +*/ +#define PFM_ERR(f, x...) printk(KERN_ERR "perfmon: " f "\n", ##x) +#define
PFM_WARN(f, x...)printk(KERN_WARNING "perfmon: " f "\n", ## x)+#definePFM_LOG(f, x...)printk(KERN_NOTICE "perfmon: " f
"\n", ## x) +#definePFM_INFO(f, x...)printk(KERN_INFO "perfmon:
" f "\n", ## x) +
hmmm what's wrong with the current set of macros the kernel has for these?
Arjan,
Quoted 19 lines · Arjan van de Ven
Quoted 5 lines · On Mon, 09 Jun 2008 15:33:40 -0700 (PDT) [email protected] wrote:
include/linux/perfmon.h new file +5
-0+#ifndef __LINUX_PERFMON_H__ +#define __LINUX_PERFMON_H__ + +/* +* This file contains all the user visible generic definitions for Quoted 7 lines
the
+ * interface. Model-specific user-visible definitions are located in
+ * theasm/perfmon.hfile.
+ */
+ */
+#definePFM_BVSIZE(x)(((x)+(sizeof(u64)<<3)-1) /
(sizeof(u64)<<3)) +#definePFM_PMD_BVPFM_BVSIZE(PFM_MAX_PMDS)can't use u64 in userspace headers; must use
__u64
Will fix that.
Quoted 6 lines
Quoted 3 lines
+ * default value for the user and group security parameters in
+ */proc/sys/kernel/perfmon/sys_group
+ */proc/sys/kernel/perfmon/task_grouphmmm that smells funky.
Will clarify this.
Quoted 7 lines
Quoted 7 lines
include/linux/perfmon.h new file +7
-0+/* +* perfmon version number +*/ +#define PFM_VERSION_MAJ 2U +#define PFM_VERSION_MIN 99U +#define PFM_VERSION (((PFM_VERSION_MAJ&0xffff)<<16)|\ + (PFM_VERSION_MIN & 0xffff))
Quoted 9 lines
include/linux/perfmon.h line 63
Quoted 2 lines
include/linux/perfmon.h new file +2
-0+#define PFM_VERSION_MAJOR (x) (((x)>>16) & 0xffff) +#define PFM_VERSION_MINOR (x) ((x) & 0xffff)I'm very nervous when seeing something like this in userspace headers; you need to assume that the app has been compiled with a very different version of the headers than the currently running kernel.... either the version of perfmon doesn't matter, in which case these don't belong here, or it does and it should be a runtime query.
I think you bring up a good point. There is indeed a way of querying the version via /sysfs.
However the question is how does an application know which API version it was compiled
for, so it can compare with what it finds in /sysfs? That ought to be somewhere in the
public headers that the application was compiled with.
Quoted 16 lines
Quoted 6 lines
include/linux/perfmon_kern.h new file +4
-0+#ifndef __LINUX_PERFMON_KERN_H__ +#define __LINUX_PERFMON_KERN_H__ +/* +* This file contains all the definitions of data structures, Quoted 6 lines
variables, macros
+ * that are to be shared between generic code and arch-specific code
+ *
+ * For generic only definitions, useperfmon/perfmon_priv.h
+ */
+#ifdef__KERNEL__no need for #ifdef
__KERNEL__, just don't expose the header to userspace.
You are right. Will remove that.
Quoted 12 lines
Quoted 8 lines
include/linux/perfmon_kern.h new file +4
-0+/* +* logging +*/ +#define PFM_ERR(f, x...) printk(KERN_ERR "perfmon: " f "\n", ##x) +#define
PFM_WARN(f, x...)printk(KERN_WARNING "perfmon: " f "\n", ## x)+#definePFM_LOG(f, x...)printk(KERN_NOTICE "perfmon: " f
"\n", ## x) +#definePFM_INFO(f, x...)printk(KERN_INFO "perfmon:
" f "\n", ## x) +hmmm what's wrong with the current set of macros the kernel has for these?
I think these simply prefix the message with "perfmon:" so you know which subsystems the messages are from.
You do it in one place instead of duplicating the "perfmon: " string everywhere.
Quoted 6 lines · stephane eranian
Quoted 6 lines
I'm very nervous when seeing something like this in userspace headers; you need to assume that the app has been compiled with a very different version of the headers than the currently running kernel.... either the version of perfmon doesn't matter, in which case these don't belong here, or it does and it should be a runtime query.
Quoted 9 lines
I think you bring up a good point. There is indeed a way of querying the version via /sysfs.
However the question is how does an application know which API version it was compiled
for, so it can compare with what it finds in /sysfs? That ought to be somewhere in the
public headers that the application was compiled with.
The normal way for an application is to just use a syscall or file interface, and check for -ENOENT or -ENOSYS error codes in order to find kernels that are too old. If older kernels had a different way of doing things, the application can fall back on that mechanism. An example for this would be pselect() which you can replace with select(), but only in a racy way that the user should avoid.
When the kernel changes an interface, it must only do that in a backwards compatible way, so that old binaries do not break. Ever.
Arnd <><