summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhwangcc <hwangcc@csie.nctu.edu.tw>2015-01-06 11:57:49 +0800
committerJavier Martinez Canillas <javier@dowhile0.org>2018-02-25 01:57:23 +0100
commit3e008f44afa83de0a5b59c736fefc309f69621d2 (patch)
tree0d56546151dcb3e8992390a828f54c3423c5ac2b
parenta5939c09225060d389727e79213f9295da410f07 (diff)
downloadldd3-3e008f44afa83de0a5b59c736fefc309f69621d2.tar.gz
jit.c: Don't use create_proc_entry
Don't use create_proc_read_entry as that is deprecated, but rather use proc_create and seq_file instead. Signed-off-by: hwangcc <hwangcc@csie.nctu.edu.tw>
-rw-r--r--misc-modules/jit.c124
1 files changed, 80 insertions, 44 deletions
diff --git a/misc-modules/jit.c b/misc-modules/jit.c
index 5f3507e..e9ff856 100644
--- a/misc-modules/jit.c
+++ b/misc-modules/jit.c
@@ -23,10 +23,12 @@
#include <linux/timer.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
+#include <linux/slab.h>
#include <asm/hardirq.h>
/*
@@ -53,17 +55,17 @@ enum jit_files {
* This function prints one line of data, after sleeping one second.
* It can sleep in different ways, according to the data pointer
*/
-int jit_fn(char *buf, char **start, off_t offset,
- int len, int *eof, void *data)
+int jit_fn_show(struct seq_file *m, void *v)
{
unsigned long j0, j1; /* jiffies */
wait_queue_head_t wait;
+ long data = (long)m->private;
init_waitqueue_head (&wait);
j0 = jiffies;
j1 = j0 + delay;
- switch((long)data) {
+ switch (data) {
case JIT_BUSY:
while (time_before(jiffies, j1))
cpu_relax();
@@ -83,16 +85,26 @@ int jit_fn(char *buf, char **start, off_t offset,
}
j1 = jiffies; /* actual value after we delayed */
- len = sprintf(buf, "%9li %9li\n", j0, j1);
- *start = buf;
- return len;
+ seq_printf(m, "%9li %9li\n", j0, j1);
+ return 0;
}
+static int jit_fn_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, jit_fn_show, PDE_DATA(inode));
+}
+
+static const struct file_operations jit_fn_fops = {
+ .open = jit_fn_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
/*
* This file, on the other hand, returns the current time forever
*/
-int jit_currentime(char *buf, char **start, off_t offset,
- int len, int *eof, void *data)
+int jit_currentime_show(struct seq_file *m, void *v)
{
struct timeval tv1;
struct timespec tv2;
@@ -106,16 +118,26 @@ int jit_currentime(char *buf, char **start, off_t offset,
tv2 = current_kernel_time();
/* print */
- len=0;
- len += sprintf(buf,"0x%08lx 0x%016Lx %10i.%06i\n"
+ seq_printf(m, "0x%08lx 0x%016Lx %10i.%06i\n"
"%40i.%09i\n",
j1, j2,
(int) tv1.tv_sec, (int) tv1.tv_usec,
(int) tv2.tv_sec, (int) tv2.tv_nsec);
- *start = buf;
- return len;
+ return 0;
}
+static int jit_currentime_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, jit_currentime_show, NULL);
+}
+
+static const struct file_operations jit_currentime_fops = {
+ .open = jit_currentime_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
/*
* The timer example follows
*/
@@ -127,10 +149,10 @@ module_param(tdelay, int, 0);
struct jit_data {
struct timer_list timer;
struct tasklet_struct tlet;
+ struct seq_file *m;
int hi; /* tasklet or tasklet_hi */
wait_queue_head_t wait;
unsigned long prevjiffies;
- unsigned char *buf;
int loops;
};
#define JIT_ASYNC_LOOPS 5
@@ -139,7 +161,7 @@ void jit_timer_fn(unsigned long arg)
{
struct jit_data *data = (struct jit_data *)arg;
unsigned long j = jiffies;
- data->buf += sprintf(data->buf, "%9li %3li %i %6i %i %s\n",
+ seq_printf(data->m, "%9li %3li %i %6i %i %s\n",
j, j - data->prevjiffies, in_interrupt() ? 1 : 0,
current->pid, smp_processor_id(), current->comm);
@@ -153,11 +175,9 @@ void jit_timer_fn(unsigned long arg)
}
/* the /proc function: allocate everything to allow concurrency */
-int jit_timer(char *buf, char **start, off_t offset,
- int len, int *eof, void *unused_data)
+int jit_timer_show(struct seq_file *m, void *v)
{
struct jit_data *data;
- char *buf2 = buf;
unsigned long j = jiffies;
data = kmalloc(sizeof(*data), GFP_KERNEL);
@@ -165,17 +185,17 @@ int jit_timer(char *buf, char **start, off_t offset,
return -ENOMEM;
init_timer(&data->timer);
- init_waitqueue_head (&data->wait);
+ init_waitqueue_head(&data->wait);
/* write the first lines in the buffer */
- buf2 += sprintf(buf2, " time delta inirq pid cpu command\n");
- buf2 += sprintf(buf2, "%9li %3li %i %6i %i %s\n",
+ seq_printf(m, " time delta inirq pid cpu command\n");
+ seq_printf(m, "%9li %3li %i %6i %i %s\n",
j, 0L, in_interrupt() ? 1 : 0,
current->pid, smp_processor_id(), current->comm);
/* fill the data for our timer function */
data->prevjiffies = j;
- data->buf = buf2;
+ data->m = m;
data->loops = JIT_ASYNC_LOOPS;
/* register the timer */
@@ -188,17 +208,27 @@ int jit_timer(char *buf, char **start, off_t offset,
wait_event_interruptible(data->wait, !data->loops);
if (signal_pending(current))
return -ERESTARTSYS;
- buf2 = data->buf;
kfree(data);
- *eof = 1;
- return buf2 - buf;
+ return 0;
}
+static int jit_timer_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, jit_timer_show, NULL);
+}
+
+static const struct file_operations jit_timer_fops = {
+ .open = jit_timer_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
void jit_tasklet_fn(unsigned long arg)
{
struct jit_data *data = (struct jit_data *)arg;
unsigned long j = jiffies;
- data->buf += sprintf(data->buf, "%9li %3li %i %6i %i %s\n",
+ seq_printf(data->m, "%9li %3li %i %6i %i %s\n",
j, j - data->prevjiffies, in_interrupt() ? 1 : 0,
current->pid, smp_processor_id(), current->comm);
@@ -214,13 +244,11 @@ void jit_tasklet_fn(unsigned long arg)
}
/* the /proc function: allocate everything to allow concurrency */
-int jit_tasklet(char *buf, char **start, off_t offset,
- int len, int *eof, void *arg)
+int jit_tasklet_show(struct seq_file *m, void *v)
{
struct jit_data *data;
- char *buf2 = buf;
unsigned long j = jiffies;
- long hi = (long)arg;
+ long hi = (long)m->private;
data = kmalloc(sizeof(*data), GFP_KERNEL);
if (!data)
@@ -229,14 +257,14 @@ int jit_tasklet(char *buf, char **start, off_t offset,
init_waitqueue_head (&data->wait);
/* write the first lines in the buffer */
- buf2 += sprintf(buf2, " time delta inirq pid cpu command\n");
- buf2 += sprintf(buf2, "%9li %3li %i %6i %i %s\n",
+ seq_printf(m, " time delta inirq pid cpu command\n");
+ seq_printf(m, "%9li %3li %i %6i %i %s\n",
j, 0L, in_interrupt() ? 1 : 0,
current->pid, smp_processor_id(), current->comm);
/* fill the data for our tasklet function */
data->prevjiffies = j;
- data->buf = buf2;
+ data->m = m;
data->loops = JIT_ASYNC_LOOPS;
/* register the tasklet */
@@ -252,25 +280,33 @@ int jit_tasklet(char *buf, char **start, off_t offset,
if (signal_pending(current))
return -ERESTARTSYS;
- buf2 = data->buf;
kfree(data);
- *eof = 1;
- return buf2 - buf;
+ return 0;
}
+static int jit_tasklet_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, jit_tasklet_show, PDE_DATA(inode));
+}
+static const struct file_operations jit_tasklet_fops = {
+ .open = jit_tasklet_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
int __init jit_init(void)
{
- create_proc_read_entry("currentime", 0, NULL, jit_currentime, NULL);
- create_proc_read_entry("jitbusy", 0, NULL, jit_fn, (void *)JIT_BUSY);
- create_proc_read_entry("jitsched",0, NULL, jit_fn, (void *)JIT_SCHED);
- create_proc_read_entry("jitqueue",0, NULL, jit_fn, (void *)JIT_QUEUE);
- create_proc_read_entry("jitschedto", 0, NULL, jit_fn, (void *)JIT_SCHEDTO);
-
- create_proc_read_entry("jitimer", 0, NULL, jit_timer, NULL);
- create_proc_read_entry("jitasklet", 0, NULL, jit_tasklet, NULL);
- create_proc_read_entry("jitasklethi", 0, NULL, jit_tasklet, (void *)1);
+ proc_create_data("currentime", 0, NULL, &jit_currentime_fops, NULL);
+ proc_create_data("jitbusy", 0, NULL, &jit_fn_fops, (void *)JIT_BUSY);
+ proc_create_data("jitsched",0, NULL, &jit_fn_fops, (void *)JIT_SCHED);
+ proc_create_data("jitqueue",0, NULL, &jit_fn_fops, (void *)JIT_QUEUE);
+ proc_create_data("jitschedto", 0, NULL, &jit_fn_fops, (void *)JIT_SCHEDTO);
+
+ proc_create_data("jitimer", 0, NULL, &jit_timer_fops, NULL);
+ proc_create_data("jitasklet", 0, NULL, &jit_tasklet_fops, NULL);
+ proc_create_data("jitasklethi", 0, NULL, &jit_tasklet_fops, (void *)1);
return 0; /* success */
}