Skip to content

Commit

Permalink
perf_counter: SIGIO support
Browse files Browse the repository at this point in the history
Provide support for fcntl() I/O availability signals.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090406094517.579788800@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Apr 7, 2009
1 parent 9c03d88 commit 3c446b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ enum perf_event_type {
#include <linux/rcupdate.h>
#include <linux/spinlock.h>
#include <linux/hrtimer.h>
#include <linux/fs.h>
#include <asm/atomic.h>

struct task_struct;
Expand Down Expand Up @@ -398,6 +399,7 @@ struct perf_counter {

/* poll related */
wait_queue_head_t waitq;
struct fasync_struct *fasync;
/* optional: for NMIs */
struct perf_wakeup_entry wakeup;

Expand Down
20 changes: 19 additions & 1 deletion kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,13 +1526,30 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
return ret;
}

static int perf_fasync(int fd, struct file *filp, int on)
{
struct perf_counter *counter = filp->private_data;
struct inode *inode = filp->f_path.dentry->d_inode;
int retval;

mutex_lock(&inode->i_mutex);
retval = fasync_helper(fd, filp, on, &counter->fasync);
mutex_unlock(&inode->i_mutex);

if (retval < 0)
return retval;

return 0;
}

static const struct file_operations perf_fops = {
.release = perf_release,
.read = perf_read,
.poll = perf_poll,
.unlocked_ioctl = perf_ioctl,
.compat_ioctl = perf_ioctl,
.mmap = perf_mmap,
.fasync = perf_fasync,
};

/*
Expand All @@ -1549,7 +1566,7 @@ void perf_counter_wakeup(struct perf_counter *counter)
rcu_read_lock();
data = rcu_dereference(counter->data);
if (data) {
(void)atomic_xchg(&data->wakeup, POLL_IN);
atomic_set(&data->wakeup, POLL_IN);
/*
* Ensure all data writes are issued before updating the
* user-space data head information. The matching rmb()
Expand All @@ -1561,6 +1578,7 @@ void perf_counter_wakeup(struct perf_counter *counter)
rcu_read_unlock();

wake_up_all(&counter->waitq);
kill_fasync(&counter->fasync, SIGIO, POLL_IN);
}

/*
Expand Down

0 comments on commit 3c446b3

Please sign in to comment.