2.6.17-rc6 perfmon2 patch for review: sampling format support
PATCH 6/16 2.6.17-rc6 perfmon2 patch for review: sampling format support
This files contains the sampling format support.
perfmon/perfmon_fmt.c +223 -0
@@ -0,0 +1,223 @@ +/* +* perfmon_fmt.c: perfmon2 sampling buffer format management +* +* This file implements the perfmon2 interface which +* provides access to the hardware performance counters +* of the host processor. +* +* The initial version of perfmon.c was written by +* Ganesh Venkitachalam, IBM Corp. +* +* Then it was modified for perfmon-1.x by Stephane Eranian and +* David Mosberger, Hewlett Packard Co. +* +* Version Perfmon-2.x is a complete rewrite of perfmon-1.x +* by Stephane Eranian, Hewlett Packard Co. +* +* Copyright (c) 1999-2006 Hewlett-Packard Development Company, L.P. +* Contributed by Stephane Eranian <[email protected]> +* David Mosberger-Tang <[email protected]> +* +* More information about perfmon available at: +* http://www.hpl.hp.com/research/linux/perfmon +*/ +#include <linux/module.h> +#include <linux/perfmon.h> + +static __cacheline_aligned_in_smp DEFINE_SPINLOCK (pfm_smpl_fmt_lock ); +static LIST_HEAD (pfm_smpl_fmt_list); +static pfm_uuid_t null_uuid; + +static inline int pfm_uuid_cmp (pfm_uuid_t a,pfm_uuid_t b) +{ +return memcmp (a, b,sizeof (a)); +} + +static inline int fmt_is_mod (struct pfm_smpl_fmt *f) +{ +return (f->fmt_flags &PFM_FMTFL_IS_BUILTIN ) ==0 ; +} + + +int pfm_use_smpl_fmt (pfm_uuid_t uuid) +{ +return pfm_uuid_cmp (uuid, null_uuid); +} + +static struct pfm_smpl_fmt *__pfm_find_smpl_fmt (pfm_uuid_t uuid) +{ +struct pfm_smpl_fmt * entry; + +list_for_each_entry (entry, &pfm_smpl_fmt_list, fmt_list) { +if (pfm_uuid_cmp (uuid, entry->fmt_uuid) ==0 ) +return entry; + } +return NULL ; +} + +static struct pfm_smpl_fmt *pfm_find_fmt_name (char *name) +{ +struct pfm_smpl_fmt * entry; + +list_for_each_entry (entry, &pfm_smpl_fmt_list, fmt_list) { +if (!strcmp (entry->fmt_name, name)) +return entry; + } +return NULL ; +} +/* +* find a buffer format based on its uuid +*/ +struct pfm_smpl_fmt *pfm_smpl_fmt_get (pfm_uuid_t uuid) +{ +struct pfm_smpl_fmt * fmt; + +spin_lock (&pfm_smpl_fmt_lock); + + fmt =__pfm_find_smpl_fmt (uuid); + +/* +* increase module refcount +*/ +if (fmt &&fmt_is_mod (fmt) && !try_module_get (fmt->owner)) + fmt =NULL ; + +spin_unlock (&pfm_smpl_fmt_lock); + +return fmt; +} + +void pfm_smpl_fmt_put (struct pfm_smpl_fmt *fmt) +{ +if (fmt ==NULL ||fmt_is_mod (fmt) ==0 ) +return ; +BUG_ON (fmt->owner ==NULL ); + +spin_lock (&pfm_smpl_fmt_lock); +module_put (fmt->owner); +spin_unlock (&pfm_smpl_fmt_lock); +} + +int pfm_register_smpl_fmt (struct pfm_smpl_fmt *fmt) +{ +int ret =0 ; + +/* some sanity checks */ +if (fmt ==NULL ) { +PFM_INFO ("perfmon: NULL format for register" ); +return -EINVAL ; + } + +if (fmt->fmt_name ==NULL ) { +PFM_INFO ("perfmon: format has no name" ); +return -EINVAL ; + } +if (pfm_uuid_cmp (fmt->fmt_uuid, null_uuid) ==0 ) { +PFM_INFO ("perfmon: format %s has null uuid" , fmt->fmt_name); +return -EINVAL ; + } + +if (fmt->fmt_qdepth >PFM_MAX_MSGS ) { +PFM_INFO ("perfmon: format %s requires %u msg queue depth (max %d)" , + fmt->fmt_name, + fmt->fmt_qdepth, +PFM_MAX_MSGS ); +return -EINVAL ; + } + +/* +* fmt is missing the initialization of .owner = THIS_MODULE +* this is only valid when format is compiled as a module +*/ +if (fmt->owner ==NULL &&fmt_is_mod (fmt)) { +PFM_INFO ("format %s has no module owner" , fmt->fmt_name); +return -EINVAL ; + } +/* +* we need at least a handler +*/ +if (fmt->fmt_handler ==NULL ) { +PFM_INFO ("format %s has no handler" , fmt->fmt_name); +return -EINVAL ; + } + +/* +* format argument size cannot be bigger than PAGE_SIZE +*/ +if (fmt->fmt_arg_size >PAGE_SIZE ) { +PFM_INFO ("format %s arguments too big" , fmt->fmt_name); +return -EINVAL ; + } + +spin_lock (&pfm_smpl_fmt_lock); + +if (__pfm_find_smpl_fmt (fmt->fmt_uuid)) { +PFM_INFO ("duplicate sampling format %s" , fmt->fmt_name); + ret = -EBUSY ; + goto out; + } + +/* +* because of sysfs, we cannot have two formats with the same name +*/ +if (pfm_find_fmt_name (fmt->fmt_name)) { +PFM_INFO ("duplicate sampling format name %s" , fmt->fmt_name); + ret = -EBUSY ; + goto out; + } + +pfm_sysfs_add_fmt (fmt); + +list_add (&fmt->fmt_list, &pfm_smpl_fmt_list); + +PFM_INFO ("added sampling format %s" , fmt->fmt_name); +out: +spin_unlock (&pfm_smpl_fmt_lock); + +return ret; +} +EXPORT_SYMBOL (pfm_register_smpl_fmt); + +int pfm_unregister_smpl_fmt (pfm_uuid_t uuid) +{ +struct pfm_smpl_fmt *fmt; +int ret =0 ; + +spin_lock (&pfm_smpl_fmt_lock); + + fmt =__pfm_find_smpl_fmt (uuid); +if (!fmt) { +PFM_INFO ("unregister failed, unknown format" ); + ret = -EINVAL ; + goto out; + } +list_del_init (&fmt->fmt_list); + +pfm_sysfs_remove_fmt (fmt); + +PFM_INFO ("removed sampling format: %s" , fmt->fmt_name); + +out: +spin_unlock (&pfm_smpl_fmt_lock); +return ret; + +} +EXPORT_SYMBOL (pfm_unregister_smpl_fmt); + +/* +* we defer adding the builtin formats to /sys/kernel/perfmon/formats +* until after the pfm sysfs subsystem is initialized. This function +* is called from pfm_sysfs_init() +*/ +void pfm_builtin_fmt_sysfs_add (void ) +{ +struct pfm_smpl_fmt * entry; + +/* +* locking not needed, kernel not fully booted +* when called +*/ +list_for_each_entry (entry, &pfm_smpl_fmt_list, fmt_list) { +pfm_sysfs_add_fmt (entry); + } +}
perfmon/perfmon_dfl_smpl.c +269 -0
269 lines not on this page · raw message