Migrated.
This commit is contained in:
201
kernel/procfs.c
201
kernel/procfs.c
@@ -24,7 +24,7 @@
|
||||
#include <page.h>
|
||||
#include <mman.h>
|
||||
|
||||
#define DEBUG_PRINT_PROCFS
|
||||
//#define DEBUG_PRINT_PROCFS
|
||||
|
||||
#ifdef DEBUG_PRINT_PROCFS
|
||||
#define dprintf(...) kprintf(__VA_ARGS__)
|
||||
@@ -46,6 +46,13 @@ static void create_proc_procfs_file(int pid, char *fname, int mode, int cpuid);
|
||||
static void delete_proc_procfs_file(int pid, char *fname);
|
||||
static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, int cpuid);
|
||||
|
||||
/**
|
||||
* \brief Create all procfs files for process.
|
||||
*
|
||||
* \param pid pid of the process
|
||||
* \param cpuid cpuid of the process
|
||||
*/
|
||||
|
||||
void create_proc_procfs_files(int pid, int cpuid)
|
||||
{
|
||||
char fname[PROCFS_NAME_MAX];
|
||||
@@ -58,12 +65,27 @@ void create_proc_procfs_files(int pid, int cpuid)
|
||||
dprintf("create procfs files: done\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a procfs file for process.
|
||||
*
|
||||
* \param pid pid of the process
|
||||
* \param fname file name of the procfs file
|
||||
* \param mode file mode
|
||||
* \param cpuid cpuid of the process
|
||||
*/
|
||||
|
||||
static void create_proc_procfs_file(int pid, char *fname, int mode, int cpuid)
|
||||
{
|
||||
dprintf("create procfs file: %s, mode: %o, cpuid: %d\n", fname, mode, cpuid);
|
||||
operate_proc_procfs_file(pid, fname, SCD_MSG_PROCFS_CREATE, mode, cpuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Delete all procfs files for process.
|
||||
*
|
||||
* \param pid pid of the process
|
||||
*/
|
||||
|
||||
void delete_proc_procfs_files(int pid)
|
||||
{
|
||||
char fname[PROCFS_NAME_MAX];
|
||||
@@ -89,6 +111,13 @@ void delete_proc_procfs_files(int pid)
|
||||
dprintf("delete procfs files: done\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Delete a procfs file for process.
|
||||
*
|
||||
* \param pid pid of the process
|
||||
* \param fname file name of the procfs file
|
||||
*/
|
||||
|
||||
static void delete_proc_procfs_file(int pid, char *fname)
|
||||
{
|
||||
dprintf("delete procfs file: %s\n", fname);
|
||||
@@ -96,6 +125,16 @@ static void delete_proc_procfs_file(int pid, char *fname)
|
||||
dprintf("delete procfs file: %s done\n", fname);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create/delete a procfs file for process.
|
||||
*
|
||||
* \param pid pid of the process
|
||||
* \param fname file name of the procfs file
|
||||
* \param msg message (create/delete)
|
||||
* \param mode file mode
|
||||
* \param cpuid cpuid of the process
|
||||
*/
|
||||
|
||||
static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, int cpuid)
|
||||
{
|
||||
struct ihk_ikc_channel_desc *syscall_channel;
|
||||
@@ -132,89 +171,165 @@ static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, in
|
||||
kfree(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The callback function for mckernel procfs files.
|
||||
*
|
||||
* \param rarg returned argument
|
||||
*/
|
||||
|
||||
void process_procfs_request(unsigned long rarg)
|
||||
{
|
||||
unsigned long parg, pbuf;
|
||||
struct process *proc = cpu_local_var(current);
|
||||
struct procfs_read *r;
|
||||
struct ikc_scd_packet packet;
|
||||
int rosnum, ret, pid, tid, ans = -ENOENT, eof = 0;
|
||||
char *buf;
|
||||
int rosnum, ret, pid, tid, ans = -EIO, eof = 0;
|
||||
char *buf, *p;
|
||||
struct ihk_ikc_channel_desc *syscall_channel;
|
||||
|
||||
dprintf("process_procfs_request: invoked.\n");
|
||||
|
||||
syscall_channel = get_cpu_local_var(0)->syscall_channel;
|
||||
|
||||
dprintf("rarg: %x\n", rarg);
|
||||
parg = ihk_mc_map_memory(NULL, rarg, sizeof(struct procfs_read));
|
||||
dprintf("parg: %x\n", parg);
|
||||
r = ihk_mc_map_virtual(parg, sizeof(struct procfs_read),
|
||||
PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||
dprintf("r: %p\n", r);
|
||||
if (r == NULL) {
|
||||
kprintf("ERROR: process_procfs_request: got a null procfs_read structure.\n");
|
||||
packet.err = -EIO;
|
||||
goto dataunavail;
|
||||
}
|
||||
|
||||
dprintf("remote pbuf: %x\n", r->pbuf);
|
||||
pbuf = ihk_mc_map_memory(NULL, r->pbuf, r->count);
|
||||
dprintf("pbuf: %x\n", pbuf);
|
||||
buf = ihk_mc_map_virtual(pbuf, r->count, PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||
dprintf("buf: %p\n", buf);
|
||||
if (buf == NULL) {
|
||||
kprintf("ERROR: process_procfs_request: got a null buffer.\n");
|
||||
packet.err = -EIO;
|
||||
goto bufunavail;
|
||||
}
|
||||
|
||||
dprintf("fname: %s, offset: %lx, count:%d.\n", r->fname, r->offset, r->count);
|
||||
|
||||
/* mcos0/PID/taks/PID/mem
|
||||
*
|
||||
* The offset is treated as the beginning of the virtual address area
|
||||
* of the process. The count is the length of the area.
|
||||
/*
|
||||
* check for "mcos%d/"
|
||||
*/
|
||||
ret = sscanf(r->fname, "mcos%d/%d/task/%d/mem", &rosnum, &pid, &tid);
|
||||
if ((ret == 3) && (pid == tid) && (osnum == rosnum)) {
|
||||
if (cpu_local_var(current)->pid != pid) {
|
||||
/* The target process has gone by migration. */
|
||||
#ifdef FIXME
|
||||
r->newcpu = ...
|
||||
#endif
|
||||
ans = 0;
|
||||
} else {
|
||||
struct vm_range *range;
|
||||
struct process_vm *vm = proc->vm;
|
||||
ans = -EIO; /* default to an I/O error */
|
||||
list_for_each_entry(range, &vm->vm_range_list, list) {
|
||||
dprintf("range: %lx - %lx\n", range->start, range->end);
|
||||
if ((range->start <= r->offset) &&
|
||||
(r->offset < range->end)) {
|
||||
unsigned int len = r->count;
|
||||
if (range->end < r->offset + r->count) {
|
||||
len = range->end - r->offset;
|
||||
}
|
||||
memcpy((void *) buf, (void *)range->start, len);
|
||||
ans = len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = sscanf(r->fname, "mcos%d/", &rosnum);
|
||||
if (ret == 1) {
|
||||
if (osnum != rosnum) {
|
||||
kprintf("ERROR: process_procfs_request osnum mismatch "
|
||||
"(we are %d != requested %d)\n",
|
||||
osnum, rosnum);
|
||||
goto end;
|
||||
}
|
||||
dprintf("matched mcos%d.\n", osnum);
|
||||
} else {
|
||||
goto end;
|
||||
}
|
||||
p = strchr(r->fname, '/') + 1;
|
||||
|
||||
/* Processing of other kinds of procfs files should be located here.
|
||||
/* Processing for pattern "mcos%d/xxx" files should be here.
|
||||
Its template is something like what follows:
|
||||
|
||||
ret = scanf(r->fname, "mcos%d/PATTERN", ...)
|
||||
if ((ret == x) && pattern has matched) {
|
||||
get the data and write it to the buffer;
|
||||
ret = sscanf(p, "PATTERN", ...)
|
||||
if ((ret == xx) && pattern has matched) {
|
||||
get the data (at 'r->offset')
|
||||
and write it to 'buf'
|
||||
up to 'r->count' bytes.
|
||||
ans = written bytes;
|
||||
goto end;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* check for "mcos%d/PID/"
|
||||
*/
|
||||
ret = sscanf(p, "%d/", &pid);
|
||||
if (ret == 1) {
|
||||
if (pid != cpu_local_var(current)->pid) {
|
||||
/* We are not located in the proper cpu for some reason. */
|
||||
void *savelock;
|
||||
unsigned long irqstate;
|
||||
struct process *proc;
|
||||
|
||||
dprintf("mismatched pid. We are %d, but requested pid is %d.\n",
|
||||
pid, cpu_local_var(current)->pid);
|
||||
if ((proc = findthread_and_lock(pid, tid, &savelock, &irqstate))){
|
||||
/* The target process has gone by migration. */
|
||||
r->newcpu = proc->cpu_id;
|
||||
dprintf("expected cpu id is %d.\n", proc->cpu_id);
|
||||
process_unlock(savelock, irqstate);
|
||||
ans = 0;
|
||||
} else {
|
||||
dprintf("We cannot find the proper cpu for requested pid.\n");
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
goto end;
|
||||
}
|
||||
dprintf("matched PID: %d.\n", pid);
|
||||
p = strchr(p, '/') + 1;
|
||||
|
||||
/*
|
||||
* mcos0/PID/taks/PID/mem
|
||||
*
|
||||
* The offset is treated as the beginning of the virtual address area
|
||||
* of the process. The count is the length of the area.
|
||||
*/
|
||||
ret = sscanf(p, "task/%d/mem", &tid);
|
||||
if (ret == 1) {
|
||||
struct vm_range *range;
|
||||
struct process_vm *vm = proc->vm;
|
||||
|
||||
if (pid != tid) {
|
||||
/* We are not multithreaded yet. */
|
||||
goto end;
|
||||
}
|
||||
list_for_each_entry(range, &vm->vm_range_list, list) {
|
||||
dprintf("range: %lx - %lx\n", range->start, range->end);
|
||||
if ((range->start <= r->offset) &&
|
||||
(r->offset < range->end)) {
|
||||
unsigned int len = r->count;
|
||||
if (range->end < r->offset + r->count) {
|
||||
len = range->end - r->offset;
|
||||
}
|
||||
memcpy((void *) buf, (void *)range->start, len);
|
||||
ans = len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
|
||||
/*
|
||||
* Processing for pattern "mcos%d/PID/xxx" files should be here.
|
||||
*/
|
||||
dprintf("could not find a matching entry for %s.\n", p);
|
||||
end:
|
||||
dprintf("read: %d, eof: %d\n", ans, eof);
|
||||
ihk_mc_unmap_virtual(buf, r->count, 0);
|
||||
dprintf("ret: %d, eof: %d\n", ans, eof);
|
||||
r->ret = ans;
|
||||
r->eof = eof;
|
||||
packet.err = 0;
|
||||
bufunavail:
|
||||
ihk_mc_unmap_memory(NULL, pbuf, r->count);
|
||||
ihk_mc_unmap_virtual(r, sizeof(struct procfs_read), 0);
|
||||
dataunavail:
|
||||
ihk_mc_unmap_memory(NULL, parg, sizeof(struct procfs_read));
|
||||
|
||||
packet.msg = SCD_MSG_PROCFS_ANSWER;
|
||||
packet.arg = rarg;
|
||||
|
||||
ihk_mc_unmap_virtual(buf, r->count, 0);
|
||||
ihk_mc_unmap_memory(NULL, pbuf, r->count);
|
||||
|
||||
ihk_mc_unmap_virtual(r, sizeof(struct procfs_read), 0);
|
||||
ihk_mc_unmap_memory(NULL, parg, sizeof(struct procfs_read));
|
||||
|
||||
ret = ihk_ikc_send(syscall_channel, &packet, 0);
|
||||
if (ret < 0) {
|
||||
kprintf("ERROR: sending IKC msg, ret: %d\n", ret);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user