Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Merge Slite with main branch, for discussion. #445

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

WenyuanShao
Copy link
Contributor

Summary of this Pull Request (PR)

Add description here.

Intent for your PR

Choose one (Mandatory):

  • This PR is for a code-review and is intended to get feedback, but not to be pulled yet.
  • This PR is mature, and ready to be integrated into the repo.

Reviewers (Mandatory):

(Specify @<github.com username(s)> of the reviewers. Ex: @user1, @user2)

Code Quality

As part of this pull request, I've considered the following:

Style:

  • Comments adhere to the Style Guide (SG)
  • Spacing adhere's to the SG
  • Naming adhere's to the SG
  • All other aspects of the SG are adhered to, or exceptions are justified in this pull request
  • I have run the auto formatter on my code before submitting this PR (see doc/auto_formatter.md for instructions)

Code Craftsmanship:

  • I've made an attempt to remove all redundant code
  • I've considered ways in which my changes might impact existing code, and cleaned it up
  • I've formatted the code in an effort to make it easier to read (proper error handling, function use, etc...)
  • I've commented appropriately where code is tricky
  • I agree that there is no "throw-away" code, and that code in this PR is of high quality

Testing

I've tested the code using the following test programs (provide list here):

  • micro_booter
  • unit_pingpong
  • unit_schedtests
  • ...(add others here)

phanikishoreg and others added 3 commits February 17, 2022 15:58
* Have SCB capability and resource working.
* TODO: DCB capabilities to work.
* TODO: Fix the API around SCB frontier.
* SCB address in a component will be the start of the heap pointer
  and the INIT DCB (initial dcb caps that are used when creating the
  INIT threads in those components) are next to SCB and statically set
  to be NUM_CPU number of pages. This is the idea to fix their addresses
  and avoid passing in component_information structure.
Copy link
Collaborator

@gparmer gparmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm posting this for now. Still working my way through. You did a very good job pulling this out. I'm mainly providing context, and provide you feedback for where areas of concern might be. Think of this as stream-of-consciousness, not as having very actionable feedback.

@@ -55,4 +58,6 @@ asndcap_t COS_STUB_DECL(capmgr_asnd_rcv_create)(arcvcap_t rcv);
asndcap_t capmgr_asnd_key_create(cos_channelkey_t key);
asndcap_t COS_STUB_DECL(capmgr_asnd_key_create)(cos_channelkey_t key);

int capmgr_thd_migrate(thdid_t tid, thdcap_t tc, cpuid_t core);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. Not sure we have this at all. Might be dead code?

@@ -21,7 +21,19 @@ COS_CLIENT_STUB(arcvcap_t, capmgr_rcv_create, spdid_t child, thdid_t tid, cos_ch
return cos_sinv(uc->cap_no, spd_tid, key_ipimax, ipiwin32b, 0);
}

COS_CLIENT_STUB(thdcap_t, capmgr_initthd_create, spdid_t child, thdid_t *tid)
COS_CLIENT_STUB(thdcap_t, capmgr_thd_retrieve, spdid_t child, thdid_t tid, thdid_t *inittid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can avoid pulling this in, we want to. Not a high priority though. Might want to add to the list of "fix later" if we have to pull it in.

thdcap_t ret;

ret = cos_sinv_2rets(uc->cap_no, child, idx, 0, 0, &tid_ret, &unused);
ret = cos_sinv_2rets(uc->cap_no, id, 0, 0, 0, &tid_ret, &dcb_ret);
*dcb = &dcb_ret;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this completely broken? We cannot return the address of a stack allocated value.

I'm worried that we aren't getting a compiler warning due to this.

thdcap_t ret;

ret = cos_sinv_2rets(uc->cap_no, child, idx, 0, 0, &tid_ret, &dcb_ret);
*dcb = &dcb_ret;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same.


aep->thd = thd;
aep->rcv = (tcrcvret << 16) >> 16;
aep->tc = (tcrcvret >> 16);
aep->tid = tid;

*dcb = &dcb_ret;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no understanding of why this is working!

static inline int
sl_thd_activate(struct sl_thd *t, sched_tok_t tok)
sl_thd_activate(struct sl_thd *t, sched_tok_t tok, tcap_time_t timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused by the timeout here. We'll see where thaht goes.

}
}

static inline int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is the core of the logic for slite. This is very very delicate, and we'll want to try and change it as little as possible. Phani took a lot of time on this, and I completely trust his judgement for where it ended up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...of course, we'll need to update for x86-64, and provide a default version that always uses the slowpath for architectures for which we don't have a fastpath.

sl_thd_aep_alloc_ext(struct cos_defcompinfo *comp, struct sl_thd *sched_thd, thdclosure_index_t idx, int is_aep, int own_tcap, cos_channelkey_t key, microsec_t ipiwin, u32_t ipimax, arcvcap_t *extrcv)
sl_thd_aep_alloc_ext_dcb(struct cos_defcompinfo *comp, struct sl_thd *sched_thd, thdclosure_index_t idx, int is_aep, int own_tcap, cos_channelkey_t key, dcbcap_t dcap, dcboff_t doff, microsec_t ipiwin, u32_t ipimax, arcvcap_t *extrcv)
{
PRINTC("UNIMPLEMENTED: Using CAPMGR API which should manage the DCB capabilities\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You pointed these out before. We'll certainly want to invert the logic. The capmgr should manage the scb/dcbs, and the backend should be easier to integrate with slm

@@ -333,3 +364,40 @@ sl_thd_free(struct sl_thd *t)
sl_thd_free_no_cs(t);
sl_cs_exit();
}

int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we'll find much use for all of this migration complexity. It spans most of the abstraction layers.

@@ -16,6 +16,8 @@
#include "include/chal/defs.h"
#include "include/hw.h"
#include "include/chal/chal_proto.h"
#include "include/scb.h"
//#include "include/dcb.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can, take the opportunity to clean up stuff like this.

Copy link
Collaborator

@gparmer gparmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, made it through. Some additional thoughts.

@@ -246,6 +336,8 @@ cap_cpy(struct captbl *t, capid_t cap_to, capid_t capin_to, capid_t cap_from, ca
type = ctfrom->type;
sz = __captbl_cap2bytes(type);

/* don't allow cap copy on SCB/DCB */
if (type == CAP_SCB || type == CAP_DCB) return -EINVAL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow, so no delegation at all for these. OK, somewhat surprising. Likely to keep things simple.

* The rest is all co-operative, so if sched_tok in scb page
* increments after someone fetching a tok, then check for that!
*
* FIXME: make sure we're checking the scb of the scheduling component and not in any other component.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a worrisome comment

@@ -581,6 +682,10 @@ cap_thd_op(struct cap_thd *thd_cap, struct thread *thd, struct pt_regs *regs, st
int ret;

if (thd_cap->cpuid != get_cpuid() || thd_cap->cpuid != next->cpuid) return -EINVAL;
if (unlikely(thd->dcbinfo && thd->dcbinfo->sp)) {
assert((unsigned long)regs->cx == thd->dcbinfo->ip + DCB_IP_KERN_OFF);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are fine for debugging, but have to go after we get it to work. User-level can cause the kernel to crash trivially with these.

ret = cap_kmem_activate(ct, ptcap, kaddr, (unsigned long *)&dcb, &pte);
if (ret) cos_throw(err, ret);

ret = dcb_activate(ct, cap, dcbcap, (vaddr_t)dcb, lid, ptcapin, uaddrin);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, great, they are both allocated as kernel memory. DCB is mapped into memory at creation time as well (uaddrin).

@@ -68,6 +81,9 @@ comp_activate(struct captbl *t, capid_t cap, capid_t capin, capid_t captbl_cap,

return 0;

/*undo_scb:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remvoe?

@@ -270,8 +286,9 @@ enum
BOOT_CAPTBL_KM_PTE = 28,

BOOT_CAPTBL_SINV_CAP = 32,
BOOT_CAPTBL_SELF_INITHW_BASE = 36,
BOOT_CAPTBL_SELF_INITTHD_BASE = 40,
BOOT_CAPTBL_SELF_SCB = 36, /* FIXME: Do we need this? */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope you were very careful when merging these!

assert(thd->tid <= MAX_NUM_THREADS);
thd_scheduler_set(thd, thd_current(cli));

thd_rcvcap_init(thd);
/* TODO: fix the way to specify scheduler in a component! */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole thing with init_data feels like a hack that might cause us headaches. Better ideas?

@@ -520,26 +585,60 @@ thd_preemption_state_update(struct thread *curr, struct thread *next, struct pt_
memcpy(&curr->regs, regs, sizeof(struct pt_regs));
}

static int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't talk about all of this. The SCB is also used to send interrupt events up to user-level now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants