Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 7, 8 #5

Merged
merged 11 commits into from
Nov 21, 2023
5 changes: 5 additions & 0 deletions linux-5.4.214/arch/arm/include/asm/current.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
static __always_inline struct task_struct *get_current(void)
{
return this_cpu_read_stable(current_task);
}
#define current get_current()
Binary file added pxt4/.ds_monitoring.h.swp
Binary file not shown.
Binary file added pxt4/.rand-write.fio.swp
Binary file not shown.
4 changes: 2 additions & 2 deletions pxt4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pxt4-y := balloc.o bitmap.o block_validity.o dir.o pxt4_jbd3.o extents.o \
extents_status.o file.o fsmap.o fsync.o hash.o ialloc.o \
indirect.o inline.o inode.o ioctl.o mballoc.o migrate.o \
mmp.o move_extent.o namei.o page-io.o readpage.o resize.o \
super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o

super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o \
calclock.o ds_monitoring.o
pxt4-m += acl.o
pxt4-m += xattr_security.o
pxt4-m += verity.o
Expand Down
19 changes: 19 additions & 0 deletions pxt4/calclock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "calclock.h"
unsigned long long calclock(struct timespec *myclock,
unsigned long long *total_time, unsigned long long *total_count)

{
unsigned long long timedelay = 0, temp = 0, temp_n = 0;
if (myclock[1].tv_nsec >= myclock[0].tv_nsec) {
temp = myclock[1].tv_sec - myclock[0].tv_sec;
temp_n = myclock[1].tv_nsec - myclock[0].tv_nsec;
timedelay = BILLION * temp + temp_n;
} else {
temp = myclock[1].tv_sec - myclock[0].tv_sec - 1;
temp_n = BILLION + myclock[1].tv_nsec - myclock[0].tv_nsec;
timedelay = BILLION * temp + temp_n;
}
__sync_fetch_and_add(total_time, timedelay);
__sync_fetch_and_add(total_count, 1);
return timedelay;
}
11 changes: 11 additions & 0 deletions pxt4/calclock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __CALCLOCK_H
#define __CALCLOCK_H

#include <linux/time.h>

#define BILLION 1000000000UL

unsigned long long calclock(struct timespec *myclock,
unsigned long long *total_time, unsigned long long *total_clock);

#endif
68 changes: 68 additions & 0 deletions pxt4/ds_monitoring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "ds_monitoring.h"
#include <linux/slab.h>

static void
insert_ds_monitoring(struct ds_monitoring *dm, unsigned long index, void *elem)
{
char *name;
struct ds_monitoring_elem *new = kmalloc(sizeof(struct ds_monitoring_elem),
GFP_KERNEL);
new->key = index;
new->count = 1;
if (dm->dm_ops->get_name) {
name = dm->dm_ops->get_name(elem);
new->name = kmalloc(strlen(name)+1, GFP_KERNEL);
strcpy(new->name, name);
} else {
new->name = NULL;
}
xa_store(dm->elements, new->key, (void*) new, GFP_KERNEL);
}

void find_ds_monitoring(struct ds_monitoring *dm, void *elem)
{
struct ds_monitoring_elem *cur;
unsigned long xa_index;
if (dm->dm_ops->get_index) {
xa_index = dm->dm_ops->get_index(elem);
// search ds_monitoring_elem at index of xa_index from xarray root
cur = (struct ds_monitoring_elem *) xa_load(dm->elements, xa_index);
if (cur) {
__sync_fetch_and_add(&cur->count, 1);
} else {
insert_ds_monitoring(dm, xa_index, elem);
}
__sync_fetch_and_add(&dm->total_counts, 1);
}
}

void print_ds_monitoring(struct ds_monitoring* dm)
{
unsigned long cur_idx;
void *cur;
char *cur_name;
unsigned long long cur_count;
int percentage;
if (!dm->total_counts)
return;
xa_for_each(dm->elements, cur_idx, cur) {
cur_name = ((struct ds_monitoring_elem *)cur)->name;
cur_count = ((struct ds_monitoring_elem *)cur)->count;
percentage = cur_count * 100 / dm->total_counts;
dm->dm_ops->print_elem(cur_idx, cur_name, cur_count, percentage);
}
}

void delete_ds_monitoring(struct ds_monitoring *dm)
{
unsigned long cur_idx;
void *cur;
char *cur_name;
xa_for_each(dm->elements, cur_idx, cur) {
cur_name = ((struct ds_monitoring_elem *)cur)->name;
kfree(cur_name);
kfree(cur);
}
xa_destroy(dm->elements);
}

55 changes: 55 additions & 0 deletions pxt4/ds_monitoring.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef __DS_MONITORING_H
#define __DS_MONITORING_H

#include <linux/xarray.h>

struct ds_monitoring_operations {
unsigned long (*get_index)(void *elem);
const char * (*get_name)(void *elem);
void (*print_elem)(
unsigned long index,
const char *name,
unsigned long long count,
int percentage
);
};

struct ds_monitoring {
struct xarray *elements;
unsigned long long total_counts;
const struct ds_monitoring_operations *dm_ops;
};

struct ds_monitoring_elem {
unsigned long key;
char *name;
unsigned long long count;
};

#define DEFINE_DS_MONITORING(name, get_idx_fn, get_name_fn, print_fn) \
DEFINE_XARRAY(name##xarray); \
DEFINE_DS_MONITORING_OPS(name, get_idx_fn, get_name_fn, print_fn);\
struct ds_monitoring name = DS_MONITORING_INIT(name##xarray, name##_dm_ops);

#define DEFINE_DS_MONITORING_OPS(name, get_idx_fn, get_name_fn, print_fn) \
static const struct ds_monitoring_operations name##_dm_ops = { \
.get_index = get_idx_fn, \
.get_name = get_name_fn, \
.print_elem = print_fn, \
}

#define DS_MONITORING_INIT(xarray, _dm_ops) \
{ \
.elements = &xarray, \
.total_counts = 0, \
.dm_ops = &_dm_ops, \
}

#define DECLARE_DS_MONITORING(name) \
extern struct ds_monitoring name;

void find_ds_monitoring(struct ds_monitoring *dm, void *elem);
void print_ds_monitoring(struct ds_monitoring* dm);
void delete_ds_monitoring(struct ds_monitoring *dm);

#endif
36 changes: 35 additions & 1 deletion pxt4/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "pxt4_jbd3.h"
#include "xattr.h"
#include "acl.h"
#include "calclock.h"

#ifdef CONFIG_FS_DAX
static ssize_t pxt4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to)
Expand Down Expand Up @@ -217,7 +218,7 @@ pxt4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
#endif

static ssize_t
pxt4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
pxt4_file_write_iter_internal(struct kiocb *iocb, struct iov_iter *from)
{
struct inode *inode = file_inode(iocb->ki_filp);
int o_direct = iocb->ki_flags & IOCB_DIRECT;
Expand Down Expand Up @@ -287,6 +288,39 @@ pxt4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
return ret;
}

#include "ds_monitoring.h"
static unsigned long get_cpu_id(void *elem)
{
return current->cpu;
}

static const char * get_cpu_name(void *elem)
{
return "";
}

static void print_cpu_dm(unsigned long id, const char * name, unsigned long long count, int percentage)
{
printk("cpu %ld called pxt4_file_write_iter() %lld times (%d%%)\n", id, count, percentage);
}


DEFINE_DS_MONITORING(cpu_dm, get_cpu_id, get_cpu_name, print_cpu_dm);
unsigned long long file_write_iter_time, file_write_iter_count;

static ssize_t pxt4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) {
ssize_t ret;
struct timespec myclock[2];

getrawmonotonic(&myclock[0]);
ret = pxt4_file_write_iter_internal(iocb, from);
getrawmonotonic(&myclock[1]);
calclock(myclock, &file_write_iter_time, &file_write_iter_count);
//printk("cpu[%d] called pxt4_file_write_iter()",current->cpu);
find_ds_monitoring(&cpu_dm, current);
return ret;
}

#ifdef CONFIG_FS_DAX
static vm_fault_t pxt4_dax_huge_fault(struct vm_fault *vmf,
enum page_entry_size pe_size)
Expand Down
Binary file added pxt4/local-fio-test-0-verify.state
Binary file not shown.
Binary file added pxt4/local-fio-test-1-verify.state
Binary file not shown.
Binary file added pxt4/local-fio-test-2-verify.state
Binary file not shown.
Binary file added pxt4/local-fio-test-3-verify.state
Binary file not shown.
Binary file added pxt4/local-fio-test-4-verify.state
Binary file not shown.
Binary file added pxt4/local-fio-test-5-verify.state
Binary file not shown.
15 changes: 15 additions & 0 deletions pxt4/rand-write.fio
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; -- start job file --
[global]
name=fio-rand-write
directory=../../mnt/assignment7
filename=fio-rand-write
rw=write
bs=4K
direct=0
numjobs=6
verify=meta

[fio-test]
size=2G
group_reporting
; -- end job file --
8 changes: 8 additions & 0 deletions pxt4/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -6334,6 +6334,10 @@ static int __init pxt4_init_fs(void)
return err;
}

#include "ds_monitoring.h"
DECLARE_DS_MONITORING(cpu_dm);

extern unsigned long long file_write_iter_time, file_write_iter_count;
static void __exit pxt4_exit_fs(void)
{
pxt4_destroy_lazyinit_thread();
Expand All @@ -6348,6 +6352,10 @@ static void __exit pxt4_exit_fs(void)
pxt4_exit_post_read_processing();
pxt4_exit_es();
pxt4_exit_pending();

printk("pxt4_file_write_iter is called %llu times and the time interval is %lluns\n", file_write_iter_count, file_write_iter_time);
print_ds_monitoring(&cpu_dm);
delete_ds_monitoring(&cpu_dm);
}

MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
Expand Down