Merge remote-tracking branch 'remotes/origin/ikc2'
Conflicts: executer/kernel/mcctrl/syscall.c It is resolved.
This commit is contained in:
@@ -110,6 +110,7 @@ int __kprintf(const char *format, ...)
|
||||
char buf[KPRINTF_LOCAL_BUF_LEN];
|
||||
|
||||
/* Copy into the local buf */
|
||||
len = sprintf(buf, "[%3d]: ", ihk_mc_get_processor_id());
|
||||
va_start(va, format);
|
||||
len += vsnprintf(buf + len, KPRINTF_LOCAL_BUF_LEN - len - 2, format, va);
|
||||
va_end(va);
|
||||
|
||||
@@ -99,7 +99,7 @@ int devobj_create(int fd, size_t len, off_t off, struct memobj **objp, int *maxp
|
||||
}
|
||||
memset(obj, 0, sizeof(*obj));
|
||||
|
||||
obj->pfn_table = allocate_pages(pfn_npages, IHK_MC_AP_NOWAIT);
|
||||
obj->pfn_table = ihk_mc_alloc_pages(pfn_npages, IHK_MC_AP_NOWAIT);
|
||||
if (!obj->pfn_table) {
|
||||
error = -ENOMEM;
|
||||
kprintf("%s: error: fd: %d, len: %lu, off: %lu allocating PFN failed.\n",
|
||||
@@ -141,7 +141,7 @@ int devobj_create(int fd, size_t len, off_t off, struct memobj **objp, int *maxp
|
||||
out:
|
||||
if (obj) {
|
||||
if (obj->pfn_table) {
|
||||
free_pages(obj->pfn_table, pfn_npages);
|
||||
ihk_mc_free_pages(obj->pfn_table, pfn_npages);
|
||||
}
|
||||
kfree(obj);
|
||||
}
|
||||
@@ -166,6 +166,8 @@ static void devobj_release(struct memobj *memobj)
|
||||
struct devobj *obj = to_devobj(memobj);
|
||||
struct devobj *free_obj = NULL;
|
||||
uintptr_t handle;
|
||||
const size_t pfn_npages =
|
||||
(obj->npages / (PAGE_SIZE / sizeof(uintptr_t))) + 1;
|
||||
|
||||
dkprintf("devobj_release(%p %lx)\n", obj, obj->handle);
|
||||
|
||||
@@ -194,7 +196,7 @@ static void devobj_release(struct memobj *memobj)
|
||||
}
|
||||
|
||||
if (obj->pfn_table) {
|
||||
free_pages(obj->pfn_table, 1);
|
||||
ihk_mc_free_pages(obj->pfn_table, pfn_npages);
|
||||
}
|
||||
kfree(free_obj);
|
||||
}
|
||||
|
||||
@@ -376,10 +376,16 @@ static int process_msg_prepare_process(unsigned long rphys)
|
||||
}
|
||||
|
||||
n = p->num_sections;
|
||||
if (n > 16) {
|
||||
kprintf("%s: ERROR: more ELF sections than 16??\n",
|
||||
__FUNCTION__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
dkprintf("# of sections: %d\n", n);
|
||||
|
||||
if((pn = ihk_mc_allocate(sizeof(struct program_load_desc)
|
||||
+ sizeof(struct program_image_section) * n, IHK_MC_AP_NOWAIT)) == NULL){
|
||||
if((pn = kmalloc(sizeof(struct program_load_desc)
|
||||
+ sizeof(struct program_image_section) * n,
|
||||
IHK_MC_AP_NOWAIT)) == NULL){
|
||||
ihk_mc_unmap_virtual(p, npages, 0);
|
||||
ihk_mc_unmap_memory(NULL, phys, sz);
|
||||
return -ENOMEM;
|
||||
@@ -388,7 +394,7 @@ static int process_msg_prepare_process(unsigned long rphys)
|
||||
+ sizeof(struct program_image_section) * n);
|
||||
|
||||
if((thread = create_thread(p->entry)) == NULL){
|
||||
ihk_mc_free(pn);
|
||||
kfree(pn);
|
||||
ihk_mc_unmap_virtual(p, npages, 1);
|
||||
ihk_mc_unmap_memory(NULL, phys, sz);
|
||||
return -ENOMEM;
|
||||
@@ -438,7 +444,7 @@ static int process_msg_prepare_process(unsigned long rphys)
|
||||
dkprintf("new process : %p [%d] / table : %p\n", proc, proc->pid,
|
||||
vm->address_space->page_table);
|
||||
|
||||
ihk_mc_free(pn);
|
||||
kfree(pn);
|
||||
|
||||
ihk_mc_unmap_virtual(p, npages, 1);
|
||||
ihk_mc_unmap_memory(NULL, phys, sz);
|
||||
@@ -446,7 +452,7 @@ static int process_msg_prepare_process(unsigned long rphys)
|
||||
|
||||
return 0;
|
||||
err:
|
||||
ihk_mc_free(pn);
|
||||
kfree(pn);
|
||||
ihk_mc_unmap_virtual(p, npages, 1);
|
||||
ihk_mc_unmap_memory(NULL, phys, sz);
|
||||
destroy_thread(thread);
|
||||
@@ -455,7 +461,7 @@ err:
|
||||
|
||||
static void process_msg_init(struct ikc_scd_init_param *pcp, struct syscall_params *lparam)
|
||||
{
|
||||
lparam->response_va = allocate_pages(RESPONSE_PAGE_COUNT, 0);
|
||||
lparam->response_va = ihk_mc_alloc_pages(RESPONSE_PAGE_COUNT, 0);
|
||||
lparam->response_pa = virt_to_phys(lparam->response_va);
|
||||
|
||||
pcp->request_page = 0;
|
||||
@@ -524,12 +530,7 @@ static void syscall_channel_send(struct ihk_ikc_channel_desc *c,
|
||||
}
|
||||
|
||||
extern unsigned long do_kill(struct thread *, int, int, int, struct siginfo *, int ptracecont);
|
||||
extern void settid(struct thread *proc, int mode, int newcpuid, int oldcpuid);
|
||||
|
||||
extern void process_procfs_request(unsigned long rarg);
|
||||
extern int memcheckall();
|
||||
extern int freecheck(int runcount);
|
||||
extern int runcount;
|
||||
extern void terminate_host(int pid);
|
||||
extern void debug_log(long);
|
||||
|
||||
@@ -564,6 +565,7 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
struct ikc_scd_packet *packet = __packet;
|
||||
struct ikc_scd_packet pckt;
|
||||
int rc;
|
||||
struct mcs_rwlock_node_irqsave lock;
|
||||
struct thread *thread;
|
||||
struct process *proc;
|
||||
struct mcctrl_signal {
|
||||
@@ -575,22 +577,17 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
} *sp, info;
|
||||
unsigned long pp;
|
||||
int cpuid;
|
||||
int ret = 0;
|
||||
|
||||
switch (packet->msg) {
|
||||
case SCD_MSG_INIT_CHANNEL_ACKED:
|
||||
dkprintf("SCD_MSG_INIT_CHANNEL_ACKED\n");
|
||||
process_msg_init_acked(c, packet->arg);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_PREPARE_PROCESS:
|
||||
|
||||
if (find_command_line("memdebug")) {
|
||||
memcheckall();
|
||||
if (runcount)
|
||||
freecheck(runcount);
|
||||
runcount++;
|
||||
}
|
||||
|
||||
if((rc = process_msg_prepare_process(packet->arg)) == 0){
|
||||
pckt.msg = SCD_MSG_PREPARE_PROCESS_ACKED;
|
||||
pckt.err = 0;
|
||||
@@ -603,19 +600,21 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
pckt.arg = packet->arg;
|
||||
syscall_channel_send(c, &pckt);
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_SCHEDULE_PROCESS:
|
||||
cpuid = obtain_clone_cpuid();
|
||||
if(cpuid == -1){
|
||||
kprintf("No CPU available\n");
|
||||
return -1;
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
dkprintf("SCD_MSG_SCHEDULE_PROCESS: %lx\n", packet->arg);
|
||||
thread = (struct thread *)packet->arg;
|
||||
proc = thread->proc;
|
||||
|
||||
settid(thread, 0, cpuid, -1);
|
||||
settid(thread, 0, cpuid, -1, 0, NULL);
|
||||
proc->status = PS_RUNNING;
|
||||
thread->status = PS_RUNNING;
|
||||
chain_thread(thread);
|
||||
@@ -623,7 +622,29 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
runq_add_thread(thread, cpuid);
|
||||
|
||||
//cpu_local_var(next) = (struct thread *)packet->arg;
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Used for syscall offload reply message to explicitly schedule in
|
||||
* the waiting thread
|
||||
*/
|
||||
case SCD_MSG_WAKE_UP_SYSCALL_THREAD:
|
||||
thread = find_thread(0, packet->ttid, &lock);
|
||||
if (!thread) {
|
||||
kprintf("%s: WARNING: no thread for SCD reply? TID: %d\n",
|
||||
__FUNCTION__, packet->ttid);
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
thread_unlock(thread, &lock);
|
||||
|
||||
dkprintf("%s: SCD_MSG_WAKE_UP_SYSCALL_THREAD: waking up tid %d\n",
|
||||
__FUNCTION__, packet->ttid);
|
||||
waitq_wakeup(&thread->scd_wq);
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_SEND_SIGNAL:
|
||||
pp = ihk_mc_map_memory(NULL, packet->arg, sizeof(struct mcctrl_signal));
|
||||
sp = (struct mcctrl_signal *)ihk_mc_map_virtual(pp, 1, PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||
@@ -638,18 +659,25 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
|
||||
rc = do_kill(NULL, info.pid, info.tid, info.sig, &info.info, 0);
|
||||
kprintf("SCD_MSG_SEND_SIGNAL: do_kill(pid=%d, tid=%d, sig=%d)=%d\n", info.pid, info.tid, info.sig, rc);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_PROCFS_REQUEST:
|
||||
process_procfs_request(packet->arg);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_CLEANUP_PROCESS:
|
||||
dkprintf("SCD_MSG_CLEANUP_PROCESS pid=%d\n", packet->pid);
|
||||
terminate_host(packet->pid);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_DEBUG_LOG:
|
||||
dkprintf("SCD_MSG_DEBUG_LOG code=%lx\n", packet->arg);
|
||||
debug_log(packet->arg);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_SYSFS_REQ_SHOW:
|
||||
case SCD_MSG_SYSFS_REQ_STORE:
|
||||
@@ -657,7 +685,8 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
sysfss_packet_handler(c, packet->msg, packet->err,
|
||||
packet->sysfs_arg1, packet->sysfs_arg2,
|
||||
packet->sysfs_arg3);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case SCD_MSG_GET_CPU_MAPPING:
|
||||
req_get_cpu_mapping(packet->arg);
|
||||
@@ -665,17 +694,21 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
pckt.msg = SCD_MSG_REPLY_GET_CPU_MAPPING;
|
||||
pckt.arg = packet->arg;
|
||||
syscall_channel_send(c, &pckt);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
kprintf("syscall_pakcet_handler:unknown message "
|
||||
"(%d.%d.%d.%d.%d.%#lx)\n",
|
||||
packet->msg, packet->ref, packet->osnum,
|
||||
packet->pid, packet->err, packet->arg);
|
||||
return 0;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
ihk_ikc_release_packet((struct ihk_ikc_free_packet *)packet, c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void init_host_syscall_channel(void)
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
* CPU Local Storage (cls)
|
||||
*/
|
||||
|
||||
struct malloc_header {
|
||||
unsigned int check;
|
||||
struct kmalloc_header {
|
||||
unsigned int front_magic;
|
||||
unsigned int cpu_id;
|
||||
struct malloc_header *next;
|
||||
unsigned long size;
|
||||
struct list_head list;
|
||||
int size; /* The size of this chunk without the header */
|
||||
unsigned int end_magic;
|
||||
/* 32 bytes */
|
||||
};
|
||||
|
||||
#include <ihk/lock.h>
|
||||
@@ -38,8 +40,9 @@ extern ihk_spinlock_t cpu_status_lock;
|
||||
|
||||
struct cpu_local_var {
|
||||
/* malloc */
|
||||
struct malloc_header free_list;
|
||||
struct malloc_header *remote_free_list;
|
||||
struct list_head free_list;
|
||||
struct list_head remote_free_list;
|
||||
ihk_spinlock_t remote_free_list_lock;
|
||||
|
||||
struct thread idle;
|
||||
struct process idle_proc;
|
||||
@@ -73,6 +76,7 @@ struct cpu_local_var {
|
||||
int in_interrupt;
|
||||
int no_preempt;
|
||||
int timer_enabled;
|
||||
int kmalloc_initialized;
|
||||
} __attribute__((aligned(64)));
|
||||
|
||||
|
||||
|
||||
@@ -32,11 +32,10 @@ void *_kmalloc(int size, enum ihk_mc_ap_flag flag, char *file, int line);
|
||||
void _kfree(void *ptr, char *file, int line);
|
||||
void *__kmalloc(int size, enum ihk_mc_ap_flag flag);
|
||||
void __kfree(void *ptr);
|
||||
void *___kmalloc(int size, enum ihk_mc_ap_flag flag);
|
||||
void ___kfree(void *ptr);
|
||||
|
||||
int _memcheck(void *ptr, char *msg, char *file, int line, int free);
|
||||
int memcheckall();
|
||||
int freecheck(int runcount);
|
||||
void kmalloc_consolidate_free_list(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
#endif
|
||||
|
||||
#define USER_STACK_NR_PAGES 8192
|
||||
#define KERNEL_STACK_NR_PAGES 25
|
||||
#define KERNEL_STACK_NR_PAGES 32
|
||||
|
||||
#define NOPHYS ((uintptr_t)-1)
|
||||
|
||||
@@ -349,6 +349,11 @@ struct sig_pending {
|
||||
|
||||
typedef void pgio_func_t(void *arg);
|
||||
|
||||
struct mcexec_tid {
|
||||
int tid;
|
||||
struct thread *thread;
|
||||
};
|
||||
|
||||
/* Represents a node in the process fork tree, it may exist even after the
|
||||
* corresponding process exited due to references from the parent and/or
|
||||
* children and is used for implementing wait/waitpid without having a
|
||||
@@ -363,6 +368,9 @@ struct process {
|
||||
// threads and children
|
||||
struct list_head threads_list;
|
||||
mcs_rwlock_lock_t threads_lock; // lock for threads_list
|
||||
/* TID set of proxy process */
|
||||
struct mcexec_tid *tids;
|
||||
int nr_tids;
|
||||
|
||||
/* The ptracing process behave as the parent of the ptraced process
|
||||
after using PTRACE_ATTACH except getppid. So we save it here. */
|
||||
@@ -559,6 +567,9 @@ struct thread {
|
||||
struct itimerval itimer_prof;
|
||||
struct timespec itimer_virtual_value;
|
||||
struct timespec itimer_prof_value;
|
||||
|
||||
/* Syscall offload wait queue head */
|
||||
struct waitq scd_wq;
|
||||
};
|
||||
|
||||
struct process_vm {
|
||||
@@ -679,5 +690,7 @@ void chain_thread(struct thread *);
|
||||
void proc_init();
|
||||
void set_timer();
|
||||
struct sig_pending *hassigpending(struct thread *thread);
|
||||
void settid(struct thread *thread, int mode, int newcpuid, int oldcpuid,
|
||||
int nr_tids, int *tids);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define SCD_MSG_PREPARE_PROCESS_ACKED 0x2
|
||||
#define SCD_MSG_PREPARE_PROCESS_NACKED 0x7
|
||||
#define SCD_MSG_SCHEDULE_PROCESS 0x3
|
||||
#define SCD_MSG_WAKE_UP_SYSCALL_THREAD 0x14
|
||||
|
||||
#define SCD_MSG_INIT_CHANNEL 0x5
|
||||
#define SCD_MSG_INIT_CHANNEL_ACKED 0x6
|
||||
@@ -117,28 +118,6 @@ struct user_desc {
|
||||
unsigned int lm:1;
|
||||
};
|
||||
|
||||
struct ikc_scd_packet {
|
||||
int msg;
|
||||
int err;
|
||||
union {
|
||||
/* for traditional SCD_MSG_* */
|
||||
struct {
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
int padding;
|
||||
unsigned long arg;
|
||||
};
|
||||
|
||||
/* for SCD_MSG_SYSFS_* */
|
||||
struct {
|
||||
long sysfs_arg1;
|
||||
long sysfs_arg2;
|
||||
long sysfs_arg3;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct program_image_section {
|
||||
unsigned long vaddr;
|
||||
unsigned long len;
|
||||
@@ -210,13 +189,58 @@ struct ikc_scd_init_param {
|
||||
};
|
||||
|
||||
struct syscall_request {
|
||||
/* TID of requesting thread */
|
||||
int rtid;
|
||||
/*
|
||||
* TID of target thread. Remote page fault response needs to designate the
|
||||
* thread that must serve the request, 0 indicates any thread from the pool
|
||||
*/
|
||||
int ttid;
|
||||
unsigned long valid;
|
||||
unsigned long number;
|
||||
unsigned long args[6];
|
||||
};
|
||||
|
||||
struct ikc_scd_packet {
|
||||
int msg;
|
||||
int err;
|
||||
union {
|
||||
/* for traditional SCD_MSG_* */
|
||||
struct {
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
unsigned long arg;
|
||||
struct syscall_request req;
|
||||
unsigned long resp_pa;
|
||||
};
|
||||
|
||||
/* for SCD_MSG_SYSFS_* */
|
||||
struct {
|
||||
long sysfs_arg1;
|
||||
long sysfs_arg2;
|
||||
long sysfs_arg3;
|
||||
};
|
||||
|
||||
/* SCD_MSG_SCHEDULE_THREAD */
|
||||
struct {
|
||||
int ttid;
|
||||
};
|
||||
};
|
||||
char padding[12];
|
||||
};
|
||||
|
||||
#define IHK_SCD_REQ_THREAD_SPINNING 0
|
||||
#define IHK_SCD_REQ_THREAD_TO_BE_WOKEN 1
|
||||
#define IHK_SCD_REQ_THREAD_DESCHEDULED 2
|
||||
|
||||
struct syscall_response {
|
||||
/* TID of the thread that requested the service */
|
||||
int ttid;
|
||||
/* TID of the mcexec thread that is serving the request */
|
||||
int stid;
|
||||
unsigned long status;
|
||||
unsigned long req_thread_status;
|
||||
long ret;
|
||||
unsigned long fault_address;
|
||||
unsigned long fault_reason;
|
||||
|
||||
@@ -371,7 +371,7 @@ int main(void)
|
||||
}
|
||||
kmsg_init(mode);
|
||||
|
||||
kputs("MCK started.\n");
|
||||
kputs("IHK/McKernel started.\n");
|
||||
|
||||
arch_init();
|
||||
|
||||
@@ -393,7 +393,7 @@ int main(void)
|
||||
|
||||
futex_init();
|
||||
|
||||
kputs("MCK/IHK booted.\n");
|
||||
kputs("IHK/McKernel booted.\n");
|
||||
|
||||
#ifdef DCFA_KMOD
|
||||
mc_cmd_client_init();
|
||||
|
||||
769
kernel/mem.c
769
kernel/mem.c
@@ -156,13 +156,17 @@ void sbox_write(int offset, unsigned int value);
|
||||
|
||||
static void query_free_mem_interrupt_handler(void *priv)
|
||||
{
|
||||
#ifdef ATTACHED_MIC
|
||||
dkprintf("query free mem handler!\n");
|
||||
|
||||
int pages = ihk_pagealloc_query_free(pa_allocator);
|
||||
|
||||
dkprintf("free pages: %d\n", pages);
|
||||
kprintf("McKernel free pages: %d\n", pages);
|
||||
|
||||
if (find_command_line("memdebug")) {
|
||||
extern void kmalloc_memcheck(void);
|
||||
|
||||
kmalloc_memcheck();
|
||||
}
|
||||
|
||||
#ifdef ATTACHED_MIC
|
||||
sbox_write(SBOX_SCRATCH0, pages);
|
||||
sbox_write(SBOX_SCRATCH1, 1);
|
||||
#endif
|
||||
@@ -265,6 +269,13 @@ void remote_flush_tlb_cpumask(struct process_vm *vm,
|
||||
unsigned long tsc;
|
||||
tsc = rdtsc() + 12884901888; /* 1.2GHz =>10 sec */
|
||||
#endif
|
||||
if (flush_entry->addr) {
|
||||
flush_tlb_single(flush_entry->addr & PAGE_MASK);
|
||||
}
|
||||
/* Zero address denotes full TLB flush */
|
||||
else {
|
||||
flush_tlb();
|
||||
}
|
||||
|
||||
/* Wait for all cores */
|
||||
while (ihk_atomic_read(&flush_entry->pending) != 0) {
|
||||
@@ -335,10 +346,9 @@ static void page_fault_handler(void *fault_addr, uint64_t reason, void *regs)
|
||||
// no return
|
||||
}
|
||||
|
||||
kprintf("[%d]page_fault_handler(%p,%lx,%p):"
|
||||
"fault vm failed. %d, TID: %d\n",
|
||||
ihk_mc_get_processor_id(), fault_addr,
|
||||
reason, regs, error, thread->tid);
|
||||
kprintf("%s fault VM failed for TID: %d, addr: 0x%lx, "
|
||||
"reason: %d, error: %d\n", __FUNCTION__,
|
||||
thread->tid, fault_addr, reason, error);
|
||||
unhandled_page_fault(thread, fault_addr, regs);
|
||||
preempt_enable();
|
||||
memset(&info, '\0', sizeof info);
|
||||
@@ -425,8 +435,9 @@ static void page_allocator_init(void)
|
||||
|
||||
ihk_mc_reserve_arch_pages(pa_start, pa_end, reserve_pages);
|
||||
|
||||
kprintf("Available pages: %ld pages\n",
|
||||
ihk_pagealloc_count(pa_allocator));
|
||||
kprintf("Available memory: %ld bytes in %ld pages\n",
|
||||
(ihk_pagealloc_count(pa_allocator) * PAGE_SIZE),
|
||||
ihk_pagealloc_count(pa_allocator));
|
||||
|
||||
/* Notify the ihk to use my page allocator */
|
||||
ihk_mc_set_page_allocator(&allocator);
|
||||
@@ -507,6 +518,9 @@ static void page_init(void)
|
||||
|
||||
static char *memdebug = NULL;
|
||||
|
||||
static void *___kmalloc(int size, enum ihk_mc_ap_flag flag);
|
||||
static void ___kfree(void *ptr);
|
||||
|
||||
void register_kmalloc(void)
|
||||
{
|
||||
if(memdebug){
|
||||
@@ -636,60 +650,100 @@ void mem_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
struct location {
|
||||
struct location *next;
|
||||
int line;
|
||||
int cnt;
|
||||
char file[0];
|
||||
};
|
||||
#define KMALLOC_TRACK_HASH_SHIFT (8)
|
||||
#define KMALLOC_TRACK_HASH_SIZE (1 << KMALLOC_TRACK_HASH_SHIFT)
|
||||
#define KMALLOC_TRACK_HASH_MASK (KMALLOC_TRACK_HASH_SIZE - 1)
|
||||
|
||||
struct alloc {
|
||||
struct alloc *next;
|
||||
struct malloc_header *p;
|
||||
struct location *loc;
|
||||
int size;
|
||||
struct list_head kmalloc_track_hash[KMALLOC_TRACK_HASH_SIZE];
|
||||
ihk_spinlock_t kmalloc_track_hash_locks[KMALLOC_TRACK_HASH_SIZE];
|
||||
|
||||
struct list_head kmalloc_addr_hash[KMALLOC_TRACK_HASH_SIZE];
|
||||
ihk_spinlock_t kmalloc_addr_hash_locks[KMALLOC_TRACK_HASH_SIZE];
|
||||
|
||||
int kmalloc_track_initialized = 0;
|
||||
int kmalloc_runcount = 0;
|
||||
|
||||
struct kmalloc_track_addr_entry {
|
||||
void *addr;
|
||||
int runcount;
|
||||
struct list_head list; /* track_entry's list */
|
||||
struct kmalloc_track_entry *entry;
|
||||
struct list_head hash; /* address hash */
|
||||
};
|
||||
|
||||
#define HASHNUM 129
|
||||
struct kmalloc_track_entry {
|
||||
char *file;
|
||||
int line;
|
||||
int size;
|
||||
ihk_atomic_t alloc_count;
|
||||
struct list_head hash;
|
||||
struct list_head addr_list;
|
||||
ihk_spinlock_t addr_list_lock;
|
||||
};
|
||||
|
||||
static struct alloc *allochash[HASHNUM];
|
||||
static struct location *lochash[HASHNUM];
|
||||
static ihk_spinlock_t alloclock;
|
||||
int runcount;
|
||||
static unsigned char *page;
|
||||
static int space;
|
||||
|
||||
static void *dalloc(unsigned long size)
|
||||
void kmalloc_init(void)
|
||||
{
|
||||
void *r;
|
||||
static int pos = 0;
|
||||
unsigned long irqstate;
|
||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||
|
||||
irqstate = ihk_mc_spinlock_lock(&alloclock);
|
||||
size = (size + 7) & 0xfffffffffffffff8L;
|
||||
if (pos + size > space) {
|
||||
page = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
space = 4096;
|
||||
pos = 0;
|
||||
register_kmalloc();
|
||||
|
||||
INIT_LIST_HEAD(&v->free_list);
|
||||
INIT_LIST_HEAD(&v->remote_free_list);
|
||||
ihk_mc_spinlock_init(&v->remote_free_list_lock);
|
||||
|
||||
v->kmalloc_initialized = 1;
|
||||
|
||||
if (!kmalloc_track_initialized) {
|
||||
int i;
|
||||
|
||||
memdebug = find_command_line("memdebug");
|
||||
|
||||
kmalloc_track_initialized = 1;
|
||||
for (i = 0; i < KMALLOC_TRACK_HASH_SIZE; ++i) {
|
||||
ihk_mc_spinlock_init(&kmalloc_track_hash_locks[i]);
|
||||
INIT_LIST_HEAD(&kmalloc_track_hash[i]);
|
||||
ihk_mc_spinlock_init(&kmalloc_addr_hash_locks[i]);
|
||||
INIT_LIST_HEAD(&kmalloc_addr_hash[i]);
|
||||
}
|
||||
}
|
||||
r = page + pos;
|
||||
pos += size;
|
||||
ihk_mc_spinlock_unlock(&alloclock, irqstate);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* NOTE: Hash lock must be held */
|
||||
struct kmalloc_track_entry *__kmalloc_track_find_entry(
|
||||
int size, char *file, int line)
|
||||
{
|
||||
struct kmalloc_track_entry *entry_iter, *entry = NULL;
|
||||
int hash = (strlen(file) + line + size) & KMALLOC_TRACK_HASH_MASK;
|
||||
|
||||
list_for_each_entry(entry_iter, &kmalloc_track_hash[hash], hash) {
|
||||
if (!strcmp(entry_iter->file, file) &&
|
||||
entry_iter->size == size &&
|
||||
entry_iter->line == line) {
|
||||
entry = entry_iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
dkprintf("%s found entry %s:%d size: %d\n", __FUNCTION__,
|
||||
file, line, size);
|
||||
}
|
||||
else {
|
||||
dkprintf("%s couldn't find entry %s:%d size: %d\n", __FUNCTION__,
|
||||
file, line, size);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* Top level routines called from macro */
|
||||
void *_kmalloc(int size, enum ihk_mc_ap_flag flag, char *file, int line)
|
||||
{
|
||||
char *r = ___kmalloc(size, flag);
|
||||
struct malloc_header *h;
|
||||
unsigned long hash;
|
||||
char *t;
|
||||
struct location *lp;
|
||||
struct alloc *ap;
|
||||
unsigned long alcsize;
|
||||
unsigned long chksize;
|
||||
unsigned long irqflags;
|
||||
struct kmalloc_track_entry *entry;
|
||||
struct kmalloc_track_addr_entry *addr_entry;
|
||||
int hash, addr_hash;
|
||||
void *r = ___kmalloc(size, flag);
|
||||
|
||||
if (!memdebug)
|
||||
return r;
|
||||
@@ -697,177 +751,177 @@ void *_kmalloc(int size, enum ihk_mc_ap_flag flag, char *file, int line)
|
||||
if (!r)
|
||||
return r;
|
||||
|
||||
h = ((struct malloc_header *)r) - 1;
|
||||
alcsize = h->size * sizeof(struct malloc_header);
|
||||
chksize = alcsize - size;
|
||||
memset(r + size, '\x5a', chksize);
|
||||
hash = (strlen(file) + line + size) & KMALLOC_TRACK_HASH_MASK;
|
||||
irqflags = ihk_mc_spinlock_lock(&kmalloc_track_hash_locks[hash]);
|
||||
|
||||
for (hash = 0, t = file; *t; t++) {
|
||||
hash <<= 1;
|
||||
hash += *t;
|
||||
entry = __kmalloc_track_find_entry(size, file, line);
|
||||
|
||||
if (!entry) {
|
||||
entry = ___kmalloc(sizeof(*entry), IHK_MC_AP_NOWAIT);
|
||||
if (!entry) {
|
||||
kprintf("%s: ERROR: allocating tracking entry\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
entry->line = line;
|
||||
entry->size = size;
|
||||
ihk_atomic_set(&entry->alloc_count, 0);
|
||||
ihk_mc_spinlock_init(&entry->addr_list_lock);
|
||||
INIT_LIST_HEAD(&entry->addr_list);
|
||||
|
||||
entry->file = ___kmalloc(strlen(file) + 1, IHK_MC_AP_NOWAIT);
|
||||
if (!entry->file) {
|
||||
kprintf("%s: ERROR: allocating file string\n");
|
||||
___kfree(entry);
|
||||
ihk_mc_spinlock_unlock(&kmalloc_track_hash_locks[hash], irqflags);
|
||||
goto out;
|
||||
}
|
||||
|
||||
strcpy(entry->file, file);
|
||||
entry->file[strlen(file)] = 0;
|
||||
list_add(&entry->hash, &kmalloc_track_hash[hash]);
|
||||
dkprintf("%s entry %s:%d size: %d added\n", __FUNCTION__,
|
||||
file, line, size);
|
||||
}
|
||||
hash += line;
|
||||
hash %= HASHNUM;
|
||||
for (lp = lochash[hash]; lp; lp = lp->next)
|
||||
if (lp->line == line &&
|
||||
!strcmp(lp->file, file))
|
||||
break;
|
||||
if (!lp) {
|
||||
lp = dalloc(sizeof(struct location) + strlen(file) + 1);
|
||||
memset(lp, '\0', sizeof(struct location));
|
||||
lp->line = line;
|
||||
strcpy(lp->file, file);
|
||||
do {
|
||||
lp->next = lochash[hash];
|
||||
} while (!compare_and_swap(lochash + hash, (unsigned long)lp->next, (unsigned long)lp));
|
||||
ihk_mc_spinlock_unlock(&kmalloc_track_hash_locks[hash], irqflags);
|
||||
|
||||
ihk_atomic_inc(&entry->alloc_count);
|
||||
|
||||
/* Add new addr entry for this allocation entry */
|
||||
addr_entry = ___kmalloc(sizeof(*addr_entry), IHK_MC_AP_NOWAIT);
|
||||
if (!addr_entry) {
|
||||
kprintf("%s: ERROR: allocating addr entry\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
hash = (unsigned long)h % HASHNUM;
|
||||
do {
|
||||
for (ap = allochash[hash]; ap; ap = ap->next)
|
||||
if (!ap->p)
|
||||
break;
|
||||
} while (ap && !compare_and_swap(&ap->p, 0UL, (unsigned long)h));
|
||||
if (!ap) {
|
||||
ap = dalloc(sizeof(struct alloc));
|
||||
memset(ap, '\0', sizeof(struct alloc));
|
||||
ap->p = h;
|
||||
do {
|
||||
ap->next = allochash[hash];
|
||||
} while (!compare_and_swap(allochash + hash, (unsigned long)ap->next, (unsigned long)ap));
|
||||
}
|
||||
addr_entry->addr = r;
|
||||
addr_entry->runcount = kmalloc_runcount;
|
||||
addr_entry->entry = entry;
|
||||
|
||||
ap->loc = lp;
|
||||
ap->size = size;
|
||||
ap->runcount = runcount;
|
||||
irqflags = ihk_mc_spinlock_lock(&entry->addr_list_lock);
|
||||
list_add(&addr_entry->list, &entry->addr_list);
|
||||
ihk_mc_spinlock_unlock(&entry->addr_list_lock, irqflags);
|
||||
|
||||
return r;
|
||||
}
|
||||
/* Add addr entry to address hash */
|
||||
addr_hash = ((unsigned long)r >> 5) & KMALLOC_TRACK_HASH_MASK;
|
||||
irqflags = ihk_mc_spinlock_lock(&kmalloc_addr_hash_locks[addr_hash]);
|
||||
list_add(&addr_entry->hash, &kmalloc_addr_hash[addr_hash]);
|
||||
ihk_mc_spinlock_unlock(&kmalloc_addr_hash_locks[addr_hash], irqflags);
|
||||
|
||||
int _memcheck(void *ptr, char *msg, char *file, int line, int flags)
|
||||
{
|
||||
struct malloc_header *h = ((struct malloc_header *)ptr) - 1;
|
||||
struct malloc_header *next;
|
||||
unsigned long hash = (unsigned long)h % HASHNUM;
|
||||
struct alloc *ap;
|
||||
static unsigned long check = 0x5a5a5a5a5a5a5a5aUL;
|
||||
unsigned long alcsize;
|
||||
unsigned long chksize;
|
||||
|
||||
|
||||
if (h->check != 0x5a5a5a5a) {
|
||||
int i;
|
||||
unsigned long max = 0;
|
||||
unsigned long cur = (unsigned long)h;
|
||||
struct alloc *maxap = NULL;
|
||||
|
||||
for (i = 0; i < HASHNUM; i++)
|
||||
for (ap = allochash[i]; ap; ap = ap->next)
|
||||
if ((unsigned long)ap->p < cur &&
|
||||
(unsigned long)ap->p > max) {
|
||||
max = (unsigned long)ap->p;
|
||||
maxap = ap;
|
||||
}
|
||||
|
||||
kprintf("%s: detect buffer overrun, alc=%s:%d size=%ld h=%p, s=%ld\n", msg, maxap->loc->file, maxap->loc->line, maxap->size, maxap->p, maxap->p->size);
|
||||
kprintf("broken header: h=%p next=%p size=%ld cpu_id=%d\n", h, h->next, h->size, h->cpu_id);
|
||||
}
|
||||
|
||||
for (ap = allochash[hash]; ap; ap = ap->next)
|
||||
if (ap->p == h)
|
||||
break;
|
||||
if (!ap) {
|
||||
if(file)
|
||||
kprintf("%s: address not found, %s:%d p=%p\n", msg, file, line, ptr);
|
||||
else
|
||||
kprintf("%s: address not found p=%p\n", msg, ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
alcsize = h->size * sizeof(struct malloc_header);
|
||||
chksize = alcsize - ap->size;
|
||||
if (chksize > 8)
|
||||
chksize = 8;
|
||||
next = (struct malloc_header *)((char *)ptr + alcsize);
|
||||
|
||||
if (next->check != 0x5a5a5a5a ||
|
||||
memcmp((char *)ptr + ap->size, &check, chksize)) {
|
||||
unsigned long buf = 0x5a5a5a5a5a5a5a5aUL;
|
||||
unsigned char *p;
|
||||
unsigned char *q;
|
||||
memcpy(&buf, (char *)ptr + ap->size, chksize);
|
||||
p = (unsigned char *)&(next->check);
|
||||
q = (unsigned char *)&buf;
|
||||
|
||||
if (file)
|
||||
kprintf("%s: broken, %s:%d alc=%s:%d %02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x size=%ld\n", msg, file, line, ap->loc->file, ap->loc->line, q[0], q[1], q[2], q[3], q[4], q[5], q[6], q[7], p[0], p[1], p[2], p[3], ap->size);
|
||||
else
|
||||
kprintf("%s: broken, alc=%s:%d %02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x size=%ld\n", msg, ap->loc->file, ap->loc->line, q[0], q[1], q[2], q[3], q[4], q[5], q[6], q[7], p[0], p[1], p[2], p[3], ap->size);
|
||||
|
||||
|
||||
if (next->check != 0x5a5a5a5a)
|
||||
kprintf("next->HEADER: next=%p size=%ld cpu_id=%d\n", next->next, next->size, next->cpu_id);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(flags & 1){
|
||||
ap->p = NULL;
|
||||
ap->loc = NULL;
|
||||
ap->size = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int memcheckall()
|
||||
{
|
||||
int i;
|
||||
struct alloc *ap;
|
||||
int r = 0;
|
||||
|
||||
for(i = 0; i < HASHNUM; i++)
|
||||
for(ap = allochash[i]; ap; ap = ap->next)
|
||||
if(ap->p)
|
||||
r |= _memcheck(ap->p + 1, "memcheck", NULL, 0, 2);
|
||||
return r;
|
||||
}
|
||||
|
||||
int freecheck(int runcount)
|
||||
{
|
||||
int i;
|
||||
struct alloc *ap;
|
||||
struct location *lp;
|
||||
int r = 0;
|
||||
|
||||
for (i = 0; i < HASHNUM; i++)
|
||||
for (lp = lochash[i]; lp; lp = lp->next)
|
||||
lp->cnt = 0;
|
||||
|
||||
for (i = 0; i < HASHNUM; i++)
|
||||
for (ap = allochash[i]; ap; ap = ap->next)
|
||||
if (ap->p && ap->runcount == runcount) {
|
||||
ap->loc->cnt++;
|
||||
r++;
|
||||
}
|
||||
|
||||
if (r) {
|
||||
kprintf("memory leak?\n");
|
||||
for (i = 0; i < HASHNUM; i++)
|
||||
for (lp = lochash[i]; lp; lp = lp->next)
|
||||
if (lp->cnt)
|
||||
kprintf(" alc=%s:%d cnt=%d\n", lp->file, lp->line, lp->cnt);
|
||||
}
|
||||
dkprintf("%s addr_entry %p added\n", __FUNCTION__, r);
|
||||
|
||||
out:
|
||||
return r;
|
||||
}
|
||||
|
||||
void _kfree(void *ptr, char *file, int line)
|
||||
{
|
||||
if (memdebug)
|
||||
_memcheck(ptr, "KFREE", file, line, 1);
|
||||
unsigned long irqflags;
|
||||
struct kmalloc_track_entry *entry;
|
||||
struct kmalloc_track_addr_entry *addr_entry_iter, *addr_entry = NULL;
|
||||
int hash;
|
||||
|
||||
if (!memdebug) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
hash = ((unsigned long)ptr >> 5) & KMALLOC_TRACK_HASH_MASK;
|
||||
irqflags = ihk_mc_spinlock_lock(&kmalloc_addr_hash_locks[hash]);
|
||||
list_for_each_entry(addr_entry_iter,
|
||||
&kmalloc_addr_hash[hash], hash) {
|
||||
if (addr_entry_iter->addr == ptr) {
|
||||
addr_entry = addr_entry_iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (addr_entry) {
|
||||
list_del(&addr_entry->hash);
|
||||
}
|
||||
ihk_mc_spinlock_unlock(&kmalloc_addr_hash_locks[hash], irqflags);
|
||||
|
||||
if (!addr_entry) {
|
||||
kprintf("%s: ERROR: kfree()ing invalid pointer\n", __FUNCTION__);
|
||||
panic("panic");
|
||||
}
|
||||
|
||||
entry = addr_entry->entry;
|
||||
|
||||
irqflags = ihk_mc_spinlock_lock(&entry->addr_list_lock);
|
||||
list_del(&addr_entry->list);
|
||||
ihk_mc_spinlock_unlock(&entry->addr_list_lock, irqflags);
|
||||
|
||||
dkprintf("%s addr_entry %p removed\n", __FUNCTION__, addr_entry->addr);
|
||||
___kfree(addr_entry);
|
||||
|
||||
/* Do we need to remove tracking entry as well? */
|
||||
if (!ihk_atomic_dec_and_test(&entry->alloc_count)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
hash = (strlen(entry->file) + entry->line + entry->size) &
|
||||
KMALLOC_TRACK_HASH_MASK;
|
||||
irqflags = ihk_mc_spinlock_lock(&kmalloc_track_hash_locks[hash]);
|
||||
list_del(&entry->hash);
|
||||
ihk_mc_spinlock_unlock(&kmalloc_track_hash_locks[hash], irqflags);
|
||||
|
||||
dkprintf("%s entry %s:%d size: %d removed\n", __FUNCTION__,
|
||||
entry->file, entry->line, entry->size);
|
||||
___kfree(entry->file);
|
||||
___kfree(entry);
|
||||
|
||||
out:
|
||||
___kfree(ptr);
|
||||
}
|
||||
|
||||
void kmalloc_memcheck(void)
|
||||
{
|
||||
int i;
|
||||
unsigned long irqflags;
|
||||
struct kmalloc_track_entry *entry = NULL;
|
||||
|
||||
for (i = 0; i < KMALLOC_TRACK_HASH_SIZE; ++i) {
|
||||
irqflags = ihk_mc_spinlock_lock(&kmalloc_track_hash_locks[i]);
|
||||
list_for_each_entry(entry, &kmalloc_track_hash[i], hash) {
|
||||
struct kmalloc_track_addr_entry *addr_entry = NULL;
|
||||
int cnt = 0;
|
||||
|
||||
ihk_mc_spinlock_lock_noirq(&entry->addr_list_lock);
|
||||
list_for_each_entry(addr_entry, &entry->addr_list, list) {
|
||||
|
||||
dkprintf("%s memory leak: %p @ %s:%d size: %d runcount: %d\n",
|
||||
__FUNCTION__,
|
||||
addr_entry->addr,
|
||||
entry->file,
|
||||
entry->line,
|
||||
entry->size,
|
||||
addr_entry->runcount);
|
||||
|
||||
if (kmalloc_runcount != addr_entry->runcount)
|
||||
continue;
|
||||
|
||||
cnt++;
|
||||
}
|
||||
ihk_mc_spinlock_unlock_noirq(&entry->addr_list_lock);
|
||||
|
||||
if (!cnt)
|
||||
continue;
|
||||
|
||||
kprintf("%s memory leak: %s:%d size: %d cnt: %d, runcount: %d\n",
|
||||
__FUNCTION__,
|
||||
entry->file,
|
||||
entry->line,
|
||||
entry->size,
|
||||
cnt,
|
||||
kmalloc_runcount);
|
||||
}
|
||||
ihk_mc_spinlock_unlock(&kmalloc_track_hash_locks[i], irqflags);
|
||||
}
|
||||
|
||||
++kmalloc_runcount;
|
||||
}
|
||||
|
||||
/* Redirection routines registered in alloc structure */
|
||||
void *__kmalloc(int size, enum ihk_mc_ap_flag flag)
|
||||
{
|
||||
return kmalloc(size, flag);
|
||||
@@ -878,160 +932,199 @@ void __kfree(void *ptr)
|
||||
kfree(ptr);
|
||||
}
|
||||
|
||||
void kmalloc_init(void)
|
||||
|
||||
static void ___kmalloc_insert_chunk(struct list_head *free_list,
|
||||
struct kmalloc_header *chunk)
|
||||
{
|
||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||
struct malloc_header *h = &v->free_list;
|
||||
int i;
|
||||
struct kmalloc_header *chunk_iter, *next_chunk = NULL;
|
||||
|
||||
h->check = 0x5a5a5a5a;
|
||||
h->next = &v->free_list;
|
||||
h->size = 0;
|
||||
|
||||
register_kmalloc();
|
||||
|
||||
memdebug = find_command_line("memdebug");
|
||||
for (i = 0; i < HASHNUM; i++) {
|
||||
allochash[i] = NULL;
|
||||
lochash[i] = NULL;
|
||||
}
|
||||
page = allocate_pages(16, IHK_MC_AP_NOWAIT);
|
||||
space = 16 * 4096;
|
||||
ihk_mc_spinlock_init(&alloclock);
|
||||
}
|
||||
|
||||
void ____kfree(struct cpu_local_var *v, struct malloc_header *p)
|
||||
{
|
||||
struct malloc_header *h = &v->free_list;
|
||||
int combined = 0;
|
||||
|
||||
h = h->next;
|
||||
|
||||
while ((p < h || p > h->next) && h != &v->free_list) {
|
||||
h = h->next;
|
||||
}
|
||||
|
||||
if (h + h->size + 1 == p && h->size != 0) {
|
||||
combined = 1;
|
||||
h->size += p->size + 1;
|
||||
h->check = 0x5a5a5a5a;
|
||||
}
|
||||
if (h->next == p + p->size + 1 && h->next->size != 0) {
|
||||
if (combined) {
|
||||
h->check = 0x5a5a5a5a;
|
||||
h->size += h->next->size + 1;
|
||||
h->next = h->next->next;
|
||||
} else {
|
||||
p->check = 0x5a5a5a5a;
|
||||
p->size += h->next->size + 1;
|
||||
p->next = h->next->next;
|
||||
h->next = p;
|
||||
/* Find out where to insert */
|
||||
list_for_each_entry(chunk_iter, free_list, list) {
|
||||
if ((void *)chunk < (void *)chunk_iter) {
|
||||
next_chunk = chunk_iter;
|
||||
break;
|
||||
}
|
||||
} else if (!combined) {
|
||||
p->next = h->next;
|
||||
h->next = p;
|
||||
}
|
||||
|
||||
/* Add in front of next */
|
||||
if (next_chunk) {
|
||||
list_add_tail(&chunk->list, &next_chunk->list);
|
||||
}
|
||||
/* Add after the head */
|
||||
else {
|
||||
list_add(&chunk->list, free_list);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void *___kmalloc(int size, enum ihk_mc_ap_flag flag)
|
||||
static void ___kmalloc_init_chunk(struct kmalloc_header *h, int size)
|
||||
{
|
||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||
struct malloc_header *h = &v->free_list, *prev, *p;
|
||||
int u, req_page;
|
||||
h->size = size;
|
||||
h->front_magic = 0x5c5c5c5c;
|
||||
h->end_magic = 0x6d6d6d6d;
|
||||
h->cpu_id = ihk_mc_get_processor_id();
|
||||
}
|
||||
|
||||
p = (struct malloc_header *)xchg8((unsigned long *)&v->remote_free_list, 0L);
|
||||
while(p){
|
||||
struct malloc_header *n = p->next;
|
||||
____kfree(v, p);
|
||||
p = n;
|
||||
static void ___kmalloc_consolidate_list(struct list_head *list)
|
||||
{
|
||||
struct kmalloc_header *chunk_iter, *chunk, *next_chunk;
|
||||
|
||||
reiterate:
|
||||
chunk_iter = NULL;
|
||||
chunk = NULL;
|
||||
|
||||
list_for_each_entry(next_chunk, list, list) {
|
||||
|
||||
if (chunk_iter && (((void *)chunk_iter + sizeof(struct kmalloc_header)
|
||||
+ chunk_iter->size) == (void *)next_chunk)) {
|
||||
chunk = chunk_iter;
|
||||
break;
|
||||
}
|
||||
|
||||
chunk_iter = next_chunk;
|
||||
}
|
||||
|
||||
if (size >= PAGE_SIZE * 4) {
|
||||
if (!chunk) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunk->size += (next_chunk->size + sizeof(struct kmalloc_header));
|
||||
list_del(&next_chunk->list);
|
||||
goto reiterate;
|
||||
}
|
||||
|
||||
|
||||
void kmalloc_consolidate_free_list(void)
|
||||
{
|
||||
struct kmalloc_header *chunk, *tmp;
|
||||
unsigned long irqflags =
|
||||
ihk_mc_spinlock_lock(&cpu_local_var(remote_free_list_lock));
|
||||
|
||||
/* Clean up remotely deallocated chunks */
|
||||
list_for_each_entry_safe(chunk, tmp,
|
||||
&cpu_local_var(remote_free_list), list) {
|
||||
|
||||
list_del(&chunk->list);
|
||||
___kmalloc_insert_chunk(&cpu_local_var(free_list), chunk);
|
||||
}
|
||||
|
||||
/* Free list lock ensures IRQs are disabled */
|
||||
___kmalloc_consolidate_list(&cpu_local_var(free_list));
|
||||
|
||||
ihk_mc_spinlock_unlock(&cpu_local_var(remote_free_list_lock), irqflags);
|
||||
}
|
||||
|
||||
#define KMALLOC_MIN_SHIFT (5)
|
||||
#define KMALLOC_MIN_SIZE (1 << KMALLOC_TRACK_HASH_SHIFT)
|
||||
#define KMALLOC_MIN_MASK (KMALLOC_MIN_SIZE - 1)
|
||||
|
||||
/* Actual low-level allocation routines */
|
||||
static void *___kmalloc(int size, enum ihk_mc_ap_flag flag)
|
||||
{
|
||||
struct kmalloc_header *chunk_iter;
|
||||
struct kmalloc_header *chunk = NULL;
|
||||
int npages;
|
||||
unsigned long kmalloc_irq_flags = cpu_disable_interrupt_save();
|
||||
|
||||
/* KMALLOC_MIN_SIZE bytes aligned size. */
|
||||
if (size & KMALLOC_MIN_MASK) {
|
||||
size = ((size + KMALLOC_MIN_SIZE - 1) & ~(KMALLOC_MIN_MASK));
|
||||
}
|
||||
|
||||
chunk = NULL;
|
||||
/* Find a chunk that is big enough */
|
||||
list_for_each_entry(chunk_iter, &cpu_local_var(free_list), list) {
|
||||
if (chunk_iter->size >= size) {
|
||||
chunk = chunk_iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
split_and_return:
|
||||
/* Did we find one? */
|
||||
if (chunk) {
|
||||
/* Do we need to split it? Only if there is enough space for
|
||||
* another header and some actual content */
|
||||
if (chunk->size > (size + sizeof(struct kmalloc_header))) {
|
||||
struct kmalloc_header *leftover;
|
||||
|
||||
leftover = (struct kmalloc_header *)
|
||||
((void *)chunk + sizeof(struct kmalloc_header) + size);
|
||||
___kmalloc_init_chunk(leftover,
|
||||
(chunk->size - size - sizeof(struct kmalloc_header)));
|
||||
list_add(&leftover->list, &chunk->list);
|
||||
chunk->size = size;
|
||||
}
|
||||
|
||||
list_del(&chunk->list);
|
||||
cpu_restore_interrupt(kmalloc_irq_flags);
|
||||
return ((void *)chunk + sizeof(struct kmalloc_header));
|
||||
}
|
||||
|
||||
|
||||
/* Allocate new memory and add it to free list */
|
||||
npages = (size + sizeof(struct kmalloc_header) + (PAGE_SIZE - 1))
|
||||
>> PAGE_SHIFT;
|
||||
chunk = ihk_mc_alloc_pages(npages, flag);
|
||||
|
||||
if (!chunk) {
|
||||
cpu_restore_interrupt(kmalloc_irq_flags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u = (size + sizeof(*h) - 1) / sizeof(*h);
|
||||
___kmalloc_init_chunk(chunk,
|
||||
(npages * PAGE_SIZE - sizeof(struct kmalloc_header)));
|
||||
___kmalloc_insert_chunk(&cpu_local_var(free_list), chunk);
|
||||
|
||||
prev = h;
|
||||
h = h->next;
|
||||
|
||||
while (1) {
|
||||
if (h == &v->free_list) {
|
||||
req_page = ((u + 2) * sizeof(*h) + PAGE_SIZE - 1)
|
||||
>> PAGE_SHIFT;
|
||||
|
||||
h = allocate_pages(req_page, flag);
|
||||
if(h == NULL) {
|
||||
kprintf("kmalloc(%#x,%#x): out of memory\n", size, flag);
|
||||
return NULL;
|
||||
}
|
||||
h->check = 0x5a5a5a5a;
|
||||
prev->next = h;
|
||||
h->size = (req_page * PAGE_SIZE) / sizeof(*h) - 2;
|
||||
/* Guard entry */
|
||||
p = h + h->size + 1;
|
||||
p->check = 0x5a5a5a5a;
|
||||
p->next = &v->free_list;
|
||||
p->size = 0;
|
||||
h->next = p;
|
||||
}
|
||||
|
||||
if (h->size >= u) {
|
||||
if (h->size == u || h->size == u + 1) {
|
||||
prev->next = h->next;
|
||||
h->cpu_id = ihk_mc_get_processor_id();
|
||||
|
||||
return h + 1;
|
||||
} else { /* Divide */
|
||||
h->size -= u + 1;
|
||||
|
||||
p = h + h->size + 1;
|
||||
p->check = 0x5a5a5a5a;
|
||||
p->size = u;
|
||||
p->cpu_id = ihk_mc_get_processor_id();
|
||||
|
||||
return p + 1;
|
||||
}
|
||||
}
|
||||
prev = h;
|
||||
h = h->next;
|
||||
}
|
||||
goto split_and_return;
|
||||
}
|
||||
|
||||
void ___kfree(void *ptr)
|
||||
static void ___kfree(void *ptr)
|
||||
{
|
||||
struct malloc_header *p = (struct malloc_header *)ptr;
|
||||
struct cpu_local_var *v = get_cpu_local_var((--p)->cpu_id);
|
||||
struct kmalloc_header *chunk =
|
||||
(struct kmalloc_header*)(ptr - sizeof(struct kmalloc_header));
|
||||
unsigned long kmalloc_irq_flags = cpu_disable_interrupt_save();
|
||||
|
||||
if(p->cpu_id == ihk_mc_get_processor_id()){
|
||||
____kfree(v, p);
|
||||
/* Sanity check */
|
||||
if (chunk->front_magic != 0x5c5c5c5c || chunk->end_magic != 0x6d6d6d6d) {
|
||||
kprintf("%s: memory corruption at address 0x%p\n", __FUNCTION__, ptr);
|
||||
panic("panic");
|
||||
}
|
||||
else{
|
||||
unsigned long oldval;
|
||||
unsigned long newval;
|
||||
unsigned long rval;
|
||||
do{
|
||||
p->next = v->remote_free_list;
|
||||
oldval = (unsigned long)p->next;
|
||||
newval = (unsigned long)p;
|
||||
rval = atomic_cmpxchg8(
|
||||
(unsigned long *)&v->remote_free_list,
|
||||
oldval, newval);
|
||||
}while(rval != oldval);
|
||||
|
||||
/* Does this chunk belong to this CPU? */
|
||||
if (chunk->cpu_id == ihk_mc_get_processor_id()) {
|
||||
|
||||
___kmalloc_insert_chunk(&cpu_local_var(free_list), chunk);
|
||||
___kmalloc_consolidate_list(&cpu_local_var(free_list));
|
||||
}
|
||||
else {
|
||||
struct cpu_local_var *v = get_cpu_local_var(chunk->cpu_id);
|
||||
unsigned long irqflags;
|
||||
|
||||
irqflags = ihk_mc_spinlock_lock(&v->remote_free_list_lock);
|
||||
list_add(&chunk->list, &v->remote_free_list);
|
||||
ihk_mc_spinlock_unlock(&v->remote_free_list_lock, irqflags);
|
||||
}
|
||||
|
||||
cpu_restore_interrupt(kmalloc_irq_flags);
|
||||
}
|
||||
|
||||
void print_free_list(void)
|
||||
|
||||
void ___kmalloc_print_free_list(struct list_head *list)
|
||||
{
|
||||
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||
struct malloc_header *h = &v->free_list;
|
||||
struct kmalloc_header *chunk_iter;
|
||||
unsigned long irqflags = kprintf_lock();
|
||||
|
||||
h = h->next;
|
||||
|
||||
kprintf("free_list : \n");
|
||||
while (h != &v->free_list) {
|
||||
kprintf(" %p : %p, %d ->\n", h, h->next, h->size);
|
||||
h = h->next;
|
||||
__kprintf("%s: [ \n", __FUNCTION__);
|
||||
list_for_each_entry(chunk_iter, &cpu_local_var(free_list), list) {
|
||||
__kprintf("%s: 0x%lx:%d (VA PFN: %lu, off: %lu)\n", __FUNCTION__,
|
||||
(unsigned long)chunk_iter,
|
||||
chunk_iter->size,
|
||||
(unsigned long)chunk_iter >> PAGE_SHIFT,
|
||||
(unsigned long)chunk_iter % PAGE_SIZE);
|
||||
}
|
||||
kprintf("\n");
|
||||
__kprintf("%s: ] \n", __FUNCTION__);
|
||||
kprintf_unlock(irqflags);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ static int copy_user_ranges(struct process_vm *vm, struct process_vm *orgvm);
|
||||
extern void release_fp_regs(struct thread *proc);
|
||||
extern void save_fp_regs(struct thread *proc);
|
||||
extern void restore_fp_regs(struct thread *proc);
|
||||
void settid(struct thread *proc, int mode, int newcpuid, int oldcpuid);
|
||||
extern void __runq_add_proc(struct thread *proc, int cpu_id);
|
||||
extern void terminate_host(int pid);
|
||||
extern void lapic_timer_enable(unsigned int clocks);
|
||||
@@ -745,7 +744,7 @@ int join_process_memory_range(struct process_vm *vm,
|
||||
memobj_release(merging->memobj);
|
||||
}
|
||||
list_del(&merging->list);
|
||||
ihk_mc_free(merging);
|
||||
kfree(merging);
|
||||
|
||||
error = 0;
|
||||
out:
|
||||
@@ -841,8 +840,9 @@ int free_process_memory_range(struct process_vm *vm, struct vm_range *range)
|
||||
if (range->memobj) {
|
||||
memobj_release(range->memobj);
|
||||
}
|
||||
|
||||
list_del(&range->list);
|
||||
ihk_mc_free(range);
|
||||
kfree(range);
|
||||
|
||||
dkprintf("free_process_memory_range(%p,%lx-%lx): 0\n",
|
||||
vm, start0, end0);
|
||||
@@ -968,7 +968,6 @@ enum ihk_mc_pt_attribute common_vrflag_to_ptattr(unsigned long flag, uint64_t fa
|
||||
return attr;
|
||||
}
|
||||
|
||||
/* XXX: インデントを揃える必要がある */
|
||||
int add_process_memory_range(struct process_vm *vm,
|
||||
unsigned long start, unsigned long end,
|
||||
unsigned long phys, unsigned long flag,
|
||||
@@ -1539,6 +1538,8 @@ retry:
|
||||
kprintf("page_fault_process_memory_range(%p,%lx-%lx %lx,%lx,%lx):cannot allocate new page. %d\n", vm, range->start, range->end, range->flag, fault_addr, reason, error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("%s: clearing 0x%lx:%lu\n",
|
||||
__FUNCTION__, pgaddr, pgsize);
|
||||
memset(virt, 0, pgsize);
|
||||
phys = virt_to_phys(virt);
|
||||
page_map(phys_to_page(phys));
|
||||
@@ -1571,6 +1572,8 @@ retry:
|
||||
kprintf("page_fault_process_memory_range(%p,%lx-%lx %lx,%lx,%lx):cannot allocate copy page. %d\n", vm, range->start, range->end, range->flag, fault_addr, reason, error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("%s: copying 0x%lx:%lu\n",
|
||||
__FUNCTION__, pgaddr, pgsize);
|
||||
memcpy(virt, phys_to_virt(phys), pgsize);
|
||||
|
||||
phys = virt_to_phys(virt);
|
||||
@@ -1651,7 +1654,7 @@ static int do_page_fault_process_vm(struct process_vm *vm, void *fault_addr0, ui
|
||||
"access denied. %d\n",
|
||||
ihk_mc_get_processor_id(), vm,
|
||||
fault_addr0, reason, error);
|
||||
kprintf("%s: reason: %s%s%s%s%s%s%s%s\n", __FUNCTION__,
|
||||
kprintf("%s: reason: %s%s%s%s%s%s%s\n", __FUNCTION__,
|
||||
(reason & PF_PROT) ? "PF_PROT " : "",
|
||||
(reason & PF_WRITE) ? "PF_WRITE " : "",
|
||||
(reason & PF_USER) ? "PF_USER " : "",
|
||||
@@ -1890,14 +1893,14 @@ unsigned long extend_process_region(struct process_vm *vm,
|
||||
aligned_end = (aligned_end + (LARGE_PAGE_SIZE - 1)) & LARGE_PAGE_MASK;
|
||||
/* Fill in the gap between old_aligned_end and aligned_end
|
||||
* with regular pages */
|
||||
if((p = allocate_pages((aligned_end - old_aligned_end) >> PAGE_SHIFT,
|
||||
if((p = ihk_mc_alloc_pages((aligned_end - old_aligned_end) >> PAGE_SHIFT,
|
||||
IHK_MC_AP_NOWAIT)) == NULL){
|
||||
return end;
|
||||
}
|
||||
if((rc = add_process_memory_range(vm, old_aligned_end,
|
||||
aligned_end, virt_to_phys(p), flag,
|
||||
LARGE_PAGE_SHIFT)) != 0){
|
||||
free_pages(p, (aligned_end - old_aligned_end) >> PAGE_SHIFT);
|
||||
ihk_mc_free_pages(p, (aligned_end - old_aligned_end) >> PAGE_SHIFT);
|
||||
return end;
|
||||
}
|
||||
|
||||
@@ -1910,7 +1913,7 @@ unsigned long extend_process_region(struct process_vm *vm,
|
||||
(LARGE_PAGE_SIZE - 1)) & LARGE_PAGE_MASK;
|
||||
address = aligned_new_end;
|
||||
|
||||
if((p = allocate_pages((aligned_new_end - aligned_end + LARGE_PAGE_SIZE) >> PAGE_SHIFT,
|
||||
if((p = ihk_mc_alloc_pages((aligned_new_end - aligned_end + LARGE_PAGE_SIZE) >> PAGE_SHIFT,
|
||||
IHK_MC_AP_NOWAIT)) == NULL){
|
||||
return end;
|
||||
}
|
||||
@@ -1918,16 +1921,16 @@ unsigned long extend_process_region(struct process_vm *vm,
|
||||
p_aligned = ((unsigned long)p + (LARGE_PAGE_SIZE - 1)) & LARGE_PAGE_MASK;
|
||||
|
||||
if (p_aligned > (unsigned long)p) {
|
||||
free_pages(p, (p_aligned - (unsigned long)p) >> PAGE_SHIFT);
|
||||
ihk_mc_free_pages(p, (p_aligned - (unsigned long)p) >> PAGE_SHIFT);
|
||||
}
|
||||
free_pages(
|
||||
ihk_mc_free_pages(
|
||||
(void *)(p_aligned + aligned_new_end - aligned_end),
|
||||
(LARGE_PAGE_SIZE - (p_aligned - (unsigned long)p)) >> PAGE_SHIFT);
|
||||
|
||||
if((rc = add_process_memory_range(vm, aligned_end,
|
||||
aligned_new_end, virt_to_phys((void *)p_aligned),
|
||||
flag, LARGE_PAGE_SHIFT)) != 0){
|
||||
free_pages(p, (aligned_new_end - aligned_end + LARGE_PAGE_SIZE) >> PAGE_SHIFT);
|
||||
ihk_mc_free_pages(p, (aligned_new_end - aligned_end + LARGE_PAGE_SIZE) >> PAGE_SHIFT);
|
||||
return end;
|
||||
}
|
||||
|
||||
@@ -1945,7 +1948,7 @@ unsigned long extend_process_region(struct process_vm *vm,
|
||||
p=0;
|
||||
}else{
|
||||
|
||||
p = allocate_pages((aligned_new_end - aligned_end) >> PAGE_SHIFT, IHK_MC_AP_NOWAIT);
|
||||
p = ihk_mc_alloc_pages((aligned_new_end - aligned_end) >> PAGE_SHIFT, IHK_MC_AP_NOWAIT);
|
||||
|
||||
if (!p) {
|
||||
return end;
|
||||
@@ -1954,7 +1957,7 @@ unsigned long extend_process_region(struct process_vm *vm,
|
||||
if((rc = add_process_memory_range(vm, aligned_end, aligned_new_end,
|
||||
(p==0?0:virt_to_phys(p)), flag, NULL, 0,
|
||||
PAGE_SHIFT)) != 0){
|
||||
free_pages(p, (aligned_new_end - aligned_end) >> PAGE_SHIFT);
|
||||
ihk_mc_free_pages(p, (aligned_new_end - aligned_end) >> PAGE_SHIFT);
|
||||
return end;
|
||||
}
|
||||
|
||||
@@ -2067,6 +2070,7 @@ release_process(struct process *proc)
|
||||
mcs_rwlock_writer_unlock(&parent->children_lock, &lock);
|
||||
}
|
||||
|
||||
if (proc->tids) kfree(proc->tids);
|
||||
kfree(proc);
|
||||
}
|
||||
|
||||
@@ -2172,6 +2176,23 @@ release_sigcommon(struct sig_common *sigcommon)
|
||||
kfree(sigcommon);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release the TID from the process' TID set corresponding to this thread.
|
||||
* NOTE: threads_lock must be held.
|
||||
*/
|
||||
void __release_tid(struct process *proc, struct thread *thread) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < proc->nr_tids; ++i) {
|
||||
if (proc->tids[i].thread != thread) continue;
|
||||
|
||||
proc->tids[i].thread = NULL;
|
||||
dkprintf("%s: tid %d has been released by %p\n",
|
||||
__FUNCTION__, thread->tid, thread);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_thread(struct thread *thread)
|
||||
{
|
||||
struct sig_pending *pending;
|
||||
@@ -2188,6 +2209,7 @@ void destroy_thread(struct thread *thread)
|
||||
|
||||
mcs_rwlock_writer_lock(&proc->threads_lock, &lock);
|
||||
list_del(&thread->siblings_list);
|
||||
__release_tid(proc, thread);
|
||||
mcs_rwlock_writer_unlock(&proc->threads_lock, &lock);
|
||||
|
||||
cpu_clear(thread->cpu_id, &thread->vm->address_space->cpu_set,
|
||||
@@ -2325,6 +2347,8 @@ static void idle(void)
|
||||
}
|
||||
if (v->status == CPU_STATUS_IDLE ||
|
||||
v->status == CPU_STATUS_RESERVED) {
|
||||
/* No work to do? Consolidate the kmalloc free list */
|
||||
kmalloc_consolidate_free_list();
|
||||
cpu_safe_halt();
|
||||
}
|
||||
else {
|
||||
@@ -2527,7 +2551,7 @@ static void do_migrate(void)
|
||||
v->flags |= CPU_FLAG_NEED_RESCHED;
|
||||
ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(cpu_id)->apic_id, 0xd1);
|
||||
double_rq_unlock(cur_v, v, irqstate);
|
||||
settid(req->thread, 2, cpu_id, old_cpu_id);
|
||||
//settid(req->thread, 2, cpu_id, old_cpu_id, 0, NULL);
|
||||
|
||||
ack:
|
||||
waitq_wakeup(&req->wq);
|
||||
@@ -2563,13 +2587,8 @@ void schedule(void)
|
||||
struct thread *last;
|
||||
|
||||
if (cpu_local_var(no_preempt)) {
|
||||
dkprintf("no schedule() while no preemption! \n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (cpu_local_var(current)
|
||||
&& cpu_local_var(current)->in_syscall_offload) {
|
||||
dkprintf("no schedule() while syscall offload!\n");
|
||||
kprintf("%s: WARNING can't schedule() while no preemption, cnt: %d\n",
|
||||
__FUNCTION__, cpu_local_var(no_preempt));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
235
kernel/syscall.c
235
kernel/syscall.c
@@ -127,11 +127,9 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
||||
static void do_mod_exit(int status);
|
||||
#endif
|
||||
|
||||
static void send_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
static void send_syscall(struct syscall_request *req, int cpu, int pid, struct syscall_response *res)
|
||||
{
|
||||
struct ikc_scd_packet packet;
|
||||
struct syscall_response *res;
|
||||
struct syscall_params *scp;
|
||||
struct ikc_scd_packet packet IHK_DMA_ALIGN;
|
||||
struct ihk_ikc_channel_desc *syscall_channel;
|
||||
int ret;
|
||||
|
||||
@@ -140,7 +138,6 @@ static void send_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
req->number == __NR_kill){ // interrupt syscall
|
||||
extern int num_processors;
|
||||
|
||||
scp = &get_cpu_local_var(0)->scp2;
|
||||
syscall_channel = get_cpu_local_var(0)->syscall_channel2;
|
||||
|
||||
/* XXX: is this really going to work if multiple processes
|
||||
@@ -152,34 +149,22 @@ static void send_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
pid = req->args[1];
|
||||
}
|
||||
else{
|
||||
scp = &get_cpu_local_var(cpu)->scp;
|
||||
syscall_channel = get_cpu_local_var(cpu)->syscall_channel;
|
||||
}
|
||||
res = scp->response_va;
|
||||
|
||||
res->status = 0;
|
||||
req->valid = 0;
|
||||
|
||||
#ifdef USE_DMA
|
||||
memcpy_async(scp->request_pa,
|
||||
virt_to_phys(req), sizeof(*req), 0, &fin);
|
||||
|
||||
memcpy_async_wait(&scp->post_fin);
|
||||
scp->post_va->v[0] = scp->post_idx;
|
||||
memcpy_async_wait(&fin);
|
||||
#else
|
||||
memcpy(scp->request_va, req, sizeof(*req));
|
||||
#endif
|
||||
memcpy(&packet.req, req, sizeof(*req));
|
||||
|
||||
barrier();
|
||||
scp->request_va->valid = 1;
|
||||
*(unsigned int *)scp->doorbell_va = cpu + 1;
|
||||
packet.req.valid = 1;
|
||||
|
||||
#ifdef SYSCALL_BY_IKC
|
||||
packet.msg = SCD_MSG_SYSCALL_ONESIDE;
|
||||
packet.ref = cpu;
|
||||
packet.pid = pid ? pid : cpu_local_var(current)->proc->pid;
|
||||
packet.arg = scp->request_rpa;
|
||||
packet.resp_pa = virt_to_phys(res);
|
||||
dkprintf("send syscall, nr: %d, pid: %d\n", req->number, packet.pid);
|
||||
|
||||
ret = ihk_ikc_send(syscall_channel, &packet, 0);
|
||||
@@ -193,9 +178,8 @@ ihk_spinlock_t syscall_lock;
|
||||
|
||||
long do_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
{
|
||||
struct syscall_response *res;
|
||||
struct syscall_response res;
|
||||
struct syscall_request req2 IHK_DMA_ALIGN;
|
||||
struct syscall_params *scp;
|
||||
int error;
|
||||
long rc;
|
||||
int islock = 0;
|
||||
@@ -206,6 +190,9 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
dkprintf("SC(%d)[%3d] sending syscall\n",
|
||||
ihk_mc_get_processor_id(),
|
||||
req->number);
|
||||
|
||||
irqstate = 0; /* for avoidance of warning */
|
||||
barrier();
|
||||
|
||||
if(req->number != __NR_exit_group){
|
||||
if(proc->nohost && // host is down
|
||||
@@ -215,20 +202,18 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
++thread->in_syscall_offload;
|
||||
}
|
||||
|
||||
irqstate = 0; /* for avoidance of warning */
|
||||
if(req->number == __NR_exit_group ||
|
||||
req->number == __NR_gettid ||
|
||||
req->number == __NR_kill){ // interrupt syscall
|
||||
scp = &get_cpu_local_var(0)->scp2;
|
||||
islock = 1;
|
||||
irqstate = ihk_mc_spinlock_lock(&syscall_lock);
|
||||
}
|
||||
else{
|
||||
scp = &get_cpu_local_var(cpu)->scp;
|
||||
}
|
||||
res = scp->response_va;
|
||||
|
||||
send_syscall(req, cpu, pid);
|
||||
/* The current thread is the requester and any thread from
|
||||
* the pool may serve the request */
|
||||
req->rtid = cpu_local_var(current)->tid;
|
||||
req->ttid = 0;
|
||||
res.req_thread_status = IHK_SCD_REQ_THREAD_SPINNING;
|
||||
send_syscall(req, cpu, pid, &res);
|
||||
|
||||
dkprintf("%s: syscall num: %d waiting for Linux.. \n",
|
||||
__FUNCTION__, req->number);
|
||||
@@ -236,60 +221,83 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
|
||||
#define STATUS_IN_PROGRESS 0
|
||||
#define STATUS_COMPLETED 1
|
||||
#define STATUS_PAGE_FAULT 3
|
||||
while (res->status != STATUS_COMPLETED) {
|
||||
while (res->status == STATUS_IN_PROGRESS) {
|
||||
while (res.status != STATUS_COMPLETED) {
|
||||
while (res.status == STATUS_IN_PROGRESS) {
|
||||
struct cpu_local_var *v;
|
||||
int call_schedule = 0;
|
||||
int do_schedule = 0;
|
||||
long runq_irqstate;
|
||||
unsigned long flags;
|
||||
DECLARE_WAITQ_ENTRY(scd_wq_entry, cpu_local_var(current));
|
||||
|
||||
cpu_pause();
|
||||
|
||||
/* XXX: Intel MPI + Intel OpenMP situation:
|
||||
* While the MPI helper thread waits in a poll() call the OpenMP master
|
||||
* thread is iterating through the CPU cores using setaffinity().
|
||||
* Unless we give a chance to it on this core the two threads seem to
|
||||
* hang in deadlock. If the new thread would make a system call on this
|
||||
* core we would be in trouble. For now, allow it, but in the future
|
||||
* we should have syscall channels for each thread instead of per core,
|
||||
* or we should multiplex syscall threads in mcexec */
|
||||
/* Spin if not preemptable */
|
||||
if (cpu_local_var(no_preempt) || !thread->tid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Spin by default, but if re-schedule is requested let
|
||||
* the other thread run */
|
||||
runq_irqstate =
|
||||
ihk_mc_spinlock_lock(&(get_this_cpu_local_var()->runq_lock));
|
||||
v = get_this_cpu_local_var();
|
||||
|
||||
if (v->flags & CPU_FLAG_NEED_RESCHED) {
|
||||
call_schedule = 1;
|
||||
--thread->in_syscall_offload;
|
||||
do_schedule = 1;
|
||||
}
|
||||
|
||||
ihk_mc_spinlock_unlock(&v->runq_lock, runq_irqstate);
|
||||
|
||||
if (call_schedule) {
|
||||
schedule();
|
||||
++thread->in_syscall_offload;
|
||||
if (!do_schedule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
flags = cpu_disable_interrupt_save();
|
||||
|
||||
/* Try to sleep until notified */
|
||||
if (__sync_bool_compare_and_swap(&res.req_thread_status,
|
||||
IHK_SCD_REQ_THREAD_SPINNING,
|
||||
IHK_SCD_REQ_THREAD_DESCHEDULED)) {
|
||||
|
||||
dkprintf("%s: tid %d waiting for syscall reply...\n",
|
||||
__FUNCTION__, thread->tid);
|
||||
waitq_init(&thread->scd_wq);
|
||||
waitq_prepare_to_wait(&thread->scd_wq, &scd_wq_entry,
|
||||
PS_INTERRUPTIBLE);
|
||||
cpu_restore_interrupt(flags);
|
||||
schedule();
|
||||
waitq_finish_wait(&thread->scd_wq, &scd_wq_entry);
|
||||
}
|
||||
|
||||
cpu_restore_interrupt(flags);
|
||||
}
|
||||
|
||||
if (res->status == STATUS_PAGE_FAULT) {
|
||||
|
||||
if (res.status == STATUS_PAGE_FAULT) {
|
||||
dkprintf("STATUS_PAGE_FAULT in syscall, pid: %d\n",
|
||||
cpu_local_var(current)->proc->pid);
|
||||
error = page_fault_process_vm(thread->vm,
|
||||
(void *)res->fault_address,
|
||||
res->fault_reason|PF_POPULATE);
|
||||
(void *)res.fault_address,
|
||||
res.fault_reason|PF_POPULATE);
|
||||
|
||||
/* send result */
|
||||
req2.number = __NR_mmap;
|
||||
#define PAGER_RESUME_PAGE_FAULT 0x0101
|
||||
req2.args[0] = PAGER_RESUME_PAGE_FAULT;
|
||||
req2.args[1] = error;
|
||||
/* The current thread is the requester and only the waiting thread
|
||||
* may serve the request */
|
||||
req2.rtid = cpu_local_var(current)->tid;
|
||||
req2.ttid = res.stid;
|
||||
|
||||
send_syscall(&req2, cpu, pid);
|
||||
res.req_thread_status = IHK_SCD_REQ_THREAD_SPINNING;
|
||||
send_syscall(&req2, cpu, pid, &res);
|
||||
}
|
||||
}
|
||||
|
||||
dkprintf("%s: syscall num: %d got host reply: %d \n",
|
||||
__FUNCTION__, req->number, res->ret);
|
||||
__FUNCTION__, req->number, res.ret);
|
||||
|
||||
rc = res->ret;
|
||||
rc = res.ret;
|
||||
if(islock){
|
||||
ihk_mc_spinlock_unlock(&syscall_lock, irqstate);
|
||||
}
|
||||
@@ -820,7 +828,8 @@ terminate(int rc, int sig)
|
||||
release_thread(mythread);
|
||||
release_process_vm(vm);
|
||||
schedule();
|
||||
// no return
|
||||
kprintf("%s: ERROR: returned from terminate() -> schedule()\n", __FUNCTION__);
|
||||
panic("panic");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -838,14 +847,15 @@ terminate_host(int pid)
|
||||
}
|
||||
|
||||
void
|
||||
interrupt_syscall(int pid, int cpuid)
|
||||
interrupt_syscall(int pid, int tid)
|
||||
{
|
||||
dkprintf("interrupt_syscall,target pid=%d,target cpuid=%d\n", pid, cpuid);
|
||||
dkprintf("interrupt_syscall,target pid=%d,target tid=%d\n", pid, tid);
|
||||
ihk_mc_user_context_t ctx;
|
||||
long lerror;
|
||||
|
||||
kprintf("interrupt_syscall pid=%d tid=%d\n", pid, tid);
|
||||
ihk_mc_syscall_arg0(&ctx) = pid;
|
||||
ihk_mc_syscall_arg1(&ctx) = cpuid;
|
||||
ihk_mc_syscall_arg1(&ctx) = tid;
|
||||
|
||||
lerror = syscall_generic_forwarding(__NR_kill, &ctx);
|
||||
if (lerror) {
|
||||
@@ -908,8 +918,6 @@ static int do_munmap(void *addr, size_t len)
|
||||
begin_free_pages_pending();
|
||||
error = remove_process_memory_range(cpu_local_var(current)->vm,
|
||||
(intptr_t)addr, (intptr_t)addr+len, &ro_freed);
|
||||
// XXX: TLB flush
|
||||
flush_tlb();
|
||||
if (error || !ro_freed) {
|
||||
clear_host_pte((uintptr_t)addr, len);
|
||||
}
|
||||
@@ -921,6 +929,8 @@ static int do_munmap(void *addr, size_t len)
|
||||
}
|
||||
}
|
||||
finish_free_pages_pending();
|
||||
dkprintf("%s: 0x%lx:%lu, error: %ld\n",
|
||||
__FUNCTION__, addr, len, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -1068,25 +1078,18 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
||||
vrflags |= PROT_TO_VR_FLAG(prot);
|
||||
vrflags |= (flags & MAP_PRIVATE)? VR_PRIVATE: 0;
|
||||
vrflags |= (flags & MAP_LOCKED)? VR_LOCKED: 0;
|
||||
vrflags |= VR_DEMAND_PAGING;
|
||||
if (flags & MAP_ANONYMOUS) {
|
||||
if (0) {
|
||||
/* dummy */
|
||||
if (!anon_on_demand) {
|
||||
populated_mapping = 1;
|
||||
}
|
||||
#ifdef USE_NOCACHE_MMAP
|
||||
#define X_MAP_NOCACHE MAP_32BIT
|
||||
else if (flags & X_MAP_NOCACHE) {
|
||||
vrflags &= ~VR_DEMAND_PAGING;
|
||||
vrflags |= VR_IO_NOCACHE;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
vrflags |= VR_DEMAND_PAGING;
|
||||
if (!anon_on_demand) {
|
||||
populated_mapping = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
vrflags |= VR_DEMAND_PAGING;
|
||||
}
|
||||
|
||||
if (flags & (MAP_POPULATE | MAP_LOCKED)) {
|
||||
@@ -1162,6 +1165,8 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
||||
error = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
dkprintf("%s: 0x%x:%lu allocated %d pages, p2align: %lx\n",
|
||||
__FUNCTION__, addr, len, npages, p2align);
|
||||
phys = virt_to_phys(p);
|
||||
}
|
||||
else if (flags & MAP_SHARED) {
|
||||
@@ -1197,10 +1202,10 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
|
||||
error = add_process_memory_range(thread->vm, addr, addr+len, phys,
|
||||
vrflags, memobj, off, pgshift);
|
||||
if (error) {
|
||||
ekprintf("do_mmap:add_process_memory_range"
|
||||
"(%p,%lx,%lx,%lx,%lx,%d) failed %d\n",
|
||||
thread->vm, addr, addr+len,
|
||||
virt_to_phys(p), vrflags, pgshift, error);
|
||||
kprintf("%s: add_process_memory_range failed for 0x%lx:%lu"
|
||||
" flags: %lx, vrflags: %lx, pgshift: %d, error: %d\n",
|
||||
__FUNCTION__, addr, addr+len,
|
||||
flags, vrflags, pgshift, error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1246,8 +1251,12 @@ out:
|
||||
if (memobj) {
|
||||
memobj_release(memobj);
|
||||
}
|
||||
dkprintf("do_mmap(%lx,%lx,%x,%x,%d,%lx): %ld %lx\n",
|
||||
addr0, len0, prot, flags, fd, off0, error, addr);
|
||||
dkprintf("%s: 0x%lx:%8lu, (req: 0x%lx:%lu), prot: %x, flags: %x, "
|
||||
"fd: %d, off: %lu, error: %ld, addr: 0x%lx\n",
|
||||
__FUNCTION__,
|
||||
addr, len, addr0, len0, prot, flags,
|
||||
fd, off0, error, addr);
|
||||
|
||||
return (!error)? addr: error;
|
||||
}
|
||||
|
||||
@@ -1478,8 +1487,8 @@ SYSCALL_DECLARE(getppid)
|
||||
return thread->proc->ppid_parent->pid;
|
||||
}
|
||||
|
||||
void
|
||||
settid(struct thread *thread, int mode, int newcpuid, int oldcpuid)
|
||||
void settid(struct thread *thread, int mode, int newcpuid, int oldcpuid,
|
||||
int nr_tids, int *tids)
|
||||
{
|
||||
struct syscall_request request IHK_DMA_ALIGN;
|
||||
unsigned long rc;
|
||||
@@ -1489,6 +1498,12 @@ settid(struct thread *thread, int mode, int newcpuid, int oldcpuid)
|
||||
request.args[1] = thread->proc->pid;
|
||||
request.args[2] = newcpuid;
|
||||
request.args[3] = oldcpuid;
|
||||
/*
|
||||
* If nr_tids is non-zero, tids should point to an array of ints
|
||||
* where the thread ids of the mcexec process are expected.
|
||||
*/
|
||||
request.args[4] = nr_tids;
|
||||
request.args[5] = virt_to_phys(tids);
|
||||
rc = do_syscall(&request, ihk_mc_get_processor_id(), thread->proc->pid);
|
||||
if (mode != 2) {
|
||||
thread->tid = rc;
|
||||
@@ -1893,7 +1908,61 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
|
||||
&new->vm->address_space->cpu_set_lock);
|
||||
|
||||
if (clone_flags & CLONE_VM) {
|
||||
settid(new, 1, cpuid, -1);
|
||||
int *tids = NULL;
|
||||
int i;
|
||||
struct mcs_rwlock_node_irqsave lock;
|
||||
|
||||
mcs_rwlock_writer_lock(&newproc->threads_lock, &lock);
|
||||
/* Obtain mcexec TIDs if not known yet */
|
||||
if (!newproc->nr_tids) {
|
||||
tids = kmalloc(sizeof(int) * num_processors, IHK_MC_AP_NOWAIT);
|
||||
if (!tids) {
|
||||
mcs_rwlock_writer_unlock(&newproc->threads_lock, &lock);
|
||||
release_cpuid(cpuid);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
newproc->tids = kmalloc(sizeof(struct mcexec_tid) * num_processors, IHK_MC_AP_NOWAIT);
|
||||
if (!newproc->tids) {
|
||||
mcs_rwlock_writer_unlock(&newproc->threads_lock, &lock);
|
||||
kfree(tids);
|
||||
release_cpuid(cpuid);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
settid(new, 1, cpuid, -1, num_processors, tids);
|
||||
|
||||
for (i = 0; (i < num_processors) && tids[i]; ++i) {
|
||||
dkprintf("%s: tid[%d]: %d\n", __FUNCTION__, i, tids[i]);
|
||||
newproc->tids[i].tid = tids[i];
|
||||
newproc->tids[i].thread = NULL;
|
||||
++newproc->nr_tids;
|
||||
}
|
||||
|
||||
kfree(tids);
|
||||
}
|
||||
|
||||
/* Find an unused TID */
|
||||
retry_tid:
|
||||
for (i = 0; i < newproc->nr_tids; ++i) {
|
||||
if (!newproc->tids[i].thread) {
|
||||
if (!__sync_bool_compare_and_swap(
|
||||
&newproc->tids[i].thread, NULL, new)) {
|
||||
goto retry_tid;
|
||||
}
|
||||
new->tid = newproc->tids[i].tid;
|
||||
dkprintf("%s: tid %d assigned to %p\n", __FUNCTION__, new->tid, new);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: spawn more mcexec threads */
|
||||
if (!new->tid) {
|
||||
kprintf("%s: no more TIDs available\n");
|
||||
panic("");
|
||||
}
|
||||
|
||||
mcs_rwlock_writer_unlock(&newproc->threads_lock, &lock);
|
||||
}
|
||||
/* fork() a new process on the host */
|
||||
else {
|
||||
@@ -1913,7 +1982,7 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
|
||||
}
|
||||
|
||||
/* In a single threaded process TID equals to PID */
|
||||
settid(new, 0, cpuid, -1);
|
||||
new->tid = newproc->pid;
|
||||
new->vm->address_space->pids[0] = new->proc->pid;
|
||||
|
||||
dkprintf("fork(): new pid: %d\n", new->proc->pid);
|
||||
@@ -5712,6 +5781,10 @@ SYSCALL_DECLARE(sched_setaffinity)
|
||||
int empty_set = 1;
|
||||
extern int num_processors;
|
||||
|
||||
if (!u_cpu_set) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (sizeof(k_cpu_set) > len) {
|
||||
memset(&k_cpu_set, 0, sizeof(k_cpu_set));
|
||||
}
|
||||
@@ -5719,7 +5792,7 @@ SYSCALL_DECLARE(sched_setaffinity)
|
||||
len = MIN2(len, sizeof(k_cpu_set));
|
||||
|
||||
if (copy_from_user(&k_cpu_set, u_cpu_set, len)) {
|
||||
kprintf("%s: error: copy_from_user failed for %p:%d\n", __FUNCTION__, u_cpu_set, len);
|
||||
dkprintf("%s: error: copy_from_user failed for %p:%d\n", __FUNCTION__, u_cpu_set, len);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ sysfs_createf(struct sysfs_ops *ops, void *instance, int mode,
|
||||
dkprintf("sysfs_createf(%p,%p,%#o,%s,...)\n",
|
||||
ops, instance, mode, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
param = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_createf:allocate_pages failed. %d\n", error);
|
||||
@@ -134,7 +134,7 @@ sysfs_createf(struct sysfs_ops *ops, void *instance, int mode,
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
ihk_mc_free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_createf(%p,%p,%#o,%s,...): %d\n",
|
||||
@@ -156,7 +156,7 @@ sysfs_mkdirf(sysfs_handle_t *dirhp, const char *fmt, ...)
|
||||
|
||||
dkprintf("sysfs_mkdirf(%p,%s,...)\n", dirhp, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
param = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_mkdirf:allocate_pages failed. %d\n", error);
|
||||
@@ -208,7 +208,7 @@ sysfs_mkdirf(sysfs_handle_t *dirhp, const char *fmt, ...)
|
||||
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
ihk_mc_free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_mkdirf(%p,%s,...): %d\n", dirhp, fmt, error);
|
||||
@@ -229,7 +229,7 @@ sysfs_symlinkf(sysfs_handle_t targeth, const char *fmt, ...)
|
||||
|
||||
dkprintf("sysfs_symlinkf(%#lx,%s,...)\n", targeth.handle, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
param = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_symlinkf:allocate_pages failed. %d\n", error);
|
||||
@@ -279,7 +279,7 @@ sysfs_symlinkf(sysfs_handle_t targeth, const char *fmt, ...)
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
ihk_mc_free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_symlinkf(%#lx,%s,...): %d\n",
|
||||
@@ -301,7 +301,7 @@ sysfs_lookupf(sysfs_handle_t *objhp, const char *fmt, ...)
|
||||
|
||||
dkprintf("sysfs_lookupf(%p,%s,...)\n", objhp, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
param = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_lookupf:allocate_pages failed. %d\n", error);
|
||||
@@ -353,7 +353,7 @@ sysfs_lookupf(sysfs_handle_t *objhp, const char *fmt, ...)
|
||||
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
ihk_mc_free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_lookupf(%p,%s,...): %d\n", objhp, fmt, error);
|
||||
@@ -374,7 +374,7 @@ sysfs_unlinkf(int flags, const char *fmt, ...)
|
||||
|
||||
dkprintf("sysfs_unlinkf(%#x,%s,...)\n", flags, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
param = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_unlinkf:allocate_pages failed. %d\n", error);
|
||||
@@ -423,7 +423,7 @@ sysfs_unlinkf(int flags, const char *fmt, ...)
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
ihk_mc_free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_unlinkf(%#x,%s,...): %d\n", flags, fmt, error);
|
||||
@@ -601,14 +601,14 @@ sysfs_init(void)
|
||||
}
|
||||
|
||||
sysfs_data_bufsize = PAGE_SIZE;
|
||||
sysfs_data_buf = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
sysfs_data_buf = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!sysfs_data_buf) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_init:allocate_pages(buf) failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
param = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_init:allocate_pages(param) failed. %d\n",
|
||||
@@ -644,7 +644,7 @@ sysfs_init(void)
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
ihk_mc_free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_init(): %d\n", error);
|
||||
|
||||
@@ -172,6 +172,10 @@ static int zeroobj_get_page(struct memobj *memobj, off_t off, int p2align,
|
||||
struct zeroobj *obj = to_zeroobj(memobj);
|
||||
struct page *page;
|
||||
|
||||
/* Don't bother about zero page, page fault handler will
|
||||
* allocate and clear pages */
|
||||
return 0;
|
||||
|
||||
dkprintf("zeroobj_get_page(%p,%#lx,%d,%p)\n",
|
||||
memobj, off, p2align, physp);
|
||||
if (off & ~PAGE_MASK) {
|
||||
|
||||
Reference in New Issue
Block a user