Blame src/perfctr-2.6.x/linux/drivers/perfctr/compat.h

Packit 577717
/* $Id: compat.h,v 1.42.2.17 2009/01/23 17:01:02 mikpe Exp $
Packit 577717
 * Performance-monitoring counters driver.
Packit 577717
 * Compatibility definitions for 2.6 kernels.
Packit 577717
 *
Packit 577717
 * Copyright (C) 1999-2009  Mikael Pettersson
Packit 577717
 */
Packit 577717
#include <linux/version.h>
Packit 577717
Packit 577717
#include "cpumask.h"
Packit 577717
Packit 577717
#define EXPORT_SYMBOL_mmu_cr4_features	EXPORT_SYMBOL(mmu_cr4_features)
Packit 577717
Packit 577717
/* Starting with 2.6.16-rc1, put_task_struct() uses an RCU callback
Packit 577717
   __put_task_struct_cb() instead of the old __put_task_struct().
Packit 577717
   2.6.16-rc6 dropped the EXPORT_SYMBOL() of __put_task_struct_cb().
Packit 577717
   2.6.17-rc1 reverted to using __put_task_struct() again. */
Packit 577717
#if defined(HAVE_EXPORT___put_task_struct)
Packit 577717
/* 2.6.5-7.201-suse added EXPORT_SYMBOL_GPL(__put_task_struct) */
Packit 577717
/* 2.6.16.46-0.12-suse added EXPORT_SYMBOL(__put_task_struct_cb) */
Packit 577717
#define EXPORT_SYMBOL___put_task_struct	/*empty*/
Packit 577717
#elif LINUX_VERSION_CODE == KERNEL_VERSION(2,6,16)
Packit 577717
#define EXPORT_SYMBOL___put_task_struct	EXPORT_SYMBOL(__put_task_struct_cb)
Packit 577717
#else
Packit 577717
#define EXPORT_SYMBOL___put_task_struct	EXPORT_SYMBOL(__put_task_struct)
Packit 577717
#endif
Packit 577717
Packit 577717
#define task_siglock(tsk)	((tsk)->sighand->siglock)
Packit 577717
Packit 577717
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)	/* names changed in 2.6.4-rc2 */
Packit 577717
#define sysdev_register(dev)	sys_device_register((dev))
Packit 577717
#define sysdev_unregister(dev)	sys_device_unregister((dev))
Packit 577717
#endif
Packit 577717
Packit 577717
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) /* remap_page_range() obsoleted in 2.6.10-rc1 */
Packit 577717
#include <linux/mm.h>
Packit 577717
static inline int
Packit 577717
remap_pfn_range(struct vm_area_struct *vma, unsigned long uvaddr,
Packit 577717
		unsigned long pfn, unsigned long size, pgprot_t prot)
Packit 577717
{
Packit 577717
	return remap_page_range(vma, uvaddr, pfn << PAGE_SHIFT, size, prot);
Packit 577717
}
Packit 577717
#endif
Packit 577717
Packit 577717
#if !defined(DEFINE_SPINLOCK) /* added in 2.6.11-rc1 */
Packit 577717
#define DEFINE_SPINLOCK(x)	spinlock_t x = SPIN_LOCK_UNLOCKED
Packit 577717
#endif
Packit 577717
Packit 577717
/* 2.6.16 introduced a new mutex type, replacing mutex-like semaphores. */
Packit 577717
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
Packit 577717
#define DEFINE_MUTEX(mutex)	DECLARE_MUTEX(mutex)
Packit 577717
#define mutex_lock(mutexp)	down(mutexp)
Packit 577717
#define mutex_unlock(mutexp)	up(mutexp)
Packit 577717
#endif
Packit 577717
Packit 577717
/* 2.6.18-8.1.1.el5 replaced ptrace with utrace */
Packit 577717
#if defined(CONFIG_UTRACE)
Packit 577717
/* alas, I don't yet know how to convert this to utrace */
Packit 577717
static inline int ptrace_check_attach(struct task_struct *task, int kill) { return -ESRCH; }
Packit 577717
#endif
Packit 577717
Packit 577717
/* 2.6.20-rc1 moved filp->f_dentry and filp->f_vfsmnt into filp->fpath */
Packit 577717
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
Packit 577717
#define filp_dentry(filp)	((filp)->f_path.dentry)
Packit 577717
#define filp_vfsmnt(filp)	((filp)->f_path.mnt)
Packit 577717
#else
Packit 577717
#define filp_dentry(filp)	((filp)->f_dentry)
Packit 577717
#define filp_vfsmnt(filp)	((filp)->f_vfsmnt)
Packit 577717
#endif
Packit 577717
Packit 577717
/* 2.6.24 introduced find_task_by_vpid() and task_pid_vnr().
Packit 577717
   2.6.26 deprecated find_task_by_pid() and 2.6.27-rc1 removed it.
Packit 577717
   We'll use 2.6.26 as the switch-over point. */
Packit 577717
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
Packit 577717
static inline struct task_struct *perfctr_find_task_by_vpid(pid_t nr)
Packit 577717
{
Packit 577717
	return find_task_by_pid(nr);
Packit 577717
}
Packit 577717
#undef find_task_by_vpid
Packit 577717
#define find_task_by_vpid(nr)	perfctr_find_task_by_vpid((nr))
Packit 577717
static inline pid_t perfctr_task_pid_vnr(const struct task_struct *tsk)
Packit 577717
{
Packit 577717
	return tsk->pid;
Packit 577717
}
Packit 577717
#undef task_pid_vnr
Packit 577717
#define task_pid_vnr(tsk)	perfctr_task_pid_vnr((tsk))
Packit 577717
#endif
Packit 577717
Packit 577717
/* 2.6.27-rc1 dropped the retry parameter from smp_call_function()
Packit 577717
   and on_each_cpu() -- we always called it with retry == 1 */
Packit 577717
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
Packit 577717
static inline int perfctr_smp_call_function(
Packit 577717
	void (*func)(void *info), void *info, int wait)
Packit 577717
{
Packit 577717
	return smp_call_function(func, info, 1, wait);
Packit 577717
}
Packit 577717
#undef smp_call_function
Packit 577717
#define smp_call_function(f,i,w)	perfctr_smp_call_function((f),(i),(w))
Packit 577717
static inline int perfctr_on_each_cpu(
Packit 577717
	void (*func)(void *info), void *info, int wait)
Packit 577717
{
Packit 577717
	return on_each_cpu(func, info, 1, wait);
Packit 577717
}
Packit 577717
#undef on_each_cpu
Packit 577717
#define on_each_cpu(f,i,w)	perfctr_on_each_cpu((f),(i),(w))
Packit 577717
#endif
Packit 577717
Packit 577717
/* 2.6.29-rc1 changed how ->fsuid and ->fsgid are accessed */
Packit 577717
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) && !defined(current_fsuid)
Packit 577717
#define current_fsuid()	(current->fsuid)
Packit 577717
#define current_fsgid()	(current->fsgid)
Packit 577717
#endif