Implemented procfs.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
IHKDIR=$(IHKBASE)/$(TARGETDIR)
|
||||
OBJS = init.o mem.o debug.o mikc.o listeners.o ap.o syscall.o cls.o host.o
|
||||
OBJS += process.o copy.o waitq.o futex.o timer.o plist.o fileobj.o shmobj.o
|
||||
OBJS += zeroobj.o
|
||||
OBJS += zeroobj.o procfs.o
|
||||
DEPSRCS=$(wildcard $(SRC)/*.c)
|
||||
|
||||
CFLAGS += -I$(SRC)/include -mcmodel=kernel -D__KERNEL__
|
||||
|
||||
@@ -416,6 +416,7 @@ static int process_msg_prepare_process(unsigned long rphys)
|
||||
ihk_mc_unmap_virtual(p, npages, 1);
|
||||
ihk_mc_unmap_memory(NULL, phys, sz);
|
||||
flush_tlb();
|
||||
|
||||
return 0;
|
||||
err:
|
||||
ihk_mc_free(pn);
|
||||
@@ -499,6 +500,8 @@ static void syscall_channel_send(struct ihk_ikc_channel_desc *c,
|
||||
extern unsigned long do_kill(int, int, int);
|
||||
extern void settid(struct process *proc, int mode, int newcpuid, int oldcpuid);
|
||||
|
||||
extern void process_procfs_request(unsigned long rarg);
|
||||
|
||||
static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
void *__packet, void *ihk_os)
|
||||
{
|
||||
@@ -541,6 +544,9 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
rc = do_kill((int)packet->pid, (int)(packet->arg >> 32), packet->arg & 0x00000000ffffffffL);
|
||||
kprintf("SCD_MSG_SEND_SIGNAL: %lx, rc=%d\n", packet->arg, rc);
|
||||
return 0;
|
||||
case SCD_MSG_PROCFS_REQUEST:
|
||||
process_procfs_request(packet->arg);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,11 @@
|
||||
#define SCD_MSG_SYSCALL_ONESIDE 0x4
|
||||
#define SCD_MSG_SEND_SIGNAL 0x8
|
||||
|
||||
#define SCD_MSG_PROCFS_CREATE 0x10
|
||||
#define SCD_MSG_PROCFS_DELETE 0x11
|
||||
#define SCD_MSG_PROCFS_REQUEST 0x12
|
||||
#define SCD_MSG_PROCFS_ANSWER 0x13
|
||||
|
||||
#define ARCH_SET_GS 0x1001
|
||||
#define ARCH_SET_FS 0x1002
|
||||
#define ARCH_GET_FS 0x1003
|
||||
@@ -87,6 +92,7 @@ struct user_desc {
|
||||
struct ikc_scd_packet {
|
||||
int msg;
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
int err;
|
||||
unsigned long arg;
|
||||
@@ -231,4 +237,26 @@ struct coretable { /* table entry for a core chunk */
|
||||
unsigned long addr; /* physical addr of the chunk */
|
||||
};
|
||||
|
||||
void create_proc_procfs_files(int pid, int cpuid);
|
||||
void delete_proc_procfs_files(int pid);
|
||||
void create_os_procfs_files(void);
|
||||
void delete_os_procfs_files(void);
|
||||
|
||||
#define PROCFS_NAME_MAX 1000
|
||||
|
||||
struct procfs_read {
|
||||
unsigned long pbuf; /* physical address of the host buffer (request) */
|
||||
unsigned long offset; /* offset to read (request) */
|
||||
int count; /* bytes to read (request) */
|
||||
int eof; /* if eof is detected, 1 otherwise 0. (answer)*/
|
||||
int ret; /* read bytes (answer) */
|
||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||
};
|
||||
|
||||
struct procfs_file {
|
||||
int status; /* status of processing (answer) */
|
||||
int mode; /* file mode (request) */
|
||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#define dkprintf(...)
|
||||
#endif
|
||||
|
||||
int osnum = 0;
|
||||
|
||||
extern struct ihk_kmsg_buf kmsg_buf;
|
||||
|
||||
@@ -133,6 +134,16 @@ void pc_init(void)
|
||||
APT_TYPE_STALL, APT_TYPE_CYCLE }, // not updated for KNC
|
||||
};
|
||||
|
||||
p = find_command_line("osnum=");
|
||||
if (p != NULL) {
|
||||
while (('0' <= *p) && (*p <= '9')) {
|
||||
osnum *= 10;
|
||||
osnum += *p++ - '0';
|
||||
}
|
||||
}
|
||||
kprintf("osnum: %d\n");
|
||||
|
||||
|
||||
if (!(p = find_command_line("perfctr"))) {
|
||||
dkprintf("perfctr not initialized.\n");
|
||||
return;
|
||||
|
||||
@@ -1661,6 +1661,8 @@ void destroy_process(struct process *proc)
|
||||
struct sig_pending *pending;
|
||||
struct sig_pending *next;
|
||||
|
||||
delete_proc_procfs_files(proc->pid);
|
||||
|
||||
if (proc->vm) {
|
||||
cpu_clear(proc->cpu_id, &proc->vm->cpu_set, &proc->vm->cpu_set_lock);
|
||||
}
|
||||
@@ -2034,6 +2036,8 @@ void runq_add_proc(struct process *proc, int cpu_id)
|
||||
__runq_add_proc(proc, cpu_id);
|
||||
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
||||
|
||||
create_proc_procfs_files(proc->pid, cpu_id);
|
||||
|
||||
/* Kick scheduler */
|
||||
if (cpu_id != ihk_mc_get_processor_id())
|
||||
ihk_mc_interrupt_cpu(
|
||||
|
||||
175
kernel/procfs.c
Normal file
175
kernel/procfs.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* \file procfs.c
|
||||
* License details are found in the file LICENSE.
|
||||
* \brief
|
||||
* McKernel procfs
|
||||
* \author Naoki Hamada <nao@axe.bz> \par
|
||||
* Copyright (C) 2014 AXE, Inc.
|
||||
*/
|
||||
/*
|
||||
* HISTORY:
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
#include <kmsg.h>
|
||||
#include <ihk/cpu.h>
|
||||
#include <ihk/mm.h>
|
||||
#include <ihk/debug.h>
|
||||
#include <ihk/ikc.h>
|
||||
#include <ikc/master.h>
|
||||
#include <syscall.h>
|
||||
#include <cls.h>
|
||||
#include <kmalloc.h>
|
||||
#include <process.h>
|
||||
#include <page.h>
|
||||
#include <mman.h>
|
||||
|
||||
#define DEBUG_PRINT_PROCFS
|
||||
|
||||
#ifdef DEBUG_PRINT_PROCFS
|
||||
#define dkprintf kprintf
|
||||
#else
|
||||
#define dkprintf(...)
|
||||
#endif
|
||||
|
||||
extern int snprintf(char * buf, size_t size, const char *fmt, ...);
|
||||
extern int sscanf(const char * buf, const char * fmt, ...);
|
||||
|
||||
extern int osnum;
|
||||
|
||||
void create_proc_procfs_files(int pid, int cpuid);
|
||||
void delete_proc_procfs_files(int pid);
|
||||
void create_os_procfs_files(void);
|
||||
void delete_os_procfs_files(void);
|
||||
|
||||
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);
|
||||
|
||||
void create_proc_procfs_files(int pid, int cpuid)
|
||||
{
|
||||
char fname[PROCFS_NAME_MAX];
|
||||
|
||||
snprintf(fname, PROCFS_NAME_MAX, "/proc/mcos%d/%d/mem", osnum, pid);
|
||||
create_proc_procfs_file(pid, fname, 0400, cpuid);
|
||||
}
|
||||
|
||||
static void create_proc_procfs_file(int pid, char *fname, int mode, int cpuid)
|
||||
{
|
||||
operate_proc_procfs_file(pid, fname, SCD_MSG_PROCFS_CREATE, mode, cpuid);
|
||||
}
|
||||
|
||||
void delete_proc_procfs_files(int pid)
|
||||
{
|
||||
char fname[PROCFS_NAME_MAX];
|
||||
|
||||
snprintf(fname, PROCFS_NAME_MAX, "/proc/mcos%d/%d/mem", osnum, pid);
|
||||
delete_proc_procfs_file(pid, fname);
|
||||
}
|
||||
|
||||
static void delete_proc_procfs_file(int pid, char *fname)
|
||||
{
|
||||
operate_proc_procfs_file(pid, fname, SCD_MSG_PROCFS_DELETE, 0, 0);
|
||||
}
|
||||
|
||||
static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, int cpuid)
|
||||
{
|
||||
struct ihk_ikc_channel_desc *syscall_channel;
|
||||
struct ikc_scd_packet pckt;
|
||||
struct procfs_file *f;
|
||||
int ret;
|
||||
|
||||
syscall_channel = get_cpu_local_var(0)->syscall_channel;
|
||||
|
||||
f = kmalloc(sizeof(struct procfs_file), IHK_MC_AP_NOWAIT);
|
||||
if (!f) {
|
||||
kprintf("ERROR: not enough memory for dealing procfs file %s!",
|
||||
fname);
|
||||
return;
|
||||
}
|
||||
f->status = 0;
|
||||
f->mode = mode;
|
||||
strncpy(f->fname, fname, PROCFS_NAME_MAX);
|
||||
pckt.arg = virt_to_phys(f);
|
||||
pckt.msg = msg;
|
||||
pckt.osnum = osnum;
|
||||
pckt.ref = cpuid;
|
||||
pckt.pid = pid;
|
||||
pckt.err = 0;
|
||||
|
||||
ret = ihk_ikc_send(syscall_channel, &pckt, 0);
|
||||
if (ret < 0) {
|
||||
kprintf("ERROR: sending IKC msg, ret: %d\n", ret);
|
||||
}
|
||||
|
||||
while (f->status != 1) {
|
||||
cpu_pause();
|
||||
}
|
||||
kfree(f);
|
||||
}
|
||||
|
||||
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;
|
||||
struct ihk_ikc_channel_desc *syscall_channel;
|
||||
|
||||
syscall_channel = get_cpu_local_var(0)->syscall_channel;
|
||||
|
||||
parg = ihk_mc_map_memory(NULL, rarg, sizeof(struct procfs_read));
|
||||
r = ihk_mc_map_virtual(parg, sizeof(struct procfs_read),
|
||||
PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||
|
||||
pbuf = ihk_mc_map_memory(NULL, r->pbuf, r->count);
|
||||
buf = ihk_mc_map_virtual(pbuf, r->count, PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||
|
||||
/* mcos0/PID/taks/PID/mem */
|
||||
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) {
|
||||
/* A hit-miss caused by migration */
|
||||
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) {
|
||||
if ((range->start <= r->offset) &&
|
||||
(r->offset <= range->end)) {
|
||||
if (r->offset + r->count <= range->end) {
|
||||
memcpy((void *) buf, (void *) range->start, r->count);
|
||||
ans = r->count;
|
||||
} else {
|
||||
unsigned int remain;
|
||||
remain = range->end - r->offset;
|
||||
memcpy((void *) buf, (void *)range->start, remain);
|
||||
ans = remain;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
goto skip;
|
||||
}
|
||||
|
||||
skip:
|
||||
r->ret = ans;
|
||||
r->eof = eof;
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user