Skip to content

Commit

Permalink
Merge pull request #119 from gedare/rm_cinfo
Browse files Browse the repository at this point in the history
Rewrite cinfo interface: continuing with the brilliant removal of the stkmgr, this cleans up the interfaces to correctly pass new stacks to components.
  • Loading branch information
gparmer committed Feb 23, 2015
2 parents 02fdb32 + ec62264 commit 5f186b6
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/components/implementation/cbuf_mgr/default/Makefile
Expand Up @@ -2,7 +2,7 @@ C_OBJS=cbuf_mgr.o
ASM_OBJS=
COMPONENT=cbuf.o
INTERFACES=cbuf_mgr stkmgr
DEPENDENCIES=sched printc lock mem_mgr_large valloc cinfo
DEPENDENCIES=sched printc lock mem_mgr_large valloc

include ../../Makefile.subsubdir
MANDITORY_LIB=simple_stklib.o
18 changes: 4 additions & 14 deletions src/components/implementation/cbuf_mgr/default/cbuf_mgr.c
Expand Up @@ -11,7 +11,6 @@
#include <mem_mgr_large.h>
#include <cbuf.h>
#include <cbuf_mgr.h>
#include <cinfo.h>
#include <cos_synchronization.h>
#include <valloc.h>
#include <cos_alloc.h>
Expand Down Expand Up @@ -86,7 +85,6 @@ struct cbuf_bin {

struct cbuf_comp_info {
spdid_t spdid;
struct cos_component_information *cinfo_page;
struct cbuf_shared_page *csp;
vaddr_t dest_csp;
int nbin;
Expand Down Expand Up @@ -157,13 +155,6 @@ cbuf_comp_info_init(spdid_t spdid, struct cbuf_comp_info *cci)
memset(cci, 0, sizeof(*cci));
cci->spdid = spdid;
cvect_add(&components, cci, spdid);

p = valloc_alloc(cos_spd_id(), cos_spd_id(), 1);
if (cinfo_map(cos_spd_id(), (vaddr_t)p, spdid)) {
DOUT("%d: couldn't cinfo_map for %d\n", cos_spd_id(), spdid);
valloc_free(cos_spd_id(), spdid, p, 1);
}
cci->cinfo_page = p;
}

static struct cbuf_comp_info *
Expand Down Expand Up @@ -741,22 +732,21 @@ void *
stkmgr_grant_stack(spdid_t d_spdid)
{
struct cbuf_comp_info *cci;
void *p;
void *p, *ret = NULL;
vaddr_t d_addr;

printl("stkmgr_grant_stack (cbuf)\n");

CBUF_TAKE();
cci = cbuf_comp_info_get(d_spdid);
assert(cci);
if (!cci) goto done;

assert(!cbuf_alloc_map(d_spdid, &d_addr, (void**)&p, PAGE_SIZE));
cci->cinfo_page->cos_stacks.freelists[0].freelist = D_COS_STK_ADDR(d_addr);
if (cbuf_alloc_map(d_spdid, &d_addr, (void**)&p, PAGE_SIZE)) goto done;
ret = (void*)D_COS_STK_ADDR(d_addr);

done:
CBUF_RELEASE();
return NULL;
return ret;
}


Expand Down
41 changes: 8 additions & 33 deletions src/components/implementation/no_interface/boot/boot_deps.h
Expand Up @@ -29,54 +29,29 @@
COS_VECT_CREATE_STATIC(spd_info_addresses);

int
cinfo_add(spdid_t spdid, spdid_t target, struct cos_component_information *ci)
cinfo_add_heap_pointer(spdid_t spdid, spdid_t target, void *heap_pointer)
{
if (cos_vect_lookup(&spd_info_addresses, target)) return -1;
cos_vect_add_id(&spd_info_addresses, (void*)round_to_page(ci), target);
cos_vect_add_id(&spd_info_addresses, heap_pointer, target);
return 0;
}

void*
cinfo_alloc_page(spdid_t spdid)
cinfo_get_heap_pointer(spdid_t spdid, spdid_t target)
{
void *p = cos_get_vas_page();
return p;
return cos_vect_lookup(&spd_info_addresses, target);
}

int
cinfo_map(spdid_t spdid, vaddr_t map_addr, spdid_t target)
{
vaddr_t cinfo_addr;

cinfo_addr = (vaddr_t)cos_vect_lookup(&spd_info_addresses, target);
if (0 == cinfo_addr) return -1;
if (map_addr !=
(__local_mman_alias_page(cos_spd_id(), cinfo_addr, spdid, map_addr, MAPPING_RW))) {
return -1;
}

return 0;
}

int
cinfo_spdid(spdid_t spdid)
{
return cos_spd_id();
}

static int boot_spd_set_symbs(struct cobj_header *h, spdid_t spdid, struct cos_component_information *ci);
static void
comp_info_record(struct cobj_header *h, spdid_t spdid, struct cos_component_information *ci)
boot_deps_init(void)
{
if (!cinfo_add(cos_spd_id(), spdid, ci)) {
boot_spd_set_symbs(h, spdid, ci);
}
cos_vect_init_static(&spd_info_addresses);
}

static void
boot_deps_init(void)
boot_deps_save_hp(spdid_t spdid, void *hp)
{
cos_vect_init_static(&spd_info_addresses);
cinfo_add_heap_pointer(cos_spd_id(), spdid, hp);
}

static void
Expand Down
13 changes: 8 additions & 5 deletions src/components/implementation/no_interface/boot/booter.c
Expand Up @@ -131,10 +131,6 @@ boot_process_cinfo(struct cobj_header *h, spdid_t spdid, vaddr_t heap_val,
ci->init_string[len] = '\0';
}

/* save the address of this page for later retrieval
* (e.g. to manipulate the stack pointer) */
comp_info_record(h, spdid, ci);

return 1;
}

Expand All @@ -161,6 +157,10 @@ boot_spd_map_memory(struct cobj_header *h, spdid_t spdid, vaddr_t comp_info)
local_md[spdid].h = h;
local_md[spdid].page_start = cos_get_heap_ptr();
local_md[spdid].comp_info = comp_info;

/* save the address of the heap for later retrieval */
boot_deps_save_hp(spdid, (void*)boot_spd_end(h));

for (i = 0 ; i < h->nsect ; i++) {
struct cobj_sect *sect;
int left;
Expand Down Expand Up @@ -229,9 +229,12 @@ boot_spd_map_populate(struct cobj_header *h, spdid_t spdid, vaddr_t comp_info, i
}

if (sect->flags & COBJ_SECT_CINFO) {
struct cos_component_information *ci;
assert(left == PAGE_SIZE);
assert(comp_info == dest_daddr);
boot_process_cinfo(h, spdid, boot_spd_end(h), start_addr + (comp_info-init_daddr), comp_info);
ci = (struct cos_component_information *)(start_addr + (comp_info - init_daddr));
boot_process_cinfo(h, spdid, boot_spd_end(h), (void*)ci, comp_info);
if (first_time) boot_spd_set_symbs(h, spdid, ci);
}
}
return 0;
Expand Down
15 changes: 5 additions & 10 deletions src/components/implementation/no_interface/cbboot/boot_deps.h
Expand Up @@ -26,19 +26,14 @@
#include <cinfo.h>
#include <cos_vect.h>

static int boot_spd_set_symbs(struct cobj_header *h, spdid_t spdid, struct cos_component_information *ci);
static void
comp_info_record(struct cobj_header *h, spdid_t spdid, struct cos_component_information *ci)
{
vaddr_t cinfo_addr = (vaddr_t)cinfo_alloc_page(cos_spd_id());
if (cinfo_addr != __local_mman_alias_page(cos_spd_id(), (vaddr_t)round_to_page(ci), cinfo_spdid(cos_spd_id()), cinfo_addr, MAPPING_RW)) BUG();
if (!cinfo_add(cos_spd_id(), spdid, cinfo_addr)) {
boot_spd_set_symbs(h, spdid, ci);
}
}
boot_deps_init(void) { return; }

static void
boot_deps_init(void) { return; }
boot_deps_save_hp(spdid_t spdid, void *hp)
{
cinfo_add_heap_pointer(cos_spd_id(), spdid, hp);
}

static void
boot_deps_run(void) { return; }
Expand Down
21 changes: 3 additions & 18 deletions src/components/implementation/no_interface/cinfo_test/citest.c
Expand Up @@ -6,29 +6,14 @@

void cos_init(void)
{
void *hp = cos_get_heap_ptr();
int i;

for (i = 0 ; i < MAX_NUM_SPDS ; i++) {
struct cos_component_information *ci;
spdid_t spdid = (spdid_t)i;

cos_set_heap_ptr((void*)(((unsigned long)hp)+PAGE_SIZE));
//spdid = cinfo_get_spdid(i);
//if (!spdid) break;

if (cinfo_map(cos_spd_id(), (vaddr_t)hp, spdid)) {
printc("Could not map cinfo page for %d.\n", spdid);
continue;
}
ci = hp;
printc("mapped -- id: %ld, hp:%x, sp:%x\n",
ci->cos_this_spd_id, (unsigned int)ci->cos_heap_ptr,
(unsigned int)ci->cos_stacks.freelists[0].freelist);

hp = cos_get_heap_ptr();
void *hp = cinfo_get_heap_pointer(cos_spd_id(), spdid);
printc("got heap -- id: %d, hp:%p\n", spdid, hp);
}
printc("Done mapping components information pages!\n");
printc("Done getting components heap pointers!\n");
}

void bin (void)
Expand Down
15 changes: 5 additions & 10 deletions src/components/implementation/no_interface/llboot/boot_deps.h
Expand Up @@ -241,16 +241,6 @@ __local_mman_alias_page(spdid_t s_spd, vaddr_t s_addr, spdid_t d_spd, vaddr_t d_
return d_addr;
}

static int boot_spd_set_symbs(struct cobj_header *h, spdid_t spdid, struct cos_component_information *ci);
static void
comp_info_record(struct cobj_header *h, spdid_t spdid, struct cos_component_information *ci)
{
if (!comp_boot_nfo[spdid].symbols_initialized) {
comp_boot_nfo[spdid].symbols_initialized = 1;
boot_spd_set_symbs(h, spdid, ci);
}
}

static inline void boot_create_init_thds(void)
{
struct llbooter_per_core *llboot = PERCPU_GET(llbooter);
Expand Down Expand Up @@ -278,6 +268,11 @@ boot_deps_init(void)
assert(nmmgrs > 0);
}

static void
boot_deps_save_hp(spdid_t spdid, void *hp)
{
}

static void
boot_deps_run(void)
{
Expand Down
9 changes: 2 additions & 7 deletions src/components/implementation/valloc/simple/valloc.c
Expand Up @@ -54,7 +54,6 @@ struct vas_extent {

struct spd_vas_tracker {
spdid_t spdid;
struct cos_component_information *ci;
struct vas_extent extents[MAX_SPD_VAS_LOCATIONS];
/* should be an array to track more than 2^27 bytes */
struct spd_vas_occupied *map;
Expand All @@ -65,7 +64,6 @@ static int __valloc_init(spdid_t spdid)
int ret = -1;
struct spd_vas_tracker *trac;
struct spd_vas_occupied *occ;
struct cos_component_information *ci;
unsigned long page_off;
void *hp;

Expand All @@ -76,12 +74,10 @@ static int __valloc_init(spdid_t spdid)
occ = alloc_page();
if (!occ) goto err_free1;

ci = cos_get_vas_page();
if (cinfo_map(cos_spd_id(), (vaddr_t)ci, spdid)) goto err_free2;
hp = (void*)ci->cos_heap_ptr;
hp = cinfo_get_heap_pointer(cos_spd_id(), spdid);
if (!hp) goto err_free2;

trac->spdid = spdid;
trac->ci = ci;
trac->map = occ;
trac->extents[0].start = (void*)round_to_pgd_page(hp);
trac->extents[0].end = (void*)round_up_to_pgd_page(hp);
Expand All @@ -96,7 +92,6 @@ static int __valloc_init(spdid_t spdid)
done:
return ret;
err_free2:
cos_release_vas_page(ci);
free_page(occ);
err_free1:
free(trac);
Expand Down
16 changes: 7 additions & 9 deletions src/components/include/cos_asm_stkmgr_stacks.h
Expand Up @@ -42,6 +42,7 @@
movl (%eax), %esp; \
COMP_INFO_CMPXCHG; \
jnz 8b; \
5: \
\
/* now we have the stack */ \
movl %eax, %esp; \
Expand Down Expand Up @@ -80,22 +81,19 @@
call stkmgr_grant_stack; \
addl $4, %esp; \
\
/* addl $0x4, %eax; */ \
\
/*restore stack */ \
/* restore regs */ \
popl %edx; \
popl %ecx; \
popl %ebx; \
popl %edi; \
popl %esi; \
popl %ebp; \
\
/* movl %eax, %esp; */ \
/* restore Thd_id in eax */ \
/* movl $THD_ID_SHARED_PAGE, %edx; */ \
/* movl (%edx), %eax; */ \
movl %edx, %eax; \
jmp 1b;
/* Check for NULL stack return */ \
testl %eax, %eax; \
je 8b; \
/* Got a stack in eax */ \
jmp 5b;

#define COS_ASM_RET_STACK \
\
Expand Down
8 changes: 2 additions & 6 deletions src/components/interface/cinfo/cinfo.h
@@ -1,11 +1,7 @@
#ifndef CINFO_H
#define CINFO_H

int cinfo_add(spdid_t spdid, spdid_t target, struct cos_component_information *ci);
void* cinfo_alloc_page(spdid_t spdid);
int cinfo_map(spdid_t spdid, vaddr_t map_addr, spdid_t target);
int cinfo_spdid(spdid_t spdid);

/* vaddr_t cinfo_map_peek(spdid_t spdid); */
int cinfo_add_heap_pointer(spdid_t spdid, spdid_t target, void *hp);
void* cinfo_get_heap_pointer(spdid_t spdid, spdid_t target);

#endif /* !CINFO_H */
6 changes: 2 additions & 4 deletions src/components/interface/cinfo/stubs/s_stub.S
Expand Up @@ -9,7 +9,5 @@

.text

cos_asm_server_stub_spdid(cinfo_add)
cos_asm_server_stub_spdid(cinfo_alloc_page)
cos_asm_server_stub_spdid(cinfo_map)
cos_asm_server_stub_spdid(cinfo_spdid)
cos_asm_server_stub_spdid(cinfo_add_heap_pointer)
cos_asm_server_stub_spdid(cinfo_get_heap_pointer)

0 comments on commit 5f186b6

Please sign in to comment.