1 / 25

Tutorial of the t-kernel (Session B) July 7, 2006

Tutorial of the t-kernel (Session B) July 7, 2006. Lin Gu Dept. of Computer Science University of Virginia. lingu@cs.virginia.edu http://www.cs.virginia.edu/~lg6e. Resources. Web page: http://www.cs.virginia.edu/~lg6e/t-kernel/

phuc
Download Presentation

Tutorial of the t-kernel (Session B) July 7, 2006

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial of the t-kernel(Session B)July 7, 2006 Lin Gu Dept. of Computer Science University of Virginia lingu@cs.virginia.edu http://www.cs.virginia.edu/~lg6e

  2. Resources • Web page: http://www.cs.virginia.edu/~lg6e/t-kernel/ • Source code in the vert repository: www.sf.net/projects/vert • Please let me know your sourceforge accounts, or use the anonymous account to check out the code • Directory: /cvsroot/vert/t-kernel

  3. Outline • Interrupt handling • Code review • Coding example • t-kernel and Aspect Oriented Programming

  4. Interrupt Handling • The kernel monitors interrupts • The application handles interrupts • The application can use any instructions, including disabling/enabling interrupts • It is possible for the application and kernel to cooperate to handle interrupts • SPI interrupts • Byte level cooperation • Frame level cooperation

  5. Source code tree townLogic() clockLogic() translate() translateBranch() pleaseBridge() leadOut()

  6. Code review – Data structure typedef uint16_t * Code; typedef struct { Code codeEntry; uint8_t cWlen, /*length of the code chunk*/ cCur /* count of the current word */; } CodeChunk; CodeChunk ccRaw;

  7. Code review – Data structure typedef struct { uint32_t lVPWCStart; uint8_t cWlen; /* length of the code chunk */ Code codeEntry; IFPMapEntry *pifpmeStanza; uint8_t cMaxStanza; uint8_t cFlag; /* TKNL_NCFLAG_* flags */ uint16_t nPgmPageNo; uint16_t nMemAreaStart; uint16_t nVoidPage[TKNL_NC_LINKIN_NUM]; } NaturalizedChunk; NaturalizedChunk ncNat;

  8. Code review – Functions uint16_t translate (uint32_t lVPWCWanted, uint16_t nPageNo, uint16_t nSrcPage, uint8_t bRevert); • Copy/modify application code to construct a natin page. • Multiple-use • Create new natin page for a new VPC • Add a new entry point to an existing natin page • Invalidate bridging jumps in a natin page

  9. Code review – Functions uint8_t translateBranch(); uint8_t pleaseBridge(uint16_t nDest); • Translate conventional conditional branches • Differentiate forward and backward branches

  10. Bridging – Backward branch • The naturalizer patches the natin page • SystemCounter is 8-bit • One trap into kernel per 256 backward branches • “headmaster” does sanity check in the dispatcher ... add r0, r1 ... push r31 in r31, 0x3f push r31 lds SystemCounter inc SystemCounter sts SystemCounter brne go cli call headmaster go: pop r31 Out 0x3f, r31 pop r31 jmp HPC ... naturalizer ... Prev: add r0, r1 ... rcall branch_stub Prev (VPC) ... ... HPC dispatcher

  11. Code review – Functions void leadOut(uint16_t nSrcPage, char bCopyLinkin); • Write or copy the link-in records • Write finis

  12. Link-in and finis • Bridging makes direct jumps between natin pages • The incoming pages are recorded in the link-in record of the natin page • Needed for invalidating direct jumps when a natin page is changed (new entry point inserted, or swapped out) ... ... last town transition incoming page 0 incoming page 1 ... incoming page 2 branch_stub ... page 109

  13. Code review – Functions uint16_t townLogic(); • Handle town transitions • Rewrite “rcall branch_stub” to bridging jumps

  14. Bridging – Forward branch • The dispatcher looks up HPC for “Next” • The naturalizer patches the natin page • Handled by “townLogic” (town transition) naturalizer rcall branch_stub Next (VPC) ... ... add r0, r1 ... jmp HPC ... ... add r0, r1 ... Stack frame Stack frame HPC ret1 branch_stub: push r31 in r31, 0x3f cli call townGate branch_stub: push r31 in r31, 0x3f cli call townGate r31 ret0 dispatcher

  15. Code review – Interrupt uint16_t clockLogic(){ uint16_t nStackHead = getAppStackHead(); IntRoom irT; ncNat.lVPWCStart = nVector[TKNL_SIG_OUTPUT_COMPARE0]; cMind |= 1; lTick++; if (checkNestInt()) return -5; irT.c1 = *((uint8_t *)(nStackHead+4)); irT.c0 = *((uint8_t *)(nStackHead+5)); irT.n0 <<= 1; pinInterruptedNatin(irT.c1); <run ncNat.lVPWCStart>; } // clockLogic

  16. Code review – Flags commtknl.h contains system-wide flags • TKNL_PRODUCTION – Disables all debug flags • TKNL_MERGE_NATIN_PAGE – Enables merging of natin pages (add entry points to a natin page) • TKNL_GREEN_LANE – Enables VPC look-aside buffer • TKNL_VISIT_TOWN – Enables bridging • TKNL_INTERRUPT_NUM_NEST – Interrupt nesting level

  17. t-kernel & Aspect Oriented Programming • Aspect oriented programming (AOP) • Pointcut • Advice • XPI • AspectJ, AspectC, etc. • Works on source code or compiled (existing) code • Techniques: aspect compilers, virtual machines, reverse-engineering

  18. t-kernel & Aspect Oriented Programming • A basic Aspect framework • Pointcut, Advice, XPI • Supporting compiled (existing) code • Aspects can be propagated in the network • How to implement such a framework in the t-kernel?

  19. t-kernel & AOP • A basic Aspect framework • Pointcut, Advice, XPI • Supporting compiled (existing) code • Aspects can be propagated in the network • How to implement such a framework in the t-kernel?

  20. t-kernel & AOP • Program+XPI  tagged program • Tags can be as simple as a number, or contain semantic information • Not limited to function calls • Advice = new code • E.g., advice1 to be attached before pointcut1 Add r0, r1 Call func1 Next: Sub r1, r2 Add r0, r1 <jp_1_start> Call func1 <jp_1_end> Next:Sub r1, r2 Pointcut: function func*

  21. t-kernel & AOP “before” a join point • Insert the new code before the “start” tag Add r0, r1 <jp_1_start> Call func1 <jp_1_end> Next:Sub r1, r2 Add r0, r1 <jp_1_start> Call adv1 Call func1 <jp_1_end> Next: Sub r1, r2 Code modification Advice1: Call adv1

  22. t-kernel & AOP “after” a join point • Insert the new code after the “end” tag Add r0, r1 <jp_1_start> Call adv1 Call func1 <jp_1_end> Next: Sub r1, r2 Add r0, r1 <jp_1_start> Call adv1 Call func1 Call adv2 <jp_1_end> Next: Sub r1, r2 Code modification Advice2: Call adv2

  23. t-kernel & AOP “around” a join point • Insert the new code after the “start” tag and jump to after the “end” tag Add r0, r1 <jp_1_start> Call adv1 Call func1 Call adv2 <jp_1_end> Next: Sub r1, r2 Add r0, r1 <jp_1_start> Call adv3 jmp jp_1_end Call adv1 Call func1 Call adv2 <jp_1_end> Next: Sub r1, r2 Code modification Advice3: Call adv3

  24. t-kernel & AOP Key function needed • Online code weaving • Invalidate old code • Generate new code based on the old code and the new advices • May be implemented by the “entry point” inserting and natin page swapping mechanism in the t-kernel • Aspect compiler • modify nesC or gcc? New compiler? Preprocessor?

  25. t-kernel & AOP Supporting mechanisms • XPI definition language • Examples exist • Advice delivery mechanism • The t-kernel support wireless communication

More Related