-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemulate_nvm_proc.c
96 lines (77 loc) · 2.32 KB
/
emulate_nvm_proc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 2015-2016 Yizhou Shan <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "emulate_nvm.h"
#include <asm/uaccess.h>
#include <linux/list.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
extern u64 read_latency_delta_ns;
extern u64 hrtimer_jiffies;
u64 proc_counts;
static int emulate_nvm_proc_show(struct seq_file *m, void *v)
{
seq_printf(m, "this moment, counts=%llu, delay_ns=%llu\n",
proc_counts, proc_counts*read_latency_delta_ns);
seq_printf(m, "total jiffies = %llu\n", hrtimer_jiffies);
return 0;
}
static int emulate_nvm_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, emulate_nvm_proc_show, NULL);
}
static ssize_t emulate_nvm_proc_write(struct file *file, const char __user *buf,
size_t count, loff_t *offs)
{
char ctl[2];
if (count !=2 || *offs)
return -EINVAL;
if (copy_from_user(ctl, buf, count))
return -EFAULT;
switch (ctl[0]) {
/*TODO modify parameters */
default:
count = -EINVAL;
}
return count;
}
const struct file_operations emulate_nvm_proc_fops = {
.open = emulate_nvm_proc_open,
.read = seq_read,
.write = emulate_nvm_proc_write,
.llseek = seq_lseek,
.release = single_release
};
static bool is_proc_registed = false;
int __must_check emulate_nvm_proc_create(void)
{
if (proc_create("emulate_nvm", 0444, NULL, &emulate_nvm_proc_fops)) {
is_proc_registed = true;
return 0;
}
return -ENOENT;
}
void emulate_nvm_proc_remove(void)
{
if (is_proc_registed)
remove_proc_entry("emulate_nvm", NULL);
}